Bug 2783 - Do deployment in the background
authorEugene Ostroukhov <eugeneo@symbian.org>
Mon, 07 Jun 2010 14:58:15 -0700
changeset 352 9e80d9bd54fe
parent 351 e317b108976d
child 353 7d239d0853b9
Bug 2783 - Do deployment in the background
org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/deploy/DeployJob.java
org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/deploy/ProgressMonitorAndLogger.java
org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/deploy/DeployWizard.java
org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/deploy/DeploymentSummaryWizardPage.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/deploy/DeployJob.java	Mon Jun 07 14:58:15 2010 -0700
@@ -0,0 +1,119 @@
+/**
+ * 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;
+
+import java.io.IOException;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.MultiStatus;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.progress.IProgressConstants2;
+import org.symbian.tools.wrttools.Activator;
+import org.symbian.tools.wrttools.WRTProject;
+import org.symbian.tools.wrttools.core.deployer.DeployException;
+import org.symbian.tools.wrttools.core.deployer.IWidgetDeployer;
+import org.symbian.tools.wrttools.core.packager.WrtPackageActionDelegate;
+import org.symbian.tools.wrttools.core.status.IWRTStatusListener;
+import org.symbian.tools.wrttools.sdt.utils.Logging;
+import org.symbian.tools.wrttools.wizards.deploy.DeploymentTarget;
+
+public class DeployJob extends Job {
+    public class AlwaysErrorMultiStatus extends MultiStatus {
+        public AlwaysErrorMultiStatus(String message) {
+            super(Activator.PLUGIN_ID, 0, message, null);
+        }
+
+        @Override
+        public int getSeverity() {
+            return IStatus.ERROR;
+        }
+    }
+
+    private final DeploymentTarget target;
+    private final WrtPackageActionDelegate packagerAction = new WrtPackageActionDelegate();
+    private final WRTProject project;
+
+    public DeployJob(WRTProject project, DeploymentTarget deploymentTarget) {
+        super(String.format("Deploying %s to %s", project.getProject().getName(), deploymentTarget.getName()));
+        setUser(true);
+        setProperty(IProgressConstants2.SHOW_IN_TASKBAR_ICON_PROPERTY, Boolean.TRUE);
+        this.project = project;
+        this.target = deploymentTarget;
+    }
+
+    private void signalDeploymentComplete(final DeploymentTarget target) {
+        if (target.getDeployMessage() != null) {
+            final Shell shell = PlatformUI.getWorkbench().getWorkbenchWindows()[0].getShell();
+            shell.getDisplay().asyncExec(new Runnable() {
+                public void run() {
+                    MessageDialog.openWarning(shell, "WRT Application Deployment", target.getDeployMessage());
+                }
+            });
+        }
+    }
+
+    public IStatus run(IProgressMonitor monitor) {
+        monitor.beginTask("Deploying application", IProgressMonitor.UNKNOWN);
+        final MultiStatus status = new AlwaysErrorMultiStatus(String.format("Cannot deploy appliction to %s",
+                target.getName()));
+        final IWRTStatusListener statusListener = new ProgressMonitorAndLogger(monitor, status);
+        IWidgetDeployer wd = target.createDeployer(statusListener);
+
+        IStatus result = new Status(IStatus.OK, Activator.PLUGIN_ID, 0, "", null);
+        IProject p = project.getProject();
+        if (p != null) {
+            /* package the files before deployment */
+            boolean packageSuccess = packagerAction.packageProject(p, statusListener);
+            if (!packageSuccess) {
+                return status;
+            }
+            String packagedPath;
+            try {
+                IPath wgzPath = new Path(p.getName() + ".wgz");
+                IFile wgz = p.getFile(wgzPath);
+                packagedPath = wgz.getLocation().toFile().getCanonicalFile().toString();
+                try {
+                    result = wd.deploy(packagedPath, target.getName(), monitor);
+                    if (result.isOK()) {
+                        project.setDeploymentTarget(target);
+                        signalDeploymentComplete(target);
+                    } else {
+                        result = status;
+                    }
+                } catch (DeployException e) {
+                    result = new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0, e.getMessage(), e);
+                    Logging.log(Activator.getDefault(), result);
+                }
+            } catch (IOException e) {
+                Activator.log(IStatus.ERROR, "Error deploying widget", e);
+            }
+        }
+        return result;
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/deploy/ProgressMonitorAndLogger.java	Mon Jun 07 14:58:15 2010 -0700
@@ -0,0 +1,56 @@
+/**
+ * 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;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.MultiStatus;
+import org.eclipse.core.runtime.Status;
+import org.symbian.tools.wrttools.Activator;
+import org.symbian.tools.wrttools.core.status.IWRTStatusListener;
+import org.symbian.tools.wrttools.core.status.WRTStatus;
+import org.symbian.tools.wrttools.util.ProjectUtils;
+
+public class ProgressMonitorAndLogger implements IWRTStatusListener {
+    private final IProgressMonitor monitor;
+    private final MultiStatus status;
+
+    public ProgressMonitorAndLogger(IProgressMonitor monitor, MultiStatus status) {
+        this.monitor = monitor;
+        this.status = status;
+    }
+
+    public void emitStatus(WRTStatus status) {
+        monitor.setTaskName(status.getStatusDescription().toString());
+        this.status.add(new Status(IStatus.INFO, Activator.PLUGIN_ID, status.getStatusDescription().toString()));
+    }
+
+    public boolean isStatusHandled(WRTStatus status) {
+        return true;
+    }
+
+    public void close() {
+        // Do nothing
+    }
+
+    public boolean canPackageWithErrors(IProject project) {
+        return ProjectUtils.canPackageWithErrors(project);
+    }
+}
--- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/deploy/DeployWizard.java	Mon Jun 07 13:48:20 2010 -0700
+++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/deploy/DeployWizard.java	Mon Jun 07 14:58:15 2010 -0700
@@ -18,57 +18,12 @@
  */
 package org.symbian.tools.wrttools.wizards.deploy;
 
