PhoneGap support
authorEugene Ostroukhov <eugeneo@symbian.org>
Mon, 23 Aug 2010 15:08:34 -0700
changeset 473 8e8aed9adb99
parent 472 bd9f2d7c64a6
child 474 e2f461f0a9e0
PhoneGap support
plugins/org.symbian.tools.tmw.ui/bin/org/symbian/tools/tmw/internal/ui/project/PrepareProjectJob$1.class
plugins/org.symbian.tools.tmw.ui/bin/org/symbian/tools/tmw/internal/ui/project/PrepareProjectJob$2.class
plugins/org.symbian.tools.tmw.ui/bin/org/symbian/tools/tmw/internal/ui/project/PrepareProjectJob.class
plugins/org.symbian.tools.tmw.ui/bin/org/symbian/tools/tmw/internal/ui/project/ProjectTemplateImpl$1.class
plugins/org.symbian.tools.tmw.ui/bin/org/symbian/tools/tmw/internal/ui/project/ProjectTemplateImpl.class
plugins/org.symbian.tools.tmw.ui/bin/org/symbian/tools/tmw/internal/ui/wizard/NewApplicationWizard.class
plugins/org.symbian.tools.tmw.ui/src/org/symbian/tools/tmw/internal/ui/project/PrepareProjectJob.java
plugins/org.symbian.tools.tmw.ui/src/org/symbian/tools/tmw/internal/ui/project/ProjectTemplateImpl.java
plugins/org.symbian.tools.tmw.ui/src/org/symbian/tools/tmw/internal/ui/wizard/NewApplicationWizard.java
plugins/org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/core/libraries/InstallPhoneGapDelegate.class
plugins/org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/core/libraries/PhoneGapLibraryInstaller.class
plugins/org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/core/libraries/PlatformServicesTypeProvider.class
plugins/org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/wizards/FlickrProjectDetailsWizardPage$Factory.class
plugins/org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/wizards/FlickrProjectDetailsWizardPage.class
plugins/org.symbian.tools.wrttools/plugin.xml
plugins/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/libraries/InstallPhoneGapDelegate.java
plugins/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/libraries/PhoneGapLibraryInstaller.java
plugins/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/libraries/PlatformServicesTypeProvider.java
plugins/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/FlickrProjectDetailsWizardPage.java
Binary file plugins/org.symbian.tools.tmw.ui/bin/org/symbian/tools/tmw/internal/ui/project/PrepareProjectJob$1.class has changed
Binary file plugins/org.symbian.tools.tmw.ui/bin/org/symbian/tools/tmw/internal/ui/project/PrepareProjectJob$2.class has changed
Binary file plugins/org.symbian.tools.tmw.ui/bin/org/symbian/tools/tmw/internal/ui/project/PrepareProjectJob.class has changed
Binary file plugins/org.symbian.tools.tmw.ui/bin/org/symbian/tools/tmw/internal/ui/project/ProjectTemplateImpl$1.class has changed
Binary file plugins/org.symbian.tools.tmw.ui/bin/org/symbian/tools/tmw/internal/ui/project/ProjectTemplateImpl.class has changed
Binary file plugins/org.symbian.tools.tmw.ui/bin/org/symbian/tools/tmw/internal/ui/wizard/NewApplicationWizard.class has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/plugins/org.symbian.tools.tmw.ui/src/org/symbian/tools/tmw/internal/ui/project/PrepareProjectJob.java	Mon Aug 23 15:08:34 2010 -0700
@@ -0,0 +1,98 @@
+/**
+ * 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.tmw.internal.ui.project;
+
+import java.lang.reflect.InvocationTargetException;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceVisitor;
+import org.eclipse.core.resources.IncrementalProjectBuilder;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.swt.widgets.Display;
+import org.symbian.tools.tmw.ui.TMWCoreUI;
+
+public class PrepareProjectJob extends Job {
+    private final IProject project;
+    private final IRunnableWithProgress action;
+
+    public PrepareProjectJob(IProject project, IRunnableWithProgress action) {
+        super(String.format("Preparing project", project.getName()));
+        this.project = project;
+        this.action = action;
+        setUser(false);
+        setRule(ResourcesPlugin.getWorkspace().getRoot());
+    }
+
+    @Override
+    protected IStatus run(IProgressMonitor monitor) {
+        monitor.beginTask("Prepare project files", 200);
+        try {
+            touchFiles();
+        } catch (CoreException e) {
+            TMWCoreUI.log(e);
+        }
+        if (action != null) {
+            Display.getDefault().asyncExec(new Runnable() {
+                public void run() {
+                    try {
+                        action.run(new NullProgressMonitor());
+                    } catch (InvocationTargetException e) {
+                        TMWCoreUI.log(e);
+                    } catch (InterruptedException e) {
+                        TMWCoreUI.log(e);
+                    }
+                }
+            });
+        }
+        monitor.done();
+        return Status.OK_STATUS;
+    }
+
+    protected void touchFiles() throws CoreException {
+        try {
+            Thread.sleep(4000); // This is plain wrong. But we have concurrency issues in JSDT/Eclipse build system
+        } catch (InterruptedException e) {
+            TMWCoreUI.log(e);
+        }
+        project.accept(new IResourceVisitor() {
+            public boolean visit(IResource resource) throws CoreException {
+                if (resource.isAccessible() && resource.getType() == IResource.FILE
+                        && resource.getFileExtension().equals("js")) {
+                    resource.touch(new NullProgressMonitor());
+                }
+                return true;
+            }
+        });
+        try {
+            Thread.sleep(1000); // This is plain wrong. But we have concurrency issues in JSDT/Eclipse build system
+        } catch (InterruptedException e) {
+            TMWCoreUI.log(e);
+        }
+        project.build(IncrementalProjectBuilder.FULL_BUILD, new NullProgressMonitor());
+    }
+
+}
--- a/plugins/org.symbian.tools.tmw.ui/src/org/symbian/tools/tmw/internal/ui/project/ProjectTemplateImpl.java	Mon Aug 23 10:30:05 2010 -0700
+++ b/plugins/org.symbian.tools.tmw.ui/src/org/symbian/tools/tmw/internal/ui/project/ProjectTemplateImpl.java	Mon Aug 23 15:08:34 2010 -0700
@@ -18,7 +18,6 @@
  */
 package org.symbian.tools.tmw.internal.ui.project;
 
