Refactored packager and deployer interfaces
authorEugene Ostroukhov <eugeneo@symbian.org>
Thu, 29 Jul 2010 10:51:59 -0700
changeset 459 c278f0c8917f
parent 458 5ff93668b08c
child 460 c0bff5ed874c
Refactored packager and deployer interfaces
org.symbian.tools.mtw.core/schema/packagers.exsd
org.symbian.tools.mtw.core/src/org/symbian/tools/mtw/core/internal/runtimes/LazyPackager.java
org.symbian.tools.mtw.core/src/org/symbian/tools/mtw/core/runtimes/IPackager.java
org.symbian.tools.mtw.core/src/org/symbian/tools/mtw/core/runtimes/IPackagerDelegate.java
org.symbian.tools.mtw.core/src/org/symbian/tools/mtw/core/utilities/ZipApplicationVisitor.java
org.symbian.tools.mtw.ui/src/org/symbian/tools/mtw/internal/deployment/DeploymentTargetWrapper.java
org.symbian.tools.mtw.ui/src/org/symbian/tools/mtw/internal/deployment/externalapp/ExternalApplicationDeploymentType.java
org.symbian.tools.mtw.ui/src/org/symbian/tools/mtw/ui/deployment/DeployWizard.java
org.symbian.tools.mtw.ui/src/org/symbian/tools/mtw/ui/deployment/IDeploymentTarget.java
org.symbian.tools.mtw.ui/src/org/symbian/tools/mtw/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/packager/WrtPackager.java
--- a/org.symbian.tools.mtw.core/schema/packagers.exsd	Thu Jul 29 10:00:34 2010 -0700
+++ b/org.symbian.tools.mtw.core/schema/packagers.exsd	Thu Jul 29 10:51:59 2010 -0700
@@ -49,13 +49,13 @@
 
    <element name="packager">
       <complexType>
-         <attribute name="class" type="string" use="required">
+         <attribute name="delegate" type="string" use="required">
             <annotation>
                <documentation>
                   
                </documentation>
                <appinfo>
-                  <meta.attribute kind="java" basedOn=":org.symbian.tools.mtw.core.runtimes.IPackager"/>
+                  <meta.attribute kind="java" basedOn=":org.symbian.tools.mtw.core.runtimes.IPackagerDelegate"/>
                </appinfo>
             </annotation>
          </attribute>
--- a/org.symbian.tools.mtw.core/src/org/symbian/tools/mtw/core/internal/runtimes/LazyPackager.java	Thu Jul 29 10:00:34 2010 -0700
+++ b/org.symbian.tools.mtw.core/src/org/symbian/tools/mtw/core/internal/runtimes/LazyPackager.java	Thu Jul 29 10:51:59 2010 -0700
@@ -29,26 +29,27 @@
 import org.symbian.tools.mtw.core.projects.IMTWProject;
 import org.symbian.tools.mtw.core.runtimes.IMobileWebRuntime;
 import org.symbian.tools.mtw.core.runtimes.IPackager;
