From: Mathieu Baudier Date: Fri, 9 Nov 2012 10:27:33 +0000 (+0000) Subject: Manage OSGi boot start level properties X-Git-Tag: argeo-slc-2.1.7~547 X-Git-Url: http://git.argeo.org/?a=commitdiff_plain;h=ef8ea7f8ddce3f1603d5e29b5e90c1cb02fd556e;hp=89f5c4b20ee5409d32534a3957543f1b4565da82;p=gpl%2Fargeo-slc.git Manage OSGi boot start level properties Fix issue with features by default. git-svn-id: https://svn.argeo.org/slc/trunk@5763 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- diff --git a/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/SlcIdeUiPlugin.java b/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/SlcIdeUiPlugin.java index 4e002587d..3570a6113 100644 --- a/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/SlcIdeUiPlugin.java +++ b/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/SlcIdeUiPlugin.java @@ -85,12 +85,11 @@ public class SlcIdeUiPlugin extends AbstractUIPlugin { if (source instanceof IProcess && event.getKind() == DebugEvent.TERMINATE) { IProcess process = (IProcess) source; - if (process == null) - continue; +// if (process == null) +// continue; ILaunch launch = process.getLaunch(); if (launch != null) refreshOsgiBootLaunch(launch); - } } } diff --git a/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/launch/osgi/OsgiBootLauncherTabGroup.java b/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/launch/osgi/OsgiBootLauncherTabGroup.java index 0195aa8ef..837a7c3bd 100644 --- a/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/launch/osgi/OsgiBootLauncherTabGroup.java +++ b/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/launch/osgi/OsgiBootLauncherTabGroup.java @@ -1,7 +1,5 @@ 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; @@ -19,27 +17,27 @@ public class OsgiBootLauncherTabGroup extends OSGiLauncherTabGroup { ILaunchConfigurationTab[] tabs = new ILaunchConfigurationTab[] { new OsgiBootMainTab(false), new BundlesTab() { - 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; - } +// 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); diff --git a/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/launch/osgi/OsgiBootMainTab.java b/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/launch/osgi/OsgiBootMainTab.java index 5e5ae5050..0bd533188 100644 --- a/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/launch/osgi/OsgiBootMainTab.java +++ b/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/launch/osgi/OsgiBootMainTab.java @@ -33,11 +33,11 @@ public class OsgiBootMainTab extends AbstractLaunchConfigurationTab implements private Text additionalProgramArgs; - private final Boolean isEclipse; + // private final Boolean isEclipse; public OsgiBootMainTab(Boolean isEclipse) { super(); - this.isEclipse = isEclipse; + // this.isEclipse = isEclipse; } public void createControl(Composite parent) { @@ -160,7 +160,7 @@ public class OsgiBootMainTab extends AbstractLaunchConfigurationTab implements addJvmPaths.getSelection()); // writeProperties(configuration); - OsgiLaunchHelper.updateLaunchConfiguration(configuration, isEclipse); + // OsgiLaunchHelper.updateLaunchConfiguration(configuration, isEclipse); } public void setDefaults(ILaunchConfigurationWorkingCopy configuration) { diff --git a/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/launch/osgi/OsgiLaunchHelper.java b/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/launch/osgi/OsgiLaunchHelper.java index 5d12fd8cb..347f26723 100644 --- a/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/launch/osgi/OsgiLaunchHelper.java +++ b/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/launch/osgi/OsgiLaunchHelper.java @@ -11,6 +11,7 @@ import java.util.Map; import java.util.Properties; import java.util.Set; import java.util.StringTokenizer; +import java.util.TreeMap; import java.util.TreeSet; import org.argeo.slc.ide.ui.SlcIdeUiPlugin; @@ -75,6 +76,10 @@ public class OsgiLaunchHelper implements OsgiLauncherConstants { IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS, ""); wc.setAttribute(ATTR_DEFAULT_VM_ARGS, originalVmArgs); + // do NOT use custom features (both must be set) + wc.setAttribute(IPDELauncherConstants.USE_CUSTOM_FEATURES, false); + wc.setAttribute(IPDELauncherConstants.USE_DEFAULT, true); + // clear config area by default wc.setAttribute(IPDELauncherConstants.CONFIG_CLEAR_AREA, true); } catch (CoreException e) { @@ -125,7 +130,7 @@ public class OsgiLaunchHelper implements OsgiLauncherConstants { Properties properties = readProperties(propertiesFile); // Extract information from the properties file - List bundlesToStart = new ArrayList(); + Map bundlesToStart = new TreeMap(); Map systemPropertiesToAppend = new HashMap(); String applicationId = interpretProperties(properties, bundlesToStart, systemPropertiesToAppend); @@ -167,7 +172,8 @@ public class OsgiLaunchHelper implements OsgiLauncherConstants { * UI. */ protected static void updateLaunchConfiguration( - ILaunchConfigurationWorkingCopy wc, List bundlesToStart, + ILaunchConfigurationWorkingCopy wc, + Map bundlesToStart, Map systemPropertiesToAppend, String dataDir, Boolean isEclipse) throws CoreException { // Convert bundle lists @@ -205,6 +211,10 @@ public class OsgiLaunchHelper implements OsgiLauncherConstants { // Update other default information wc.setAttribute(IPDELauncherConstants.DEFAULT_AUTO_START, false); + // do NOT use custom features (both must be set) + wc.setAttribute(IPDELauncherConstants.USE_CUSTOM_FEATURES, false); + wc.setAttribute(IPDELauncherConstants.USE_DEFAULT, true); + // VM arguments (system properties) String defaultVmArgs = wc.getAttribute( OsgiLauncherConstants.ATTR_DEFAULT_VM_ARGS, ""); @@ -273,21 +283,25 @@ public class OsgiLaunchHelper implements OsgiLauncherConstants { * found */ protected static String interpretProperties(Properties properties, - List bundlesToStart, + Map bundlesToStart, Map systemPropertiesToAppend) { - String argeoOsgiStart = properties - .getProperty(OsgiLauncherConstants.ARGEO_OSGI_START); - if (argeoOsgiStart != null) { - StringTokenizer st = new StringTokenizer(argeoOsgiStart, ","); - while (st.hasMoreTokens()) - bundlesToStart.add(st.nextToken()); - } + // String argeoOsgiStart = properties + // .getProperty(OsgiLauncherConstants.ARGEO_OSGI_START); + // if (argeoOsgiStart != null) { + // StringTokenizer st = new StringTokenizer(argeoOsgiStart, ","); + // while (st.hasMoreTokens()) + // bundlesToStart.add(st.nextToken()); + // } + + computeBundlesToStart(bundlesToStart, properties, null); String applicationId = null; propKeys: for (Object keyObj : properties.keySet()) { String key = keyObj.toString(); if (OsgiLauncherConstants.ARGEO_OSGI_START.equals(key)) continue propKeys; + if (key.startsWith(OsgiLauncherConstants.ARGEO_OSGI_START + ".")) + continue propKeys; else if (OsgiLauncherConstants.ARGEO_OSGI_BUNDLES.equals(key)) continue propKeys; else if (OsgiLauncherConstants.ARGEO_OSGI_LOCATIONS.equals(key)) @@ -357,9 +371,10 @@ public class OsgiLaunchHelper implements OsgiLauncherConstants { * Reformat the bundle list in order to reflect which bundles have to be * started. */ - protected static String convertBundleList(List bundlesToStart, - String original) { - debug("Original bundle list: " + original); + protected static String convertBundleList( + Map bundlesToStart, String original) { + if (debug) + debug("Original bundle list: " + original); StringTokenizer stComa = new StringTokenizer(original, ","); // sort by bundle symbolic name @@ -399,10 +414,14 @@ public class OsgiLaunchHelper implements OsgiLauncherConstants { else bufBundles.append(','); boolean modified = false; - if (bundlesToStart.contains(bundleId)) { - bufBundles.append(bundleId).append('@').append("default:true"); + if (bundlesToStart.containsKey(bundleId)) { + Integer startLevel = bundlesToStart.get(bundleId); + String startLevelStr = startLevel != null ? startLevel + .toString() : "default"; + bufBundles.append(bundleId).append('@').append(startLevelStr) + .append(":true"); modified = true; - debug("Will start " + bundleId); + debug("Will start " + bundleId + " at level " + startLevelStr); } if (!modified) @@ -448,6 +467,58 @@ public class OsgiLaunchHelper implements OsgiLauncherConstants { return props; } + /** Determines the start levels for the bundles */ + private static void computeBundlesToStart( + Map bundlesToStart, Properties properties, + Integer defaultStartLevel) { + + // default (and previously, only behaviour) + appendBundlesToStart(bundlesToStart, defaultStartLevel, + properties.getProperty(OsgiLauncherConstants.ARGEO_OSGI_START, + "")); + + // list argeo.osgi.start.* system properties + Iterator keys = properties.keySet().iterator(); + final String prefix = OsgiLauncherConstants.ARGEO_OSGI_START + "."; + while (keys.hasNext()) { + String key = (String) keys.next(); + if (key.startsWith(prefix)) { + Integer startLevel; + String suffix = key.substring(prefix.length()); + String[] tokens = suffix.split("\\."); + if (tokens.length > 0 && !tokens[0].trim().equals("")) + try { + // first token is start level + startLevel = new Integer(tokens[0]); + } catch (NumberFormatException e) { + startLevel = defaultStartLevel; + } + else + startLevel = defaultStartLevel; + + // append bundle names + String bundleNames = properties.getProperty(key); + appendBundlesToStart(bundlesToStart, startLevel, bundleNames); + } + } + } + + /** Append a comma-separated list of bundles to the start levels. */ + private static void appendBundlesToStart( + Map bundlesToStart, Integer startLevel, String str) { + if (str == null || str.trim().equals("")) + return; + + String[] bundleNames = str.split(","); + for (int i = 0; i < bundleNames.length; i++) { + if (bundleNames[i] != null && !bundleNames[i].trim().equals("")) + bundlesToStart.put(bundleNames[i], startLevel); + } + } + + /* + * HACKED UTILITIES + */ // Hacked from // org.eclipse.pde.internal.ui.launcher.LaunchArgumentsHelper.getWorkingDirectory(ILaunchConfiguration) private static File getWorkingDirectory(ILaunchConfiguration configuration)