-import java.lang.reflect.InvocationTargetException;
 import java.util.Map;
 import java.util.TreeMap;
 
@@ -28,12 +27,9 @@
 import org.eclipse.core.runtime.IPath;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.SubProgressMonitor;
-import org.eclipse.jface.dialogs.ProgressMonitorDialog;
 import org.eclipse.jface.operation.IRunnableWithProgress;
 import org.eclipse.jface.resource.ImageDescriptor;
 import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.ui.PlatformUI;
 import org.eclipse.wst.common.project.facet.core.IProjectFacet;
 import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
 import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
@@ -144,27 +140,13 @@
             monitor.beginTask("Copying project files", files.length * 10);
             templateInstaller.copyFiles(files, new SubProgressMonitor(monitor, files.length * 10));
             final IRunnableWithProgress action = templateInstaller.getPostCreateAction();
-            if (action != null) {
-                Display.getDefault().asyncExec(new Runnable() {
-                    public void run() {
-                        ProgressMonitorDialog dialog = new ProgressMonitorDialog(PlatformUI.getWorkbench()
-                                .getActiveWorkbenchWindow().getShell());
-                        try {
-                            dialog.run(false, true, action);
-                        } catch (InvocationTargetException e) {
-                            TMWCoreUI.log(e);
-                        } catch (InterruptedException e) {
-                            TMWCoreUI.log(e);
-                        }
-                    }
-                });
-            }
+            monitor.done();
+            new PrepareProjectJob(project, action).schedule();
         } catch (CoreException e) {
             TMWCoreUI.log(e);
         } finally {
             templateInstaller.cleanup();
         }
