Minor bugfix
authorEugene Ostroukhov <eugeneo@symbian.org>
Tue, 10 Aug 2010 09:52:29 -0700
changeset 462 cdc4995b1677
parent 461 7a8f9fa8d278
child 463 aea4c83725d8
Minor bugfix
org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/ui/deployment/bluetooth/BluetoothTarget.java
org.symbian.tools.wrttools/plugin.xml
org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/deploy/emulator/Emulator.java
org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/deploy/emulator/EmulatorTargetType.java
--- a/org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/ui/deployment/bluetooth/BluetoothTarget.java	Mon Aug 09 15:18:34 2010 -0700
+++ b/org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/ui/deployment/bluetooth/BluetoothTarget.java	Tue Aug 10 09:52:29 2010 -0700
@@ -76,6 +76,10 @@
         statuses.clear();
         monitor.beginTask(String.format("Deploying application %s to %s", project.getName(), name),
                 IProgressMonitor.UNKNOWN);
+        if (packager == null) {
+            return new Status(IStatus.ERROR, TMWCore.PLUGIN_ID, String.format(
+                    "No packager found for project %s with runtime %s", project.getName(), project.getTargetRuntime()));
+        }
         final File application = packager.packageApplication(project, new SubProgressMonitor(monitor, 100));
         try {
             deployWidget(application, packager.getFileType(project), new SubProgressMonitor(monitor, 10));
--- a/org.symbian.tools.wrttools/plugin.xml	Mon Aug 09 15:18:34 2010 -0700
+++ b/org.symbian.tools.wrttools/plugin.xml	Tue Aug 10 09:52:29 2010 -0700
@@ -816,7 +816,7 @@
       <image
             path="icons/main16_prev.gif"
             runtime-component-type="org.symbian.tools.wrttools.wrt"
-            version="1.0">
+            version="1.1">
       </image>
    </extension>
    <extension
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/deploy/emulator/Emulator.java	Tue Aug 10 09:52:29 2010 -0700
@@ -0,0 +1,142 @@
+/**
+ * Copyright (c) 2010 Symbian Foundation and/or its subsidiary(-ies).
+ * All rights reserved.
+ * This component and the accompanying materials are made available
+ * under the terms of the License "Eclipse Public License v1.0"
+ * which accompanies this distribution, and is available
+ * at the URL "http://www.eclipse.org/legal/epl-v10.html".
+ *
+ * Initial Contributors:
+ * Symbian Foundation - initial contribution.
+ * Contributors:
+ * Description:
+ * Overview:
+ * Details:
+ * Platforms/Drives/Compatibility:
+ * Assumptions/Requirement/Pre-requisites:
+ * Failures and causes:
+ */
+package org.symbian.tools.wrttools.core.deploy.emulator;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.PlatformObject;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.ui.IMemento;
+import org.symbian.tools.tmw.core.projects.IMTWProject;
+import org.symbian.tools.tmw.core.runtimes.IPackager;
+import org.symbian.tools.tmw.ui.deployment.IDeploymentTarget;
+import org.symbian.tools.wrttools.Activator;
+
+public class Emulator extends PlatformObject implements IDeploymentTarget {
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((id == null) ? 0 : id.hashCode());
+        result = prime * result + ((path == null) ? 0 : path.hashCode());
+        return result;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (obj == null) {
+            return false;
+        }
+        if (getClass() != obj.getClass()) {
+            return false;
+        }
+        Emulator other = (Emulator) obj;
+        if (id == null) {
+            if (other.id != null) {
+                return false;
+            }
+        } else if (!id.equals(other.id)) {
+            return false;
+        }
+        if (path == null) {
+            if (other.path != null) {
+                return false;
+            }
+        } else if (!path.equals(other.path)) {
+            return false;
+        }
+        return true;
+    }
+
+    private final String id;
+    private final String path;
+
+    public Emulator(String id, String path) {
+        this.id = id;
+        this.path = path;
+    }
+
+    public String getId() {
+        return id;
+    }
+
+    public String getName() {
+        return id;
+    }
+
+    public String getDescription() {
+        return path;
+    }
+
+    public IStatus deploy(IMTWProject project, IPackager packager, IProgressMonitor monitor)
+            throws CoreException {
+        final File application = packager.packageApplication(project, monitor);
+        final File outputFile = new File(path);
+        if (!outputFile.isDirectory()) {
+            outputFile.mkdir();
+        }
+
+        final File out = new File(outputFile + "/" + application.getName()); //$NON-NLS-1$
+        deployWidget(application, out);
+        return new Status(
+                IStatus.OK,
+                Activator.PLUGIN_ID,
+                "Application was successfully deployed to emulator. You will need to complete installation process using your emulator UI.");
+    }
+
+    /**
+     * Deploys the widget from the source to the destination path of the emulator.
+     * @param inputFile the actual widget path from where widget needs to be deployed.
+     * @param outputFile the path of the emulator where the widget will be deoplyed.
+     */
+    private void deployWidget(File inputFile, File outputFile) throws CoreException {
+        try {
+            InputStream in = new FileInputStream(inputFile);
+            OutputStream out = new FileOutputStream(outputFile);
+            int c;
+
+            while ((c = in.read()) != -1) {
+                out.write(c);
+            }
+            in.close();
+            out.close();
+        } catch (IOException e) {
+            throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Application deployment failed", e));
+        }
+    }
+
+    public void save(IMemento memento) {
+        // Do nothing
+    }
+
+    public void init(IMTWProject project, IPackager packager, IMemento memento) {
+        // Do nothing
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/deploy/emulator/EmulatorTargetType.java	Tue Aug 10 09:52:29 2010 -0700
@@ -0,0 +1,197 @@
+/**
+ * Copyright (c) 2010 Symbian Foundation and/or its subsidiary(-ies).
+ * All rights reserved.
+ * This component and the accompanying materials are made available
+ * under the terms of the License "Eclipse Public License v1.0"
+ * which accompanies this distribution, and is available
+ * at the URL "http://www.eclipse.org/legal/epl-v10.html".
+ *
+ * Initial Contributors:
+ * Symbian Foundation - initial contribution.
+ * Contributors:
+ * Description:
+ * Overview:
+ * Details:
+ * Platforms/Drives/Compatibility:
+ * Assumptions/Requirement/Pre-requisites:
+ * Failures and causes:
+ */
+package org.symbian.tools.wrttools.core.deploy.emulator;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.jobs.ISchedulingRule;
+import org.symbian.tools.tmw.core.projects.IMTWProject;
+import org.symbian.tools.tmw.ui.deployment.IDeploymentTarget;
+import org.symbian.tools.tmw.ui.deployment.IDeploymentTargetType;
+import org.symbian.tools.wrttools.core.IWRTConstants;
+import org.w3c.dom.Document;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+
+public final class EmulatorTargetType implements IDeploymentTargetType {
+    /**
+     * Map containing of the SDKS with the corresponding paths.
+     */
+    private Map<String, Emulator> listofEmulators;
+
+    public EmulatorTargetType() {
+        discoverTargets(new NullProgressMonitor());
+    }
+
+    public IDeploymentTarget[] getTargets(IMTWProject project) {
+        Collection<Emulator> values = listofEmulators.values();
+        return values.toArray(new Emulator[values.size()]);
+    }
+
+    public void discoverTargets(IProgressMonitor monitor) {
+        if (listofEmulators == null) {
+            listofEmulators = new HashMap<String, Emulator>();
+        }
+        listofEmulators.clear();
+        initialize();
+    }
+
+    public IDeploymentTarget findTarget(IMTWProject project, String id) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public boolean targetsDiscovered() {
+        return true;
+    }
+
+    public ISchedulingRule getSchedulingRule(IDeploymentTarget target) {
+        return null;
+    }
+
+    // helper methods
+
+    /**
+     * This will parse the xml and create the nodes to be displayed on the table
+     * viewer. The information will be used by content & label provider to get
+     * the contents and display accordingly in the list of the projects in the view.
+     */
+    public Map<String, Emulator> initialize() {
+
+        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+        // Parse the devices.xml and retrieve the list of the emulators from it
+        // and build the list to be displayed in the view.
+
+        try {
+            DocumentBuilder builder = factory.newDocumentBuilder();
+            File file = new File(IWRTConstants.DEVICES_XML_PATH);
+            if (!file.exists()) {
+                IPath otherPath = new Path(System.getProperty("user.home"))
+                        .append(IWRTConstants.DEVICES_VISTA_XML_PATH);
+                file = otherPath.toFile();
+            }
+            if (file.exists()) {
+                FileInputStream fin = new FileInputStream(file);
+                Document document = builder.parse(fin);
+                NodeList childNodes = document.getChildNodes();
+
+                for (int i = 0; i < childNodes.getLength(); i++) {
+
+                    Node node = childNodes.item(i);
+                    String nodeName = node.getNodeName();
+                    // If the node name is "devices" it is the root node of the xml.
+                    if (nodeName.equals(IWRTConstants.DEVICES_TAG)) {
+                        // once we have the root node get the child information to
+                        // build the devices list.
+                        createDevicesList(node);
+
+                    }
+                }
+            }
+        } catch (ParserConfigurationException e) {
+            //          WidgetUtils.getView().getLogger().severe(e.getMessage());
+        } catch (SAXException e) {
+            //          WidgetUtils.getView().getLogger().severe(e.getMessage());
+        } catch (IOException e) {
+            //          WidgetUtils.getView().getLogger().severe(e.getMessage());
+        }
+        return listofEmulators;
+    }
+
+    /**
+     * Creates the devices nodes in the table.
+     * @param parentNode
+     */
+    private void createDevicesList(Node parentNode) {
+        NodeList list = getChildNodes(parentNode);
+        for (int i = 0; i < list.getLength(); i++) {
+            Node node = list.item(i);
+            String nodeName = node.getNodeName();
+            if (nodeName.equals(IWRTConstants.DEVICE_TAG)) {
+                createDeviceChildNode(node);
+            }
+        }
+    }
+
+    /**
+     * Gets the EPOC ROOT node and than finally the list of devices.
+     * @param parentNode
+     */
+    private void createDeviceChildNode(Node parentNode) {
+        NodeList list = getChildNodes(parentNode);
+        for (int i = 0; i < list.getLength(); i++) {
+            Node node = list.item(i);
+            String nodeName = node.getNodeName();
+            if (nodeName.equals(IWRTConstants.EPOC_ROOT_TAG)) {
+                addProject(node, parentNode);
+            }
+        }
+    }
+
+    /**
+     * Adds the devices to the list to be displayed.
+     * @param deviceNode the device node 
+     * @param epocNode the epoc root node.
+     */
+    private void addProject(Node epocNode, Node deviceNode) {
+        NodeList list = getChildNodes(epocNode);
+        NamedNodeMap attributes = deviceNode.getAttributes();
+        String sdkId = "";
+        String sdkName = "";
+        for (int i = 0; i < attributes.getLength(); i++) {
+            Node item = attributes.item(i);
+            if (item.getNodeName().equals(IWRTConstants.NAME_ATTR)) {
+                sdkName = item.getNodeValue();
+            }
+            if (item.getNodeName().equals(IWRTConstants.ID_ATTR)) {
+                sdkId = item.getNodeValue();
+            }
+        }
+        for (int i = 0; i < list.getLength(); i++) {
+            Node node = list.item(i);
+            if (sdkName.equals(IWRTConstants.EMULATOR_NAME)) {
+                listofEmulators.put(sdkId, new Emulator(sdkId, node.getNodeValue()));
+            }
+        }
+    }
+
+    /**
+     * Returns the child list of the particular Node.
+     * @param parentNode
+     */
+    private static NodeList getChildNodes(Node parentNode) {
+        return parentNode.getChildNodes();
+    }
+
+}