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 public class OsgiBootLaunchShortcut
extends OSGiLaunchShortcut
implements
25 OsgiLauncherConstants
{
26 private StringBuffer name
= null;
27 private IFile propertiesFile
= null;
30 protected String
getLaunchConfigurationTypeName() {
31 return OsgiBootEquinoxLaunchConfiguration
.ID
;
35 public void launch(ISelection selection
, String mode
) {
36 // System.out.println("Launch shortcut... " + selection);
42 IStructuredSelection sSelection
= (IStructuredSelection
) selection
;
43 Iterator
<?
> it
= sSelection
.iterator();
44 propertiesFile
= (IFile
) it
.next();
46 name
= new StringBuffer(extractName(propertiesFile
));
48 super.launch(selection
, mode
);
52 protected void initializeConfiguration(
53 ILaunchConfigurationWorkingCopy configuration
) {
54 IResource
[] resources
= { propertiesFile
};
55 configuration
.setMappedResources(resources
);
56 super.initializeConfiguration(configuration
);
59 configuration
.setAttribute(ATTR_ADD_JVM_PATHS
, false);
60 configuration
.setAttribute(ATTR_ADDITIONAL_VM_ARGS
, "-Xmx128m");
62 .setAttribute(ATTR_ADDITIONAL_PROGRAM_ARGS
, "-console");
65 String originalVmArgs
= configuration
.getAttribute(
66 IJavaLaunchConfigurationConstants
.ATTR_VM_ARGUMENTS
, "");
67 configuration
.setAttribute(ATTR_DEFAULT_VM_ARGS
, originalVmArgs
);
68 configuration
.setAttribute(IPDELauncherConstants
.CONFIG_CLEAR_AREA
,
71 configuration
.setAttribute(
72 IJavaLaunchConfigurationConstants
.ATTR_WORKING_DIRECTORY
,
73 findWorkingDirectory());
75 OsgiLaunchHelper
.updateLaunchConfiguration(configuration
);
76 } catch (CoreException e
) {
77 Shell shell
= Display
.getCurrent().getActiveShell();
78 ErrorDialog
.openError(shell
, "Error",
79 "Cannot execute initalize configuration", e
.getStatus());
83 protected String
findWorkingDirectory() {
85 IProject project
= propertiesFile
.getProject();
86 IPath parent
= propertiesFile
.getProjectRelativePath()
87 .removeLastSegments(1);
88 IFolder execFolder
= project
.getFolder(parent
.append("exec"));
89 if (!execFolder
.exists())
90 execFolder
.create(true, true, null);
91 IFolder launchFolder
= project
.getFolder(execFolder
92 .getProjectRelativePath().append(
93 extractName(propertiesFile
)));
94 if (!launchFolder
.exists())
95 launchFolder
.create(true, true, null);
96 return "${workspace_loc:"
97 + launchFolder
.getFullPath().toString().substring(1) + "}";
98 } catch (Exception e
) {
100 throw new RuntimeException("Cannot create working directory", e
);
104 protected String
extractName(IFile file
) {
105 IPath path
= propertiesFile
.getFullPath();
106 IPath pathNoExt
= path
.removeFileExtension();
107 return pathNoExt
.segment(pathNoExt
.segmentCount() - 1);
111 protected String
getName(ILaunchConfigurationType type
) {
112 if (name
!= null && !name
.toString().trim().equals(""))
113 return DebugPlugin
.getDefault().getLaunchManager()
114 .generateUniqueLaunchConfigurationNameFrom(name
.toString());
116 return DebugPlugin
.getDefault().getLaunchManager()
117 .generateUniqueLaunchConfigurationNameFrom("SLC");
121 protected boolean isGoodMatch(ILaunchConfiguration configuration
) {
123 return name
.toString().equals(configuration
.getName());
125 return super.isGoodMatch(configuration
);