X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;ds=sidebyside;f=eclipse%2Fplugins%2Forg.argeo.slc.ide.ui%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fide%2Fui%2Flaunch%2Fosgi%2FOsgiBootLaunchShortcut.java;h=b73b612a3d94e222985fb9d4b8c0414dc887b847;hb=331ed178b4b5ee277a5c62477d4892f8f089a8b9;hp=3dbdbb19da7611d3b33f5419d4f05bf516c4eed2;hpb=01e4319b49fcc2a6cdf6f0f9271ae27343c7430f;p=gpl%2Fargeo-slc.git 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..b73b612a3 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,35 +1,23 @@ 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; -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; +/** Launch shortcut simplifying the launch of a pure OSGi runtime */ 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() { @@ -38,102 +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)); - // 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 - 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 name.toString(); + return DebugPlugin.getDefault().getLaunchManager() + .generateLaunchConfigurationName(name.toString()); else - return "SLC"; + return DebugPlugin.getDefault().getLaunchManager() + .generateLaunchConfigurationName("SLC"); } @Override