1 package org
.argeo
.slc
.ui
.launch
.osgi
;
3 import java
.util
.ArrayList
;
4 import java
.util
.HashMap
;
5 import java
.util
.Iterator
;
8 import java
.util
.StringTokenizer
;
10 import org
.argeo
.slc
.ui
.launch
.SlcUiLaunchPlugin
;
11 import org
.eclipse
.core
.resources
.IProject
;
12 import org
.eclipse
.core
.runtime
.Assert
;
13 import org
.eclipse
.core
.runtime
.CoreException
;
14 import org
.eclipse
.debug
.core
.ILaunchConfigurationType
;
15 import org
.eclipse
.debug
.core
.ILaunchConfigurationWorkingCopy
;
16 import org
.eclipse
.jface
.dialogs
.ErrorDialog
;
17 import org
.eclipse
.jface
.viewers
.ISelection
;
18 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
19 import org
.eclipse
.osgi
.service
.resolver
.BundleDescription
;
20 import org
.eclipse
.pde
.core
.plugin
.IPluginModelBase
;
21 import org
.eclipse
.pde
.core
.plugin
.PluginRegistry
;
22 import org
.eclipse
.pde
.ui
.launcher
.IPDELauncherConstants
;
23 import org
.eclipse
.pde
.ui
.launcher
.OSGiLaunchShortcut
;
24 import org
.eclipse
.swt
.widgets
.Shell
;
26 public class SlcLaunchShortcut
extends OSGiLaunchShortcut
{
27 private Boolean debug
= false;
29 private String springOsgiExtenderId
= "org.springframework.osgi.extender";
30 private String slcSupportEquinoxId
= "org.argeo.slc.support.equinox";
31 // private String slcAgentId = "org.argeo.slc.agent";
32 // private String osgiBootId = "org.argeo.slc.osgiboot";
34 private ISelection selection
= null;
35 private StringBuffer name
= null;
37 private final List
<String
> defaultBundlesToStart
= new ArrayList
<String
>();
38 private List
<String
> bundlesToStart
= new ArrayList
<String
>();
40 public SlcLaunchShortcut() {
42 defaultBundlesToStart
.add(springOsgiExtenderId
);
43 defaultBundlesToStart
.add(slcSupportEquinoxId
);
44 // defaultBundlesToStart.add(slcAgentId);
47 public void launch(ISelection selection
, String mode
) {
48 this.selection
= selection
;
49 this.name
= new StringBuffer();
51 bundlesToStart
= new ArrayList
<String
>();
52 bundlesToStart
.addAll(defaultBundlesToStart
);
54 if (selection
!= null) {
55 addSelectedProjects(bundlesToStart
);
58 super.launch(selection
, mode
);
61 this.selection
= null;
63 bundlesToStart
= null;
66 protected void initializeConfiguration(
67 ILaunchConfigurationWorkingCopy configuration
) {
69 super.initializeConfiguration(configuration
);
71 // Convert bundle lists
72 String targetBundles
= configuration
.getAttribute(
73 IPDELauncherConstants
.TARGET_BUNDLES
, "");
74 configuration
.setAttribute(IPDELauncherConstants
.TARGET_BUNDLES
,
75 convertBundleList(bundlesToStart
, targetBundles
));
77 String wkSpaceBundles
= configuration
.getAttribute(
78 IPDELauncherConstants
.WORKSPACE_BUNDLES
, "");
79 configuration
.setAttribute(IPDELauncherConstants
.WORKSPACE_BUNDLES
,
80 convertBundleList(bundlesToStart
, wkSpaceBundles
));
82 // Update other default information
83 configuration
.setAttribute(
84 IPDELauncherConstants
.DEFAULT_AUTO_START
, false);
86 } catch (CoreException e
) {
87 Shell shell
= SlcUiLaunchPlugin
.getDefault().getWorkbench()
88 .getActiveWorkbenchWindow().getShell();
89 ErrorDialog
.openError(shell
, "Error",
90 "Cannot execute SLC launch shortcut", e
.getStatus());
95 protected String
convertBundleList(List
<String
> bundlesToStart
,
97 StringBuffer bufBundles
= new StringBuffer(1024);
98 StringTokenizer stComa
= new StringTokenizer(original
, ",");
100 while (stComa
.hasMoreTokens()) {
104 bufBundles
.append(',');
106 String tkComa
= stComa
.nextToken();
107 int indexAt
= tkComa
.indexOf('@');
108 boolean modified
= false;
110 String bundelId
= tkComa
.substring(0, indexAt
);
112 if (bundlesToStart
.contains(bundelId
)) {
113 bufBundles
.append(bundelId
).append('@').append(
117 System
.out
.println("Will start " + bundelId
);
122 bufBundles
.append(tkComa
);
124 String output
= bufBundles
.toString();
128 protected void addSelectedProjects(List
<String
> bundlesToStart
) {
129 Assert
.isNotNull(selection
);
131 Map
<String
, IPluginModelBase
> bundleProjects
= new HashMap
<String
, IPluginModelBase
>();
132 for (IPluginModelBase modelBase
: PluginRegistry
.getWorkspaceModels()) {
133 IProject bundleProject
= modelBase
.getUnderlyingResource()
135 bundleProjects
.put(bundleProject
.getName(), modelBase
);
138 IStructuredSelection sSelection
= (IStructuredSelection
) selection
;
139 for (Iterator
<?
> it
= sSelection
.iterator(); it
.hasNext();) {
140 Object obj
= it
.next();
141 if (obj
instanceof IProject
) {
142 IProject project
= (IProject
) obj
;
143 if (bundleProjects
.containsKey(project
.getName())) {
144 IPluginModelBase modelBase
= bundleProjects
.get(project
147 BundleDescription bundleDescription
= null;
148 if (modelBase
.isFragmentModel()) {
149 BundleDescription
[] hosts
= modelBase
150 .getBundleDescription().getHost().getHosts();
151 for (BundleDescription bd
: hosts
) {
153 System
.out
.println("Host for "
154 + modelBase
.getBundleDescription()
155 .getSymbolicName() + ": "
156 + bd
.getSymbolicName());
157 bundleDescription
= bd
;
160 bundleDescription
= modelBase
.getBundleDescription();
163 if (bundleDescription
!= null) {
164 String symbolicName
= bundleDescription
166 String bundleName
= bundleDescription
.getName();
168 bundlesToStart
.add(symbolicName
);
170 if (name
.length() > 0)
172 if (bundleName
!= null)
173 name
.append(bundleName
);
175 name
.append(symbolicName
);
182 protected String
getName(ILaunchConfigurationType type
) {
183 if (name
!= null && !name
.toString().trim().equals(""))
184 return name
.toString();