1 package org
.argeo
.slc
.ide
.ui
.launch
.osgi
;
3 import java
.util
.Iterator
;
4 import java
.util
.Properties
;
6 import org
.eclipse
.core
.resources
.IFile
;
7 import org
.eclipse
.core
.resources
.IFolder
;
8 import org
.eclipse
.core
.resources
.IProject
;
9 import org
.eclipse
.core
.resources
.IResource
;
10 import org
.eclipse
.core
.runtime
.CoreException
;
11 import org
.eclipse
.core
.runtime
.IPath
;
12 import org
.eclipse
.debug
.core
.ILaunchConfigurationWorkingCopy
;
13 import org
.eclipse
.jface
.dialogs
.ErrorDialog
;
14 import org
.eclipse
.jface
.viewers
.ISelection
;
15 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
16 import org
.eclipse
.swt
.widgets
.Display
;
18 public class OsgiBootLaunchShortcut
extends AbstractOsgiLaunchShortcut
{
19 protected IFile propertiesFile
= null;
22 protected String
getLaunchConfigurationTypeName() {
23 return OsgiBootEquinoxLaunchConfiguration
.ID
;
27 public void launch(ISelection selection
, String mode
) {
28 // System.out.println("Launch shortcut... " + selection);
34 IStructuredSelection sSelection
= (IStructuredSelection
) selection
;
35 Iterator
<?
> it
= sSelection
.iterator();
36 propertiesFile
= (IFile
) it
.next();
38 name
= new StringBuffer(extractName(propertiesFile
));
40 Properties properties
= null;
42 properties
= OsgiLaunchHelper
.readProperties(propertiesFile
);
43 } catch (CoreException e
) {
44 ErrorDialog
.openError(Display
.getCurrent().getActiveShell(),
45 "Error", "Cannot execute launch shortcut", e
.getStatus());
49 OsgiLaunchHelper
.interpretProperties(properties
, bundlesToStart
,
50 systemPropertiesToAppend
);
51 super.launch(selection
, mode
);
53 propertiesFile
= null;
57 protected void initializeConfiguration(
58 ILaunchConfigurationWorkingCopy configuration
) {
59 IResource
[] resources
= { propertiesFile
};
60 configuration
.setMappedResources(resources
);
61 super.initializeConfiguration(configuration
);
65 protected String
findWorkingDirectory() {
67 // String relPath = "exec/" + extractName(propertiesFile);
69 IProject project
= propertiesFile
.getProject();
70 IPath parent
= propertiesFile
.getProjectRelativePath()
71 .removeLastSegments(1);
72 IFolder execFolder
= project
.getFolder(parent
.append("exec"));
73 if (!execFolder
.exists())
74 execFolder
.create(true, true, null);
75 IFolder launchFolder
= project
.getFolder(execFolder
76 .getProjectRelativePath().append(
77 extractName(propertiesFile
)));
78 if (!launchFolder
.exists())
79 launchFolder
.create(true, true, null);
81 // IPath execDirPath = propertiesFile.getFullPath()
82 // .removeLastSegments(1).append(relPath);
83 // File baseDir = propertiesFile.getRawLocation().toFile()
85 // File execDir = new File(baseDir.getCanonicalPath()
86 // + File.separatorChar
87 // + relPath.replace('/', File.separatorChar));
88 // File execDir = execDirPath.toFile();
90 // return "${workspace_loc:" + execDirPath.toString().substring(1)
92 return "${workspace_loc:"
93 + launchFolder
.getFullPath().toString().substring(1) + "}";
94 } catch (Exception e
) {
96 throw new RuntimeException("Cannot create working directory", e
);
100 protected String
extractName(IFile file
) {
101 IPath path
= propertiesFile
.getFullPath();
102 IPath pathNoExt
= path
.removeFileExtension();
103 return pathNoExt
.segment(pathNoExt
.segmentCount() - 1);