Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [Dltk-dev] code freeze question


  here's a patch w/ the two new files, a utility class and an interface.

  ryan rusaw (of the octclipse project - http://octclipse.sourceforge.net/) emailed me about using this code. looks like another project that wants the to use the language to perform tasks for the editor, etc.

On Tue, Jun 3, 2008 at 10:49 AM, Andrei Sobolev <andrei.sobolev@xxxxxxxxx> wrote:
Hi Jae,

I suppose is is not a problem to add something new, if it is required,
and need to be in core.
Could you please send a message with a patch for your changes.

Best regards,
Andrei Sobolev.
> hello all -
>
>   what is the current standing on adding new classes and interfaces to
> the dltk head? i have some code related to executing 'internal'
> scripts (handles looking up the interpreter, executing the process,
> etc) checked in for my perlipse project that i was planning on
> promoting after the 0.9.5 release, but i just got an email from
> someone else working on a dltk project who wants to use the code as
> well, and wanted to see if this code could still be added (it is all
> new classes/interfaces) - otherwise i will just tell him it will be
> available in the head after 0.9.5 and to just 'cut and paste' the code
> for now.
>
> --
> -jae
> ------------------------------------------------------------------------
>
> _______________________________________________
_______________________________________________



--
-jae
### Eclipse Workspace Patch 1.0
#P org.eclipse.dltk.launching
Index: src/org/eclipse/dltk/launching/InternalScriptExecutor.java
===================================================================
RCS file: src/org/eclipse/dltk/launching/InternalScriptExecutor.java
diff -N src/org/eclipse/dltk/launching/InternalScriptExecutor.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/dltk/launching/InternalScriptExecutor.java	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,107 @@
+package org.eclipse.dltk.launching;
+
+import java.io.IOException;
+import java.util.ArrayList;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.dltk.core.environment.IDeployment;
+import org.eclipse.dltk.core.environment.IExecutionEnvironment;
+import org.eclipse.dltk.core.environment.IFileHandle;
+import org.eclipse.dltk.launching.IScriptProcessHandler.ScriptResult;
+
+/**
+ * Utility class which may be used to execute a script, or perform an
+ * interpreter action on a script, such as compilation.
+ * 
+ * @see IScriptProcessHandler
+ */
+public class InternalScriptExecutor {
+
+	public interface IInternalScriptDeployer {
+		/**
+		 * Deploy the internal script to be executed.
+		 */
+		IPath deployScript(IDeployment deployment) throws IOException;
+	}
+
+	private IScriptProcessHandler handler;
+	private IInterpreterInstall install;
+
+	public InternalScriptExecutor(IInterpreterInstall install,
+			IScriptProcessHandler handler) {
+		Assert.isNotNull(install, "IInterpreterInstall must not be null");
+		Assert.isNotNull(handler, "IProcessHandler must not be null");
+
+		this.install = install;
+		this.handler = handler;
+	}
+
+	/**
+	 * Execute a script or interpreter action
+	 * 
+	 * @param deployer
+	 *            implementation of <code>IInternalScriptDeployer</code> to
+	 *            deploy the script being executed.
+	 * 
+	 * @param interpreterArgs
+	 *            command line arguments for the interpreter, may be
+	 *            <code>null</code>
+	 * 
+	 * @param scriptArgs
+	 *            command line arguments for the script, may be
+	 *            <code>null</code>
+	 * @param stdin
+	 *            stdin to pass to script, may be <code>null</code>
+	 * 
+	 * @throws CoreException
+	 *             if there was an error handling the process
+	 * @throws IOException
+	 *             if there was an error deploying the script
+	 */
+	public ScriptResult execute(IInternalScriptDeployer deployer,
+			String[] interpreterArgs, String[] scriptArgs, char[] stdin)
+			throws CoreException, IOException {
+		IExecutionEnvironment execEnv = install.getExecEnvironment();
+
+		IDeployment deployment = execEnv.createDeployment();
+		IPath deploymentPath = deployer.deployScript(deployment);
+
+		try {
+			IFileHandle interpreter = install.getInstallLocation();
+			IFileHandle script = deployment.getFile(deploymentPath);
+
+			String[] cmdLine = buildCommandLine(interpreter, interpreterArgs,
+					script, scriptArgs);
+
+			Process process = execEnv.exec(cmdLine, null, null);
+			ScriptResult result = handler.handle(process, stdin);
+
+			return result;
+		} finally {
+			deployment.dispose();
+		}
+	}
+
+	private void addArgs(ArrayList list, String[] args) {
+		if (args != null) {
+			for (int i = 0; i < args.length; i++) {
+				list.add(args[i]);
+			}
+		}
+	}
+
+	private String[] buildCommandLine(IFileHandle interpreter,
+			String[] interpreterArgs, IFileHandle script, String[] scriptArgs) {
+		ArrayList cmdLine = new ArrayList();
+
+		cmdLine.add(interpreter.getCanonicalPath());
+		addArgs(cmdLine, interpreterArgs);
+
+		cmdLine.add(script.getCanonicalPath());
+		addArgs(cmdLine, scriptArgs);
+
+		return (String[]) cmdLine.toArray(new String[cmdLine.size()]);
+	}
+}
Index: src/org/eclipse/dltk/launching/IScriptProcessHandler.java
===================================================================
RCS file: src/org/eclipse/dltk/launching/IScriptProcessHandler.java
diff -N src/org/eclipse/dltk/launching/IScriptProcessHandler.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/dltk/launching/IScriptProcessHandler.java	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,52 @@
+package org.eclipse.dltk.launching;
+
+import java.util.List;
+
+import org.eclipse.core.runtime.CoreException;
+
+/**
+ * Represents a handler that can be used to read/write data to/from a
+ * <code>Process</code> object that has been created to execute an internal 
+ * script.
+ * 
+ * @see InternalScriptExecutor
+ */
+public interface IScriptProcessHandler {
+
+	/**
+	 * Handles the <code>Process</code> object
+	 * 
+	 * @param process
+	 *            process
+	 * 
+	 * @param stdin
+	 *            data that should be fed to the script via stdin, may be
+	 *            <code>null</code>.
+	 * 
+	 * @return object containing the results of the script execution
+	 * 
+	 * @throws CoreException
+	 *             if there was a error handling the process
+	 */
+	ScriptResult handle(Process process, char[] stdin) throws CoreException;
+
+	/**
+	 * Simple value object to return the results of an internal script execution
+	 */
+	public static class ScriptResult {
+		/** script exit code */
+		public int exitValue;
+
+		/** stderr of script as a single string */
+		public String stderr;
+
+		/** stderr split into individual lines */
+		public List stderrLines;
+
+		/** stdout of script as a single string */
+		public String stdout;
+
+		/** stdout split into individual lines */
+		public List stdoutLines;
+	}
+}

Back to the top