]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - eclipse/plugins/org.argeo.slc.ui.launch/src/main/java/org/argeo/slc/ui/launch/script/SlcScriptLaunchDelegate.java
Launching SLC can now use the project classpath (EmbeddedSlcRuntime)
[gpl/argeo-slc.git] / eclipse / plugins / org.argeo.slc.ui.launch / src / main / java / org / argeo / slc / ui / launch / script / SlcScriptLaunchDelegate.java
index 02a00e05406d8649f470da95e2597c6b6811af7d..7acbb2920204e4f8217797e3a5d6db669cde0201 100644 (file)
@@ -3,6 +3,11 @@ package org.argeo.slc.ui.launch.script;
 import java.util.List;\r
 import java.util.Vector;\r
 \r
+import org.argeo.slc.ui.launch.DeployedSlcRuntime;\r
+import org.argeo.slc.ui.launch.EmbeddedSlcRuntime;\r
+import org.argeo.slc.ui.launch.SlcRuntime;\r
+import org.argeo.slc.ui.launch.SlcUiLaunchPlugin;\r
+import org.argeo.slc.ui.launch.preferences.SlcPreferencePage;\r
 import org.eclipse.core.resources.IFile;\r
 import org.eclipse.core.resources.IProject;\r
 import org.eclipse.core.resources.IResource;\r
@@ -14,19 +19,15 @@ import org.eclipse.debug.core.ILaunch;
 import org.eclipse.debug.core.ILaunchConfiguration;\r
 import org.eclipse.debug.core.ILaunchManager;\r
 import org.eclipse.jdt.core.IJavaProject;\r
+import org.eclipse.jdt.core.IType;\r
+import org.eclipse.jdt.core.JavaCore;\r
+import org.eclipse.jdt.core.JavaModelException;\r
 import org.eclipse.jdt.launching.AbstractJavaLaunchConfigurationDelegate;\r
-import org.eclipse.jdt.launching.IVMInstall;\r
 import org.eclipse.jdt.launching.IVMRunner;\r
-import org.eclipse.jdt.launching.JavaRuntime;\r
 import org.eclipse.jdt.launching.VMRunnerConfiguration;\r
 import org.eclipse.jface.dialogs.ErrorDialog;\r
 import org.eclipse.swt.widgets.Shell;\r
 \r
