]> 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/OsgiBootEquinoxLaunchConfiguration.java
6f2a93d3ce154b5048460aba5d032d7f75a44d1b
[gpl/argeo-slc.git] / eclipse / plugins / org.argeo.slc.ide.ui / src / main / java / org / argeo / slc / ide / ui / launch / osgi / OsgiBootEquinoxLaunchConfiguration.java
1 package org.argeo.slc.ide.ui.launch.osgi;
2
3 import java.io.File;
4 import java.util.ArrayList;
5 import java.util.HashMap;
6 import java.util.List;
7 import java.util.Map;
8 import java.util.Properties;
9
10 import org.argeo.slc.ide.ui.SlcIdeUiPlugin;
11 import org.eclipse.core.resources.IFile;
12 import org.eclipse.core.resources.IResource;
13 import org.eclipse.core.runtime.CoreException;
14 import org.eclipse.core.runtime.IProgressMonitor;
15 import org.eclipse.debug.core.ILaunch;
16 import org.eclipse.debug.core.ILaunchConfiguration;
17 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
18 import org.eclipse.jface.dialogs.ErrorDialog;
19 import org.eclipse.pde.ui.launcher.EquinoxLaunchConfiguration;
20 import org.eclipse.pde.ui.launcher.OSGiLaunchShortcut;
21 import org.eclipse.swt.widgets.Display;
22
23 public class OsgiBootEquinoxLaunchConfiguration extends
24 EquinoxLaunchConfiguration {
25 public final static String ID = SlcIdeUiPlugin.ID
26 + ".OsgiBootEquinoxLauncher";
27
28 @Override
29 public void launch(ILaunchConfiguration configuration, String mode,
30 ILaunch launch, IProgressMonitor monitor) throws CoreException {
31 super.launch(configuration, mode, launch, monitor);
32
33 // TODO: add launch listener to be notified when is terminated and
34 // refresh resources
35
36 IFile propertiesFile = (IFile) configuration.getMappedResources()[0];
37 propertiesFile.getProject().refreshLocal(IResource.DEPTH_INFINITE,
38 monitor);
39 }
40
41 @Override
42 protected void preLaunchCheck(ILaunchConfiguration configuration,
43 ILaunch launch, IProgressMonitor monitor) throws CoreException {
44 // System.out.println("Launching... " + launch);
45 IFile propertiesFile = (IFile) configuration.getMappedResources()[0];
46
47 Properties properties = null;
48 try {
49 properties = OsgiLaunchHelper.readProperties(propertiesFile);
50 } catch (CoreException e) {
51 ErrorDialog.openError(Display.getCurrent().getActiveShell(),
52 "Error", "Cannot execute launch shortcut", e.getStatus());
53 return;
54 }
55
56 List<String> bundlesToStart = new ArrayList<String>();
57 Map<String, String> systemPropertiesToAppend = new HashMap<String, String>();
58 OsgiLaunchHelper.interpretProperties(properties, bundlesToStart,
59 systemPropertiesToAppend);
60
61 File workingDir = getWorkingDirectory(configuration);
62
63 ILaunchConfigurationWorkingCopy wc = configuration.getWorkingCopy();
64
65 // Reinitialize using standard OSGi launch shortcut
66 // Kind of a hack but it lacks extension capabilities and it is still
67 // cleaner than forking the code (which would imply a lot of fork indeed
68 // because of all the internal classes)
69 new OSGiLaunchShortcut() {
70 @Override
71 public void initializeConfiguration(
72 ILaunchConfigurationWorkingCopy configuration) {
73 // TODO Auto-generated method stub
74 super.initializeConfiguration(configuration);
75 }
76 }.initializeConfiguration(wc);
77
78 OsgiLaunchHelper.updateLaunchConfiguration(wc, bundlesToStart,
79 systemPropertiesToAppend, null, new File(workingDir, "data")
80 .getAbsolutePath());
81 wc.doSave();
82
83 super.preLaunchCheck(configuration, launch, monitor);
84 }
85
86 }