import java.io.IOException;\r
import java.io.StringReader;\r
import java.util.List;\r
-import java.util.Map;\r
import java.util.Properties;\r
import java.util.Vector;\r
\r
import org.eclipse.jdt.launching.VMRunnerConfiguration;\r
import org.eclipse.jface.dialogs.ErrorDialog;\r
import org.eclipse.swt.widgets.Shell;\r
-import org.omg.CORBA.VM_CUSTOM;\r
\r
public class SlcScriptLaunchDelegate extends\r
AbstractJavaLaunchConfigurationDelegate {\r
public final static String ATTR_TARGETS = "targets";\r
public final static String ATTR_PRE093 = "pre093";\r
\r
- private final static String ANT_MAIN = "org.apache.tools.ant.Main";\r
- private final static String SLC_MAIN = "org.argeo.slc.cli.SlcMain";\r
+ public final static String ANT_MAIN = "org.apache.tools.ant.Main";\r
+ public final static String SLC_MAIN = "org.argeo.slc.cli.SlcMain";\r
\r
public void launch(ILaunchConfiguration configuration, String mode,\r
ILaunch launch, IProgressMonitor monitor) throws CoreException {\r
boolean pre093 = configuration.getAttribute(ATTR_PRE093, false);\r
\r
// Retrieve SLC Runtime\r
- SlcSystem slcSystem = findSlcSystem(file);\r
+ SlcSystem slcSystem = findSlcSystem(file, pre093);\r
if (slcSystem == null)\r
return;\r
\r
} else {\r
vmConfig = createConfig(slcSystem, file, mode, configuration);\r
}\r
- vmRunner.run(vmConfig, launch, null);\r
+ vmRunner.run(vmConfig, launch, monitor);\r
}\r
\r
- protected SlcSystem findSlcSystem(IFile file) throws CoreException {\r
+ protected SlcSystem findSlcSystem(IFile file, boolean pre093)\r
+ throws CoreException {\r
SlcSystem slcSystem = null;\r
\r
IProject project = file.getProject();\r
if (project.getNature("org.eclipse.jdt.core.javanature") != null) {\r
IJavaProject javaProject = JavaCore.create(project);\r
- if (checkProjectForEmbedded(javaProject)) {\r
+ if (checkProjectForEmbedded(javaProject, pre093)) {\r
slcSystem = new EmbeddedSlcSystem(javaProject);\r
}\r
}\r
return slcSystem;\r
}\r
\r
- protected boolean checkProjectForEmbedded(IJavaProject project) {\r
+ protected boolean checkProjectForEmbedded(IJavaProject project,\r
+ boolean pre093) {\r
try {\r
- IType antmainType = project.findType(ANT_MAIN);\r
- if (antmainType == null)\r
+ IType mainType = null;\r
+ if (pre093)\r
+ mainType = project.findType(ANT_MAIN);\r
+ else\r
+ mainType = project.findType(SLC_MAIN);\r
+\r
+ if (mainType == null)\r
return false;\r
else\r
return true;\r
}\r
\r
// Utilities\r
- private void showError(String message) {\r
+ private static void showError(String message) {\r
Shell shell = SlcUiLaunchPlugin.getDefault().getWorkbench()\r
.getActiveWorkbenchWindow().getShell();\r
\r
package org.argeo.slc.ui.launch.script;\r
\r
+import org.argeo.slc.ui.launch.SlcUiLaunchPlugin;\r
import org.eclipse.core.resources.IFile;\r
-import org.eclipse.core.resources.IProject;\r
+import org.eclipse.core.resources.IResource;\r
import org.eclipse.core.runtime.CoreException;\r
import org.eclipse.core.runtime.IPath;\r
import org.eclipse.debug.core.DebugPlugin;\r
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;\r
import org.eclipse.debug.core.ILaunchManager;\r
import org.eclipse.debug.ui.ILaunchShortcut;\r
+import org.eclipse.jface.dialogs.ErrorDialog;\r
import org.eclipse.jface.viewers.ISelection;\r
import org.eclipse.jface.viewers.IStructuredSelection;\r
+import org.eclipse.swt.widgets.Shell;\r
import org.eclipse.ui.IEditorPart;\r
\r
public class SlcScriptLaunchShortcut implements ILaunchShortcut {\r
throw new RuntimeException("Can only launch files.");\r
}\r
IFile file = ((IFile) obj);\r
- IProject project = file.getProject();\r
- IPath relativePath = file.getProjectRelativePath();\r
- String name = "[" + project.getName() + "] - "\r
- + relativePath.toString();\r
- name = name.replace('/', '_');// otherwise not properly saved\r
-\r
- System.out.println(name);\r
\r
ILaunchManager manager = DebugPlugin.getDefault()\r
.getLaunchManager();\r
ILaunchConfigurationType type = manager\r
.getLaunchConfigurationType(SlcScriptLaunchDelegate.ID);\r
- ILaunchConfigurationWorkingCopy wc = type.newInstance(null, name);\r
- wc.setMappedResources(new IFile[] { file });\r
- ILaunchConfiguration config = wc.doSave();\r
+\r
+ // Find or create config\r
+ ILaunchConfiguration config = findLaunchConfiguration(file, manager\r
+ .getLaunchConfigurations(type));\r
+ if (config == null) {\r
+ ILaunchConfigurationWorkingCopy wc = type.newInstance(null,\r
+ generateName(file));\r
+ wc.setMappedResources(new IFile[] { file });\r
+ config = wc.doSave();\r
+ }\r
+ \r
+ // Launch\r
config.launch(mode, null);\r
} catch (CoreException e) {\r
- e.printStackTrace();\r
+ Shell shell = SlcUiLaunchPlugin.getDefault().getWorkbench()\r
+ .getActiveWorkbenchWindow().getShell();\r
+ ErrorDialog.openError(shell, "Error",\r
+ "Cannot execute SLC launch shortcut", e.getStatus());\r
}\r
\r
}\r
\r
+ protected String generateName(IFile file) {\r
+ IPath relativePath = file.getProjectRelativePath();\r
+ String name = relativePath.toString();\r
+ int idx = name.lastIndexOf(".xml");\r
+ if (idx > 0)\r
+ name = name.substring(0, idx);\r
+\r
+ if (name.startsWith("src/main/slc/root/"))\r
+ name = name.substring("src/main/slc/root/".length());\r
+ else if (name.startsWith("src/main/slc/"))\r
+ name = name.substring("src/main/slc/".length());\r
+\r
+ name = name.replace('/', '.');// otherwise not properly saved\r
+ return name;\r
+ }\r
+\r
+ protected ILaunchConfiguration findLaunchConfiguration(IFile file,\r
+ ILaunchConfiguration[] configs) throws CoreException {\r
+ for (ILaunchConfiguration config : configs) {\r
+ IResource[] res = config.getMappedResources();\r
+ if (res.length > 1) {\r
+ IFile fileT = (IFile) res[0];\r
+ if (fileT.equals(file)) {\r
+ return config;\r
+ }\r
+ }\r
+ }\r
+ return null;\r
+ }\r
+\r
public void launch(IEditorPart editor, String mode) {\r
// not (yet) implemented\r
}\r