-import org.argeo.slc.ui.launch.DefaultSlcRuntime;\r
-import org.argeo.slc.ui.launch.SlcRuntime;\r
-import org.argeo.slc.ui.launch.SlcUiLaunchPlugin;\r
-import org.argeo.slc.ui.launch.preferences.SlcPreferencePage;\r
-\r
 public class SlcScriptLaunchDelegate extends\r
                AbstractJavaLaunchConfigurationDelegate {\r
        public static final String ID = "org.argeo.slc.launch.slcScriptLaunchType";\r
@@ -46,54 +47,43 @@ public class SlcScriptLaunchDelegate extends
                System.out.println("Launched " + file.getLocation().toFile());\r
 \r
                // Retrieve SLC Runtime\r
-               String slcRuntimePath = SlcUiLaunchPlugin.getDefault()\r
-                               .getPreferenceStore().getString(\r
-                                               SlcPreferencePage.PREF_SLC_RUNTIME_LOCATION);\r
-               if (slcRuntimePath == null || slcRuntimePath.equals("")) {\r
-                       showError("SLC Runtime path is not set. Set it in Windows > Preferences > SLC");\r
-                       return;\r
-               }\r
-               SlcRuntime deployedSlc = new DefaultSlcRuntime(slcRuntimePath);\r
+               SlcRuntime deployedSlc = null;\r
 \r
                IProject project = file.getProject();\r
-\r
-               IVMInstall vmInstall = null;\r
-               String[] classPath = null;\r
-\r
-               if (project instanceof IJavaProject) {\r
-                       JavaRuntime.getVMInstall((IJavaProject) project);\r
-                       classPath = JavaRuntime\r
-                                       .computeDefaultRuntimeClassPath((IJavaProject) project);\r
+               if (project.getNature("org.eclipse.jdt.core.javanature") != null) {\r
+                       IJavaProject javaProject = JavaCore.create(project);\r
+                       if (checkProjectForEmbedded(javaProject)) {\r
+                               deployedSlc = new EmbeddedSlcRuntime(javaProject);\r
+                       }\r
                }\r
 \r
-               if (vmInstall == null)\r
-                       vmInstall = JavaRuntime.getDefaultVMInstall();\r
-               if (vmInstall != null) {\r
-                       IVMRunner vmRunner = vmInstall.getVMRunner(mode);\r
-                       if (vmRunner != null) {\r
-                               if (classPath == null) {\r
-                                       classPath = deployedSlc.getClasspath();\r
-                               }\r
-\r
-                               if (classPath != null) {\r
-                                       VMRunnerConfiguration vmConfig = new VMRunnerConfiguration(\r
-                                                       ANT_MAIN, classPath);\r
-                                       vmConfig.setVMArguments(getVmArguments(deployedSlc));\r
-                                       vmConfig.setWorkingDirectory(file.getLocation().toFile()\r
-                                                       .getParent());\r
-                                       vmConfig.setProgramArguments(getProgramArguments(\r
-                                                       deployedSlc, file, mode));\r
-                                       vmRunner.run(vmConfig, launch, null);\r
-                               }\r
+               if (deployedSlc == null) {\r
+                       String slcRuntimePath = SlcUiLaunchPlugin.getDefault()\r
+                                       .getPreferenceStore().getString(\r
+                                                       SlcPreferencePage.PREF_SLC_RUNTIME_LOCATION);\r
+                       if (slcRuntimePath == null || slcRuntimePath.equals("")) {\r
+                               showError("SLC Runtime path is not set. Set it in Windows > Preferences > SLC");\r
+                               return;\r
                        }\r
+\r
+                       deployedSlc = new DeployedSlcRuntime(slcRuntimePath);\r
                }\r
 \r
+               IVMRunner vmRunner = deployedSlc.getVmInstall().getVMRunner(mode);\r
+               VMRunnerConfiguration vmConfig = new VMRunnerConfiguration(ANT_MAIN,\r
+                               deployedSlc.getClasspath());\r
+               vmConfig.setVMArguments(getVmArguments(deployedSlc));\r
+               vmConfig.setWorkingDirectory(file.getLocation().toFile().getParent());\r
+               vmConfig.setProgramArguments(getProgramArguments(deployedSlc, file,\r
+                               mode));\r
+               vmRunner.run(vmConfig, launch, null);\r
        }\r
 \r
        private String[] getVmArguments(SlcRuntime deployedSlc) {\r
                List<String> list = new Vector<String>();\r
-               list.add("-Dant.home=" + deployedSlc.getAntHome());\r
-               list.add("-Djava.library.path=" + deployedSlc.getJavaLibraryPath());\r
+               // list.add("-Dant.home=" + deployedSlc.getAntHome());\r
+               if (deployedSlc.getJavaLibraryPath() != null)\r
+                       list.add("-Djava.library.path=" + deployedSlc.getJavaLibraryPath());\r
                return list.toArray(new String[list.size()]);\r
        }\r
 \r
@@ -117,4 +107,17 @@ public class SlcScriptLaunchDelegate extends
                ErrorDialog.openError(shell, "Error", "Cannot launch SLC script",\r
                                status);\r
        }\r
+\r
+       protected boolean checkProjectForEmbedded(IJavaProject project) {\r
+               try {\r
+                       IType antmainType = project.findType(ANT_MAIN);\r
+                       if (antmainType == null)\r
+                               return false;\r
+                       else\r
+                               return true;\r
+               } catch (JavaModelException e) {\r
+                       e.printStackTrace();\r
+                       return false;\r
+               }\r
+       }\r
 }\r