Bundle-ManifestVersion: 2
Bundle-Name: SLC UI Launch
Bundle-SymbolicName: org.argeo.slc.ui.launch;singleton:=true
-Bundle-Version: 0.9.1
+Bundle-Version: 0.9.3
Bundle-Activator: org.argeo.slc.ui.launch.SlcUiLaunchPlugin
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
org.eclipse.jdt.launching,
org.eclipse.debug.ui,
org.eclipse.jdt.core,
- org.eclipse.ui.console
+ org.eclipse.ui.console,
+ org.eclipse.jdt.debug.ui
Eclipse-LazyStart: true
+++ /dev/null
-package org.argeo.slc.ui.launch;\r
-\r
-import java.io.File;\r
-import java.io.IOException;\r
-import java.util.List;\r
-import java.util.Vector;\r
-\r
-import org.eclipse.core.runtime.CoreException;\r
-import org.eclipse.jdt.launching.IVMInstall;\r
-import org.eclipse.jdt.launching.JavaRuntime;\r
-\r
-public class DeployedSlcRuntime implements SlcRuntime {\r
- private File baseDir;\r
- private String relLibDir = "lib";\r
-\r
- public DeployedSlcRuntime(String baseDirPath) {\r
- try {\r
- this.baseDir = new File(baseDirPath).getCanonicalFile();\r
- } catch (IOException e) {\r
- throw new RuntimeException("Cannot get path for " + baseDirPath, e);\r
- }\r
- }\r
-\r
- public String[] getClasspath() throws CoreException {\r
- List<String> classpath = new Vector<String>();\r
- File libDir = new File(baseDir.getPath() + File.separator + relLibDir);\r
- File[] files = libDir.listFiles();\r
- for (File file : files) {\r
- try {\r
- classpath.add(file.getCanonicalPath());\r
- } catch (IOException e) {\r
- throw new RuntimeException("Cannot get path for " + file, e);\r
- }\r
- }\r
- return classpath.toArray(new String[classpath.size()]);\r
- }\r
-\r
- public IVMInstall getVmInstall() throws CoreException {\r
- return JavaRuntime.getDefaultVMInstall();\r
- }\r
-\r
- public String getAntHome() {\r
- return baseDir.getPath();\r
- }\r
-\r
- public String getJavaLibraryPath() {\r
- return baseDir.getPath() + File.separator + "bin";\r
- }\r
-\r
-}\r
--- /dev/null
+package org.argeo.slc.ui.launch;\r
+\r
+import java.io.File;\r
+import java.io.IOException;\r
+import java.util.List;\r
+import java.util.Vector;\r
+\r
+import org.eclipse.core.runtime.CoreException;\r
+import org.eclipse.jdt.launching.IVMInstall;\r
+import org.eclipse.jdt.launching.JavaRuntime;\r
+\r
+public class DeployedSlcSystem implements SlcSystem {\r
+ private File baseDir;\r
+ private String relLibDir = "lib";\r
+\r
+ public DeployedSlcSystem(String baseDirPath) {\r
+ try {\r
+ this.baseDir = new File(baseDirPath).getCanonicalFile();\r
+ } catch (IOException e) {\r
+ throw new RuntimeException("Cannot get path for " + baseDirPath, e);\r
+ }\r
+ }\r
+\r
+ public String[] getClasspath() throws CoreException {\r
+ List<String> classpath = new Vector<String>();\r
+ File libDir = new File(baseDir.getPath() + File.separator + relLibDir);\r
+ File[] files = libDir.listFiles();\r
+ for (File file : files) {\r
+ try {\r
+ classpath.add(file.getCanonicalPath());\r
+ } catch (IOException e) {\r
+ throw new RuntimeException("Cannot get path for " + file, e);\r
+ }\r
+ }\r
+ return classpath.toArray(new String[classpath.size()]);\r
+ }\r
+\r
+ public IVMInstall getVmInstall() throws CoreException {\r
+ return JavaRuntime.getDefaultVMInstall();\r
+ }\r
+\r
+ public String getAntHome() {\r
+ return baseDir.getPath();\r
+ }\r
+\r
+ public String getJavaLibraryPath() {\r
+ return baseDir.getPath() + File.separator + "bin";\r
+ }\r
+\r
+}\r
+++ /dev/null
-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;
- }
-
- public String[] getClasspath() throws CoreException {
- return JavaRuntime.computeDefaultRuntimeClassPath(project);
- }
-
- public String getJavaLibraryPath() {
- String javaLibPath = SlcUiLaunchPlugin.getDefault()
- .getPreferenceStore().getString(
- SlcPreferencePage.PREF_SLC_RUNTIME_LOCATION);
- if (javaLibPath == null || javaLibPath.equals(""))
- return null;
- else
- return javaLibPath;
- }
-
- public IVMInstall getVmInstall() throws CoreException {
- return JavaRuntime.getVMInstall(project);
- }
-
-}
--- /dev/null
+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 EmbeddedSlcSystem implements SlcSystem {
+ private final IJavaProject project;
+
+ public EmbeddedSlcSystem(IJavaProject project) {
+ this.project = project;
+ }
+
+ public String[] getClasspath() throws CoreException {
+ return JavaRuntime.computeDefaultRuntimeClassPath(project);
+ }
+
+ public String getJavaLibraryPath() {
+ String javaLibPath = SlcUiLaunchPlugin.getDefault()
+ .getPreferenceStore().getString(
+ SlcPreferencePage.PREF_SLC_RUNTIME_LOCATION);
+ if (javaLibPath == null || javaLibPath.equals(""))
+ return null;
+ else
+ return javaLibPath;
+ }
+
+ public IVMInstall getVmInstall() throws CoreException {
+ return JavaRuntime.getVMInstall(project);
+ }
+
+}
+++ /dev/null
-package org.argeo.slc.ui.launch;\r
-\r
-import org.eclipse.core.runtime.CoreException;\r
-import org.eclipse.jdt.launching.IVMInstall;\r
-\r
-public interface SlcRuntime {\r
- public String[] getClasspath() throws CoreException;\r
- public String getJavaLibraryPath();\r
- public IVMInstall getVmInstall() throws CoreException;\r
-}\r
--- /dev/null
+package org.argeo.slc.ui.launch;\r
+\r
+import org.eclipse.core.runtime.CoreException;\r
+import org.eclipse.jdt.launching.IVMInstall;\r
+\r
+public interface SlcSystem {\r
+ public String[] getClasspath() throws CoreException;\r
+ public String getJavaLibraryPath();\r
+ public IVMInstall getVmInstall() throws CoreException;\r
+}\r
package org.argeo.slc.ui.launch.script;\r
\r
+import java.io.IOException;\r
+import java.io.StringReader;\r
+import java.io.StringWriter;\r
+import java.util.HashMap;\r
+import java.util.Map;\r
+import java.util.Properties;\r
+\r
import org.eclipse.core.resources.IFile;\r
import org.eclipse.core.runtime.CoreException;\r
import org.eclipse.debug.core.ILaunchConfiguration;\r
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;\r
+import org.eclipse.debug.internal.ui.SWTFactory;\r
import org.eclipse.debug.ui.AbstractLaunchConfigurationTab;\r
import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.events.ModifyEvent;\r
+import org.eclipse.swt.events.ModifyListener;\r
+import org.eclipse.swt.events.SelectionEvent;\r
+import org.eclipse.swt.events.SelectionListener;\r
+import org.eclipse.swt.layout.GridData;\r
+import org.eclipse.swt.layout.GridLayout;\r
+import org.eclipse.swt.widgets.Button;\r
import org.eclipse.swt.widgets.Composite;\r
import org.eclipse.swt.widgets.Label;\r
+import org.eclipse.swt.widgets.Text;\r
\r
public class SlcScriptLaunchConfigurationTab extends\r
AbstractLaunchConfigurationTab {\r
\r
- private IFile script;\r
- \r
+ private Text scriptL;\r
+ private Text propertiesTF;\r
+ private Text runtimeTF;\r
+ private Text targetsTF;\r
+ private Button pre093B;\r
+\r
public void createControl(Composite parent) {\r
- Composite body = new Composite(parent,SWT.NONE);\r
- new Label(parent, SWT.LEAD).setText("Script location");\r
- if (script != null) {\r
- new Label(parent, SWT.LEAD).setText(script.getLocation().toFile()\r
- .getAbsolutePath());\r
- }\r
+ Composite body = new Composite(parent, SWT.NONE);\r
setControl(body);\r
+ body.setLayout(new GridLayout(1, false));\r
+ body.setFont(parent.getFont());\r
+\r
+ createLabel(body, "Script location");\r
+ scriptL = createSingleText(body);\r
+ scriptL.setEditable(false);\r
+ scriptL.setBackground(body.getBackground());\r
+\r
+ createLabel(body, "Runtime");\r
+ runtimeTF = createSingleText(body);\r
+\r
+ createLabel(body, "Targets");\r
+ targetsTF = createSingleText(body);\r
+\r
+ createLabel(body, "Properties");\r
+ propertiesTF = createMultipleText(body, 10);\r
+\r
+ pre093B = createCheckBox(body, "Pre SLC v0.9.3");\r
}\r
\r
public String getName() {\r
\r
public void initializeFrom(ILaunchConfiguration configuration) {\r
try {\r
- script = (IFile) configuration.getMappedResources()[0];\r
+ IFile script = (IFile) configuration.getMappedResources()[0];\r
+ scriptL.setText(script.getLocation().toFile().getAbsolutePath());\r
+\r
+ boolean pre093 = configuration.getAttribute(\r
+ SlcScriptLaunchDelegate.ATTR_PRE093, false);\r
+\r
+ propertiesTF.setText(configuration.getAttribute(\r
+ SlcScriptLaunchDelegate.ATTR_PROPERTIES, ""));\r
+ runtimeTF.setText(configuration.getAttribute(\r
+ SlcScriptLaunchDelegate.ATTR_RUNTIME, ""));\r
+ targetsTF.setText(configuration.getAttribute(\r
+ SlcScriptLaunchDelegate.ATTR_TARGETS, ""));\r
+ pre093B.setSelection(pre093);\r
} catch (CoreException e) {\r
throw new RuntimeException("Cannot initialize tab", e);\r
}\r
}\r
\r
public void performApply(ILaunchConfigurationWorkingCopy configuration) {\r
+ configuration.setAttribute(SlcScriptLaunchDelegate.ATTR_PROPERTIES,\r
+ propertiesTF.getText());\r
+ configuration.setAttribute(SlcScriptLaunchDelegate.ATTR_RUNTIME,\r
+ runtimeTF.getText());\r
+ configuration.setAttribute(SlcScriptLaunchDelegate.ATTR_TARGETS,\r
+ targetsTF.getText());\r
+ configuration.setAttribute(SlcScriptLaunchDelegate.ATTR_PRE093, pre093B\r
+ .getSelection());\r
}\r
\r
public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {\r
}\r
\r
+ // UI Utils\r
+ protected Label createLabel(Composite parent, String text) {\r
+ Label t = new Label(parent, SWT.NONE | SWT.WRAP);\r
+ t.setText(text);\r
+ t.setFont(parent.getFont());\r
+ GridData gd = new GridData(GridData.FILL_HORIZONTAL);\r
+ gd.horizontalSpan = 1;\r
+ t.setLayoutData(gd);\r
+ return t;\r
+ }\r
+\r
+ protected Text createSingleText(Composite parent) {\r
+ Text t = new Text(parent, SWT.SINGLE | SWT.BORDER);\r
+ t.setFont(parent.getFont());\r
+ GridData gd = new GridData(GridData.FILL_HORIZONTAL);\r
+ gd.horizontalSpan = 1;\r
+ t.setLayoutData(gd);\r
+ t.addModifyListener(modifyListener);\r
+ return t;\r
+ }\r
+\r
+ protected Text createMultipleText(Composite parent, int verticalSpan) {\r
+ Text t = new Text(parent, SWT.MULTI | SWT.BORDER);\r
+ t.setFont(parent.getFont());\r
+ GridData gd = new GridData(GridData.FILL, GridData.FILL, true, true);\r
+ gd.horizontalSpan = 1;\r
+ gd.verticalSpan = verticalSpan;\r
+ t.setLayoutData(gd);\r
+ t.addModifyListener(modifyListener);\r
+ return t;\r
+ }\r
+\r
+ protected Button createCheckBox(Composite parent, String label) {\r
+ Button b = new Button(parent, SWT.CHECK);\r
+ b.setFont(parent.getFont());\r
+ b.setText(label);\r
+ b.addSelectionListener(selectionListener);\r
+ return b;\r
+\r
+ }\r
+\r
+ // LISTENERS\r
+ /**\r
+ * Modify listener that simply updates the owning launch configuration\r
+ * dialog.\r
+ */\r
+ private ModifyListener modifyListener = new ModifyListener() {\r
+ public void modifyText(ModifyEvent evt) {\r
+ updateLaunchConfigurationDialog();\r
+ }\r
+ };\r
+ private SelectionListener selectionListener = new SelectionListener() {\r
+ public void widgetDefaultSelected(SelectionEvent e) {\r
+ }\r
+\r
+ public void widgetSelected(SelectionEvent e) {\r
+ updateLaunchConfigurationDialog();\r
+ }\r
+ };\r
+\r
}\r
package org.argeo.slc.ui.launch.script;\r
\r
+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.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.DeployedSlcSystem;\r
+import org.argeo.slc.ui.launch.EmbeddedSlcSystem;\r
+import org.argeo.slc.ui.launch.SlcSystem;\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.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 static final String ID = "org.argeo.slc.launch.slcScriptLaunchType";\r
\r
+ public final static String ATTR_SCRIPT = "script";\r
+ public final static String ATTR_PROPERTIES = "properties";\r
+ public final static String ATTR_RUNTIME = "runtime";\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
\r
public void launch(ILaunchConfiguration configuration, String mode,\r
ILaunch launch, IProgressMonitor monitor) throws CoreException {\r
IResource[] resources = configuration.getMappedResources();\r
+\r
if (resources.length != 1) {\r
throw new RuntimeException("Can only launch one script.");\r
}\r
IFile file = (IFile) resources[0];\r
System.out.println("Launched " + file.getLocation().toFile());\r
\r
+ boolean pre093 = configuration.getAttribute(ATTR_PRE093, false);\r
+\r
// Retrieve SLC Runtime\r
- SlcRuntime deployedSlc = null;\r
+ SlcSystem slcSystem = findSlcSystem(file);\r
+ if (slcSystem == null)\r
+ return;\r
+\r
+ IVMRunner vmRunner = slcSystem.getVmInstall().getVMRunner(mode);\r
+ final VMRunnerConfiguration vmConfig;\r
+ if (pre093) {\r
+ vmConfig = createPre093Config(slcSystem, file, mode);\r
+ } else {\r
+ vmConfig = createConfig(slcSystem, file, mode, configuration);\r
+ }\r
+ vmRunner.run(vmConfig, launch, null);\r
+ }\r
+\r
+ protected SlcSystem findSlcSystem(IFile file) 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
- deployedSlc = new EmbeddedSlcRuntime(javaProject);\r
+ slcSystem = new EmbeddedSlcSystem(javaProject);\r
}\r
}\r
\r
- if (deployedSlc == null) {\r
+ if (slcSystem == 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
+ return null;\r
}\r
\r
- deployedSlc = new DeployedSlcRuntime(slcRuntimePath);\r
+ slcSystem = new DeployedSlcSystem(slcRuntimePath);\r
}\r
\r
- IVMRunner vmRunner = deployedSlc.getVmInstall().getVMRunner(mode);\r
- VMRunnerConfiguration vmConfig = new VMRunnerConfiguration(ANT_MAIN,\r
+ return slcSystem;\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
+ // Regular SLC\r
+ protected VMRunnerConfiguration createConfig(SlcSystem deployedSlc,\r
+ IFile file, String mode, ILaunchConfiguration configuration)\r
+ throws CoreException {\r
+ VMRunnerConfiguration vmConfig = new VMRunnerConfiguration(SLC_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
+ mode, configuration));\r
+ return vmConfig;\r
}\r
\r
- private String[] getVmArguments(SlcRuntime deployedSlc) {\r
+ protected String[] getVmArguments(SlcSystem deployedSlc) {\r
+ List<String> list = new Vector<String>();\r
+ if (deployedSlc.getJavaLibraryPath() != null)\r
+ list.add("-Djava.library.path=" + deployedSlc.getJavaLibraryPath());\r
+ return list.toArray(new String[list.size()]);\r
+ }\r
+\r
+ protected String[] getProgramArguments(SlcSystem deployedSlc, IFile file,\r
+ String mode, ILaunchConfiguration configuration)\r
+ throws CoreException {\r
+ List<String> list = new Vector<String>();\r
+\r
+ list.add("--mode");\r
+ list.add("single");\r
+\r
+ // Script\r
+ list.add("--script");\r
+ list.add(file.getLocation().toFile().getAbsolutePath());\r
+\r
+ // Runtime\r
+ String runtime = configuration.getAttribute(ATTR_RUNTIME, "");\r
+ if (!runtime.equals("")) {\r
+ list.add("--runtime");\r
+ list.add(runtime);\r
+ }\r
+\r
+ // Targets\r
+ String targets = configuration.getAttribute(ATTR_RUNTIME, "");\r
+ if (!runtime.equals("")) {\r
+ list.add("--targets");\r
+ list.add(targets);\r
+ }\r
+\r
+ // Properties\r
+ Properties properties = new Properties();\r
+ StringReader reader = new StringReader(configuration.getAttribute(\r
+ ATTR_PROPERTIES, ""));\r
+ try {\r
+ properties.load(reader);\r
+ } catch (IOException e) {\r
+ throw new RuntimeException("Cannot read properties", e);\r
+ } finally {\r
+ if (reader != null)\r
+ reader.close();\r
+ }\r
+\r
+ for (Object key : properties.keySet()) {\r
+ list.add("-p");\r
+ StringBuffer buf = new StringBuffer("");\r
+ buf.append(key).append('=').append(properties.get(key));\r
+ list.add(buf.toString());\r
+ }\r
+\r
+ // Debug mode\r
+ if (mode.equals(ILaunchManager.DEBUG_MODE)) {\r
+ list.add("--property");\r
+ list.add("log4j.logger.org.argeo.slc=DEBUG");\r
+ }\r
+ return list.toArray(new String[list.size()]);\r
+ }\r
+\r
+ // Pre SLC v0.9.3\r
+ protected VMRunnerConfiguration createPre093Config(SlcSystem deployedSlc,\r
+ IFile file, String mode) throws CoreException {\r
+ VMRunnerConfiguration vmConfig = new VMRunnerConfiguration(ANT_MAIN,\r
+ deployedSlc.getClasspath());\r
+ vmConfig.setVMArguments(getPre093VmArguments(deployedSlc));\r
+ vmConfig.setWorkingDirectory(file.getLocation().toFile().getParent());\r
+ vmConfig.setProgramArguments(getPre093ProgramArguments(deployedSlc,\r
+ file, mode));\r
+ return vmConfig;\r
+ }\r
+\r
+ protected String[] getPre093VmArguments(SlcSystem deployedSlc) {\r
List<String> list = new Vector<String>();\r
// list.add("-Dant.home=" + deployedSlc.getAntHome());\r
if (deployedSlc.getJavaLibraryPath() != null)\r
return list.toArray(new String[list.size()]);\r
}\r
\r
- private String[] getProgramArguments(SlcRuntime deployedSlc, IFile file,\r
- String mode) {\r
+ protected String[] getPre093ProgramArguments(SlcSystem deployedSlc,\r
+ IFile file, String mode) {\r
List<String> list = new Vector<String>();\r
list.add("-f");\r
list.add(file.getLocation().toFile().getAbsolutePath());\r
return list.toArray(new String[list.size()]);\r
}\r
\r
+ // Utilities\r
private void showError(String message) {\r
Shell shell = SlcUiLaunchPlugin.getDefault().getWorkbench()\r
.getActiveWorkbenchWindow().getShell();\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
IFile file = ((IFile) obj);\r
IProject project = file.getProject();\r
IPath relativePath = file.getProjectRelativePath();\r
- String name = "["+project.getName() + "] - " + relativePath.toString();\r
+ String name = "[" + project.getName() + "] - "\r
+ + relativePath.toString();\r
name = name.replace('/', '_');// otherwise not properly saved\r
\r
System.out.println(name);\r