From 5c3611122fcc51cf6635f7110081a80393fb3c18 Mon Sep 17 00:00:00 2001 From: Mathieu Baudier Date: Mon, 2 Jun 2008 16:32:00 +0000 Subject: [PATCH] Launching SLC can now use the project classpath (EmbeddedSlcRuntime) git-svn-id: https://svn.argeo.org/slc/trunk@1173 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- .../META-INF/MANIFEST.MF | 2 +- ...lcRuntime.java => DeployedSlcRuntime.java} | 20 +++- .../slc/ui/launch/EmbeddedSlcRuntime.java | 37 ++++++++ .../org/argeo/slc/ui/launch/SlcRuntime.java | 7 +- .../launch/preferences/SlcPreferencePage.java | 4 + .../script/SlcScriptLaunchDelegate.java | 91 ++++++++++--------- 6 files changed, 109 insertions(+), 52 deletions(-) rename eclipse/plugins/org.argeo.slc.ui.launch/src/main/java/org/argeo/slc/ui/launch/{DefaultSlcRuntime.java => DeployedSlcRuntime.java} (65%) create mode 100644 eclipse/plugins/org.argeo.slc.ui.launch/src/main/java/org/argeo/slc/ui/launch/EmbeddedSlcRuntime.java diff --git a/eclipse/plugins/org.argeo.slc.ui.launch/META-INF/MANIFEST.MF b/eclipse/plugins/org.argeo.slc.ui.launch/META-INF/MANIFEST.MF index 203abbf0a..42ad0aba3 100644 --- a/eclipse/plugins/org.argeo.slc.ui.launch/META-INF/MANIFEST.MF +++ b/eclipse/plugins/org.argeo.slc.ui.launch/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: SLC UI Launch Bundle-SymbolicName: org.argeo.slc.ui.launch;singleton:=true -Bundle-Version: 0.6.0 +Bundle-Version: 0.9.2.SNAPSHOT Bundle-Activator: org.argeo.slc.ui.launch.SlcUiLaunchPlugin Require-Bundle: org.eclipse.ui, org.eclipse.core.runtime, diff --git a/eclipse/plugins/org.argeo.slc.ui.launch/src/main/java/org/argeo/slc/ui/launch/DefaultSlcRuntime.java b/eclipse/plugins/org.argeo.slc.ui.launch/src/main/java/org/argeo/slc/ui/launch/DeployedSlcRuntime.java similarity index 65% rename from eclipse/plugins/org.argeo.slc.ui.launch/src/main/java/org/argeo/slc/ui/launch/DefaultSlcRuntime.java rename to eclipse/plugins/org.argeo.slc.ui.launch/src/main/java/org/argeo/slc/ui/launch/DeployedSlcRuntime.java index 42e62e8e0..e6691baf8 100644 --- a/eclipse/plugins/org.argeo.slc.ui.launch/src/main/java/org/argeo/slc/ui/launch/DefaultSlcRuntime.java +++ b/eclipse/plugins/org.argeo.slc.ui.launch/src/main/java/org/argeo/slc/ui/launch/DeployedSlcRuntime.java @@ -5,11 +5,15 @@ import java.io.IOException; import java.util.List; import java.util.Vector; -public class DefaultSlcRuntime implements SlcRuntime { +import org.eclipse.core.runtime.CoreException; +import org.eclipse.jdt.launching.IVMInstall; +import org.eclipse.jdt.launching.JavaRuntime; + +public class DeployedSlcRuntime implements SlcRuntime { private File baseDir; private String relLibDir = "lib"; - public DefaultSlcRuntime(String baseDirPath) { + public DeployedSlcRuntime(String baseDirPath) { try { this.baseDir = new File(baseDirPath).getCanonicalFile(); } catch (IOException e) { @@ -17,7 +21,8 @@ public class DefaultSlcRuntime implements SlcRuntime { } } - public String[] getClasspath() { + @Override + public String[] getClasspath() throws CoreException { List classpath = new Vector(); File libDir = new File(baseDir.getPath() + File.separator + relLibDir); File[] files = libDir.listFiles(); @@ -31,13 +36,18 @@ public class DefaultSlcRuntime implements SlcRuntime { return classpath.toArray(new String[classpath.size()]); } + @Override + public IVMInstall getVmInstall() throws CoreException { + return JavaRuntime.getDefaultVMInstall(); + } + public String getAntHome() { return baseDir.getPath(); } + @Override public String getJavaLibraryPath() { return baseDir.getPath() + File.separator + "bin"; } - - + } diff --git a/eclipse/plugins/org.argeo.slc.ui.launch/src/main/java/org/argeo/slc/ui/launch/EmbeddedSlcRuntime.java b/eclipse/plugins/org.argeo.slc.ui.launch/src/main/java/org/argeo/slc/ui/launch/EmbeddedSlcRuntime.java new file mode 100644 index 000000000..9b3dcd76b --- /dev/null +++ b/eclipse/plugins/org.argeo.slc.ui.launch/src/main/java/org/argeo/slc/ui/launch/EmbeddedSlcRuntime.java @@ -0,0 +1,37 @@ +package org.argeo.slc.ui.launch; + +import org.argeo.slc.ui.launch.preferences.SlcPreferencePage; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.launching.IVMInstall; +import org.eclipse.jdt.launching.JavaRuntime; + +public class EmbeddedSlcRuntime implements SlcRuntime { + private final IJavaProject project; + + public EmbeddedSlcRuntime(IJavaProject project) { + this.project = project; + } + + @Override + public String[] getClasspath() throws CoreException { + return JavaRuntime.computeDefaultRuntimeClassPath(project); + } + + @Override + public String getJavaLibraryPath() { + String javaLibPath = SlcUiLaunchPlugin.getDefault() + .getPreferenceStore().getString( + SlcPreferencePage.PREF_SLC_RUNTIME_LOCATION); + if (javaLibPath == null || javaLibPath.equals("")) + return null; + else + return javaLibPath; + } + + @Override + public IVMInstall getVmInstall() throws CoreException { + return JavaRuntime.getVMInstall(project); + } + +} diff --git a/eclipse/plugins/org.argeo.slc.ui.launch/src/main/java/org/argeo/slc/ui/launch/SlcRuntime.java b/eclipse/plugins/org.argeo.slc.ui.launch/src/main/java/org/argeo/slc/ui/launch/SlcRuntime.java index 92e846bc7..b1cbef67c 100644 --- a/eclipse/plugins/org.argeo.slc.ui.launch/src/main/java/org/argeo/slc/ui/launch/SlcRuntime.java +++ b/eclipse/plugins/org.argeo.slc.ui.launch/src/main/java/org/argeo/slc/ui/launch/SlcRuntime.java @@ -1,7 +1,10 @@ package org.argeo.slc.ui.launch; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.jdt.launching.IVMInstall; + public interface SlcRuntime { - public String[] getClasspath(); - public String getAntHome(); + public String[] getClasspath() throws CoreException; public String getJavaLibraryPath(); + public IVMInstall getVmInstall() throws CoreException; } diff --git a/eclipse/plugins/org.argeo.slc.ui.launch/src/main/java/org/argeo/slc/ui/launch/preferences/SlcPreferencePage.java b/eclipse/plugins/org.argeo.slc.ui.launch/src/main/java/org/argeo/slc/ui/launch/preferences/SlcPreferencePage.java index d2fd3e7a2..cc1a013b4 100644 --- a/eclipse/plugins/org.argeo.slc.ui.launch/src/main/java/org/argeo/slc/ui/launch/preferences/SlcPreferencePage.java +++ b/eclipse/plugins/org.argeo.slc.ui.launch/src/main/java/org/argeo/slc/ui/launch/preferences/SlcPreferencePage.java @@ -12,6 +12,8 @@ public class SlcPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage { public final static String PREF_SLC_RUNTIME_LOCATION = SlcUiLaunchPlugin.ID + ".slcRuntimeLocation"; + public final static String PREF_EMBEDDED_JAVA_LIBRARY_PATH = SlcUiLaunchPlugin.ID + + ".embeddedJavaLibraryPath"; public SlcPreferencePage() { IPreferenceStore store = SlcUiLaunchPlugin.getDefault() @@ -24,6 +26,8 @@ public class SlcPreferencePage extends FieldEditorPreferencePage implements protected void createFieldEditors() { addField(new DirectoryFieldEditor(PREF_SLC_RUNTIME_LOCATION, "SLC Runtime", getFieldEditorParent())); + addField(new DirectoryFieldEditor(PREF_EMBEDDED_JAVA_LIBRARY_PATH, + "Embedded Java Library Path", getFieldEditorParent())); } public void init(IWorkbench workbench) { 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; + } + } } -- 2.39.2