]> 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
Start working on serialized JMS
[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
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;
23
24 /** OSGiBoot launch shortcut. */
25 public class OsgiBootLaunchShortcut extends OSGiLaunchShortcut implements
26 OsgiLauncherConstants {
27 private StringBuffer name = null;
28 private IFile propertiesFile = null;
29
30 @Override
31 protected String getLaunchConfigurationTypeName() {
32 return OsgiBootEquinoxLaunchConfiguration.ID;
33 }
34
35 @Override
36 public void launch(ISelection selection, String mode) {
37 // System.out.println("Launch shortcut... " + selection);
38
39 // we assume that:
40 // - only one
41 // - file
42 // - is selected
43 IStructuredSelection sSelection = (IStructuredSelection) selection;
44 Iterator<?> it = sSelection.iterator();
45 propertiesFile = (IFile) it.next();
46
47 name = new StringBuffer(extractName(propertiesFile));
48
49 super.launch(selection, mode);
50 }
51
52 @Override
53 protected void initializeConfiguration(
54 ILaunchConfigurationWorkingCopy configuration) {
55 IResource[] resources = { propertiesFile };
56 configuration.setMappedResources(resources);
57 super.initializeConfiguration(configuration);
58
59 try {
60 configuration.setAttribute(ATTR_ADD_JVM_PATHS, false);
61 configuration.setAttribute(ATTR_ADDITIONAL_VM_ARGS, "-Xmx128m");
62 configuration
63 .setAttribute(ATTR_ADDITIONAL_PROGRAM_ARGS, "-console");
64
65 // Defaults
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,
70 true);
71
72 configuration.setAttribute(
73 IJavaLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY,
74 findWorkingDirectory());
75
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());
81 }
82 }
83
84 protected String findWorkingDirectory() {
85 try {
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) {
100 e.printStackTrace();
101 throw new RuntimeException("Cannot create working directory", e);
102 }
103 }
104
105 protected String extractName(IFile file) {
106 IPath path = propertiesFile.getFullPath();
107 IPath pathNoExt = path.removeFileExtension();
108 return pathNoExt.segment(pathNoExt.segmentCount() - 1);
109
110 }
111
112 protected String getName(ILaunchConfigurationType type) {
113 if (name != null && !name.toString().trim().equals(""))
114 return DebugPlugin.getDefault().getLaunchManager()
115 .generateUniqueLaunchConfigurationNameFrom(name.toString());
116 else
117 return DebugPlugin.getDefault().getLaunchManager()
118 .generateUniqueLaunchConfigurationNameFrom("SLC");
119 }
120
121 @Override
122 protected boolean isGoodMatch(ILaunchConfiguration configuration) {
123 if (name != null) {
124 return name.toString().equals(configuration.getName());
125 }
126 return super.isGoodMatch(configuration);
127 }
128
129 }