Clean up code
authorMathieu Baudier <mbaudier@argeo.org>
Tue, 20 Apr 2010 15:50:13 +0000 (15:50 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Tue, 20 Apr 2010 15:50:13 +0000 (15:50 +0000)
git-svn-id: https://svn.argeo.org/slc/trunk@3481 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

eclipse/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/SlcIdeUiPlugin.java
eclipse/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/launch/osgi/AbstractOsgiLaunchShortcut.java
eclipse/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/launch/osgi/OsgiBootEquinoxLaunchConfiguration.java
eclipse/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/launch/osgi/OsgiBootLaunchShortcut.java
eclipse/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/launch/osgi/OsgiBootLauncherTabGroup.java
eclipse/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/launch/osgi/OsgiLaunchHelper.java

index 2c288cff598f2a85148c2ca3e305f5df1894912d..67374bf08f2aa25877b67cf32c89dace59102b8e 100644 (file)
@@ -2,6 +2,13 @@ package org.argeo.slc.ide.ui;
 \r
 import java.net.URL;\r
 \r
+import org.eclipse.core.resources.IResource;\r
+import org.eclipse.core.runtime.CoreException;\r
+import org.eclipse.debug.core.DebugEvent;\r
+import org.eclipse.debug.core.DebugPlugin;\r
+import org.eclipse.debug.core.IDebugEventSetListener;\r
+import org.eclipse.debug.core.ILaunch;\r
+import org.eclipse.debug.core.model.IProcess;\r
 import org.eclipse.jface.resource.ImageDescriptor;\r
 import org.eclipse.jface.resource.ImageRegistry;\r
 import org.eclipse.swt.graphics.Image;\r
@@ -29,6 +36,8 @@ public class SlcIdeUiPlugin extends AbstractUIPlugin {
        public void start(BundleContext context) throws Exception {\r
                super.start(context);\r
                plugin = this;\r
+               DebugPlugin.getDefault()\r
+                               .addDebugEventListener(new DebugEventListener());\r
        }\r
 \r
        @Override\r
@@ -58,4 +67,40 @@ public class SlcIdeUiPlugin extends AbstractUIPlugin {
                }\r
                return image;\r
        }\r
+\r
+       protected static class DebugEventListener implements IDebugEventSetListener {\r
+               public void handleDebugEvents(DebugEvent[] events) {\r
+                       for (int i = 0; i < events.length; i++) {\r
+                               DebugEvent event = events[i];\r
+                               Object source = event.getSource();\r
+                               if (source instanceof IProcess\r
+                                               && event.getKind() == DebugEvent.TERMINATE) {\r
+                                       IProcess process = (IProcess) source;\r
+                                       ILaunch launch = process.getLaunch();\r
+                                       if (launch != null) {\r
+                                               refreshOsgiBootLaunch(launch);\r
+                                       }\r
+                               }\r
+                       }\r
+               }\r
+\r
+               protected void refreshOsgiBootLaunch(ILaunch launch) {\r
+                       try {\r
+                               IResource[] resources = launch.getLaunchConfiguration()\r
+                                               .getMappedResources();\r
+                               if (resources.length > 0) {\r
+                                       IResource propertiesFile = resources[0];\r
+                                       propertiesFile.getParent().refreshLocal(\r
+                                                       IResource.DEPTH_INFINITE, null);\r
+//                                     System.out.println("Refreshed "\r
+//                                                     + propertiesFile.getParent());\r
+                               }\r
+                       } catch (CoreException e) {\r
+                               e.printStackTrace();\r
+                       }\r
+\r
+               }\r
+\r
+       }\r
+\r
 }\r
index c9337d85f56a3b114f39db1268666f3ac5e5e9f8..08c06e09d9c47cebe52da578d885fa26053b828e 100644 (file)
@@ -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,
index c00b3075224ebb86d5e1f5509de12090faa185d4..853775ac6fdc2e05dbf3fa321688a80c38d3998b 100644 (file)
@@ -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
index 3dbdbb19da7611d3b33f5419d4f05bf516c4eed2..097adc836067f34a3b86e1cf8517a259e9410dbd 100644 (file)
@@ -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<String> bundlesToStart = new ArrayList<String>();
-       protected Map<String, String> systemPropertiesToAppend = new HashMap<String, String>();
+       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
index d7fa841a542eec1b110e76a0f3900d220a8697c7..419862d86af9a7ee81e554080ed71b9b114b9b79 100644 (file)
@@ -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);
        }
 
index 253a82afff007924286368ea02da6fe9aa596228..31aaf136f68dd9f82fc4f3aaf5fb0617e7c7092b 100644 (file)
@@ -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<String> bundlesToStart,
                        Map<String, String> 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);
+       // }
 
 }