From 331ed178b4b5ee277a5c62477d4892f8f089a8b9 Mon Sep 17 00:00:00 2001 From: Mathieu Baudier Date: Wed, 13 Apr 2011 15:45:38 +0000 Subject: [PATCH] NEW - bug 11: Introduce a simplified launch for RCP https://bugzilla.argeo.org/show_bug.cgi?id=11 git-svn-id: https://svn.argeo.org/slc/trunk@4432 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- .../org.argeo.slc.ide.ui/META-INF/MANIFEST.MF | 2 +- .../icons/eclipse-launch.gif | Bin 0 -> 578 bytes .../plugins/org.argeo.slc.ide.ui/plugin.xml | 131 ++++-------- .../osgi/EclipseBootLaunchConfiguration.java | 53 +++++ .../osgi/EclipseBootLaunchShortcut.java | 72 +++++++ .../osgi/EclipseBootLauncherTabGroup.java | 50 +++++ .../OsgiBootEquinoxLaunchConfiguration.java | 17 +- .../launch/osgi/OsgiBootLaunchShortcut.java | 84 ++------ .../launch/osgi/OsgiBootLauncherTabGroup.java | 23 +-- .../ide/ui/launch/osgi/OsgiBootMainTab.java | 21 +- .../ide/ui/launch/osgi/OsgiLaunchHelper.java | 187 ++++++++++++++---- .../ui/launch/osgi/OsgiLauncherConstants.java | 6 +- 12 files changed, 397 insertions(+), 249 deletions(-) create mode 100644 eclipse/plugins/org.argeo.slc.ide.ui/icons/eclipse-launch.gif create mode 100644 eclipse/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/launch/osgi/EclipseBootLaunchConfiguration.java create mode 100644 eclipse/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/launch/osgi/EclipseBootLaunchShortcut.java create mode 100644 eclipse/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/launch/osgi/EclipseBootLauncherTabGroup.java diff --git a/eclipse/plugins/org.argeo.slc.ide.ui/META-INF/MANIFEST.MF b/eclipse/plugins/org.argeo.slc.ide.ui/META-INF/MANIFEST.MF index 4ae043d40..5a2b5cbb6 100644 --- a/eclipse/plugins/org.argeo.slc.ide.ui/META-INF/MANIFEST.MF +++ b/eclipse/plugins/org.argeo.slc.ide.ui/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 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, diff --git a/eclipse/plugins/org.argeo.slc.ide.ui/icons/eclipse-launch.gif b/eclipse/plugins/org.argeo.slc.ide.ui/icons/eclipse-launch.gif new file mode 100644 index 0000000000000000000000000000000000000000..4b42e57020ca9dd072797121ce9b4dcdb1464ded GIT binary patch literal 578 zcmZ?wbhEHb6krfwc*ek>9X(Ss|A=PpLCw5_S~+{QviE3aZP&`$p_#r(3y4zIXeF=K zN?fWHw?HdqmR95xZ6J!6s2wpuJFNHj-~WIA{oj4}*RdymFTDKMxbJQI!T0^gKFmD* zdC8@(>#u*m@$UbRKmULI{r~;X|Ifew|NQ&^&%gigfBnDu`Ty&m|KI)k|Ksofmp}i% z`St(vpa0+g{{Qy(|F3`lbop8aYI7$zQ*RgjgybIAK1IOInS&*)1o-VIxWT_G175brT(OH!|o#EoOs*+|Nk=# zR-pKkg^_{5hd~GAKv0}8u+MMsX=-k1ZEJ587UbvS<>BUFXJKM&VU(1TmXVbc6PJ*m z+AJ(2z|hCV$;QgOsL4ZpblChx{8Jl4)%toicQ|?N=gb^s)m-<78X{9O>XKU42dBf2N$#V eOPI6CMxF@p;E^}XsBl&}F_WiDf|Zqt!5RQ(vci7= literal 0 HcmV?d00001 diff --git a/eclipse/plugins/org.argeo.slc.ide.ui/plugin.xml b/eclipse/plugins/org.argeo.slc.ide.ui/plugin.xml index ca6221abb..158d007d4 100644 --- a/eclipse/plugins/org.argeo.slc.ide.ui/plugin.xml +++ b/eclipse/plugins/org.argeo.slc.ide.ui/plugin.xml @@ -18,30 +18,14 @@ name="SLC"> - - @@ -56,48 +40,26 @@ - @@ -108,6 +70,13 @@ modes="run, debug" sourceLocatorId="org.eclipse.pde.ui.launcher.PDESourceLookupDirector" sourcePathComputerId="org.eclipse.jdt.launching.sourceLookup.javaSourcePathComputer"/> + @@ -116,6 +85,11 @@ class="org.argeo.slc.ide.ui.launch.osgi.OsgiBootLauncherTabGroup" id="org.argeo.slc.ide.ui.OsgiBootLauncherTabGroup"> + + @@ -124,47 +98,10 @@ configTypeID="org.argeo.slc.ide.ui.OsgiBootEquinoxLauncher" id="org.argeo.slc.ide.ui.OsgiBootEquinoxLauncherImage"> + + - - - diff --git a/eclipse/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/launch/osgi/EclipseBootLaunchConfiguration.java b/eclipse/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/launch/osgi/EclipseBootLaunchConfiguration.java new file mode 100644 index 000000000..6611f209b --- /dev/null +++ b/eclipse/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/launch/osgi/EclipseBootLaunchConfiguration.java @@ -0,0 +1,53 @@ +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)); + // } + } + +} diff --git a/eclipse/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/launch/osgi/EclipseBootLaunchShortcut.java b/eclipse/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/launch/osgi/EclipseBootLaunchShortcut.java new file mode 100644 index 000000000..aa7f8618b --- /dev/null +++ b/eclipse/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/launch/osgi/EclipseBootLaunchShortcut.java @@ -0,0 +1,72 @@ +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); + } +} diff --git a/eclipse/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/launch/osgi/EclipseBootLauncherTabGroup.java b/eclipse/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/launch/osgi/EclipseBootLauncherTabGroup.java new file mode 100644 index 000000000..7d77ce624 --- /dev/null +++ b/eclipse/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/launch/osgi/EclipseBootLauncherTabGroup.java @@ -0,0 +1,50 @@ +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); + } + +} diff --git a/eclipse/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/launch/osgi/OsgiBootEquinoxLaunchConfiguration.java b/eclipse/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/launch/osgi/OsgiBootEquinoxLaunchConfiguration.java index 1f39aac0a..19cdee12b 100644 --- a/eclipse/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/launch/osgi/OsgiBootEquinoxLaunchConfiguration.java +++ b/eclipse/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/launch/osgi/OsgiBootEquinoxLaunchConfiguration.java @@ -8,8 +8,7 @@ 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.ui.launcher.EquinoxLaunchConfiguration; -import org.eclipse.pde.ui.launcher.IPDELauncherConstants; +import org.eclipse.pde.launching.EquinoxLaunchConfiguration; /** OSGiBoot launch configuration. */ public class OsgiBootEquinoxLaunchConfiguration extends @@ -22,12 +21,12 @@ 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]; @@ -40,7 +39,7 @@ public class OsgiBootEquinoxLaunchConfiguration extends 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); diff --git a/eclipse/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/launch/osgi/OsgiBootLaunchShortcut.java b/eclipse/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/launch/osgi/OsgiBootLaunchShortcut.java index b1994e814..b73b612a3 100644 --- a/eclipse/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/launch/osgi/OsgiBootLaunchShortcut.java +++ b/eclipse/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/launch/osgi/OsgiBootLaunchShortcut.java @@ -3,25 +3,17 @@ package org.argeo.slc.ide.ui.launch.osgi; 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; @@ -34,88 +26,38 @@ public class OsgiBootLaunchShortcut extends OSGiLaunchShortcut implements @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 diff --git a/eclipse/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/launch/osgi/OsgiBootLauncherTabGroup.java b/eclipse/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/launch/osgi/OsgiBootLauncherTabGroup.java index de3b20caf..0195aa8ef 100644 --- a/eclipse/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/launch/osgi/OsgiBootLauncherTabGroup.java +++ b/eclipse/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/launch/osgi/OsgiBootLauncherTabGroup.java @@ -11,32 +11,13 @@ import org.eclipse.pde.ui.launcher.OSGiLauncherTabGroup; 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; diff --git a/eclipse/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/launch/osgi/OsgiBootMainTab.java b/eclipse/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/launch/osgi/OsgiBootMainTab.java index cbe41cdc9..d0a76ce9d 100644 --- a/eclipse/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/launch/osgi/OsgiBootMainTab.java +++ b/eclipse/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/launch/osgi/OsgiBootMainTab.java @@ -33,6 +33,13 @@ public class OsgiBootMainTab extends AbstractLaunchConfigurationTab implements 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()); @@ -136,20 +143,20 @@ public class OsgiBootMainTab extends AbstractLaunchConfigurationTab implements 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) { diff --git a/eclipse/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/launch/osgi/OsgiLaunchHelper.java b/eclipse/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/launch/osgi/OsgiLaunchHelper.java index ee01f02a2..2e55f87f3 100644 --- a/eclipse/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/launch/osgi/OsgiLaunchHelper.java +++ b/eclipse/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/launch/osgi/OsgiLaunchHelper.java @@ -13,10 +13,12 @@ import java.util.StringTokenizer; 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; @@ -35,41 +37,120 @@ 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.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 bundlesToStart = new ArrayList(); Map systemPropertiesToAppend = new HashMap(); - 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; @@ -82,14 +163,13 @@ public class OsgiLaunchHelper implements OsgiLauncherConstants { * UI. */ protected static void updateLaunchConfiguration( - ILaunchConfigurationWorkingCopy configuration, - List bundlesToStart, - Map systemPropertiesToAppend, String dataDir) - throws CoreException { + ILaunchConfigurationWorkingCopy wc, List bundlesToStart, + Map 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()); @@ -108,44 +188,45 @@ public class OsgiLaunchHelper implements OsgiLauncherConstants { } 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(""); @@ -153,25 +234,41 @@ public class OsgiLaunchHelper implements OsgiLauncherConstants { 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 bundlesToStart, Map systemPropertiesToAppend) { String argeoOsgiStart = properties @@ -182,6 +279,7 @@ public class OsgiLaunchHelper implements OsgiLauncherConstants { bundlesToStart.add(st.nextToken()); } + String applicationId = null; propKeys: for (Object keyObj : properties.keySet()) { String key = keyObj.toString(); if (OsgiLauncherConstants.ARGEO_OSGI_START.equals(key)) @@ -192,10 +290,12 @@ public class OsgiLaunchHelper implements OsgiLauncherConstants { 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. */ @@ -203,7 +303,6 @@ public class OsgiLaunchHelper implements OsgiLauncherConstants { String value) { surroundSpaces(value); String str = "-D" + key + "=" + value; - // surroundSpaces(str); vmArgs.append(' ').append(str); } @@ -227,8 +326,8 @@ public class OsgiLaunchHelper implements OsgiLauncherConstants { 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); } } } @@ -354,7 +453,15 @@ public class OsgiLaunchHelper implements OsgiLauncherConstants { } 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; diff --git a/eclipse/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/launch/osgi/OsgiLauncherConstants.java b/eclipse/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/launch/osgi/OsgiLauncherConstants.java index 0586caf93..8ada5272a 100644 --- a/eclipse/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/launch/osgi/OsgiLauncherConstants.java +++ b/eclipse/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/launch/osgi/OsgiLauncherConstants.java @@ -5,14 +5,14 @@ import org.argeo.slc.ide.ui.SlcIdeUiPlugin; /** 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 -- 2.39.2