package org.argeo.slc.ui.launch.script;\r
\r
+import java.io.ByteArrayInputStream;\r
import java.io.IOException;\r
-import java.io.StringReader;\r
import java.util.List;\r
import java.util.Properties;\r
import java.util.Vector;\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
+import org.eclipse.core.resources.ResourcesPlugin;\r
import org.eclipse.core.runtime.CoreException;\r
+import org.eclipse.core.runtime.IPath;\r
import org.eclipse.core.runtime.IProgressMonitor;\r
import org.eclipse.core.runtime.IStatus;\r
+import org.eclipse.core.runtime.Path;\r
import org.eclipse.core.runtime.Status;\r
+import org.eclipse.core.variables.IStringVariableManager;\r
+import org.eclipse.core.variables.VariablesPlugin;\r
+import org.eclipse.debug.core.DebugPlugin;\r
import org.eclipse.debug.core.ILaunch;\r
import org.eclipse.debug.core.ILaunchConfiguration;\r
import org.eclipse.debug.core.ILaunchManager;\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
public final static String ANT_MAIN = "org.apache.tools.ant.Main";\r
public 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
+ if (!saveBeforeLaunch(configuration, mode, monitor))\r
+ return;\r
\r
- if (resources.length != 1) {\r
- throw new RuntimeException("Can only launch one script.");\r
- }\r
- if (!(resources[0] instanceof IFile)) {\r
- throw new RuntimeException("Can only launch file.");\r
- }\r
- IFile file = (IFile) resources[0];\r
- System.out.println("Launched " + file.getLocation().toFile());\r
+ String scriptLocation = configuration.getAttribute(\r
+ SlcScriptUtils.ATTR_SCRIPT, "");\r
+ if (scriptLocation.equals(""))\r
+ abort("Script has to be provided", null, 1);\r
\r
- boolean pre093 = configuration.getAttribute(ATTR_PRE093, false);\r
+ IStringVariableManager manager = VariablesPlugin.getDefault()\r
+ .getStringVariableManager();\r
+ scriptLocation = manager.performStringSubstitution(scriptLocation);\r
+ IPath path = new Path(scriptLocation);\r
+ IFile[] files = ResourcesPlugin.getWorkspace().getRoot()\r
+ .findFilesForLocation(path);\r
+\r
+ if (files.length == 0)\r
+ abort("Coulkd not find related file", null, 1);\r
+\r
+ IFile file = (IFile) files[0];\r
+ DebugPlugin\r
+ .logMessage("Launching " + file.getLocation().toFile(), null);\r
+\r
+ boolean pre093 = configuration.getAttribute(SlcScriptUtils.ATTR_PRE093,\r
+ false);\r
\r
// Retrieve SLC Runtime\r
SlcSystem slcSystem = findSlcSystem(file, pre093);\r
list.add(file.getLocation().toFile().getAbsolutePath());\r
\r
// Runtime\r
- String runtime = configuration.getAttribute(ATTR_RUNTIME, "");\r
+ String runtime = configuration.getAttribute(\r
+ SlcScriptUtils.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
+ String targets = configuration.getAttribute(\r
+ SlcScriptUtils.ATTR_TARGETS, "");\r
+ if (!targets.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
+ String str = configuration.getAttribute(SlcScriptUtils.ATTR_PROPERTIES,\r
+ "");\r
+ ByteArrayInputStream in = new ByteArrayInputStream(str.getBytes());\r
try {\r
- properties.load(reader);\r
+ properties.load(in);\r
} catch (IOException e) {\r
throw new RuntimeException("Cannot read properties", e);\r
} finally {\r
- if (reader != null)\r
- reader.close();\r
+ if (in != null)\r
+ try {\r
+ in.close();\r
+ } catch (IOException e) {\r
+ // silent\r
+ }\r
}\r
\r
for (Object key : properties.keySet()) {\r