-import java.io.IOException;
-import java.lang.reflect.InvocationTargetException;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.operation.IRunnableWithProgress;
 import org.eclipse.jface.wizard.Wizard;
-import org.symbian.tools.wrttools.Activator;
 import org.symbian.tools.wrttools.WRTProject;
-import org.symbian.tools.wrttools.core.deployer.DeployException;
-import org.symbian.tools.wrttools.core.deployer.IWidgetDeployer;
-import org.symbian.tools.wrttools.core.packager.WrtPackageActionDelegate;
-import org.symbian.tools.wrttools.core.status.IWRTStatusListener;
-import org.symbian.tools.wrttools.core.status.WRTStatus;
-import org.symbian.tools.wrttools.sdt.utils.Logging;
-import org.symbian.tools.wrttools.util.ProjectUtils;
+import org.symbian.tools.wrttools.core.deploy.DeployJob;
 
 public class DeployWizard extends Wizard {
-    public class PagePrinter implements IWRTStatusListener {
-        private final DeploymentSummaryWizardPage page;
-
-        public PagePrinter(DeploymentSummaryWizardPage summaryPage) {
-            page = summaryPage;
-        }
-
-        public void emitStatus(WRTStatus status) {
-            page.log(status.getStatusDescription().toString());
-        }
-
-        public boolean isStatusHandled(WRTStatus status) {
-            return true;
-        }
-
-        public void close() {
-            // Do nothing
-        }
-
-        public boolean canPackageWithErrors(IProject project) {
-            return ProjectUtils.canPackageWithErrors(project);
-        }
-
-    }
-
     private final DeployWizardContext context;
-    private final DeploymentSummaryWizardPage summaryPage = new DeploymentSummaryWizardPage();
     private final WRTProject project;
 
     public DeployWizard(WRTProject project) {
@@ -81,13 +36,10 @@
     @Override
     public void addPages() {
         addPage(new DeploymentTargetWizardPage(context, project.getDeploymentTarget()));
-        addPage(summaryPage);
     }
 
     @Override
     public boolean performFinish() {
-        summaryPage.clear();
-        getContainer().showPage(summaryPage);
         return deploy();
     }
 
@@ -101,75 +53,8 @@
      */
     private boolean deploy() {
         DeploymentTarget target = context.getTarget();
-        DeployJob job = new DeployJob(context.getProject(), target);
-        try {
-            getContainer().run(true, true, job);
-        } catch (InvocationTargetException e) {
-            Activator.log(e);
-        } catch (InterruptedException e) {
-            Activator.log(e);
-        }
-        return job.isSuccessful();
-    }
-
-    private final class DeployJob implements IRunnableWithProgress {
-        private final DeploymentTarget target;
-        private final WrtPackageActionDelegate packagerAction = new WrtPackageActionDelegate();
-        private final IProject project;
-        private boolean successful = false;
-
-        private DeployJob(IProject project, DeploymentTarget deploymentTarget) {
-            this.project = project;
-            this.target = deploymentTarget;
-        }
-
-        public boolean isSuccessful() {
-            return successful;
-        }
-
-        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
-            IWRTStatusListener statusListener = new PagePrinter(summaryPage);
-            IWidgetDeployer wd = target.createDeployer(statusListener);
-
-            IStatus result = new Status(IStatus.OK, Activator.PLUGIN_ID, 0, "", null);
-
-            if (project != null) {
-                /* package the files before deployment */
-                boolean packageSuccess = packagerAction.packageProject(project, statusListener);
-                if (!packageSuccess) {
-                    return;
-                }
-                String packagedPath;
-                try {
-                    IPath wgzPath = new Path(project.getName() + ".wgz");
-                    IFile wgz = project.getFile(wgzPath);
-                    packagedPath = wgz.getLocation().toFile().getCanonicalFile().toString();
-                    try {
-                        result = wd.deploy(packagedPath, target.getName(), monitor);
-                        if (result.isOK()) {
-                            DeployWizard.this.project.setDeploymentTarget(target);
-                            successful = true;
-                            signalDeploymentComplete(target);
-                        }
-                    } catch (DeployException e) {
-                        result = new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0, e.getMessage(), e);
-                        Logging.log(Activator.getDefault(), result);
-                    }
-                } catch (IOException e) {
-                    Activator.log(IStatus.ERROR, "Error deploying widget", e);
-                }
-            }
-        }
-
-    }
-
-    private void signalDeploymentComplete(final DeploymentTarget target) {
-        if (target.getDeployMessage() != null) {
-            getShell().getDisplay().asyncExec(new Runnable() {
-                public void run() {
-                    MessageDialog.openWarning(getShell(), "WRT Application Deployment", target.getDeployMessage());
-                }
-            });
-        }
+        DeployJob job = new DeployJob(project, target);
+        job.schedule();
+        return true;
     }
 }
--- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/deploy/DeploymentSummaryWizardPage.java	Mon Jun 07 13:48:20 2010 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,58 +0,0 @@
-/**
- * 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.wizards.deploy;
-
-import org.eclipse.jface.wizard.WizardPage;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Text;
-
-public class DeploymentSummaryWizardPage extends WizardPage {
-    private StringBuilder buffer = new StringBuilder(1000);
-    private Text log;
-
-    protected DeploymentSummaryWizardPage() {
-        super("deploy");
-        setTitle("WRT Application Deployment");
-        setDescription("Please wait while deployment is in progress");
-    }
-
-    public void createControl(Composite parent) {
-        log = new Text(parent, SWT.BORDER | SWT.MULTI | SWT.READ_ONLY | SWT.WRAP);
-        setControl(log);
-    }
-
-    public void log(String line) {
-        synchronized (buffer) {
-            buffer.append(line).append("\n");
-        }
-        log.getDisplay().asyncExec(new Runnable() {
-            public void run() {
-                synchronized (buffer) {
-                    log.setText(buffer.toString());
-                }
-            }
-        });
-    }
-
-    public void clear() {
-        log.setText("");
-        buffer = new StringBuilder();
-    }
-}