]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - eclipse/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/launch/osgi/OsgiBootLaunchShortcut.java
NEW - bug 11: Introduce a simplified launch for RCP
[gpl/argeo-slc.git] / eclipse / plugins / org.argeo.slc.ide.ui / src / main / java / org / argeo / slc / ide / ui / launch / osgi / OsgiBootLaunchShortcut.java
index b1994e8144388a680deb8cabe4130a80cdb56204..b73b612a3d94e222985fb9d4b8c0414dc887b847 100644 (file)
@@ -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