1 package org
.argeo
.slc
.ide
.ui
.launch
.osgi
;
3 import java
.util
.Iterator
;
5 import org
.eclipse
.core
.resources
.IFile
;
6 import org
.eclipse
.core
.resources
.IFolder
;
7 import org
.eclipse
.core
.resources
.IProject
;
8 import org
.eclipse
.core
.resources
.IResource
;
9 import org
.eclipse
.core
.runtime
.CoreException
;
10 import org
.eclipse
.core
.runtime
.IPath
;
11 import org
.eclipse
.debug
.core
.DebugPlugin
;
12 import org
.eclipse
.debug
.core
.ILaunchConfiguration
;
13 import org
.eclipse
.debug
.core
.ILaunchConfigurationType
;
14 import org
.eclipse
.debug
.core
.ILaunchConfigurationWorkingCopy
;
15 import org
.eclipse
.jdt
.launching
.IJavaLaunchConfigurationConstants
;
16 import org
.eclipse
.jface
.dialogs
.ErrorDialog
;
17 import org
.eclipse
.jface
.viewers
.ISelection
;
18 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
19 import org
.eclipse
.pde
.ui
.launcher
.IPDELauncherConstants
;
20 import org
.eclipse
.pde
.ui
.launcher
.OSGiLaunchShortcut
;
21 import org
.eclipse
.swt
.widgets
.Display
;
22 import org
.eclipse
.swt
.widgets
.Shell
;
24 /** OSGiBoot launch shortcut. */
25 public class OsgiBootLaunchShortcut
extends OSGiLaunchShortcut
implements
26 OsgiLauncherConstants
{
27 private StringBuffer name
= null;
28 private IFile propertiesFile
= null;
31 protected String
getLaunchConfigurationTypeName() {
32 return OsgiBootEquinoxLaunchConfiguration
.ID
;
36 public void launch(ISelection selection
, String mode
) {
37 // System.out.println("Launch shortcut... " + selection);
43 IStructuredSelection sSelection
= (IStructuredSelection
) selection
;
44 Iterator
<?
> it
= sSelection
.iterator();
45 propertiesFile
= (IFile
) it
.next();
47 name
= new StringBuffer(extractName(propertiesFile
));
49 super.launch(selection
, mode
);
53 protected void initializeConfiguration(
54 ILaunchConfigurationWorkingCopy configuration
) {
55 IResource
[] resources
= { propertiesFile
};
56 configuration
.setMappedResources(resources
);
57 super.initializeConfiguration(configuration
);
60 configuration
.setAttribute(ATTR_ADD_JVM_PATHS
, false);
61 configuration
.setAttribute(ATTR_ADDITIONAL_VM_ARGS
, "-Xmx128m");
63 .setAttribute(ATTR_ADDITIONAL_PROGRAM_ARGS
, "-console");
66 String originalVmArgs
= configuration
.getAttribute(
67 IJavaLaunchConfigurationConstants
.ATTR_VM_ARGUMENTS
, "");
68 configuration
.setAttribute(ATTR_DEFAULT_VM_ARGS
, originalVmArgs
);
69 configuration
.setAttribute(IPDELauncherConstants
.CONFIG_CLEAR_AREA
,
72 configuration
.setAttribute(
73 IJavaLaunchConfigurationConstants
.ATTR_WORKING_DIRECTORY
,
74 findWorkingDirectory());
76 OsgiLaunchHelper
.updateLaunchConfiguration(configuration
);
77 } catch (CoreException e
) {
78 Shell shell
= Display
.getCurrent().getActiveShell();
79 ErrorDialog
.openError(shell
, "Error",
80 "Cannot execute initalize configuration", e
.getStatus());
84 protected String
findWorkingDirectory() {
86 IProject project
= propertiesFile
.getProject();
87 IPath parent
= propertiesFile
.getProjectRelativePath()
88 .removeLastSegments(1);
89 IFolder execFolder
= project
.getFolder(parent
.append("exec"));
90 if (!execFolder
.exists())
91 execFolder
.create(true, true, null);
92 IFolder launchFolder
= project
.getFolder(execFolder
93 .getProjectRelativePath().append(
94 extractName(propertiesFile
)));
95 if (!launchFolder
.exists())
96 launchFolder
.create(true, true, null);
97 return "${workspace_loc:"
98 + launchFolder
.getFullPath().toString().substring(1) + "}";
99 } catch (Exception e
) {
101 throw new RuntimeException("Cannot create working directory", e
);
105 protected String
extractName(IFile file
) {
106 IPath path
= propertiesFile
.getFullPath();
107 IPath pathNoExt
= path
.removeFileExtension();
108 return pathNoExt
.segment(pathNoExt
.segmentCount() - 1);
112 protected String
getName(ILaunchConfigurationType type
) {
113 if (name
!= null && !name
.toString().trim().equals(""))
114 return DebugPlugin
.getDefault().getLaunchManager()
115 .generateUniqueLaunchConfigurationNameFrom(name
.toString());
117 return DebugPlugin
.getDefault().getLaunchManager()
118 .generateUniqueLaunchConfigurationNameFrom("SLC");
122 protected boolean isGoodMatch(ILaunchConfiguration configuration
) {
124 return name
.toString().equals(configuration
.getName());
126 return super.isGoodMatch(configuration
);