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