+import org.symbian.tools.mtw.core.runtimes.IPackagerDelegate;
 
 public class LazyPackager implements IPackager {
     private final IConfigurationElement element;
-    private IPackager packager;
+    private IPackagerDelegate packager;
 
     public LazyPackager(IConfigurationElement element) {
         this.element = element;
     }
 
-    public File packageApplication(IMTWProject project, IMobileWebRuntime runtime, IProgressMonitor monitor)
+    public File packageApplication(IMTWProject project, IProgressMonitor monitor)
             throws CoreException {
-        return getPackager().packageApplication(project, runtime, monitor);
+        return getPackager().packageApplication(project, monitor);
     }
 
-    private IPackager getPackager() {
+    private IPackagerDelegate getPackager() {
         if (packager == null) {
             try {
-                packager = (IPackager) element.createExecutableExtension("class");
+                packager = (IPackagerDelegate) element.createExecutableExtension("delegate");
             } catch (CoreException e) {
-                MTWCore.log(String.format("Cannot instantiate %s from plugin %s", element.getAttribute("class"),
+                MTWCore.log(String.format("Cannot instantiate %s from plugin %s", element.getAttribute("delegate"),
                         element.getDeclaringExtension().getNamespaceIdentifier()), e);
                 throw new RuntimeException(e);
             }
@@ -64,4 +65,19 @@
         return getPackager().getFileType(project);
     }
 
+    public IMobileWebRuntime getTargetRuntime() {
+        String id = element.getAttribute("targetRuntime");
+        if (id != null) {
+            return MTWCore.getDefault().getRuntimesManager().getRuntime(id);
+        } else {
+            return getSourceRuntime();
+        }
+    }
+
+    public IMobileWebRuntime getSourceRuntime() {
+        IMobileWebRuntime runtime = MTWCore.getDefault().getRuntimesManager()
+                .getRuntime(element.getAttribute("sourceRuntime"));
+        return runtime;
+    }
+
 }
--- a/org.symbian.tools.mtw.core/src/org/symbian/tools/mtw/core/runtimes/IPackager.java	Thu Jul 29 10:00:34 2010 -0700
+++ b/org.symbian.tools.mtw.core/src/org/symbian/tools/mtw/core/runtimes/IPackager.java	Thu Jul 29 10:51:59 2010 -0700
@@ -36,9 +36,9 @@
     /**
      * Synchronously packages application for the specified runtime.
      * 
-     * @return URI of the application package that can be deployed to targets
+     * @return {@link File} denoting location of the application package that can be deployed to targets
      */
-    File packageApplication(IMTWProject project, IMobileWebRuntime runtime, IProgressMonitor monitor)
+    File packageApplication(IMTWProject project, IProgressMonitor monitor)
             throws CoreException;
 
     /**
@@ -51,4 +51,13 @@
      */
     String getFileType(IMTWProject project);
 
+    /**
+     * @return target runtime that this packager packages for
+     */
+    IMobileWebRuntime getTargetRuntime();
+
+    /**
+     * @return source runtime. It is the runtime that the project should target to be packaged with this packager.
+     */
+    IMobileWebRuntime getSourceRuntime();
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/org.symbian.tools.mtw.core/src/org/symbian/tools/mtw/core/runtimes/IPackagerDelegate.java	Thu Jul 29 10:51:59 2010 -0700
@@ -0,0 +1,51 @@
+/**
+ * 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.mtw.core.runtimes;
+
+import java.io.File;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.symbian.tools.mtw.core.projects.IMTWProject;
+
+/**
+ * Delegate performs application packaging.
+ * 
+ * @author Eugene Ostroukhov (eugeneo@symbian.org)
+ */
+public interface IPackagerDelegate {
+    /**
+     * Synchronously packages application for the specified runtime.
+     * 
+     * @return URI of the application package that can be deployed to targets
+     */
+    File packageApplication(IMTWProject project, IProgressMonitor monitor) throws CoreException;
+
+    /**
+     * @return application package root-relative path where the workspace resource will be packaged. Can be <code>null</code>.
+     */
+    IPath getPathInPackage(IResource resource);
+
+    /**
+     * @return file type of the application archive
+     */
+    String getFileType(IMTWProject project);
+}
--- a/org.symbian.tools.mtw.core/src/org/symbian/tools/mtw/core/utilities/ZipApplicationVisitor.java	Thu Jul 29 10:00:34 2010 -0700
+++ b/org.symbian.tools.mtw.core/src/org/symbian/tools/mtw/core/utilities/ZipApplicationVisitor.java	Thu Jul 29 10:51:59 2010 -0700
@@ -32,7 +32,7 @@
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.Status;
 import org.symbian.tools.mtw.core.MTWCore;
-import org.symbian.tools.mtw.core.runtimes.IPackager;
+import org.symbian.tools.mtw.core.runtimes.IPackagerDelegate;
 
 /**
  * Use this visitor to zip application if the web runtime uses zip archive as application
@@ -43,9 +43,9 @@
 public class ZipApplicationVisitor implements IResourceVisitor {
     private static final int DEFAULT_BUFFER_SIZE = 65536;
     private final ZipOutputStream zipStream;
-    private final IPackager packager;
+    private final IPackagerDelegate packager;
 
-    public ZipApplicationVisitor(ZipOutputStream zipStream, IPackager packager) {
+    public ZipApplicationVisitor(ZipOutputStream zipStream, IPackagerDelegate packager) {
         this.zipStream = zipStream;
         this.packager = packager;
     }
--- a/org.symbian.tools.mtw.ui/src/org/symbian/tools/mtw/internal/deployment/DeploymentTargetWrapper.java	Thu Jul 29 10:00:34 2010 -0700
+++ b/org.symbian.tools.mtw.ui/src/org/symbian/tools/mtw/internal/deployment/DeploymentTargetWrapper.java	Thu Jul 29 10:51:59 2010 -0700
@@ -28,7 +28,7 @@
 import org.eclipse.ui.model.IWorkbenchAdapter;
 import org.eclipse.ui.model.IWorkbenchAdapter2;
 import org.symbian.tools.mtw.core.projects.IMTWProject;
-import org.symbian.tools.mtw.core.runtimes.IMobileWebRuntime;
+import org.symbian.tools.mtw.core.runtimes.IPackager;
 import org.symbian.tools.mtw.ui.deployment.IDeploymentTarget;
 import org.symbian.tools.mtw.ui.deployment.IDeploymentTargetType;
 
@@ -84,9 +84,9 @@
         this.type = type;
     }
 
-    public IStatus deploy(IMTWProject project, IMobileWebRuntime runtime, IProgressMonitor monitor)
+    public IStatus deploy(IMTWProject project, IPackager packager, IProgressMonitor monitor)
             throws CoreException {
-        return target.deploy(project, runtime, monitor);
+        return target.deploy(project, packager, monitor);
     }
 
     @Override
--- a/org.symbian.tools.mtw.ui/src/org/symbian/tools/mtw/internal/deployment/externalapp/ExternalApplicationDeploymentType.java	Thu Jul 29 10:00:34 2010 -0700
+++ b/org.symbian.tools.mtw.ui/src/org/symbian/tools/mtw/internal/deployment/externalapp/ExternalApplicationDeploymentType.java	Thu Jul 29 10:51:59 2010 -0700
@@ -30,7 +30,6 @@
 import org.eclipse.ui.IMemento;
 import org.symbian.tools.mtw.core.MTWCore;
 import org.symbian.tools.mtw.core.projects.IMTWProject;
-import org.symbian.tools.mtw.core.runtimes.IMobileWebRuntime;
 import org.symbian.tools.mtw.core.runtimes.IPackager;
 import org.symbian.tools.mtw.ui.deployment.IDeploymentTarget;
 import org.symbian.tools.mtw.ui.deployment.IDeploymentTargetType;
@@ -40,11 +39,10 @@
 
     private IMTWProject project;
 
-    public IStatus deploy(IMTWProject project, IMobileWebRuntime runtime, IProgressMonitor monitor)
+    public IStatus deploy(IMTWProject project, IPackager packager, IProgressMonitor monitor)
             throws CoreException {
         Program app = getExternalApp(project);
-        IPackager packager = MTWCore.getDefault().getRuntimesManager().getPackager(project, runtime);
-        File file = packager.packageApplication(project, runtime, monitor);
+        File file = packager.packageApplication(project, monitor);
         if (file != null) {
             app.execute(file.toString());
             return new Status(
--- a/org.symbian.tools.mtw.ui/src/org/symbian/tools/mtw/ui/deployment/DeployWizard.java	Thu Jul 29 10:00:34 2010 -0700
+++ b/org.symbian.tools.mtw.ui/src/org/symbian/tools/mtw/ui/deployment/DeployWizard.java	Thu Jul 29 10:51:59 2010 -0700
@@ -26,7 +26,9 @@
 import org.eclipse.core.runtime.jobs.MultiRule;
 import org.eclipse.jface.wizard.Wizard;
 import org.eclipse.ui.statushandlers.StatusManager;
+import org.symbian.tools.mtw.core.MTWCore;
 import org.symbian.tools.mtw.core.projects.IMTWProject;
+import org.symbian.tools.mtw.core.runtimes.IPackager;
 import org.symbian.tools.mtw.internal.deployment.DeployWizardContext;
 import org.symbian.tools.mtw.internal.deployment.DeploymentTargetWizardPage;
 import org.symbian.tools.mtw.internal.deployment.DeploymentTargetWrapper;
@@ -90,7 +92,8 @@
         public IStatus run(IProgressMonitor monitor) {
             IStatus status;
             try {
-                status = target.deploy(project, project.getTargetRuntime(), monitor);
+                IPackager packager = MTWCore.getDefault().getRuntimesManager().getPackager(project);
+                status = target.deploy(project, packager, monitor);
             } catch (CoreException e) {
                 status = e.getStatus();
             }
--- a/org.symbian.tools.mtw.ui/src/org/symbian/tools/mtw/ui/deployment/IDeploymentTarget.java	Thu Jul 29 10:00:34 2010 -0700
+++ b/org.symbian.tools.mtw.ui/src/org/symbian/tools/mtw/ui/deployment/IDeploymentTarget.java	Thu Jul 29 10:51:59 2010 -0700
@@ -24,7 +24,7 @@
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.ui.IMemento;
 import org.symbian.tools.mtw.core.projects.IMTWProject;
-import org.symbian.tools.mtw.core.runtimes.IMobileWebRuntime;
+import org.symbian.tools.mtw.core.runtimes.IPackager;
 
 /**
  * <p>This is particular deployment target instance. It can be a Bluetooth phone
@@ -74,7 +74,7 @@
      * @param runtime runtime that will be used to run packaged application
      * @param monitor progress monitor to report deployment progress
      */
-    IStatus deploy(IMTWProject project, IMobileWebRuntime runtime, IProgressMonitor monitor) throws CoreException;
+    IStatus deploy(IMTWProject project, IPackager packager, IProgressMonitor monitor) throws CoreException;
 
     /**
      * Save project-specific settings to the memento. Workspace-wide settings 
--- a/org.symbian.tools.mtw.ui/src/org/symbian/tools/mtw/ui/deployment/bluetooth/BluetoothTarget.java	Thu Jul 29 10:00:34 2010 -0700
+++ b/org.symbian.tools.mtw.ui/src/org/symbian/tools/mtw/ui/deployment/bluetooth/BluetoothTarget.java	Thu Jul 29 10:51:59 2010 -0700
@@ -51,7 +51,6 @@
 import org.eclipse.ui.IMemento;
 import org.symbian.tools.mtw.core.MTWCore;
 import org.symbian.tools.mtw.core.projects.IMTWProject;
-import org.symbian.tools.mtw.core.runtimes.IMobileWebRuntime;
 import org.symbian.tools.mtw.core.runtimes.IPackager;
 import org.symbian.tools.mtw.ui.deployment.IDeploymentTarget;
 
@@ -71,16 +70,11 @@
         this.provider = provider;
     }
 
-    public IStatus deploy(IMTWProject project, IMobileWebRuntime runtime, IProgressMonitor monitor)
+    public IStatus deploy(IMTWProject project, IPackager packager, IProgressMonitor monitor)
             throws CoreException {
         monitor.beginTask(String.format("Deploying application %s to %s", project.getName(), name),
                 IProgressMonitor.UNKNOWN);
-        final IPackager packager = MTWCore.getDefault().getRuntimesManager().getPackager(project, runtime);
-        if (packager == null) {
-            return new Status(IStatus.ERROR, MTWCore.PLUGIN_ID, String.format("Project %s does not support runtime %s",
-                    project.getName(), runtime.getName()));
-        }
-        final File application = packager.packageApplication(project, runtime, new SubProgressMonitor(monitor, 100));
+        final File application = packager.packageApplication(project, new SubProgressMonitor(monitor, 100));
         try {
             deployWidget(application, packager.getFileType(project), new SubProgressMonitor(monitor, 10));
         } finally {
--- a/org.symbian.tools.wrttools/plugin.xml	Thu Jul 29 10:00:34 2010 -0700
+++ b/org.symbian.tools.wrttools/plugin.xml	Thu Jul 29 10:51:59 2010 -0700
@@ -822,7 +822,7 @@
    <extension
          point="org.symbian.tools.mtw.core.packagers">
       <packager
-            class="org.symbian.tools.wrttools.core.packager.WrtPackager"
+            delegate="org.symbian.tools.wrttools.core.packager.WrtPackager"
             targetRuntime="org.symbian.wrt11">
       </packager>
    </extension>
--- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/deploy/emulator/Emulator.java	Thu Jul 29 10:00:34 2010 -0700
+++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/deploy/emulator/Emulator.java	Thu Jul 29 10:51:59 2010 -0700
@@ -31,9 +31,7 @@
 import org.eclipse.core.runtime.PlatformObject;
 import org.eclipse.core.runtime.Status;
 import org.eclipse.ui.IMemento;
-import org.symbian.tools.mtw.core.MTWCore;
 import org.symbian.tools.mtw.core.projects.IMTWProject;
-import org.symbian.tools.mtw.core.runtimes.IMobileWebRuntime;
 import org.symbian.tools.mtw.core.runtimes.IPackager;
 import org.symbian.tools.mtw.ui.deployment.IDeploymentTarget;
 import org.symbian.tools.wrttools.Activator;
@@ -97,17 +95,15 @@
         return path;
     }
 
-    public IStatus deploy(IMTWProject project, IMobileWebRuntime runtime, IProgressMonitor monitor)
+    public IStatus deploy(IMTWProject project, IPackager packager, IProgressMonitor monitor)
             throws CoreException {
-        final IPackager packager = MTWCore.getDefault().getRuntimesManager().getPackager(project, runtime);
-        File application = packager.packageApplication(project, runtime, monitor);
-
-        File outputFile = new File(path);
+        final File application = packager.packageApplication(project, monitor);
+        final File outputFile = new File(path);
         if (!outputFile.isDirectory()) {
             outputFile.mkdir();
         }
 
-        File out = new File(outputFile + "/" + application.getName()); //$NON-NLS-1$
+        final File out = new File(outputFile + "/" + application.getName()); //$NON-NLS-1$
         deployWidget(application, out);
         return new Status(
                 IStatus.OK,
--- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/packager/WrtPackager.java	Thu Jul 29 10:00:34 2010 -0700
+++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/packager/WrtPackager.java	Thu Jul 29 10:51:59 2010 -0700
@@ -30,15 +30,13 @@
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.Status;
 import org.symbian.tools.mtw.core.projects.IMTWProject;
-import org.symbian.tools.mtw.core.runtimes.IMobileWebRuntime;
-import org.symbian.tools.mtw.core.runtimes.IPackager;
+import org.symbian.tools.mtw.core.runtimes.IPackagerDelegate;
 import org.symbian.tools.mtw.core.utilities.ZipApplicationVisitor;
 import org.symbian.tools.wrttools.Activator;
 import org.symbian.tools.wrttools.util.ProjectUtils;
 
-public class WrtPackager implements IPackager {
-    public File packageApplication(IMTWProject project, IMobileWebRuntime runtime, IProgressMonitor monitor)
-            throws CoreException {
+public class WrtPackager implements IPackagerDelegate {
+    public File packageApplication(IMTWProject project, IProgressMonitor monitor) throws CoreException {
         monitor.beginTask(String.format("Packaging %s", project.getName()), IProgressMonitor.UNKNOWN);
 
         IPath stateLocation = Activator.getDefault().getStateLocation();