]> 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
Introduce specific tab to OSGi boot
[gpl/argeo-slc.git] / eclipse / plugins / org.argeo.slc.ide.ui / src / main / java / org / argeo / slc / ide / ui / launch / osgi / OsgiBootLaunchShortcut.java
index 513ba50a6c600d32d0b1a730898595ea55891e04..3dbdbb19da7611d3b33f5419d4f05bf516c4eed2 100644 (file)
@@ -1,7 +1,10 @@
 package org.argeo.slc.ide.ui.launch.osgi;
 
+import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.Iterator;
-import java.util.Properties;
+import java.util.List;
+import java.util.Map;
 
 import org.eclipse.core.resources.IFile;
 import org.eclipse.core.resources.IFolder;
@@ -9,14 +12,24 @@ 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.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;
 
-public class OsgiBootLaunchShortcut extends AbstractOsgiLaunchShortcut {
+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>();
 
        @Override
        protected String getLaunchConfigurationTypeName() {
@@ -37,20 +50,23 @@ public class OsgiBootLaunchShortcut extends AbstractOsgiLaunchShortcut {
 
                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);
+               // 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);
-               
-               propertiesFile = null;
+               // name = null;
+               // bundlesToStart.clear();
+               // systemPropertiesToAppend.clear();
+               //
+               // propertiesFile = null;
        }
 
        @Override
@@ -59,13 +75,34 @@ public class OsgiBootLaunchShortcut extends AbstractOsgiLaunchShortcut {
                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);
+
+                       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());
+               }
        }
 
-       @Override
        protected String findWorkingDirectory() {
                try {
-                       // String relPath = "exec/" + extractName(propertiesFile);
-
                        IProject project = propertiesFile.getProject();
                        IPath parent = propertiesFile.getProjectRelativePath()
                                        .removeLastSegments(1);
@@ -77,18 +114,6 @@ public class OsgiBootLaunchShortcut extends AbstractOsgiLaunchShortcut {
                                                        extractName(propertiesFile)));
                        if (!launchFolder.exists())
                                launchFolder.create(true, true, null);
-
-                       // IPath execDirPath = propertiesFile.getFullPath()
-                       // .removeLastSegments(1).append(relPath);
-                       // File baseDir = propertiesFile.getRawLocation().toFile()
-                       // .getParentFile();
-                       // File execDir = new File(baseDir.getCanonicalPath()
-                       // + File.separatorChar
-                       // + relPath.replace('/', File.separatorChar));
-                       // File execDir = execDirPath.toFile();
-                       // execDir.mkdirs();
-                       // return "${workspace_loc:" + execDirPath.toString().substring(1)
-                       // + "}";
                        return "${workspace_loc:"
                                        + launchFolder.getFullPath().toString().substring(1) + "}";
                } catch (Exception e) {
@@ -103,4 +128,20 @@ public class OsgiBootLaunchShortcut extends AbstractOsgiLaunchShortcut {
                return pathNoExt.segment(pathNoExt.segmentCount() - 1);
 
        }
+
+       protected String getName(ILaunchConfigurationType type) {
+               if (name != null && !name.toString().trim().equals(""))
+                       return name.toString();
+               else
+                       return "SLC";
+       }
+
+       @Override
+       protected boolean isGoodMatch(ILaunchConfiguration configuration) {
+               if (name != null) {
+                       return name.toString().equals(configuration.getName());
+               }
+               return super.isGoodMatch(configuration);
+       }
+
 }