]> git.argeo.org Git - gpl/argeo-slc.git/blob - eclipse/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/launch/osgi/SlcLaunchShortcut.java
Introduce OSGiBoot launch
[gpl/argeo-slc.git] / eclipse / plugins / org.argeo.slc.ide.ui / src / main / java / org / argeo / slc / ide / ui / launch / osgi / SlcLaunchShortcut.java
1 package org.argeo.slc.ide.ui.launch.osgi;
2
3 import java.util.ArrayList;
4 import java.util.HashMap;
5 import java.util.Iterator;
6 import java.util.List;
7 import java.util.Map;
8
9 import org.eclipse.core.resources.IProject;
10 import org.eclipse.core.runtime.Assert;
11 import org.eclipse.jface.viewers.ISelection;
12 import org.eclipse.jface.viewers.IStructuredSelection;
13 import org.eclipse.osgi.service.resolver.BundleDescription;
14 import org.eclipse.pde.core.plugin.IPluginModelBase;
15 import org.eclipse.pde.core.plugin.PluginRegistry;
16
17 public class SlcLaunchShortcut extends AbstractOsgiLaunchShortcut {
18 private Boolean debug = false;
19
20 private String springOsgiExtenderId = "org.springframework.osgi.extender";
21 private String slcSupportEquinoxId = "org.argeo.slc.support.equinox";
22 // private String slcAgentId = "org.argeo.slc.agent";
23 // private String osgiBootId = "org.argeo.slc.osgiboot";
24
25 private ISelection selection = null;
26
27 private final List<String> defaultBundlesToStart = new ArrayList<String>();
28 public SlcLaunchShortcut() {
29 super();
30 defaultBundlesToStart.add(springOsgiExtenderId);
31 defaultBundlesToStart.add(slcSupportEquinoxId);
32 // defaultBundlesToStart.add(slcAgentId);
33 }
34
35 public void launch(ISelection selection, String mode) {
36 this.selection = selection;
37 this.name = new StringBuffer();
38
39 bundlesToStart = new ArrayList<String>();
40 bundlesToStart.addAll(defaultBundlesToStart);
41 // Evaluate selection
42 if (selection != null) {
43 addSelectedProjects(bundlesToStart);
44 }
45
46 super.launch(selection, mode);
47
48 // Reset
49 this.selection = null;
50 this.name = null;
51 bundlesToStart = null;
52 }
53
54 protected void addSelectedProjects(List<String> bundlesToStart) {
55 Assert.isNotNull(selection);
56
57 Map<String, IPluginModelBase> bundleProjects = new HashMap<String, IPluginModelBase>();
58 for (IPluginModelBase modelBase : PluginRegistry.getWorkspaceModels()) {
59 IProject bundleProject = modelBase.getUnderlyingResource()
60 .getProject();
61 bundleProjects.put(bundleProject.getName(), modelBase);
62 }
63
64 IStructuredSelection sSelection = (IStructuredSelection) selection;
65 for (Iterator<?> it = sSelection.iterator(); it.hasNext();) {
66 Object obj = it.next();
67 if (obj instanceof IProject) {
68 IProject project = (IProject) obj;
69 if (bundleProjects.containsKey(project.getName())) {
70 IPluginModelBase modelBase = bundleProjects.get(project
71 .getName());
72
73 BundleDescription bundleDescription = null;
74 if (modelBase.isFragmentModel()) {
75 BundleDescription[] hosts = modelBase
76 .getBundleDescription().getHost().getHosts();
77 for (BundleDescription bd : hosts) {
78 if (debug)
79 System.out.println("Host for "
80 + modelBase.getBundleDescription()
81 .getSymbolicName() + ": "
82 + bd.getSymbolicName());
83 bundleDescription = bd;
84 }
85 } else {
86 bundleDescription = modelBase.getBundleDescription();
87 }
88
89 if (bundleDescription != null) {
90 String symbolicName = bundleDescription
91 .getSymbolicName();
92 String bundleName = bundleDescription.getName();
93
94 bundlesToStart.add(symbolicName);
95
96 if (name.length() > 0)
97 name.append(" ");
98 if (bundleName != null)
99 name.append(bundleName);
100 else
101 name.append(symbolicName);
102 }
103 }
104 }
105 }
106 }
107 }