-        monitor.done();
     }
 
     public Map<String, String> getDefaultParameterValues() {
--- a/plugins/org.symbian.tools.tmw.ui/src/org/symbian/tools/tmw/internal/ui/wizard/NewApplicationWizard.java	Mon Aug 23 10:30:05 2010 -0700
+++ b/plugins/org.symbian.tools.tmw.ui/src/org/symbian/tools/tmw/internal/ui/wizard/NewApplicationWizard.java	Mon Aug 23 15:08:34 2010 -0700
@@ -25,6 +25,7 @@
 import java.util.Set;
 
 import org.eclipse.core.databinding.DataBindingContext;
+import org.eclipse.core.resources.IncrementalProjectBuilder;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IPath;
 import org.eclipse.core.runtime.IProgressMonitor;
@@ -214,9 +215,13 @@
 
     @Override
     protected void performFinish(IProgressMonitor monitor) throws CoreException {
-        monitor.beginTask("Preparing project", 100);
+        monitor.beginTask("Preparing project", 300);
         super.performFinish(new SubProgressMonitor(monitor, 20));
         wizardContext.initialize(getFacetedProject().getProject(), new SubProgressMonitor(monitor, 80));
+        getFacetedProject().getProject().build(IncrementalProjectBuilder.CLEAN_BUILD,
+                new SubProgressMonitor(monitor, 100));
+        getFacetedProject().getProject().build(IncrementalProjectBuilder.FULL_BUILD,
+                new SubProgressMonitor(monitor, 100));
         monitor.done();
     }
 }
Binary file plugins/org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/core/libraries/InstallPhoneGapDelegate.class has changed
Binary file plugins/org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/core/libraries/PhoneGapLibraryInstaller.class has changed
Binary file plugins/org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/core/libraries/PlatformServicesTypeProvider.class has changed
Binary file plugins/org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/wizards/FlickrProjectDetailsWizardPage$Factory.class has changed
Binary file plugins/org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/wizards/FlickrProjectDetailsWizardPage.class has changed
--- a/plugins/org.symbian.tools.wrttools/plugin.xml	Mon Aug 23 10:30:05 2010 -0700
+++ b/plugins/org.symbian.tools.wrttools/plugin.xml	Mon Aug 23 15:08:34 2010 -0700
@@ -161,20 +161,6 @@
          <requires-library>phonegap</requires-library>
       </projectTemplate>
 
-      <projectTemplate
-            archive="projecttemplates/flickr.zip"
-            default-css-name="Flickr"
-            default-html-name="index"
-            default-js-name="Flickr"
-            icon="icons/flickr.gif"
-            name="Flickr Project"
-            order="3"
-            wizard-page-factory="org.symbian.tools.wrttools.wizards.FlickrProjectDetailsWizardPage$Factory">
-         <description>
-            This wizard generates an Flickr project with a minimal Info.plist, html,css and js and WRTKit.
-         </description>
-         <requires-library>org.symbian.wrtkit</requires-library>
-      </projectTemplate>
 
       <projectTemplate
             archive="projecttemplates/rssreader.zip"
@@ -972,8 +958,11 @@
          <action
                type="install">
             <delegate
-                  class="org.symbian.tools.wrttools.core.libraries.PhoneGapLibraryInstaller">
+                  class="org.symbian.tools.wrttools.core.libraries.InstallPhoneGapDelegate">
             </delegate>
+            <config-factory
+                  class="org.symbian.tools.tmw.core.runtimes.ProjectCreationConfigFactory">
+            </config-factory>
          </action>
       </project-facet-version>
    </extension>
@@ -984,6 +973,11 @@
             path="icons/main16_prev.gif"
             version="1.0">
       </image>
