X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;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=513ba50a6c600d32d0b1a730898595ea55891e04;hpb=24f738dcddf83ec2c13fe2e7498a47a4bcd0f427;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 513ba50a6..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,22 +1,23 @@ package org.argeo.slc.ide.ui.launch.osgi; import java.util.Iterator; -import java.util.Properties; 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.jface.dialogs.ErrorDialog; +import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.swt.widgets.Display; +import org.eclipse.pde.ui.launcher.OSGiLaunchShortcut; -public class OsgiBootLaunchShortcut extends AbstractOsgiLaunchShortcut { - protected IFile propertiesFile = null; +/** Launch shortcut simplifying the launch of a pure OSGi runtime */ +public class OsgiBootLaunchShortcut extends OSGiLaunchShortcut implements + OsgiLauncherConstants { + private StringBuffer name = null; + private IFile propertiesFile = null; @Override protected String getLaunchConfigurationTypeName() { @@ -25,82 +26,46 @@ public class OsgiBootLaunchShortcut extends AbstractOsgiLaunchShortcut { @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)); - - Properties properties = null; - try { - properties = OsgiLaunchHelper.readProperties(propertiesFile); - } catch (CoreException e) { - ErrorDialog.openError(Display.getCurrent().getActiveShell(), - "Error", "Cannot execute launch shortcut", e.getStatus()); - return; - } + name = new StringBuffer(OsgiLaunchHelper.extractName(propertiesFile)); - OsgiLaunchHelper.interpretProperties(properties, bundlesToStart, - systemPropertiesToAppend); super.launch(selection, mode); - - propertiesFile = null; } @Override - protected void initializeConfiguration( - ILaunchConfigurationWorkingCopy configuration) { + protected void initializeConfiguration(ILaunchConfigurationWorkingCopy wc) { IResource[] resources = { propertiesFile }; - configuration.setMappedResources(resources); - super.initializeConfiguration(configuration); - } + wc.setMappedResources(resources); + super.initializeConfiguration(wc); - @Override - protected String findWorkingDirectory() { - try { - // String relPath = "exec/" + extractName(propertiesFile); + OsgiLaunchHelper.setDefaults(wc, true); - 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); + wc.setAttribute( + IJavaLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, + OsgiLaunchHelper.findWorkingDirectory(propertiesFile)); - // 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) { - e.printStackTrace(); - throw new RuntimeException("Cannot create working directory", e); - } + OsgiLaunchHelper.updateLaunchConfiguration(wc, false); } - protected String extractName(IFile file) { - IPath path = propertiesFile.getFullPath(); - IPath pathNoExt = path.removeFileExtension(); - return pathNoExt.segment(pathNoExt.segmentCount() - 1); + protected String getName(ILaunchConfigurationType type) { + if (name != null && !name.toString().trim().equals("")) + return DebugPlugin.getDefault().getLaunchManager() + .generateLaunchConfigurationName(name.toString()); + else + return DebugPlugin.getDefault().getLaunchManager() + .generateLaunchConfigurationName("SLC"); + } + @Override + protected boolean isGoodMatch(ILaunchConfiguration configuration) { + if (name != null) { + return name.toString().equals(configuration.getName()); + } + return super.isGoodMatch(configuration); } + }