From: Mathieu Baudier Date: Tue, 20 Apr 2010 15:50:13 +0000 (+0000) Subject: Clean up code X-Git-Tag: argeo-slc-2.1.7~1357 X-Git-Url: http://git.argeo.org/?a=commitdiff_plain;h=16016e4621c540a86bbc40c040bc9d528a5b573d;p=gpl%2Fargeo-slc.git Clean up code git-svn-id: https://svn.argeo.org/slc/trunk@3481 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 2c288cff5..67374bf08 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 @@ -2,6 +2,13 @@ package org.argeo.slc.ide.ui; import java.net.URL; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.debug.core.DebugEvent; +import org.eclipse.debug.core.DebugPlugin; +import org.eclipse.debug.core.IDebugEventSetListener; +import org.eclipse.debug.core.ILaunch; +import org.eclipse.debug.core.model.IProcess; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.resource.ImageRegistry; import org.eclipse.swt.graphics.Image; @@ -29,6 +36,8 @@ public class SlcIdeUiPlugin extends AbstractUIPlugin { public void start(BundleContext context) throws Exception { super.start(context); plugin = this; + DebugPlugin.getDefault() + .addDebugEventListener(new DebugEventListener()); } @Override @@ -58,4 +67,40 @@ public class SlcIdeUiPlugin extends AbstractUIPlugin { } return image; } + + protected static class DebugEventListener implements IDebugEventSetListener { + public void handleDebugEvents(DebugEvent[] events) { + for (int i = 0; i < events.length; i++) { + DebugEvent event = events[i]; + Object source = event.getSource(); + if (source instanceof IProcess + && event.getKind() == DebugEvent.TERMINATE) { + IProcess process = (IProcess) source; + ILaunch launch = process.getLaunch(); + if (launch != null) { + refreshOsgiBootLaunch(launch); + } + } + } + } + + protected void refreshOsgiBootLaunch(ILaunch launch) { + try { + IResource[] resources = launch.getLaunchConfiguration() + .getMappedResources(); + if (resources.length > 0) { + IResource propertiesFile = resources[0]; + propertiesFile.getParent().refreshLocal( + IResource.DEPTH_INFINITE, null); +// 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/AbstractOsgiLaunchShortcut.java b/eclipse/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/launch/osgi/AbstractOsgiLaunchShortcut.java index c9337d85f..08c06e09d 100644 --- a/eclipse/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/launch/osgi/AbstractOsgiLaunchShortcut.java +++ b/eclipse/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/launch/osgi/AbstractOsgiLaunchShortcut.java @@ -45,12 +45,12 @@ public abstract class AbstractOsgiLaunchShortcut extends OSGiLaunchShortcut { .getAttribute( IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS, "")); - String defaultProgArgs = configuration.getAttribute( - IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, - ""); - // configuration.setAttribute( - // OsgiLauncherConstants.ATTR_DEFAULT_PROGRAM_ARGS, - // defaultProgArgs); +// String defaultProgArgs = configuration.getAttribute( +// IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, +// ""); +// configuration.setAttribute( +// OsgiLauncherConstants.ATTR_DEFAULT_PROGRAM_ARGS, +// defaultProgArgs); configuration.setAttribute( IJavaLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, 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 c00b30752..853775ac6 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 @@ -19,15 +19,10 @@ public class OsgiBootEquinoxLaunchConfiguration extends public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException { super.launch(configuration, mode, launch, monitor); - - // TODO: add launch listener to be notified when is terminated and - // refresh resources - - IFile propertiesFile = (IFile) configuration.getMappedResources()[0]; + // Refresh resources before launching + final IFile propertiesFile = (IFile) configuration.getMappedResources()[0]; propertiesFile.getParent().refreshLocal(IResource.DEPTH_INFINITE, monitor); - // propertiesFile.getProject().refreshLocal(IResource.DEPTH_INFINITE, - // monitor); } @Override 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 3dbdbb19d..097adc836 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 @@ -1,10 +1,6 @@ package org.argeo.slc.ide.ui.launch.osgi; -import java.util.ArrayList; -import java.util.HashMap; import java.util.Iterator; -import java.util.List; -import java.util.Map; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFolder; @@ -12,6 +8,7 @@ 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; @@ -26,10 +23,8 @@ import org.eclipse.swt.widgets.Shell; public class OsgiBootLaunchShortcut extends OSGiLaunchShortcut implements OsgiLauncherConstants { - protected StringBuffer name = null; - protected IFile propertiesFile = null; - protected List bundlesToStart = new ArrayList(); - protected Map systemPropertiesToAppend = new HashMap(); + private StringBuffer name = null; + private IFile propertiesFile = null; @Override protected String getLaunchConfigurationTypeName() { @@ -50,23 +45,7 @@ public class OsgiBootLaunchShortcut extends OSGiLaunchShortcut implements name = new StringBuffer(extractName(propertiesFile)); - // Properties properties = null; - // try { - // properties = OsgiLaunchHelper.readProperties(propertiesFile); - // } catch (CoreException e) { - // ErrorDialog.openError(Display.getCurrent().getActiveShell(), - // "Error", "Cannot execute launch shortcut", e.getStatus()); - // return; - // } - // - // OsgiLaunchHelper.interpretProperties(properties, bundlesToStart, - // systemPropertiesToAppend); super.launch(selection, mode); - // name = null; - // bundlesToStart.clear(); - // systemPropertiesToAppend.clear(); - // - // propertiesFile = null; } @Override @@ -131,9 +110,11 @@ public class OsgiBootLaunchShortcut extends OSGiLaunchShortcut implements protected String getName(ILaunchConfigurationType type) { if (name != null && !name.toString().trim().equals("")) - return name.toString(); + return DebugPlugin.getDefault().getLaunchManager() + .generateUniqueLaunchConfigurationNameFrom(name.toString()); else - return "SLC"; + return DebugPlugin.getDefault().getLaunchManager() + .generateUniqueLaunchConfigurationNameFrom("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 d7fa841a5..419862d86 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 @@ -1,12 +1,12 @@ package org.argeo.slc.ide.ui.launch.osgi; import org.eclipse.core.runtime.CoreException; -import org.eclipse.debug.core.ILaunchConfiguration; 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.jdt.debug.ui.launchConfigurations.JavaArgumentsTab; import org.eclipse.pde.ui.launcher.BundlesTab; import org.eclipse.pde.ui.launcher.OSGiLauncherTabGroup; import org.eclipse.pde.ui.launcher.OSGiSettingsTab; @@ -17,13 +17,13 @@ public class OsgiBootLauncherTabGroup extends OSGiLauncherTabGroup { @Override public void createTabs(ILaunchConfigurationDialog dialog, String mode) { ILaunchConfigurationTab[] tabs = new ILaunchConfigurationTab[] { - new OsgiBootMainTab(), new EnvironmentTab(), new BundlesTab() { + new OsgiBootMainTab(), + new BundlesTab() { private boolean activating = false; @Override public void performApply( ILaunchConfigurationWorkingCopy config) { - System.out.println("performApply"); super.performApply(config); if (activating) { try { @@ -40,7 +40,20 @@ public class OsgiBootLauncherTabGroup extends OSGiLauncherTabGroup { ILaunchConfigurationWorkingCopy workingCopy) { activating = true; } - }, new OSGiSettingsTab(), new TracingTab(), new CommonTab() }; + }, new OSGiSettingsTab(), new EnvironmentTab(), + new JavaArgumentsTab() { + private boolean initializing = false; + + @Override + public void performApply( + ILaunchConfigurationWorkingCopy configuration) { + if (initializing) + return; + initializing = true; + initializeFrom(configuration); + initializing = false; + } + }, 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/OsgiLaunchHelper.java b/eclipse/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/launch/osgi/OsgiLaunchHelper.java index 253a82aff..31aaf136f 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 @@ -12,6 +12,7 @@ import java.util.StringTokenizer; 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.IStatus; import org.eclipse.core.runtime.Status; @@ -26,7 +27,6 @@ import org.eclipse.jdt.launching.IVMInstallType; import org.eclipse.jdt.launching.JavaRuntime; import org.eclipse.jface.dialogs.ErrorDialog; import org.eclipse.pde.ui.launcher.IPDELauncherConstants; -import org.eclipse.pde.ui.launcher.OSGiLaunchConfigurationInitializer; import org.eclipse.swt.widgets.Display; public class OsgiLaunchHelper implements OsgiLauncherConstants { @@ -37,6 +37,7 @@ public class OsgiLaunchHelper implements OsgiLauncherConstants { ILaunchConfigurationWorkingCopy configuration) { try { IFile propertiesFile = (IFile) configuration.getMappedResources()[0]; + propertiesFile.refreshLocal(IResource.DEPTH_ONE, null); Properties properties = OsgiLaunchHelper .readProperties(propertiesFile); @@ -46,23 +47,6 @@ public class OsgiLaunchHelper implements OsgiLauncherConstants { OsgiLaunchHelper.interpretProperties(properties, bundlesToStart, systemPropertiesToAppend); - // Reinitialize using standard OSGi launch shortcut - // Kind of a hack but it lacks extension capabilities and it is - // still - // cleaner than forking the code (which would imply a lot of fork - // indeed - // because of all the internal classes) - // new OSGiLaunchShortcut() { - // @Override - // public void initializeConfiguration( - // ILaunchConfigurationWorkingCopy configuration) { - // // TODO Auto-generated method stub - // super.initializeConfiguration(configuration); - // } - // }.initializeConfiguration(configuration); - - // initializeConfiguration(configuration); - File workingDir = getWorkingDirectory(configuration); File dataDir = new File(workingDir, "data"); @@ -78,7 +62,7 @@ public class OsgiLaunchHelper implements OsgiLauncherConstants { } } - public static void updateLaunchConfiguration( + static void updateLaunchConfiguration( ILaunchConfigurationWorkingCopy configuration, List bundlesToStart, Map systemPropertiesToAppend, String dataDir) @@ -97,12 +81,16 @@ public class OsgiLaunchHelper implements OsgiLauncherConstants { // Update other default information configuration.setAttribute(IPDELauncherConstants.DEFAULT_AUTO_START, false); + + // VM arguments (system properties) String defaultVmArgs = configuration.getAttribute( OsgiLauncherConstants.ATTR_DEFAULT_VM_ARGS, ""); StringBuffer vmArgs = new StringBuffer(defaultVmArgs); - vmArgs.append(" " - + configuration.getAttribute(ATTR_ADDITIONAL_VM_ARGS, "")); + // Data dir system property + if (dataDir != null) + addSysProperty(vmArgs, OsgiLauncherConstants.ARGEO_OSGI_DATA_DIR, + dataDir); // Add locations of JVMs if (configuration.getAttribute(ATTR_ADD_JVM_PATHS, false)) addVms(vmArgs); @@ -111,27 +99,25 @@ public class OsgiLaunchHelper implements OsgiLauncherConstants { for (String key : systemPropertiesToAppend.keySet()) addSysProperty(vmArgs, key, systemPropertiesToAppend.get(key)); - if (dataDir != null) - addSysProperty(vmArgs, OsgiLauncherConstants.ARGEO_OSGI_DATA_DIR, - dataDir); + vmArgs.append(" ").append( + configuration.getAttribute(ATTR_ADDITIONAL_VM_ARGS, "")); configuration.setAttribute( IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS, vmArgs .toString()); // Program arguments - StringBuffer progArgs = new StringBuffer(configuration.getAttribute( - OsgiLauncherConstants.ATTR_ADDITIONAL_PROGRAM_ARGS, "")); + StringBuffer progArgs = new StringBuffer(""); if (dataDir != null) { - progArgs.append(" -data "); + progArgs.append("-data "); progArgs.append(surroundSpaces(dataDir)); } + String additionalProgramArgs = configuration.getAttribute( + OsgiLauncherConstants.ATTR_ADDITIONAL_PROGRAM_ARGS, ""); + progArgs.append(' ').append(additionalProgramArgs); configuration.setAttribute( IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, progArgs.toString()); - - // String dir = findWorkingDirectory(); - } protected static void addVms(StringBuffer vmArgs) { @@ -172,7 +158,7 @@ public class OsgiLaunchHelper implements OsgiLauncherConstants { surroundSpaces(value); String str = "-D" + key + "=" + value; // surroundSpaces(str); - vmArgs.append(" " + str); + vmArgs.append(' ').append(str); } protected static String surroundSpaces(String str) { @@ -297,9 +283,9 @@ public class OsgiLaunchHelper implements OsgiLauncherConstants { return mgr.performStringSubstitution(text); } - static void initializeConfiguration( - ILaunchConfigurationWorkingCopy configuration) { - new OSGiLaunchConfigurationInitializer().initialize(configuration); - } + // static void initializeConfiguration( + // ILaunchConfigurationWorkingCopy configuration) { + // new OSGiLaunchConfigurationInitializer().initialize(configuration); + // } }