1 package org
.argeo
.slc
.ui
.launch
.script
;
4 import java
.util
.Vector
;
6 import org
.argeo
.slc
.ui
.launch
.DeployedSlcRuntime
;
7 import org
.argeo
.slc
.ui
.launch
.EmbeddedSlcRuntime
;
8 import org
.argeo
.slc
.ui
.launch
.SlcRuntime
;
9 import org
.argeo
.slc
.ui
.launch
.SlcUiLaunchPlugin
;
10 import org
.argeo
.slc
.ui
.launch
.preferences
.SlcPreferencePage
;
11 import org
.eclipse
.core
.resources
.IFile
;
12 import org
.eclipse
.core
.resources
.IProject
;
13 import org
.eclipse
.core
.resources
.IResource
;
14 import org
.eclipse
.core
.runtime
.CoreException
;
15 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
16 import org
.eclipse
.core
.runtime
.IStatus
;
17 import org
.eclipse
.core
.runtime
.Status
;
18 import org
.eclipse
.debug
.core
.ILaunch
;
19 import org
.eclipse
.debug
.core
.ILaunchConfiguration
;
20 import org
.eclipse
.debug
.core
.ILaunchManager
;
21 import org
.eclipse
.jdt
.core
.IJavaProject
;
22 import org
.eclipse
.jdt
.core
.IType
;
23 import org
.eclipse
.jdt
.core
.JavaCore
;
24 import org
.eclipse
.jdt
.core
.JavaModelException
;
25 import org
.eclipse
.jdt
.launching
.AbstractJavaLaunchConfigurationDelegate
;
26 import org
.eclipse
.jdt
.launching
.IVMRunner
;
27 import org
.eclipse
.jdt
.launching
.VMRunnerConfiguration
;
28 import org
.eclipse
.jface
.dialogs
.ErrorDialog
;
29 import org
.eclipse
.swt
.widgets
.Shell
;
31 public class SlcScriptLaunchDelegate
extends
32 AbstractJavaLaunchConfigurationDelegate
{
33 public static final String ID
= "org.argeo.slc.launch.slcScriptLaunchType";
35 private final static String ANT_MAIN
= "org.apache.tools.ant.Main";
37 public void launch(ILaunchConfiguration configuration
, String mode
,
38 ILaunch launch
, IProgressMonitor monitor
) throws CoreException
{
39 IResource
[] resources
= configuration
.getMappedResources();
40 if (resources
.length
!= 1) {
41 throw new RuntimeException("Can only launch one script.");
43 if (!(resources
[0] instanceof IFile
)) {
44 throw new RuntimeException("Can only launch file.");
46 IFile file
= (IFile
) resources
[0];
47 System
.out
.println("Launched " + file
.getLocation().toFile());
49 // Retrieve SLC Runtime
50 SlcRuntime deployedSlc
= null;
52 IProject project
= file
.getProject();
53 if (project
.getNature("org.eclipse.jdt.core.javanature") != null) {
54 IJavaProject javaProject
= JavaCore
.create(project
);
55 if (checkProjectForEmbedded(javaProject
)) {
56 deployedSlc
= new EmbeddedSlcRuntime(javaProject
);
60 if (deployedSlc
== null) {
61 String slcRuntimePath
= SlcUiLaunchPlugin
.getDefault()
62 .getPreferenceStore().getString(
63 SlcPreferencePage
.PREF_SLC_RUNTIME_LOCATION
);
64 if (slcRuntimePath
== null || slcRuntimePath
.equals("")) {
65 showError("SLC Runtime path is not set. Set it in Windows > Preferences > SLC");
69 deployedSlc
= new DeployedSlcRuntime(slcRuntimePath
);
72 IVMRunner vmRunner
= deployedSlc
.getVmInstall().getVMRunner(mode
);
73 VMRunnerConfiguration vmConfig
= new VMRunnerConfiguration(ANT_MAIN
,
74 deployedSlc
.getClasspath());
75 vmConfig
.setVMArguments(getVmArguments(deployedSlc
));
76 vmConfig
.setWorkingDirectory(file
.getLocation().toFile().getParent());
77 vmConfig
.setProgramArguments(getProgramArguments(deployedSlc
, file
,
79 vmRunner
.run(vmConfig
, launch
, null);
82 private String
[] getVmArguments(SlcRuntime deployedSlc
) {
83 List
<String
> list
= new Vector
<String
>();
84 // list.add("-Dant.home=" + deployedSlc.getAntHome());
85 if (deployedSlc
.getJavaLibraryPath() != null)
86 list
.add("-Djava.library.path=" + deployedSlc
.getJavaLibraryPath());
87 return list
.toArray(new String
[list
.size()]);
90 private String
[] getProgramArguments(SlcRuntime deployedSlc
, IFile file
,
92 List
<String
> list
= new Vector
<String
>();
94 list
.add(file
.getLocation().toFile().getAbsolutePath());
95 if (mode
.equals(ILaunchManager
.DEBUG_MODE
)) {
98 return list
.toArray(new String
[list
.size()]);
101 private void showError(String message
) {
102 Shell shell
= SlcUiLaunchPlugin
.getDefault().getWorkbench()
103 .getActiveWorkbenchWindow().getShell();
105 IStatus status
= new Status(IStatus
.ERROR
, SlcUiLaunchPlugin
.ID
,
107 ErrorDialog
.openError(shell
, "Error", "Cannot launch SLC script",
111 protected boolean checkProjectForEmbedded(IJavaProject project
) {
113 IType antmainType
= project
.findType(ANT_MAIN
);
114 if (antmainType
== null)
118 } catch (JavaModelException e
) {