]> git.argeo.org Git - gpl/argeo-slc.git/commitdiff
NEW - bug 11: Introduce a simplified launch for RCP
authorMathieu Baudier <mbaudier@argeo.org>
Wed, 13 Apr 2011 15:45:38 +0000 (15:45 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Wed, 13 Apr 2011 15:45:38 +0000 (15:45 +0000)
https://bugzilla.argeo.org/show_bug.cgi?id=11

git-svn-id: https://svn.argeo.org/slc/trunk@4432 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

12 files changed:
eclipse/plugins/org.argeo.slc.ide.ui/META-INF/MANIFEST.MF
eclipse/plugins/org.argeo.slc.ide.ui/icons/eclipse-launch.gif [new file with mode: 0644]
eclipse/plugins/org.argeo.slc.ide.ui/plugin.xml
eclipse/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/launch/osgi/EclipseBootLaunchConfiguration.java [new file with mode: 0644]
eclipse/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/launch/osgi/EclipseBootLaunchShortcut.java [new file with mode: 0644]
eclipse/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/launch/osgi/EclipseBootLauncherTabGroup.java [new file with mode: 0644]
eclipse/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/launch/osgi/OsgiBootEquinoxLaunchConfiguration.java
eclipse/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/launch/osgi/OsgiBootLaunchShortcut.java
eclipse/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/launch/osgi/OsgiBootLauncherTabGroup.java
eclipse/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/launch/osgi/OsgiBootMainTab.java
eclipse/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/launch/osgi/OsgiLaunchHelper.java
eclipse/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/launch/osgi/OsgiLauncherConstants.java

index 4ae043d40db04995a631e822db141d08dbcf9562..5a2b5cbb6ee77dd16c480381ff75ca3448c4339b 100644 (file)
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
 Bundle-ManifestVersion: 2
 Bundle-Name: SLC IDE UI
 Bundle-SymbolicName: org.argeo.slc.ide.ui;singleton:=true
-Bundle-Version: 0.13.1.SNAPSHOT
+Bundle-Version: 0.13.1.D20110413_1126
 Bundle-Activator: org.argeo.slc.ide.ui.SlcIdeUiPlugin
 Require-Bundle: org.eclipse.ui,
  org.eclipse.core.runtime,
diff --git a/eclipse/plugins/org.argeo.slc.ide.ui/icons/eclipse-launch.gif b/eclipse/plugins/org.argeo.slc.ide.ui/icons/eclipse-launch.gif
new file mode 100644 (file)
index 0000000..4b42e57
Binary files /dev/null and b/eclipse/plugins/org.argeo.slc.ide.ui/icons/eclipse-launch.gif differ
index ca6221abbba1744ddf37b5c4b73f942f00c1d179..158d007d402862347d27dafb7ef3907321c56d30 100644 (file)
          name="SLC">\r
    </perspective>\r
 </extension>\r
-<!--\r
-<extension\r
-      point="org.eclipse.pde.core.targets">\r
-   <target\r
-         definition="slc-sdk-dev.target"\r
-         id="org.argeo.slc.ide.ui.targetSlcSdkDev"\r
-         name="SLC SDK Dev">\r
-   </target>\r
-   <target\r
-         definition="slc-sdk-0.12.target"\r
-         id="org.argeo.slc.ide.ui.targetSlcSdk0_12"\r
-         name="SLC SDK v0.12.x">\r
-   </target>\r
-</extension> \r
--->\r
 <extension\r
       point="org.eclipse.debug.ui.launchShortcuts">\r
    <shortcut\r
-         class="org.argeo.slc.ide.ui.launch.osgi.OsgiBootLaunchShortcut"\r
-         icon="icons/slc-launch.gif"\r
-         id="org.argeo.slc.ide.ui.osgiBootLaunchShortcut"\r
-         label="OSGiBoot"\r
+         class="org.argeo.slc.ide.ui.launch.osgi.EclipseBootLaunchShortcut"\r
+         icon="icons/eclipse-launch.gif"\r
+         id="org.argeo.slc.ide.ui.eclipseBootLaunchShortcut"\r
+         label="Eclipse Boot (RCP)"\r
          modes="run,debug">\r
-    \r
          <contextualLaunch>\r
             <enablement>\r
             <with variable="selection">\r
            </enablement>\r
          </contextualLaunch>         \r
    </shortcut>\r
-   <!--\r
    <shortcut\r
-         class="org.argeo.slc.ui.launch.script.SlcScriptLaunchShortcut"\r
-         icon="icons/slcScriptLaunch.gif"\r
-         id="org.argeo.slc.ui.launch.slcScriptLaunchShortcut"\r
-         label="SLC script"\r
+         class="org.argeo.slc.ide.ui.launch.osgi.OsgiBootLaunchShortcut"\r
+         icon="icons/slc-launch.gif"\r
+         id="org.argeo.slc.ide.ui.osgiBootLaunchShortcut"\r
+         label="OSGi Boot (Equinox, RAP)"\r
          modes="run,debug">\r
-    \r
-        <contextualLaunch>\r
-           <enablement>\r
-             <with variable="selection">\r
-                <count value="1"/>\r
+         <contextualLaunch>\r
+            <enablement>\r
+            <with variable="selection">\r
+               <count value="1"/>\r
                <iterate>\r
-               <or>\r
-                   <test property="org.eclipse.debug.ui.matchesPattern" value="*.xml"/>\r
-                   </or>\r
+                 <or>\r
+                   <test property="org.eclipse.debug.ui.matchesPattern" value="*.properties"/>\r
+                   <test property="org.eclipse.debug.ui.matchesPattern" value="config.ini"/>\r
+                 </or>\r
                 </iterate>\r
              </with>\r
            </enablement>\r
-                </contextualLaunch>\r
-   </shortcut>\r
-   <shortcut
-         class="org.argeo.slc.ui.launch.script.SlcScriptLaunchShortcutWithDialog"
-         icon="icons/slcScriptLaunch.gif"
-         id="org.argeo.slc.ui.launch.slcScriptLaunchShortcutWithDialog"
-         label="SLC script..."
-         modes="run,debug">
-    
-        <contextualLaunch>
-           <enablement>
-             <with variable="selection">
-                <count value="1"/>
-               <iterate>
-               <or>
-                   <test property="org.eclipse.debug.ui.matchesPattern" value="*.xml"/>
-                   </or>
-                </iterate>
-             </with>
-           </enablement>
-                </contextualLaunch>
+         </contextualLaunch>         \r
    </shortcut>\r
--->
 </extension>\r
   <extension\r
          point="org.eclipse.debug.core.launchConfigurationTypes">\r
             modes="run, debug"\r
             sourceLocatorId="org.eclipse.pde.ui.launcher.PDESourceLookupDirector"\r
             sourcePathComputerId="org.eclipse.jdt.launching.sourceLookup.javaSourcePathComputer"/>\r
+      <launchConfigurationType\r
+            id="org.argeo.slc.ide.ui.EclipseBootLauncher"\r
+            name="Eclipse Boot"\r
+            delegate="org.argeo.slc.ide.ui.launch.osgi.EclipseBootLaunchConfiguration"\r
+            modes="run, debug"\r
+            sourceLocatorId="org.eclipse.pde.ui.launcher.PDESourceLookupDirector"\r
+            sourcePathComputerId="org.eclipse.jdt.launching.sourceLookup.javaSourcePathComputer"/>\r
    </extension>\r
   <extension\r
          point="org.eclipse.debug.ui.launchConfigurationTabGroups">\r
             class="org.argeo.slc.ide.ui.launch.osgi.OsgiBootLauncherTabGroup"\r
             id="org.argeo.slc.ide.ui.OsgiBootLauncherTabGroup">\r
       </launchConfigurationTabGroup>\r
+      <launchConfigurationTabGroup\r
+            type="org.argeo.slc.ide.ui.EclipseBootLauncher"\r
+            class="org.argeo.slc.ide.ui.launch.osgi.EclipseBootLauncherTabGroup"\r
+            id="org.argeo.slc.ide.ui.EclipseBootLauncherTabGroup">\r
+      </launchConfigurationTabGroup>\r
   </extension>\r
    <extension\r
          point="org.eclipse.debug.ui.launchConfigurationTypeImages">\r
             configTypeID="org.argeo.slc.ide.ui.OsgiBootEquinoxLauncher"\r
             id="org.argeo.slc.ide.ui.OsgiBootEquinoxLauncherImage">\r
       </launchConfigurationTypeImage>\r
+      <launchConfigurationTypeImage\r
+            icon="icons/eclipse-launch.gif"\r
+            configTypeID="org.argeo.slc.ide.ui.EclipseBootLauncher"\r
+            id="org.argeo.slc.ide.ui.EclipseBootLauncherImage">\r
+      </launchConfigurationTypeImage>\r
    </extension>\r
-<!--\r
-<extension point = "org.eclipse.debug.core.launchConfigurationTypes">\r
-   <launchConfigurationType\r
-          id="org.argeo.slc.ide.ui.slcScriptLaunchType"\r
-          name="SLC Script"\r
-          delegate="org.argeo.slc.ide.ui.launch.script.SlcScriptLaunchDelegate"\r
-          modes= "run, debug">\r
-   </launchConfigurationType>\r
-</extension>\r
-<extension\r
-      point="org.eclipse.debug.ui.launchConfigurationTabGroups">\r
-   <launchConfigurationTabGroup\r
-         class="org.argeo.slc.ui.launch.script.SlcScriptLaunchConfigurationTabGroup"\r
-         id="org.argeo.slc.ui.launch.slcScriptLaunchConfigurationTabGroup1"\r
-         type="org.argeo.slc.launch.slcScriptLaunchType">\r
-   </launchConfigurationTabGroup>\r
-</extension>\r
--->\r
-<!-- See http://www.eclipseplugincentral.com/PNphpBB2-printview-t-4335-start-0.html\r
-<extension point="org.eclipse.core.runtime.adapters">\r
-<factory adaptableType="org.eclipse.core.resources.IResource" class="">\r
-<adapter type="org.eclipse.debug.ui.actions.ILaunchable"/>\r
-</factory>\r
-</extension> -->\r
-<!--\r
-<extension\r
-      point="org.eclipse.ui.preferencePages">\r
-   <page\r
-         class="org.argeo.slc.ui.launch.preferences.SlcPreferencePage"\r
-         id="org.argeo.slc.ui.slcPreferencePage"\r
-         name="SLC">\r
-   </page>\r
-</extension>\r
-<extension\r
-      point="org.eclipse.debug.ui.launchConfigurationTypeImages">\r
-   <launchConfigurationTypeImage\r
-         configTypeID="org.argeo.slc.launch.slcScriptLaunchType"\r
-         icon="icons/slcScriptLaunch.gif"\r
-         id="org.argeo.slc.launch.slcScriptLaunchTypeImage">\r
-   </launchConfigurationTypeImage>\r
-</extension>\r
--->\r
 </plugin>\r
diff --git a/eclipse/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/launch/osgi/EclipseBootLaunchConfiguration.java b/eclipse/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/launch/osgi/EclipseBootLaunchConfiguration.java
new file mode 100644 (file)
index 0000000..6611f20
--- /dev/null
@@ -0,0 +1,53 @@
+package org.argeo.slc.ide.ui.launch.osgi;
+
+import org.argeo.slc.ide.ui.SlcIdeUiPlugin;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.debug.core.ILaunch;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.pde.launching.EclipseApplicationLaunchConfiguration;
+
+/** OSGiBoot launch configuration. */
+public class EclipseBootLaunchConfiguration extends
+               EclipseApplicationLaunchConfiguration {
+       public final static String ID = SlcIdeUiPlugin.ID + ".EclipseBootLauncher";
+
+       @Override
+       public void launch(ILaunchConfiguration configuration, String mode,
+                       ILaunch launch, IProgressMonitor monitor) throws CoreException {
+               super.launch(configuration, mode, launch, monitor);
+
+               // System.out.println("targetBundles="
+               // + configuration.getAttribute(
+               // IPDELauncherConstants.SELECTED_TARGET_PLUGINS, ""));
+               // System.out.println("workspaceBundles="
+               // + configuration.getAttribute(
+               // IPDELauncherConstants.SELECTED_WORKSPACE_PLUGINS, ""));
+
+               // Refresh resources before launching
+               final IFile propertiesFile = (IFile) configuration.getMappedResources()[0];
+               propertiesFile.getParent().refreshLocal(IResource.DEPTH_INFINITE,
+                               monitor);
+       }
+
+       @Override
+       protected void preLaunchCheck(ILaunchConfiguration configuration,
+                       ILaunch launch, IProgressMonitor monitor) throws CoreException {
+               ILaunchConfigurationWorkingCopy wc = configuration.getWorkingCopy();
+               OsgiLaunchHelper.updateLaunchConfiguration(wc, true);
+               wc.doSave();
+               super.preLaunchCheck(configuration, launch, monitor);
+
+               // Note that if a Java project contains a build.properties it has to
+               // declare the sources otherwise it will be skipped in the generation of
+               // the dev.properties file!
+
+               // for(Object bundleId:fAllBundles.keySet()){
+               // System.out.println(bundleId+"="+fAllBundles.get(bundleId));
+               // }
+       }
+
+}
diff --git a/eclipse/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/launch/osgi/EclipseBootLaunchShortcut.java b/eclipse/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/launch/osgi/EclipseBootLaunchShortcut.java
new file mode 100644 (file)
index 0000000..aa7f861
--- /dev/null
@@ -0,0 +1,72 @@
+package org.argeo.slc.ide.ui.launch.osgi;
+
+import java.util.Iterator;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.debug.core.DebugPlugin;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.ILaunchConfigurationType;
+import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.pde.ui.launcher.EclipseLaunchShortcut;
+
+/**
+ * Launch shortcut simplifying the launch of an Eclipse application (typically
+ * an RCP).
+ */
+public class EclipseBootLaunchShortcut extends EclipseLaunchShortcut implements
+               OsgiLauncherConstants {
+       private StringBuffer name = null;
+       private IFile propertiesFile = null;
+
+       @Override
+       protected String getLaunchConfigurationTypeName() {
+               return EclipseBootLaunchConfiguration.ID;
+       }
+
+       @Override
+       public void launch(ISelection selection, String mode) {
+               // we assume that only one file is selected
+               IStructuredSelection sSelection = (IStructuredSelection) selection;
+               Iterator<?> it = sSelection.iterator();
+               propertiesFile = (IFile) it.next();
+
+               name = new StringBuffer(OsgiLaunchHelper.extractName(propertiesFile));
+
+               super.launch(selection, mode);
+       }
+
+       @Override
+       protected void initializeConfiguration(ILaunchConfigurationWorkingCopy wc) {
+               IResource[] resources = { propertiesFile };
+               wc.setMappedResources(resources);
+               super.initializeConfiguration(wc);
+
+               OsgiLaunchHelper.setDefaults(wc, true);
+               wc.setAttribute(
+                               IJavaLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY,
+                               OsgiLaunchHelper.findWorkingDirectory(propertiesFile));
+
+               OsgiLaunchHelper.updateLaunchConfiguration(wc, true);
+       }
+
+       protected String getName(ILaunchConfigurationType type) {
+               if (name != null && !name.toString().trim().equals(""))
+                       return DebugPlugin.getDefault().getLaunchManager()
+                                       .generateLaunchConfigurationName(name.toString());
+               else
+                       return DebugPlugin.getDefault().getLaunchManager()
+                                       .generateLaunchConfigurationName("SLC");
+       }
+
+       @Override
+       protected boolean isGoodMatch(ILaunchConfiguration configuration) {
+               if (name != null) {
+                       return name.toString().equals(configuration.getName());
+               }
+               return super.isGoodMatch(configuration);
+       }
+}
diff --git a/eclipse/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/launch/osgi/EclipseBootLauncherTabGroup.java b/eclipse/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/launch/osgi/EclipseBootLauncherTabGroup.java
new file mode 100644 (file)
index 0000000..7d77ce6
--- /dev/null
@@ -0,0 +1,50 @@
+package org.argeo.slc.ide.ui.launch.osgi;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.debug.ui.CommonTab;
+import org.eclipse.debug.ui.EnvironmentTab;
+import org.eclipse.debug.ui.ILaunchConfigurationDialog;
+import org.eclipse.debug.ui.ILaunchConfigurationTab;
+import org.eclipse.pde.ui.launcher.EclipseLauncherTabGroup;
+import org.eclipse.pde.ui.launcher.MainTab;
+import org.eclipse.pde.ui.launcher.OSGiSettingsTab;
+import org.eclipse.pde.ui.launcher.PluginsTab;
+import org.eclipse.pde.ui.launcher.TracingTab;
+
+/** Definition of the set of tabs used in Eclipse Boot launch configuration UI. */
+public class EclipseBootLauncherTabGroup extends EclipseLauncherTabGroup {
+
+       @Override
+       public void createTabs(ILaunchConfigurationDialog dialog, String mode) {
+               ILaunchConfigurationTab[] tabs = new ILaunchConfigurationTab[] {
+                               new OsgiBootMainTab(true),
+                               new MainTab(),
+                               new PluginsTab() {
+                                       private boolean activating = false;
+
+                                       @Override
+                                       public void performApply(
+                                                       ILaunchConfigurationWorkingCopy config) {
+                                               super.performApply(config);
+                                               if (activating) {
+                                                       try {
+                                                               config.doSave();
+                                                       } catch (CoreException e) {
+                                                               e.printStackTrace();
+                                                       }
+                                                       activating = false;
+                                               }
+                                       }
+
+                                       @Override
+                                       public void activated(
+                                                       ILaunchConfigurationWorkingCopy workingCopy) {
+                                               activating = true;
+                                       }
+                               }, new OSGiSettingsTab(), new EnvironmentTab(),
+                               new TracingTab(), new CommonTab() };
+               setTabs(tabs);
+       }
+
+}
index 1f39aac0ad58d01022319f49f85de9e4a78708c5..19cdee12b8b1896f839293499d8fd66f208f9e3b 100644 (file)
@@ -8,8 +8,7 @@ import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.debug.core.ILaunch;
 import org.eclipse.debug.core.ILaunchConfiguration;
 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
-import org.eclipse.pde.ui.launcher.EquinoxLaunchConfiguration;
-import org.eclipse.pde.ui.launcher.IPDELauncherConstants;
+import org.eclipse.pde.launching.EquinoxLaunchConfiguration;
 
 /** OSGiBoot launch configuration. */
 public class OsgiBootEquinoxLaunchConfiguration extends
@@ -22,12 +21,12 @@ public class OsgiBootEquinoxLaunchConfiguration extends
                        ILaunch launch, IProgressMonitor monitor) throws CoreException {
                super.launch(configuration, mode, launch, monitor);
 
-               System.out.println("targetBundles="
-                               + configuration.getAttribute(
-                                               IPDELauncherConstants.TARGET_BUNDLES, ""));
-               System.out.println("workspaceBundles="
-                               + configuration.getAttribute(
-                                               IPDELauncherConstants.WORKSPACE_BUNDLES, ""));
+//             System.out.println("targetBundles="
+//                             + configuration.getAttribute(
+//                                             IPDELauncherConstants.TARGET_BUNDLES, ""));
+//             System.out.println("workspaceBundles="
+//                             + configuration.getAttribute(
+//                                             IPDELauncherConstants.WORKSPACE_BUNDLES, ""));
 
                // Refresh resources before launching
                final IFile propertiesFile = (IFile) configuration.getMappedResources()[0];
@@ -40,7 +39,7 @@ public class OsgiBootEquinoxLaunchConfiguration extends
                        ILaunch launch, IProgressMonitor monitor) throws CoreException {
                // System.out.println("Launching... " + launch);
                ILaunchConfigurationWorkingCopy wc = configuration.getWorkingCopy();
-               OsgiLaunchHelper.updateLaunchConfiguration(wc);
+               OsgiLaunchHelper.updateLaunchConfiguration(wc, false);
                wc.doSave();
                super.preLaunchCheck(configuration, launch, monitor);
 
index b1994e8144388a680deb8cabe4130a80cdb56204..b73b612a3d94e222985fb9d4b8c0414dc887b847 100644 (file)
@@ -3,25 +3,17 @@ package org.argeo.slc.ide.ui.launch.osgi;
 import java.util.Iterator;
 
 import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IFolder;
-import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IPath;
 import org.eclipse.debug.core.DebugPlugin;
 import org.eclipse.debug.core.ILaunchConfiguration;
 import org.eclipse.debug.core.ILaunchConfigurationType;
 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
 import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
-import org.eclipse.jface.dialogs.ErrorDialog;
 import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.pde.ui.launcher.IPDELauncherConstants;
 import org.eclipse.pde.ui.launcher.OSGiLaunchShortcut;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Shell;
 
-/** OSGiBoot launch shortcut. */
+/** Launch shortcut simplifying the launch of a pure OSGi runtime */
 public class OsgiBootLaunchShortcut extends OSGiLaunchShortcut implements
                OsgiLauncherConstants {
        private StringBuffer name = null;
@@ -34,88 +26,38 @@ public class OsgiBootLaunchShortcut extends OSGiLaunchShortcut implements
 
        @Override
        public void launch(ISelection selection, String mode) {
-               // System.out.println("Launch shortcut... " + selection);
-
-               // we assume that:
-               // - only one
-               // - file
-               // - is selected
+               // we assume that only one file is selected
                IStructuredSelection sSelection = (IStructuredSelection) selection;
                Iterator<?> it = sSelection.iterator();
                propertiesFile = (IFile) it.next();
 
-               name = new StringBuffer(extractName(propertiesFile));
+               name = new StringBuffer(OsgiLaunchHelper.extractName(propertiesFile));
 
                super.launch(selection, mode);
        }
 
        @Override
-       protected void initializeConfiguration(
-                       ILaunchConfigurationWorkingCopy configuration) {
+       protected void initializeConfiguration(ILaunchConfigurationWorkingCopy wc) {
                IResource[] resources = { propertiesFile };
-               configuration.setMappedResources(resources);
-               super.initializeConfiguration(configuration);
-
-               try {
-                       configuration.setAttribute(ATTR_ADD_JVM_PATHS, false);
-                       configuration.setAttribute(ATTR_ADDITIONAL_VM_ARGS, "-Xmx128m");
-                       configuration
-                                       .setAttribute(ATTR_ADDITIONAL_PROGRAM_ARGS, "-console");
-
-                       // Defaults
-                       String originalVmArgs = configuration.getAttribute(
-                                       IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS, "");
-                       configuration.setAttribute(ATTR_DEFAULT_VM_ARGS, originalVmArgs);
-                       configuration.setAttribute(IPDELauncherConstants.CONFIG_CLEAR_AREA,
-                                       true);
+               wc.setMappedResources(resources);
+               super.initializeConfiguration(wc);
 
-                       configuration.setAttribute(
-                                       IJavaLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY,
-                                       findWorkingDirectory());
-
-                       OsgiLaunchHelper.updateLaunchConfiguration(configuration);
-               } catch (CoreException e) {
-                       Shell shell = Display.getCurrent().getActiveShell();
-                       ErrorDialog.openError(shell, "Error",
-                                       "Cannot execute initalize configuration", e.getStatus());
-               }
-       }
-
-       protected String findWorkingDirectory() {
-               try {
-                       IProject project = propertiesFile.getProject();
-                       IPath parent = propertiesFile.getProjectRelativePath()
-                                       .removeLastSegments(1);
-                       IFolder execFolder = project.getFolder(parent.append("exec"));
-                       if (!execFolder.exists())
-                               execFolder.create(true, true, null);
-                       IFolder launchFolder = project.getFolder(execFolder
-                                       .getProjectRelativePath().append(
-                                                       extractName(propertiesFile)));
-                       if (!launchFolder.exists())
-                               launchFolder.create(true, true, null);
-                       return "${workspace_loc:"
-                                       + launchFolder.getFullPath().toString().substring(1) + "}";
-               } catch (Exception e) {
-                       e.printStackTrace();
-                       throw new RuntimeException("Cannot create working directory", e);
-               }
-       }
+               OsgiLaunchHelper.setDefaults(wc, true);
 
-       protected String extractName(IFile file) {
-               IPath path = propertiesFile.getFullPath();
-               IPath pathNoExt = path.removeFileExtension();
-               return pathNoExt.segment(pathNoExt.segmentCount() - 1);
+               wc.setAttribute(
+                               IJavaLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY,
+                               OsgiLaunchHelper.findWorkingDirectory(propertiesFile));
 
+               OsgiLaunchHelper.updateLaunchConfiguration(wc, false);
        }
 
        protected String getName(ILaunchConfigurationType type) {
                if (name != null && !name.toString().trim().equals(""))
                        return DebugPlugin.getDefault().getLaunchManager()
-                                       .generateUniqueLaunchConfigurationNameFrom(name.toString());
+                                       .generateLaunchConfigurationName(name.toString());
                else
                        return DebugPlugin.getDefault().getLaunchManager()
-                                       .generateUniqueLaunchConfigurationNameFrom("SLC");
+                                       .generateLaunchConfigurationName("SLC");
        }
 
        @Override
index de3b20cafbc9a574cd6af4d59466cffb4183c558..0195aa8efdb37a7a58718436226e05de6d2cec59 100644 (file)
@@ -11,32 +11,13 @@ import org.eclipse.pde.ui.launcher.OSGiLauncherTabGroup;
 import org.eclipse.pde.ui.launcher.OSGiSettingsTab;
 import org.eclipse.pde.ui.launcher.TracingTab;
 
-/** Definition of the set of tabs used in OSGiBoot launch configuration UI. */
+/** Definition of the set of tabs used in OSGi Boot launch configuration UI. */
 public class OsgiBootLauncherTabGroup extends OSGiLauncherTabGroup {
 
        @Override
        public void createTabs(ILaunchConfigurationDialog dialog, String mode) {
-               // JavaArgumentsTab javaArgumentsTab = new JavaArgumentsTab() {
-               // private boolean initializing = false;
-               //
-               // @Override
-               // public void performApply(
-               // ILaunchConfigurationWorkingCopy configuration) {
-               // if (initializing)
-               // return;
-               // initializing = true;
-               // initializeFrom(configuration);
-               // initializing = false;
-               // }
-               //
-               // @Override
-               // public boolean isValid(ILaunchConfiguration config) {
-               // return true;
-               // }
-               // };
-
                ILaunchConfigurationTab[] tabs = new ILaunchConfigurationTab[] {
-                               new OsgiBootMainTab(),
+                               new OsgiBootMainTab(false),
                                new BundlesTab() {
                                        private boolean activating = false;
 
index cbe41cdc9d3a1f5ecd4fca93095b5e21b448305e..d0a76ce9d2c1344649673c547c1973c3c40a33e5 100644 (file)
@@ -33,6 +33,13 @@ public class OsgiBootMainTab extends AbstractLaunchConfigurationTab implements
 
        private Text additionalProgramArgs;
 
+       private final Boolean isEclipse;
+
+       public OsgiBootMainTab(Boolean isEclipse) {
+               super();
+               this.isEclipse = isEclipse;
+       }
+
        public void createControl(Composite parent) {
                Composite container = new Composite(parent, SWT.NONE);
                container.setLayout(new GridLayout());
@@ -136,20 +143,20 @@ public class OsgiBootMainTab extends AbstractLaunchConfigurationTab implements
 
        public void performApply(ILaunchConfigurationWorkingCopy configuration) {
                // System.out.println("performApply");
-               configuration.setAttribute(ATTR_SYNC_BUNDLES, syncBundles
-                               .getSelection());
+               configuration.setAttribute(ATTR_SYNC_BUNDLES,
+                               syncBundles.getSelection());
                configuration.setAttribute(ATTR_CLEAR_DATA_DIRECTORY,
                                clearDataDirectory.getSelection());
 
                configuration.setAttribute(ATTR_ADDITIONAL_PROGRAM_ARGS,
                                additionalProgramArgs.getText());
-               configuration.setAttribute(ATTR_ADDITIONAL_VM_ARGS, additionalVmArgs
-                               .getText());
-               configuration.setAttribute(ATTR_ADD_JVM_PATHS, addJvmPaths
-                               .getSelection());
+               configuration.setAttribute(ATTR_ADDITIONAL_VM_ARGS,
+                               additionalVmArgs.getText());
+               configuration.setAttribute(ATTR_ADD_JVM_PATHS,
+                               addJvmPaths.getSelection());
                // writeProperties(configuration);
 
-               OsgiLaunchHelper.updateLaunchConfiguration(configuration);
+               OsgiLaunchHelper.updateLaunchConfiguration(configuration, isEclipse);
        }
 
        public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
index ee01f02a2d2eaf0c3d27b81c278f2b07298b47b4..2e55f87f3bc452a27c0975aed1d935c1e93e0300 100644 (file)
@@ -13,10 +13,12 @@ import java.util.StringTokenizer;
 
 import org.argeo.slc.ide.ui.SlcIdeUiPlugin;
 import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.IResource;
 import org.eclipse.core.runtime.Assert;
 import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.Status;
 import org.eclipse.core.variables.IStringVariableManager;
@@ -35,41 +37,120 @@ import org.eclipse.osgi.service.resolver.BundleDescription;
 import org.eclipse.pde.core.plugin.IPluginModelBase;
 import org.eclipse.pde.core.plugin.PluginRegistry;
 import org.eclipse.pde.internal.build.IPDEBuildConstants;
-import org.eclipse.pde.ui.launcher.IPDELauncherConstants;
+import org.eclipse.pde.launching.IPDELauncherConstants;
+import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.Shell;
 
+/**
+ * Most of the actual logic is concentrated in this class which manipulates
+ * {@link ILaunchConfigurationWorkingCopy}. Static method are used since the
+ * shortcut and launch configuration classes are already extending PDE classes.
+ */
 @SuppressWarnings("restriction")
 public class OsgiLaunchHelper implements OsgiLauncherConstants {
        private static Boolean debug = false;
 
+       private final static String DEFAULT_DATA_DIR = "data";
+       private final static String DEFAULT_EXEC_DIR = "exec";
+       private final static String DEFAULT_VMARGS = "-Xmx128m";
+       private final static String DEFAULT_PROGRAM_ARGS = "-console";
+
+       /** Sets default values on this configuration. */
+       public static void setDefaults(ILaunchConfigurationWorkingCopy wc,
+                       Boolean isEclipse) {
+               try {
+                       if (isEclipse) {
+                               wc.setAttribute(IPDELauncherConstants.USE_DEFAULT, false);
+                               wc.setAttribute(IPDELauncherConstants.USE_PRODUCT, false);
+                       }
+
+                       wc.setAttribute(ATTR_ADD_JVM_PATHS, false);
+                       wc.setAttribute(ATTR_ADDITIONAL_VM_ARGS, DEFAULT_VMARGS);
+                       wc.setAttribute(ATTR_ADDITIONAL_PROGRAM_ARGS, DEFAULT_PROGRAM_ARGS);
+
+                       // Defaults
+                       String originalVmArgs = wc.getAttribute(
+                                       IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS, "");
+                       wc.setAttribute(ATTR_DEFAULT_VM_ARGS, originalVmArgs);
+                       wc.setAttribute(IPDELauncherConstants.CONFIG_CLEAR_AREA, true);
+               } catch (CoreException e) {
+                       Shell shell = Display.getCurrent().getActiveShell();
+                       ErrorDialog.openError(shell, "Error",
+                                       "Cannot execute initalize configuration", e.getStatus());
+               }
+       }
+
+       /** Find the working directory based on this properties file. */
+       public static String findWorkingDirectory(IFile propertiesFile) {
+               try {
+                       IProject project = propertiesFile.getProject();
+                       IPath parent = propertiesFile.getProjectRelativePath()
+                                       .removeLastSegments(1);
+                       IFolder execFolder = project.getFolder(parent
+                                       .append(DEFAULT_EXEC_DIR));
+                       if (!execFolder.exists())
+                               execFolder.create(true, true, null);
+                       IFolder launchFolder = project.getFolder(execFolder
+                                       .getProjectRelativePath().append(
+                                                       extractName(propertiesFile)));
+                       if (!launchFolder.exists())
+                               launchFolder.create(true, true, null);
+                       return "${workspace_loc:"
+                                       + launchFolder.getFullPath().toString().substring(1) + "}";
+               } catch (Exception e) {
+                       e.printStackTrace();
+                       throw new RuntimeException("Cannot create working directory", e);
+               }
+       }
+
+       /** Extract the launch configuration name from the properties file. */
+       public static String extractName(IFile propertiesFile) {
+               IPath path = propertiesFile.getFullPath();
+               IPath pathNoExt = path.removeFileExtension();
+               return pathNoExt.segment(pathNoExt.segmentCount() - 1);
+
+       }
+
        /** Expects properties file to be set as mapped resources */
        public static void updateLaunchConfiguration(
-                       ILaunchConfigurationWorkingCopy configuration) {
+                       ILaunchConfigurationWorkingCopy wc, Boolean isEclipse) {
                try {
                        // Finds the properties file and load it
-                       IFile propertiesFile = (IFile) configuration.getMappedResources()[0];
+                       IFile propertiesFile = (IFile) wc.getMappedResources()[0];
                        propertiesFile.refreshLocal(IResource.DEPTH_ONE, null);
                        Properties properties = readProperties(propertiesFile);
 
                        // Extract information from the properties file
                        List<String> bundlesToStart = new ArrayList<String>();
                        Map<String, String> systemPropertiesToAppend = new HashMap<String, String>();
-                       interpretProperties(properties, bundlesToStart,
-                                       systemPropertiesToAppend);
+                       String applicationId = interpretProperties(properties,
+                                       bundlesToStart, systemPropertiesToAppend);
+
+                       if (applicationId != null)
+                               wc.setAttribute(IPDELauncherConstants.APPLICATION,
+                                               applicationId);
+                       else {
+                               if (isEclipse)
+                                       throw new Exception("No application defined,"
+                                                       + " please set the 'eclipse.application' property"
+                                                       + " in the properties file");
+                       }
 
                        // Define directories
-                       File workingDir = getWorkingDirectory(configuration);
-                       File dataDir = new File(workingDir, "data");
+                       File workingDir = getWorkingDirectory(wc);
+                       File dataDir = new File(workingDir, DEFAULT_DATA_DIR);
 
                        // Update the launch configuration accordingly
-                       updateLaunchConfiguration(configuration, bundlesToStart,
-                                       systemPropertiesToAppend, dataDir.getAbsolutePath());
+                       updateLaunchConfiguration(wc, bundlesToStart,
+                                       systemPropertiesToAppend, dataDir.getAbsolutePath(),
+                                       isEclipse);
                } catch (Exception e) {
                        e.printStackTrace();
                        Shell shell = SlcIdeUiPlugin.getDefault().getWorkbench()
                                        .getActiveWorkbenchWindow().getShell();
                        // Shell shell= Display.getCurrent().getActiveShell();
-                       ErrorDialog.openError(shell, "Error", "Cannot read properties",
+                       ErrorDialog.openError(shell, "Error",
+                                       "Cannot prepare launch configuration",
                                        new Status(IStatus.ERROR, SlcIdeUiPlugin.ID,
                                                        e.getMessage(), e));
                        return;
@@ -82,14 +163,13 @@ public class OsgiLaunchHelper implements OsgiLauncherConstants {
         * UI.
         */
        protected static void updateLaunchConfiguration(
-                       ILaunchConfigurationWorkingCopy configuration,
-                       List<String> bundlesToStart,
-                       Map<String, String> systemPropertiesToAppend, String dataDir)
-                       throws CoreException {
+                       ILaunchConfigurationWorkingCopy wc, List<String> bundlesToStart,
+                       Map<String, String> systemPropertiesToAppend, String dataDir,
+                       Boolean isEclipse) throws CoreException {
                // Convert bundle lists
                final String targetBundles;
                final String wkSpaceBundles;
-               if (configuration.getAttribute(ATTR_SYNC_BUNDLES, true)) {
+               if (wc.getAttribute(ATTR_SYNC_BUNDLES, true)) {
                        StringBuffer tBuf = new StringBuffer();
                        for (IPluginModelBase model : PluginRegistry.getExternalModels()) {
                                tBuf.append(model.getBundleDescription().getSymbolicName());
@@ -108,44 +188,45 @@ public class OsgiLaunchHelper implements OsgiLauncherConstants {
                        }
                        wkSpaceBundles = wBuf.toString();
                } else {
-                       targetBundles = configuration.getAttribute(
-                                       IPDELauncherConstants.TARGET_BUNDLES, "");
-                       wkSpaceBundles = configuration.getAttribute(
-                                       IPDELauncherConstants.WORKSPACE_BUNDLES, "");
+                       targetBundles = wc.getAttribute(targetBundlesAttr(isEclipse), "");
+                       wkSpaceBundles = wc.getAttribute(workspaceBundlesAttr(isEclipse),
+                                       "");
                }
-               configuration.setAttribute(IPDELauncherConstants.TARGET_BUNDLES,
+               wc.setAttribute(targetBundlesAttr(isEclipse),
                                convertBundleList(bundlesToStart, targetBundles));
 
-               configuration.setAttribute(IPDELauncherConstants.WORKSPACE_BUNDLES,
+               wc.setAttribute(workspaceBundlesAttr(isEclipse),
                                convertBundleList(bundlesToStart, wkSpaceBundles));
 
                // Update other default information
-               configuration.setAttribute(IPDELauncherConstants.DEFAULT_AUTO_START,
-                               false);
+               wc.setAttribute(IPDELauncherConstants.DEFAULT_AUTO_START, false);
 
                // VM arguments (system properties)
-               String defaultVmArgs = configuration.getAttribute(
+               String defaultVmArgs = wc.getAttribute(
                                OsgiLauncherConstants.ATTR_DEFAULT_VM_ARGS, "");
                StringBuffer vmArgs = new StringBuffer(defaultVmArgs);
 
                // Data dir system property
-               if (dataDir != null)
+               if (dataDir != null) {
                        addSysProperty(vmArgs, OsgiLauncherConstants.ARGEO_OSGI_DATA_DIR,
                                        dataDir);
+                       if (isEclipse) {
+                               wc.setAttribute(IPDELauncherConstants.LOCATION, dataDir);
+                       }
+               }
+
                // Add locations of JVMs
-               if (configuration.getAttribute(ATTR_ADD_JVM_PATHS, false))
+               if (wc.getAttribute(ATTR_ADD_JVM_PATHS, false))
                        addVms(vmArgs);
 
                // Add other system properties
                for (String key : systemPropertiesToAppend.keySet())
                        addSysProperty(vmArgs, key, systemPropertiesToAppend.get(key));
 
-               vmArgs.append(" ").append(
-                               configuration.getAttribute(ATTR_ADDITIONAL_VM_ARGS, ""));
+               vmArgs.append(" ").append(wc.getAttribute(ATTR_ADDITIONAL_VM_ARGS, ""));
 
-               configuration.setAttribute(
-                               IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS, vmArgs
-                                               .toString());
+               wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS,
+                               vmArgs.toString());
 
                // Program arguments
                StringBuffer progArgs = new StringBuffer("");
@@ -153,25 +234,41 @@ public class OsgiLaunchHelper implements OsgiLauncherConstants {
                        progArgs.append("-data ");
                        progArgs.append(surroundSpaces(dataDir));
 
-                       if (configuration.getAttribute(ATTR_CLEAR_DATA_DIRECTORY, false)) {
+                       if (wc.getAttribute(ATTR_CLEAR_DATA_DIRECTORY, false)) {
                                File dataDirFile = new File(dataDir);
                                deleteDir(dataDirFile);
                                dataDirFile.mkdirs();
                        }
                }
-               String additionalProgramArgs = configuration.getAttribute(
+               String additionalProgramArgs = wc.getAttribute(
                                OsgiLauncherConstants.ATTR_ADDITIONAL_PROGRAM_ARGS, "");
                progArgs.append(' ').append(additionalProgramArgs);
-               configuration.setAttribute(
+               wc.setAttribute(
                                IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS,
                                progArgs.toString());
        }
 
+       /** The launch configuration attribute to use for target bundles */
+       protected static String targetBundlesAttr(Boolean isEclipse) {
+               return isEclipse ? IPDELauncherConstants.SELECTED_TARGET_PLUGINS
+                               : IPDELauncherConstants.TARGET_BUNDLES;
+       }
+
+       /** The launch configuration attribute to use for workspace bundles */
+       protected static String workspaceBundlesAttr(Boolean isEclipse) {
+               return isEclipse ? IPDELauncherConstants.SELECTED_WORKSPACE_PLUGINS
+                               : IPDELauncherConstants.WORKSPACE_BUNDLES;
+       }
+
        /**
         * Interprets special properties and register the others as system
         * properties to append.
+        * 
+        * @return the application id defined by
+        *         {@link OsgiLauncherConstants#ECLIPSE_APPLICATION}, or null if not
+        *         found
         */
-       protected static void interpretProperties(Properties properties,
+       protected static String interpretProperties(Properties properties,
                        List<String> bundlesToStart,
                        Map<String, String> systemPropertiesToAppend) {
                String argeoOsgiStart = properties
@@ -182,6 +279,7 @@ public class OsgiLaunchHelper implements OsgiLauncherConstants {
                                bundlesToStart.add(st.nextToken());
                }
 
+               String applicationId = null;
                propKeys: for (Object keyObj : properties.keySet()) {
                        String key = keyObj.toString();
                        if (OsgiLauncherConstants.ARGEO_OSGI_START.equals(key))
@@ -192,10 +290,12 @@ public class OsgiLaunchHelper implements OsgiLauncherConstants {
                                continue propKeys;
                        else if (OsgiLauncherConstants.OSGI_BUNDLES.equals(key))
                                continue propKeys;
+                       else if (OsgiLauncherConstants.ECLIPSE_APPLICATION.equals(key))
+                               applicationId = properties.getProperty(key);
                        else
                                systemPropertiesToAppend.put(key, properties.getProperty(key));
                }
-
+               return applicationId;
        }
 
        /** Adds a regular system property. */
@@ -203,7 +303,6 @@ public class OsgiLaunchHelper implements OsgiLauncherConstants {
                        String value) {
                surroundSpaces(value);
                String str = "-D" + key + "=" + value;
-               // surroundSpaces(str);
                vmArgs.append(' ').append(str);
        }
 
@@ -227,8 +326,8 @@ public class OsgiLaunchHelper implements OsgiLauncherConstants {
                                        while (st.hasMoreTokens())
                                                tokens.add(st.nextToken());
                                        if (tokens.size() >= 2)
-                                               addVmSysProperty(vmArgs, tokens.get(0) + "."
-                                                               + tokens.get(1), vmInstall);
+                                               addVmSysProperty(vmArgs,
+                                                               tokens.get(0) + "." + tokens.get(1), vmInstall);
                                }
                        }
                }
@@ -354,7 +453,15 @@ public class OsgiLaunchHelper implements OsgiLauncherConstants {
                } catch (IOException e) {
                        working = "${workspace_loc}/../"; //$NON-NLS-1$
                }
-               File dir = new File(getSubstitutedString(working));
+               File dir;
+               try {
+                       dir = new File(getSubstitutedString(working));
+               } catch (Exception e) {
+                       // the directory was most probably deleted
+                       IFile propertiesFile = (IFile) configuration.getMappedResources()[0];
+                       working = findWorkingDirectory(propertiesFile);
+                       dir = new File(getSubstitutedString(working));
+               }
                if (!dir.exists())
                        dir.mkdirs();
                return dir;
index 0586caf9322ae85aa9ec3fbcfaf55105c667516e..8ada5272acaa5fc0508a1671b6859006243f4a6b 100644 (file)
@@ -5,14 +5,14 @@ import org.argeo.slc.ide.ui.SlcIdeUiPlugin;
 /** Constants used by OSGi launch. */
 public interface OsgiLauncherConstants {
 
+       public final static String OSGI_BUNDLES = "osgi.bundles";
+       public final static String ECLIPSE_APPLICATION = "eclipse.application";
+
        public final static String ARGEO_OSGI_START = "argeo.osgi.start";
        public final static String ARGEO_OSGI_BUNDLES = "argeo.osgi.bundles";
        public final static String ARGEO_OSGI_LOCATIONS = "argeo.osgi.locations";
        public final static String ARGEO_OSGI_DATA_DIR = "argeo.osgi.data.dir";
-       public final static String OSGI_BUNDLES = "osgi.bundles";
        public final static String VMS_PROPERTY_PREFIX = "slc.launch.vm";
-       // public final static String ATTR_DEFAULT_PROGRAM_ARGS = SlcIdeUiPlugin.ID
-       // + ".defaultProgramArgs";
 
        // Configuration
        public final static String ATTR_SYNC_BUNDLES = SlcIdeUiPlugin.ID