From: Mathieu Baudier Date: Thu, 6 May 2010 07:47:25 +0000 (+0000) Subject: Additional launch configuration options X-Git-Tag: argeo-slc-2.1.7~1312 X-Git-Url: http://git.argeo.org/?a=commitdiff_plain;h=1ff8b2dd13c5a2472960bcde78946267da351013;hp=9b15274f8e1425882bee220a1dd7f9ab9e5aba6f;p=gpl%2Fargeo-slc.git Additional launch configuration options git-svn-id: https://svn.argeo.org/slc/trunk@3556 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- diff --git a/eclipse/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/SlcIdeUiPlugin.java b/eclipse/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/SlcIdeUiPlugin.java index 67374bf08..088b4f48b 100644 --- a/eclipse/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/SlcIdeUiPlugin.java +++ b/eclipse/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/SlcIdeUiPlugin.java @@ -70,30 +70,43 @@ public class SlcIdeUiPlugin extends AbstractUIPlugin { protected static class DebugEventListener implements IDebugEventSetListener { public void handleDebugEvents(DebugEvent[] events) { + if (events == null) + return; + for (int i = 0; i < events.length; i++) { DebugEvent event = events[i]; + if (event == null) + continue; Object source = event.getSource(); if (source instanceof IProcess && event.getKind() == DebugEvent.TERMINATE) { IProcess process = (IProcess) source; + if (process == null) + continue; ILaunch launch = process.getLaunch(); - if (launch != null) { + if (launch != null) refreshOsgiBootLaunch(launch); - } + } } } protected void refreshOsgiBootLaunch(ILaunch launch) { try { + if (launch == null) + return; IResource[] resources = launch.getLaunchConfiguration() .getMappedResources(); + if (resources == null) + return; if (resources.length > 0) { IResource propertiesFile = resources[0]; + if (propertiesFile.getParent() == null) + return; propertiesFile.getParent().refreshLocal( IResource.DEPTH_INFINITE, null); -// System.out.println("Refreshed " -// + propertiesFile.getParent()); + // System.out.println("Refreshed " + // + propertiesFile.getParent()); } } catch (CoreException e) { e.printStackTrace(); 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 95d32eb95..c52c767cc 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 @@ -23,6 +23,10 @@ import org.eclipse.swt.widgets.Text; public class OsgiBootMainTab extends AbstractLaunchConfigurationTab implements OsgiLauncherConstants { private Listener listener = new Listener(); + + private Button syncBundles; + private Button clearDataDirectory; + private Button addJvmPaths; private Text additionalVmArgs; @@ -32,12 +36,32 @@ public class OsgiBootMainTab extends AbstractLaunchConfigurationTab implements Composite container = new Composite(parent, SWT.NONE); container.setLayout(new GridLayout()); container.setLayoutData(new GridData(GridData.FILL_BOTH)); + + createGeneral(container); createAdditionalProgramArgs(container); createAdditionalVmArgumentBlock(container); Dialog.applyDialogFont(container); setControl(container); } + protected void createGeneral(Composite parent) { + Group container = new Group(parent, SWT.NONE); + container.setText("General"); + GridLayout layout = new GridLayout(); + layout.numColumns = 2; + container.setLayout(layout); + container.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + + syncBundles = new Button(container, SWT.CHECK); + syncBundles.addSelectionListener(listener); + new Label(container, SWT.NONE) + .setText("Always keep bundle in line with the target platform"); + clearDataDirectory = new Button(container, SWT.CHECK); + clearDataDirectory.addSelectionListener(listener); + new Label(container, SWT.NONE) + .setText("Clear data directory before launch"); + } + protected void createAdditionalProgramArgs(Composite parent) { Group container = new Group(parent, SWT.NONE); container.setText("Additional Program Arguments"); @@ -92,6 +116,11 @@ public class OsgiBootMainTab extends AbstractLaunchConfigurationTab implements public void initializeFrom(ILaunchConfiguration configuration) { // System.out.println("initializeFrom"); try { + syncBundles.setSelection(configuration.getAttribute( + ATTR_SYNC_BUNDLES, true)); + clearDataDirectory.setSelection(configuration.getAttribute( + ATTR_CLEAR_DATA_DIRECTORY, false)); + additionalProgramArgs.setText(configuration.getAttribute( ATTR_ADDITIONAL_PROGRAM_ARGS, "")); addJvmPaths.setSelection(configuration.getAttribute( @@ -106,6 +135,11 @@ 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_CLEAR_DATA_DIRECTORY, + clearDataDirectory.getSelection()); + configuration.setAttribute(ATTR_ADDITIONAL_PROGRAM_ARGS, additionalProgramArgs.getText()); configuration.setAttribute(ATTR_ADDITIONAL_VM_ARGS, additionalVmArgs @@ -119,6 +153,8 @@ public class OsgiBootMainTab extends AbstractLaunchConfigurationTab implements public void setDefaults(ILaunchConfigurationWorkingCopy configuration) { // System.out.println("setDefaults"); + configuration.setAttribute(ATTR_SYNC_BUNDLES, true); + configuration.setAttribute(ATTR_CLEAR_DATA_DIRECTORY, false); configuration.setAttribute(ATTR_ADD_JVM_PATHS, false); configuration.setAttribute(ATTR_ADDITIONAL_VM_ARGS, "-Xmx128m"); configuration.setAttribute(ATTR_ADDITIONAL_PROGRAM_ARGS, "-console"); 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 31aaf136f..3646a7b6d 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 @@ -26,6 +26,8 @@ import org.eclipse.jdt.launching.IVMInstall2; import org.eclipse.jdt.launching.IVMInstallType; import org.eclipse.jdt.launching.JavaRuntime; import org.eclipse.jface.dialogs.ErrorDialog; +import org.eclipse.pde.core.plugin.IPluginModelBase; +import org.eclipse.pde.core.plugin.PluginRegistry; import org.eclipse.pde.ui.launcher.IPDELauncherConstants; import org.eclipse.swt.widgets.Display; @@ -68,8 +70,17 @@ public class OsgiLaunchHelper implements OsgiLauncherConstants { Map systemPropertiesToAppend, String dataDir) throws CoreException { // Convert bundle lists - String targetBundles = configuration.getAttribute( - IPDELauncherConstants.TARGET_BUNDLES, ""); + final String targetBundles; + if (configuration.getAttribute(ATTR_SYNC_BUNDLES, true)) { + StringBuffer buf = new StringBuffer(); + for (IPluginModelBase model : PluginRegistry.getExternalModels()) { + buf.append(model.getBundleDescription().getSymbolicName()); + buf.append(','); + } + targetBundles = buf.toString(); + } else + targetBundles = configuration.getAttribute( + IPDELauncherConstants.TARGET_BUNDLES, ""); configuration.setAttribute(IPDELauncherConstants.TARGET_BUNDLES, convertBundleList(bundlesToStart, targetBundles)); @@ -111,6 +122,12 @@ public class OsgiLaunchHelper implements OsgiLauncherConstants { if (dataDir != null) { progArgs.append("-data "); progArgs.append(surroundSpaces(dataDir)); + + if (configuration.getAttribute(ATTR_CLEAR_DATA_DIRECTORY, false)) { + File dataDirFile = new File(dataDir); + deleteDir(dataDirFile); + dataDirFile.mkdirs(); + } } String additionalProgramArgs = configuration.getAttribute( OsgiLauncherConstants.ATTR_ADDITIONAL_PROGRAM_ARGS, ""); @@ -120,6 +137,17 @@ public class OsgiLaunchHelper implements OsgiLauncherConstants { progArgs.toString()); } + private static void deleteDir(File dir) { + File[] files = dir.listFiles(); + for (File file : files) { + if (file.isDirectory()) + deleteDir(file); + else + file.delete(); + } + dir.delete(); + } + protected static void addVms(StringBuffer vmArgs) { addVmSysProperty(vmArgs, "default", JavaRuntime.getDefaultVMInstall()); IVMInstallType[] vmTypes = JavaRuntime.getVMInstallTypes(); @@ -180,6 +208,12 @@ public class OsgiLaunchHelper implements OsgiLauncherConstants { bufBundles.append(','); String bundleId = stComa.nextToken(); + if (bundleId.indexOf('*') >= 0) + throw new RuntimeException( + "Bundle id " + + bundleId + + " not properly formatted, clean your workspace projects"); + int indexAt = bundleId.indexOf('@'); boolean modified = false; if (indexAt >= 0) { 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 208f384ae..7a2d531b6 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 @@ -14,6 +14,11 @@ public interface OsgiLauncherConstants { // + ".defaultProgramArgs"; // Configuration + public final static String ATTR_SYNC_BUNDLES = SlcIdeUiPlugin.ID + + ".syncBundles"; + public final static String ATTR_CLEAR_DATA_DIRECTORY = SlcIdeUiPlugin.ID + + ".clearDataDirectory"; + public final static String ATTR_DEFAULT_VM_ARGS = SlcIdeUiPlugin.ID + ".defaultVmArgs"; public final static String ATTR_ADDITIONAL_PROGRAM_ARGS = SlcIdeUiPlugin.ID