Integrate with PDE
authorMathieu Baudier <mbaudier@argeo.org>
Wed, 29 Apr 2009 13:53:41 +0000 (13:53 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Wed, 29 Apr 2009 13:53:41 +0000 (13:53 +0000)
git-svn-id: https://svn.argeo.org/slc/trunk@2392 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

eclipse/plugins/org.argeo.slc.ui.launch/META-INF/MANIFEST.MF
eclipse/plugins/org.argeo.slc.ui.launch/plugin.xml
eclipse/plugins/org.argeo.slc.ui.launch/src/main/java/org/argeo/slc/ui/launch/osgi/SlcLaunchShortcut.java [new file with mode: 0644]

index dbcb4be548a4ec024134316e2eb6d088c08ba941..17591eb63d97a9b6ca93c61c6ca843a611103da2 100644 (file)
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
 Bundle-ManifestVersion: 2
 Bundle-Name: SLC UI Launch
 Bundle-SymbolicName: org.argeo.slc.ui.launch;singleton:=true
-Bundle-Version: 0.10.1.qualifier
+Bundle-Version: 0.11.3.D20090429_1550
 Bundle-Activator: org.argeo.slc.ui.launch.SlcUiLaunchPlugin
 Require-Bundle: org.eclipse.ui,
  org.eclipse.core.runtime,
@@ -14,7 +14,8 @@ Require-Bundle: org.eclipse.ui,
  org.eclipse.jdt.debug.ui,
  org.eclipse.ui.ide,
  org.eclipse.core.variables,
- org.eclipse.pde.build
+ org.eclipse.pde.build,
+ org.eclipse.pde.ui;bundle-version="3.4.0"
 Eclipse-LazyStart: true
 Bundle-RequiredExecutionEnvironment: J2SE-1.5
 Bundle-Vendor: Argeo
index da77f3a96ccefd4c7c8c83dbe9e28d30d9a3c730..f4bace663df11bc0df01750881b3ce6a67804524 100644 (file)
 </extension>\r
 <extension\r
       point="org.eclipse.debug.ui.launchShortcuts">\r
-   <shortcut
-         class="org.argeo.slc.ui.launch.script.SlcScriptLaunchShortcut"
-         icon="icons/slcScriptLaunch.gif"
-         id="org.argeo.slc.ui.launch.slcScriptLaunchShortcut"
-         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>
-   </shortcut>
+   <shortcut\r
+         class="org.argeo.slc.ui.launch.osgi.SlcLaunchShortcut"\r
+         icon="icons/slcScriptLaunch.gif"\r
+         id="org.argeo.slc.ui.launch.slcOsgiLaunchShortcut"\r
+         label="SLC"\r
+         modes="run,debug">\r
+    \r
+         <contextualLaunch>\r
+            <enablement>\r
+               <with variable="selection">\r
+                         <iterate>\r
+                               <and>\r
+                                       <test property="org.eclipse.debug.ui.projectNature" value="org.eclipse.pde.PluginNature"/>\r
+                                       <or>\r
+                                       <adapt type="org.eclipse.core.resources.IProject"/>\r
+                                       <test property="org.eclipse.debug.ui.matchesPattern" value="MANIFEST.MF"/>\r
+                                       </or>\r
+                                </and>\r
+                             </iterate>\r
+               </with>\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
+         modes="run,debug">\r
+    \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
+                </iterate>\r
+             </with>\r
+           </enablement>\r
+                </contextualLaunch>\r
+   </shortcut>\r
    <shortcut
          class="org.argeo.slc.ui.launch.script.SlcScriptLaunchShortcutWithDialog"
          icon="icons/slcScriptLaunch.gif"
              </with>
            </enablement>
                 </contextualLaunch>
-   </shortcut>
+   </shortcut>\r
+-->
 </extension>\r
+<!--\r
 <extension\r
       point="org.eclipse.debug.ui.launchConfigurationTabGroups">\r
    <launchConfigurationTabGroup\r
          type="org.argeo.slc.launch.slcScriptLaunchType">\r
    </launchConfigurationTabGroup>\r
 </extension>\r
-\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
          name="SLC">\r
    </page>\r
 </extension>\r
+-->\r
 <extension\r
       point="org.eclipse.debug.ui.launchConfigurationTypeImages">\r
    <launchConfigurationTypeImage\r
diff --git a/eclipse/plugins/org.argeo.slc.ui.launch/src/main/java/org/argeo/slc/ui/launch/osgi/SlcLaunchShortcut.java b/eclipse/plugins/org.argeo.slc.ui.launch/src/main/java/org/argeo/slc/ui/launch/osgi/SlcLaunchShortcut.java
new file mode 100644 (file)
index 0000000..e7764a7
--- /dev/null
@@ -0,0 +1,190 @@
+package org.argeo.slc.ui.launch.osgi;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.StringTokenizer;
+
+import org.argeo.slc.ui.launch.SlcUiLaunchPlugin;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.debug.core.ILaunchConfigurationType;
+import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.jface.dialogs.ErrorDialog;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+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.ui.launcher.IPDELauncherConstants;
+import org.eclipse.pde.ui.launcher.OSGiLaunchShortcut;
+import org.eclipse.swt.widgets.Shell;
+
+public class SlcLaunchShortcut extends OSGiLaunchShortcut {
+       private Boolean debug = false;
+
+       private String springOsgiExtenderId = "org.springframework.osgi.extender";
+       // private String slcAgentId = "org.argeo.slc.agent";
+       // private String osgiBootId = "org.argeo.slc.osgiboot";
+
+       private ISelection selection = null;
+       private StringBuffer name = null;
+
+       private final List<String> defaultBundlesToStart = new ArrayList<String>();
+       private List<String> bundlesToStart = new ArrayList<String>();
+
+       public SlcLaunchShortcut() {
+               super();
+               defaultBundlesToStart.add(springOsgiExtenderId);
+               // defaultBundlesToStart.add(slcAgentId);
+       }
+
+       @Override
+       public void launch(ISelection selection, String mode) {
+               this.selection = selection;
+               this.name = new StringBuffer();
+
+               bundlesToStart = new ArrayList<String>();
+               bundlesToStart.addAll(defaultBundlesToStart);
+               // Evaluate selection
+               if (selection != null) {
+                       addSelectedProjects(bundlesToStart);
+               }
+
+               super.launch(selection, mode);
+
+               // Reset
+               this.selection = null;
+               this.name = null;
+               bundlesToStart = null;
+       }
+
+       @Override
+       protected void initializeConfiguration(
+                       ILaunchConfigurationWorkingCopy configuration) {
+               try {
+                       super.initializeConfiguration(configuration);
+
+                       // Convert bundle lists
+                       String targetBundles = configuration.getAttribute(
+                                       IPDELauncherConstants.TARGET_BUNDLES, "");
+                       configuration.setAttribute(IPDELauncherConstants.TARGET_BUNDLES,
+                                       convertBundleList(bundlesToStart, targetBundles));
+
+                       String wkSpaceBundles = configuration.getAttribute(
+                                       IPDELauncherConstants.WORKSPACE_BUNDLES, "");
+                       configuration.setAttribute(IPDELauncherConstants.WORKSPACE_BUNDLES,
+                                       convertBundleList(bundlesToStart, wkSpaceBundles));
+
+                       // Update other default information
+                       configuration.setAttribute(
+                                       IPDELauncherConstants.DEFAULT_AUTO_START, false);
+
+               } catch (CoreException e) {
+                       Shell shell = SlcUiLaunchPlugin.getDefault().getWorkbench()
+                                       .getActiveWorkbenchWindow().getShell();
+                       ErrorDialog.openError(shell, "Error",
+                                       "Cannot execute SLC launch shortcut", e.getStatus());
+               }
+
+       }
+
+       protected String convertBundleList(List<String> bundlesToStart,
+                       String original) {
+               StringBuffer bufBundles = new StringBuffer(1024);
+               StringTokenizer stComa = new StringTokenizer(original, ",");
+               boolean first = true;
+               while (stComa.hasMoreTokens()) {
+                       if (first)
+                               first = false;
+                       else
+                               bufBundles.append(',');
+
+                       String tkComa = stComa.nextToken();
+                       int indexAt = tkComa.indexOf('@');
+                       boolean modified = false;
+                       if (indexAt >= 0) {
+                               String bundelId = tkComa.substring(0, indexAt);
+
+                               if (bundlesToStart.contains(bundelId)) {
+                                       bufBundles.append(bundelId).append('@').append(
+                                                       "default:true");
+                                       modified = true;
+                                       if (debug)
+                                               System.out.println("Will start " + bundelId);
+                               }
+                       }
+
+                       if (!modified)
+                               bufBundles.append(tkComa);
+               }
+               String output = bufBundles.toString();
+               return output;
+       }
+
+       protected void addSelectedProjects(List<String> bundlesToStart) {
+               Assert.isNotNull(selection);
+
+               Map<String, IPluginModelBase> bundleProjects = new HashMap<String, IPluginModelBase>();
+               for (IPluginModelBase modelBase : PluginRegistry.getWorkspaceModels()) {
+                       IProject bundleProject = modelBase.getUnderlyingResource()
+                                       .getProject();
+                       bundleProjects.put(bundleProject.getName(), modelBase);
+               }
+
+               IStructuredSelection sSelection = (IStructuredSelection) selection;
+               for (Iterator<?> it = sSelection.iterator(); it.hasNext();) {
+                       Object obj = it.next();
+                       if (obj instanceof IProject) {
+                               IProject project = (IProject) obj;
+                               if (bundleProjects.containsKey(project.getName())) {
+                                       IPluginModelBase modelBase = bundleProjects.get(project
+                                                       .getName());
+
+                                       BundleDescription bundleDescription = null;
+                                       if (modelBase.isFragmentModel()) {
+                                               BundleDescription[] hosts = modelBase
+                                                               .getBundleDescription().getHost().getHosts();
+                                               for (BundleDescription bd : hosts) {
+                                                       if (debug)
+                                                               System.out.println("Host for "
+                                                                               + modelBase.getBundleDescription()
+                                                                                               .getSymbolicName() + ": "
+                                                                               + bd.getSymbolicName());
+                                                       bundleDescription = bd;
+                                               }
+                                       } else {
+                                               bundleDescription = modelBase.getBundleDescription();
+                                       }
+
+                                       if (bundleDescription != null) {
+                                               String symbolicName = bundleDescription
+                                                               .getSymbolicName();
+                                               String bundleName = bundleDescription.getName();
+
+                                               bundlesToStart.add(symbolicName);
+
+                                               if (name.length() > 0)
+                                                       name.append(" ");
+                                               if (bundleName != null)
+                                                       name.append(bundleName);
+                                               else
+                                                       name.append(symbolicName);
+                                       }
+                               }
+                       }
+               }
+       }
+
+       @Override
+       protected String getName(ILaunchConfigurationType type) {
+               if (name != null)
+                       return name.toString();
+               else
+                       return "SLC";
+       }
+
+}