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,
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
--- /dev/null
+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));
+ // }
+ }
+
+}
--- /dev/null
+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);
+ }
+}
--- /dev/null
+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);
+ }
+
+}
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
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];
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);
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;
@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
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;
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());
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) {
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;
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;
* 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());
}
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("");
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
bundlesToStart.add(st.nextToken());
}
+ String applicationId = null;
propKeys: for (Object keyObj : properties.keySet()) {
String key = keyObj.toString();
if (OsgiLauncherConstants.ARGEO_OSGI_START.equals(key))
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. */
String value) {
surroundSpaces(value);
String str = "-D" + key + "=" + value;
- // surroundSpaces(str);
vmArgs.append(' ').append(str);
}
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);
}
}
}
} 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;
/** 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