[Pydev-cvs] org.python.pydev/src/org/python/pydev/runners SimpleRunner.java, 1.24, 1.25 SimplePytho
Brought to you by:
fabioz
From: Fabio Z. <fa...@us...> - 2008-05-21 01:38:04
|
Update of /cvsroot/pydev/org.python.pydev/src/org/python/pydev/runners In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4510/src/org/python/pydev/runners Modified Files: SimpleRunner.java SimplePythonRunner.java SimpleJythonRunner.java SimpleExeRunner.java Log Message: - No longer using Runtime.exec(String), only Runtime.exec(String[]) - Updating the markers in a better (faster) way Index: SimpleExeRunner.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/runners/SimpleExeRunner.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** SimpleExeRunner.java 26 Jun 2006 23:40:46 -0000 1.1 --- SimpleExeRunner.java 21 May 2008 01:38:08 -0000 1.2 *************** *** 7,14 **** --- 7,16 ---- import java.io.File; import java.util.ArrayList; + import java.util.Arrays; import java.util.List; import java.util.StringTokenizer; import org.eclipse.core.resources.IProject; + import org.eclipse.core.runtime.NullProgressMonitor; import org.python.pydev.core.Tuple; import org.python.pydev.core.docutils.StringUtils; *************** *** 16,24 **** public class SimpleExeRunner extends SimpleRunner{ - @Override - public Tuple<String, String> runAndGetOutput(String script, String[] args, File workingDir, IProject project) { - String executionString = getCommandLineAsString(new String[]{script}, args); - return runAndGetOutput(executionString, workingDir, project); - } /** --- 18,21 ---- *************** *** 72,76 **** ArrayList<String> ret = new ArrayList<String>(); ! Tuple<String, String> output = runAndGetOutput(cygpathLoc, paths, (File)null, (IProject)null); if(output.o2 != null && output.o2.length() > 0){ throw new RuntimeException("Error converting windows paths to cygwin paths: "+output.o2+".\nCygpath location:"+cygpathLoc); --- 69,76 ---- ArrayList<String> ret = new ArrayList<String>(); ! List<String> asList = new ArrayList<String>(Arrays.asList(paths)); ! asList.add(0, cygpathLoc); ! ! Tuple<String, String> output = runAndGetOutput(asList.toArray(new String[0]), (File)null, (IProject)null, new NullProgressMonitor()); if(output.o2 != null && output.o2.length() > 0){ throw new RuntimeException("Error converting windows paths to cygwin paths: "+output.o2+".\nCygpath location:"+cygpathLoc); Index: SimpleRunner.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/runners/SimpleRunner.java,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** SimpleRunner.java 12 May 2008 11:39:06 -0000 1.24 --- SimpleRunner.java 21 May 2008 01:38:08 -0000 1.25 *************** *** 34,45 **** /** ! * Just execute the string. Does nothing else. */ ! public Process createProcess(String executionString, File workingDir) throws IOException { ! return Runtime.getRuntime().exec(executionString, null, workingDir); ! } ! ! public Process createProcess(String[] parameters, File workingDir) throws IOException { ! return Runtime.getRuntime().exec(parameters, null, workingDir); } --- 34,41 ---- /** ! * Passes the commands directly to Runtime.exec (with a null envp) */ ! public static Process createProcess(String[] cmdarray, File workingDir) throws IOException { ! return Runtime.getRuntime().exec(cmdarray, null, workingDir); } *************** *** 146,150 **** * @return */ ! public static String getCommandLineAsString(String[] commandLine, String ... args) { if(args != null && args.length > 0){ String[] newCommandLine = new String[commandLine.length + args.length]; --- 142,146 ---- * @return */ ! public static String getArgumentsAsStr(String[] commandLine, String ... args) { if(args != null && args.length > 0){ String[] newCommandLine = new String[commandLine.length + args.length]; *************** *** 280,318 **** } /** ! * shortcut ! */ ! public Tuple<String,String> runAndGetOutput(String executionString, File workingDir, IProgressMonitor monitor) { ! return runAndGetOutput(executionString, workingDir, null, monitor); ! } ! ! /** ! * shortcut ! */ ! public Tuple<String,String> runAndGetOutput(String executionString, File workingDir) { ! return runAndGetOutput(executionString, workingDir, null, new NullProgressMonitor()); ! } ! ! /** ! * shortcut ! */ ! public Tuple<String,String> runAndGetOutput(String executionString, File workingDir, IProject project) { ! return runAndGetOutput(executionString, workingDir, project, new NullProgressMonitor()); ! } ! ! public Tuple<String,String> runAndGetOutput(String[] arguments, File workingDir, IProject project) { ! return runAndGetOutput(arguments, workingDir, project, new NullProgressMonitor()); ! } ! ! /** ! * shortcut */ ! public Tuple<String,String> runAndGetOutput(String script, String[] args, File workingDir) { ! return runAndGetOutput(script, args, workingDir, null); ! } ! ! ! public Tuple<String, String> runAndGetOutput(String[] arguments, File workingDir, IProject project, IProgressMonitor monitor) { ! String executionString = getCommandLineAsString(arguments); monitor.setTaskName("Executing: "+executionString); monitor.worked(5); --- 276,295 ---- } + /** ! * Runs the given command line and returns a tuple with the output (stdout and stderr) of executing it. ! * ! * @param cmdarray array with the commands to be passed to Runtime.exec ! * @param workingDir the working dir (may be null) ! * @param project the project (used to get the pythonpath and put it into the environment) -- if null, no environment is passed. ! * @param monitor the progress monitor to be used -- may be null ! * ! * @return a tuple with stdout and stderr */ ! public Tuple<String, String> runAndGetOutput(String[] cmdarray, File workingDir, IProject project, IProgressMonitor monitor) { ! if(monitor == null){ ! monitor = new NullProgressMonitor(); ! } ! String executionString = getArgumentsAsStr(cmdarray); monitor.setTaskName("Executing: "+executionString); monitor.worked(5); *************** *** 327,331 **** } } ! process = Runtime.getRuntime().exec(arguments, envp, workingDir); } catch (Exception e) { throw new RuntimeException(e); --- 304,308 ---- } } ! process = Runtime.getRuntime().exec(cmdarray, envp, workingDir); } catch (Exception e) { throw new RuntimeException(e); *************** *** 341,345 **** * @return a tuple with the output of stdout and stderr */ ! private Tuple<String, String> getProcessOutput(Process process, String executionString, IProgressMonitor monitor) { if (process != null) { --- 318,322 ---- * @return a tuple with the output of stdout and stderr */ ! protected Tuple<String, String> getProcessOutput(Process process, String executionString, IProgressMonitor monitor) { if (process != null) { *************** *** 390,437 **** - /** - * This is the method that actually does the running (all others are just 'shortcuts' to this one). - * - * @param executionString this is the string that will be executed - * @param workingDir this is the directory where the execution will happen - * @param project this is the project that is related to the run (it is used to get the environment for the shell we are going to - * execute with the correct pythonpath environment variable). - * @param monitor this is the monitor used to communicate the progress to the user - * - * @return the string that is the output of the process (stdout) and the stderr (o2) - */ - public Tuple<String,String> runAndGetOutput(String executionString, File workingDir, IProject project, IProgressMonitor monitor) { - monitor.setTaskName("Executing: "+executionString); - monitor.worked(5); - Process process = null; - - try { - monitor.setTaskName("Making pythonpath environment..."+executionString); - String[] envp = getEnvironment(PythonNature.getPythonNature(project), null); //should get the environment for the default interpreter and the given project - monitor.setTaskName("Making exec..."+executionString); - if(workingDir != null){ - if(!workingDir.isDirectory()){ - throw new RuntimeException(StringUtils.format("Working dir must be an existing directory (received: %s)", workingDir)); - } - } - process = Runtime.getRuntime().exec(executionString, envp, workingDir); - } catch (Exception e) { - throw new RuntimeException(e); - } - - return getProcessOutput(process, executionString, monitor); - } - - /** - * Execute the script specified with the interpreter for a given project - * - * @param script the script we will execute - * @param args the arguments to pass to the script - * @param workingDir the working directory - * @param project the project that is associated to this run - * - * @return a string with the output of the process (stdout) - */ - public abstract Tuple<String,String> runAndGetOutput(String script, String args[], File workingDir, IProject project); /** --- 367,370 ---- Index: SimpleJythonRunner.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/runners/SimpleJythonRunner.java,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** SimpleJythonRunner.java 7 Apr 2008 00:52:02 -0000 1.25 --- SimpleJythonRunner.java 21 May 2008 01:38:08 -0000 1.26 *************** *** 6,9 **** --- 6,12 ---- import java.io.File; import java.io.IOException; + import java.util.ArrayList; + import java.util.Arrays; + import java.util.List; import org.eclipse.core.resources.IProject; *************** *** 57,78 **** ,script }; - String executionString = getCommandLineAsString(s); - - return runAndGetOutput(executionString, workingDir, project, monitor); - } catch (RuntimeException e) { - throw e; - } catch (Exception e) { - throw new RuntimeException(e); - } - - } - @Override - public Tuple<String,String> runAndGetOutput(String script, String[] args, File workingDir, IProject project) { - //"java.exe" -classpath "C:\bin\jython21\jython.jar" -Dpython.path xxx;xxx;xxx org.python.util.jython script %ARGS% ! try { ! String executionString = makeExecutableCommandStr(script, ""); ! ! return runAndGetOutput(executionString, workingDir, project); } catch (RuntimeException e) { throw e; --- 60,65 ---- ,script }; ! return runAndGetOutput(s, workingDir, project, monitor); } catch (RuntimeException e) { throw e; *************** *** 83,87 **** } ! public static String makeExecutableCommandStr(String script, String basePythonPath, String ... args) throws IOException, JDTNotAvailableException { return makeExecutableCommandStrWithVMArgs(script, basePythonPath, "", args); } --- 70,74 ---- } ! public static String[] makeExecutableCommandStr(String script, String basePythonPath, String ... args) throws IOException, JDTNotAvailableException { return makeExecutableCommandStrWithVMArgs(script, basePythonPath, "", args); } *************** *** 92,96 **** * @throws IOException */ ! public static String makeExecutableCommandStrWithVMArgs(String script, String basePythonPath, String vmArgs, String ... args) throws IOException, JDTNotAvailableException { IInterpreterManager interpreterManager = PydevPlugin.getJythonInterpreterManager(); String javaLoc = JavaVmLocationFinder.findDefaultJavaExecutable().getCanonicalPath(); --- 79,83 ---- * @throws IOException */ ! public static String[] makeExecutableCommandStrWithVMArgs(String script, String basePythonPath, String vmArgs, String ... args) throws IOException, JDTNotAvailableException { IInterpreterManager interpreterManager = PydevPlugin.getJythonInterpreterManager(); String javaLoc = JavaVmLocationFinder.findDefaultJavaExecutable().getCanonicalPath(); *************** *** 147,153 **** script }; ! String executionString = getCommandLineAsString(s, args); ! ! return executionString; } --- 134,141 ---- script }; ! ! List<String> asList = new ArrayList<String>(Arrays.asList(s)); ! asList.addAll(Arrays.asList(args)); ! return asList.toArray(new String[0]); } Index: SimplePythonRunner.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/runners/SimplePythonRunner.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** SimplePythonRunner.java 12 May 2008 11:39:06 -0000 1.11 --- SimplePythonRunner.java 21 May 2008 01:38:08 -0000 1.12 *************** *** 8,14 **** --- 8,18 ---- import java.io.File; + import java.util.ArrayList; + import java.util.Arrays; + import java.util.List; import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.IProgressMonitor; + import org.eclipse.core.runtime.NullProgressMonitor; import org.python.pydev.core.Tuple; import org.python.pydev.plugin.PydevPlugin; *************** *** 41,47 **** * @return a string with the output of the process (stdout) */ ! public Tuple<String,String> runAndGetOutput(String script, String[] args, File workingDir, IProject project) { String[] parameters = addInterpreterToArgs(script, args); ! return runAndGetOutput(parameters, workingDir, project); } --- 45,51 ---- * @return a string with the output of the process (stdout) */ ! public Tuple<String,String> runAndGetOutputFromPythonScript(String script, String[] args, File workingDir, IProject project) { String[] parameters = addInterpreterToArgs(script, args); ! return runAndGetOutput(parameters, workingDir, project, new NullProgressMonitor()); } *************** *** 51,57 **** * @return the string with the command to run the passed script with jython */ ! public static String makeExecutableCommandStr(String script, String[] args) { String[] s = addInterpreterToArgs(script, args); ! return getCommandLineAsString(s, args); } --- 55,65 ---- * @return the string with the command to run the passed script with jython */ ! public static String[] makeExecutableCommandStr(String script, String[] args) { String[] s = addInterpreterToArgs(script, args); ! ! List<String> asList = new ArrayList<String>(Arrays.asList(s)); ! asList.addAll(Arrays.asList(args)); ! ! return asList.toArray(new String[0]); } |