]> git.argeo.org Git - gpl/argeo-slc.git/blob - eclipse/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/launch/osgi/OsgiBootLaunchShortcut.java
Restructure SLC development environment
[gpl/argeo-slc.git] / eclipse / plugins / org.argeo.slc.ide.ui / src / main / java / org / argeo / slc / ide / ui / launch / osgi / OsgiBootLaunchShortcut.java
1 package org.argeo.slc.ide.ui.launch.osgi;
2
3 import java.util.Iterator;
4 import java.util.Properties;
5
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;
17
18 public class OsgiBootLaunchShortcut extends AbstractOsgiLaunchShortcut {
19 protected IFile propertiesFile = null;
20
21 @Override
22 protected String getLaunchConfigurationTypeName() {
23 return OsgiBootEquinoxLaunchConfiguration.ID;
24 }
25
26 @Override
27 public void launch(ISelection selection, String mode) {
28 // System.out.println("Launch shortcut... " + selection);
29
30 // we assume that:
31 // - only one
32 // - file
33 // - is selected
34 IStructuredSelection sSelection = (IStructuredSelection) selection;
35 Iterator<?> it = sSelection.iterator();
36 propertiesFile = (IFile) it.next();
37
38 name = new StringBuffer(extractName(propertiesFile));
39
40 Properties properties = null;
41 try {
42 properties = OsgiLaunchHelper.readProperties(propertiesFile);
43 } catch (CoreException e) {
44 ErrorDialog.openError(Display.getCurrent().getActiveShell(),
45 "Error", "Cannot execute launch shortcut", e.getStatus());
46 return;
47 }
48
49 OsgiLaunchHelper.interpretProperties(properties, bundlesToStart,
50 systemPropertiesToAppend);
51 super.launch(selection, mode);
52
53 propertiesFile = null;
54 }
55
56 @Override
57 protected void initializeConfiguration(
58 ILaunchConfigurationWorkingCopy configuration) {
59 IResource[] resources = { propertiesFile };
60 configuration.setMappedResources(resources);
61 super.initializeConfiguration(configuration);
62 }
63
64 @Override
65 protected String findWorkingDirectory() {
66 try {
67 // String relPath = "exec/" + extractName(propertiesFile);
68
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);
80
81 // IPath execDirPath = propertiesFile.getFullPath()
82 // .removeLastSegments(1).append(relPath);
83 // File baseDir = propertiesFile.getRawLocation().toFile()
84 // .getParentFile();
85 // File execDir = new File(baseDir.getCanonicalPath()
86 // + File.separatorChar
87 // + relPath.replace('/', File.separatorChar));
88 // File execDir = execDirPath.toFile();
89 // execDir.mkdirs();
90 // return "${workspace_loc:" + execDirPath.toString().substring(1)
91 // + "}";
92 return "${workspace_loc:"
93 + launchFolder.getFullPath().toString().substring(1) + "}";
94 } catch (Exception e) {
95 e.printStackTrace();
96 throw new RuntimeException("Cannot create working directory", e);
97 }
98 }
99
100 protected String extractName(IFile file) {
101 IPath path = propertiesFile.getFullPath();
102 IPath pathNoExt = path.removeFileExtension();
103 return pathNoExt.segment(pathNoExt.segmentCount() - 1);
104
105 }
106 }