+      <image
+            facet="symbian.phonegap"
+            path="icons/phonegap.png"
+            version="1.0">
+      </image>
    </extension>
    <extension
          point="org.symbian.tools.tmw.previewer.layoutProviders">
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/plugins/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/libraries/InstallPhoneGapDelegate.java	Mon Aug 23 15:08:34 2010 -0700
@@ -0,0 +1,74 @@
+/**
+ * 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.libraries;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.FileLocator;
+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.wst.common.project.facet.core.IDelegate;
+import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
+import org.symbian.tools.tmw.core.TMWCore;
+import org.symbian.tools.tmw.core.projects.IProjectSetupConfig;
+import org.symbian.tools.wrttools.Activator;
+
+public final class InstallPhoneGapDelegate implements IDelegate {
+    private static final String PHONEGAP_JS = "phonegap.js";
+
+    private IPath getBasePath(IProject project, IProjectSetupConfig setupConfig) {
+        return new Path("phonegap");
+    }
+
+    public void execute(IProject project, IProjectFacetVersion fv, Object config, IProgressMonitor monitor)
+            throws CoreException {
+        if (config instanceof IProjectSetupConfig) {
+            final IProjectSetupConfig setupConfig = (IProjectSetupConfig) config;
+            final IPath basePath = getBasePath(project, setupConfig);
+            InputStream file = null;
+            try {
+                URL url = FileLocator.find(Activator.getDefault().getBundle(),
+                        new Path("libraries").append(PHONEGAP_JS), null);
+                if (url != null) {
+                    file = url.openStream();
+                    final IFile f = setupConfig.addFile(project, basePath.append(PHONEGAP_JS), file,
+                            new NullProgressMonitor());
+                    setupConfig.addIncludedJsFile(f);
+                }
+            } catch (IOException e) {
+                Activator.log(e);
+            } finally {
+                try {
+                    if (file != null) {
+                        file.close();
+                    }
+                } catch (IOException e) {
+                    TMWCore.log(null, e);
+                }
+            }
+        }
+    }
+}
--- a/plugins/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/libraries/PhoneGapLibraryInstaller.java	Mon Aug 23 10:30:05 2010 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,56 +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.core.libraries;
-
-import java.io.InputStream;
-
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
-import org.symbian.tools.tmw.core.projects.IProjectSetupConfig;
-import org.symbian.tools.tmw.core.runtimes.LibraryInstallDelegate;
-
-public class PhoneGapLibraryInstaller extends LibraryInstallDelegate {
-
-    public void execute(IProject project, IProjectFacetVersion fv, Object config, IProgressMonitor monitor)
-            throws CoreException {
-
-    }
-
-    @Override
-    protected IPath getBasePath(IProject project, IProjectSetupConfig setupConfig) {
-        // TODO Auto-generated method stub
-        return null;
-    }
-
-    @Override
-    protected boolean isIncludeFile(IPath entry) {
-        // TODO Auto-generated method stub
-        return false;
-    }
-
-    @Override
-    protected InputStream openInputStream() throws CoreException {
-        // TODO Auto-generated method stub
-        return null;
-    }
-
-}
--- a/plugins/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/libraries/PlatformServicesTypeProvider.java	Mon Aug 23 10:30:05 2010 -0700
+++ b/plugins/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/libraries/PlatformServicesTypeProvider.java	Mon Aug 23 15:08:34 2010 -0700
@@ -27,7 +27,7 @@
 import org.eclipse.wst.jsdt.core.infer.InferrenceProvider;
 import org.eclipse.wst.jsdt.core.infer.RefactoringSupport;
 import org.eclipse.wst.jsdt.core.infer.ResolutionConfiguration;
-import org.symbian.tools.wrttools.util.ProjectUtils;
+import org.symbian.tools.tmw.core.TMWCore;
 
 public class PlatformServicesTypeProvider implements InferrenceProvider {
     public static final String ID = "org.symbian.tools.wrttools.platformservices";
@@ -40,7 +40,7 @@
                 IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
                 if (file.exists()) {
                     IProject project = file.getProject();
-                    if (ProjectUtils.hasWrtNature(project)) {
+                    if (TMWCore.create(project) != null) {
                         return InferrenceProvider.MAYBE_THIS;
                     }
                 }
--- a/plugins/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/FlickrProjectDetailsWizardPage.java	Mon Aug 23 10:30:05 2010 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,49 +0,0 @@
-/**
- * Copyright (c) 2009 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;
-
-import org.eclipse.core.databinding.DataBindingContext;
-import org.eclipse.swt.widgets.Composite;
-
-public class FlickrProjectDetailsWizardPage extends WRTProjectFilesWizardPage {
-
-    public FlickrProjectDetailsWizardPage(WizardContext context,
-            DataBindingContext bindingContext) {
-        super(context, bindingContext);
-    }
-
-    @Override
-    protected void addTemplateControls(Composite root) {
-        context.getExtensions().put("flickrUrl",
-                "http://flickr.com/photos/symbianfoundation");
-        context.createLabel(root, "Flickr URL:");
-        context.createTextForExt(root, "flickrUrl", "Flickr URL",
-                bindingContext, this);
-        context.createLabel(root, "");
-        context.createLabel(root, "");
-
-    }
-
-    public static final class Factory implements IWizardPageFactory {
-        public WRTProjectFilesWizardPage createPage(WizardContext context,
-                DataBindingContext bindingContext) {
-            return new FlickrProjectDetailsWizardPage(context, bindingContext);
-        }
-    }
-}