[Pydev-cvs] org.python.pydev.debug/src/org/python/pydev/debug/ui/launching PythonRunner.java,1.8,1.9
Brought to you by:
fabioz
|
From: Fabio Z. <fa...@us...> - 2004-10-08 16:44:54
|
Update of /cvsroot/pydev/org.python.pydev.debug/src/org/python/pydev/debug/ui/launching In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12619/src/org/python/pydev/debug/ui/launching Modified Files: PythonRunner.java PythonRunnerConfig.java LaunchShortcut.java Log Message: Making code coverage. Index: PythonRunner.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.debug/src/org/python/pydev/debug/ui/launching/PythonRunner.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** PythonRunner.java 21 Jul 2004 18:08:10 -0000 1.8 --- PythonRunner.java 8 Oct 2004 16:44:40 -0000 1.9 *************** *** 18,21 **** --- 18,22 ---- import org.eclipse.debug.core.ILaunch; import org.eclipse.debug.core.model.IProcess; + import org.python.pydev.debug.codecoverage.PyCoverage; import org.python.pydev.debug.core.Constants; import org.python.pydev.debug.core.PydevDebugPlugin; *************** *** 32,35 **** --- 33,52 ---- public class PythonRunner { + /** + * Launches the configuration + * + * The code is modeled after Ant launching example. + */ + public void run(PythonRunnerConfig config, ILaunch launch, IProgressMonitor monitor) throws CoreException, IOException { + if (config.isDebug) { + runDebug(config, launch, monitor); + + }else if (config.isProfile){ + runProfile(config, launch, monitor); + + }else{ //default + runDefault(config, launch, monitor); + } + } /** *************** *** 81,114 **** } /** ! * Launches the configuration ! * ! * The code is modeled after Ant launching example. ! */ ! public void run(PythonRunnerConfig config, ILaunch launch, IProgressMonitor monitor) throws CoreException, IOException { ! if (config.isDebug) { ! runDebug(config, launch, monitor); ! return; ! } ! if (monitor == null) ! monitor = new NullProgressMonitor(); ! IProgressMonitor subMonitor = new SubProgressMonitor(monitor, 5); ! subMonitor.beginTask("Launching python", 1); ! ! // Launch & connect to the debugger ! subMonitor.subTask("Constructing command_line..."); ! String[] cmdLine = config.getCommandLine(); ! ! subMonitor.subTask("Exec..."); ! Process p = DebugPlugin.exec(cmdLine, config.workingDirectory, config.envp); ! if (p == null) ! throw new CoreException(PydevDebugPlugin.makeStatus(IStatus.ERROR, "Could not execute python process. Was it cancelled?", null)); ! // Register the process with the debug plugin ! subMonitor.subTask("Done"); ! registerWithDebugPlugin(config, launch, p); ! } ! /** * The debug plugin needs to be notified about our process. * It'll then display the appropriate UI. --- 98,171 ---- } + /** ! * @param config ! * @param launch ! * @param monitor ! * @throws CoreException ! */ ! protected void runDefault(PythonRunnerConfig config, ILaunch launch, IProgressMonitor monitor) throws CoreException { ! if (monitor == null) ! monitor = new NullProgressMonitor(); ! IProgressMonitor subMonitor = new SubProgressMonitor(monitor, 5); ! subMonitor.beginTask("Launching python", 1); ! ! // Launch & connect to the debugger ! subMonitor.subTask("Constructing command_line..."); ! String[] cmdLine = config.getCommandLine(); ! ! subMonitor.subTask("Exec..."); ! Process p = DebugPlugin.exec(cmdLine, config.workingDirectory, config.envp); ! if (p == null) ! throw new CoreException(PydevDebugPlugin.makeStatus(IStatus.ERROR, "Could not execute python process. Was it cancelled?", null)); ! // Register the process with the debug plugin ! subMonitor.subTask("Done"); ! registerWithDebugPlugin(config, launch, p); ! } ! /** ! * @param config ! * @param launch ! * @param monitor ! * @throws CoreException ! */ ! private void runProfile(PythonRunnerConfig config, ILaunch launch, IProgressMonitor monitor) throws CoreException { ! if (monitor == null) ! monitor = new NullProgressMonitor(); ! IProgressMonitor subMonitor = new SubProgressMonitor(monitor, 5); ! subMonitor.beginTask("Launching python", 1); ! ! // Launch & connect to the debugger ! subMonitor.subTask("Constructing command_line..."); ! ! subMonitor.subTask("Exec..."); ! String[] envp = config.envp; ! ! envp = PyCoverage.setCoverageFileEnviromentVariable(envp); ! ! Process p = DebugPlugin.exec(config.getCommandLine(), config.workingDirectory, envp); ! if (p == null) ! throw new CoreException(PydevDebugPlugin.makeStatus(IStatus.ERROR, "Could not execute python process. Was it cancelled?", null)); ! ! // Register the process with the debug plugin ! subMonitor.subTask("Done"); ! registerWithDebugPlugin(config, launch, p); ! ! ! // try { ! // p.waitFor(); ! // } catch (InterruptedException e) { ! // e.printStackTrace(); ! // } ! // ! // Process p1 = DebugPlugin.exec(config.getProfileResultsCommandLine(), config.workingDirectory, config.envp); ! // if (p1 == null) ! // throw new CoreException(PydevDebugPlugin.makeStatus(IStatus.ERROR, "Could not execute python process. Was it cancelled?", null)); ! // registerWithDebugPlugin(config, launch, p1); ! ! } ! ! /** * The debug plugin needs to be notified about our process. * It'll then display the appropriate UI. Index: PythonRunnerConfig.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.debug/src/org/python/pydev/debug/ui/launching/PythonRunnerConfig.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** PythonRunnerConfig.java 14 Sep 2004 17:41:27 -0000 1.9 --- PythonRunnerConfig.java 8 Oct 2004 16:44:40 -0000 1.10 *************** *** 7,12 **** import java.io.File; - import java.io.IOException; - import java.net.URL; import java.util.Vector; --- 7,10 ---- *************** *** 14,24 **** import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IStatus; - import org.eclipse.core.runtime.Path; - import org.eclipse.core.runtime.Platform; import org.eclipse.debug.core.DebugPlugin; import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.ILaunchManager; import org.eclipse.ui.externaltools.internal.launchConfigurations.ExternalToolsUtil; - import org.osgi.framework.Bundle; import org.python.pydev.debug.core.Constants; import org.python.pydev.debug.core.PydevDebugPlugin; --- 12,19 ---- *************** *** 40,48 **** // debugging public boolean isDebug; private int debugPort = 0; // use getDebugPort - public String debugScript; public int acceptTimeout = 5000; // miliseconds public String[] envp = null; /** * Sets defaults. --- 35,46 ---- // debugging public boolean isDebug; + public boolean isProfile; private int debugPort = 0; // use getDebugPort public int acceptTimeout = 5000; // miliseconds public String[] envp = null; + public String debugScript; + public String profileScript; + /** * Sets defaults. *************** *** 51,54 **** --- 49,54 ---- public PythonRunnerConfig(ILaunchConfiguration conf, String mode) throws CoreException { isDebug = mode.equals(ILaunchManager.DEBUG_MODE); + isProfile = mode.equals(ILaunchManager.PROFILE_MODE); + file = ExternalToolsUtil.getLocation(conf); interpreter = conf.getAttribute(Constants.ATTR_INTERPRETER, "python"); *************** *** 59,67 **** if (isDebug) { debugScript = getDebugScript(); } envp = DebugPlugin.getDefault().getLaunchManager().getEnvironment(conf); } ! public int getDebugPort() throws CoreException { if (debugPort == 0) { debugPort= SocketUtil.findUnusedLocalPort("", 5000, 15000); //$NON-NLS-1$ --- 59,70 ---- if (isDebug) { debugScript = getDebugScript(); + }else if(isProfile){ + profileScript = getProfileScript(); } envp = DebugPlugin.getDefault().getLaunchManager().getEnvironment(conf); } ! ! public int getDebugPort() throws CoreException { if (debugPort == 0) { debugPort= SocketUtil.findUnusedLocalPort("", 5000, 15000); //$NON-NLS-1$ *************** *** 91,111 **** } ! /** * gets location of jpydaemon.py */ public static String getDebugScript() throws CoreException { ! IPath relative = new Path("pysrc").addTrailingSeparator().append("pydevd.py"); // IPath relative = new Path("pysrc").addTrailingSeparator().append("jpydaemon.py"); // IPath relative = new Path("pysrc").addTrailingSeparator().append("rpdb.py"); ! Bundle bundle = PydevDebugPlugin.getDefault().getBundle(); ! URL bundleURL = Platform.find( bundle, relative); ! URL fileURL; ! try { ! fileURL = Platform.asLocalURL( bundleURL); ! String filePath = new File(fileURL.getPath()).getAbsolutePath(); ! return filePath; ! } catch (IOException e) { ! throw new CoreException(PydevDebugPlugin.makeStatus(IStatus.ERROR, "Can't find python debug script", null)); ! } } --- 94,124 ---- } ! /** ! * @return ! * @throws CoreException ! */ ! public static String getProfileScript() throws CoreException { ! return PydevDebugPlugin.getScriptWithinPySrc("coverage.py").getAbsolutePath(); ! } ! ! /** * gets location of jpydaemon.py */ public static String getDebugScript() throws CoreException { ! return PydevDebugPlugin.getScriptWithinPySrc("pydevd.py").getAbsolutePath(); ! ! // IPath relative = new Path("pysrc").addTrailingSeparator().append("pydevd.py"); // IPath relative = new Path("pysrc").addTrailingSeparator().append("jpydaemon.py"); // IPath relative = new Path("pysrc").addTrailingSeparator().append("rpdb.py"); ! // Bundle bundle = PydevDebugPlugin.getDefault().getBundle(); ! // URL bundleURL = Platform.find( bundle, relative); ! // URL fileURL; ! // try { ! // fileURL = Platform.asLocalURL( bundleURL); ! // String filePath = new File(fileURL.getPath()).getAbsolutePath(); ! // return filePath; ! // } catch (IOException e) { ! // throw new CoreException(PydevDebugPlugin.makeStatus(IStatus.ERROR, "Can't find python debug script", null)); ! // } } *************** *** 133,136 **** --- 146,155 ---- cmdArgs.add("--file"); } + + if(isProfile){ + cmdArgs.add(profileScript); + cmdArgs.add("-x"); + } + cmdArgs.add(file.toOSString()); for (int i=0; arguments != null && i<arguments.length; i++) *************** *** 141,144 **** --- 160,184 ---- } + public String[] getProfileResultsCommandLine(){ + Vector cmdArgs = new Vector(10); + cmdArgs.add(interpreter); + // Next option is for unbuffered stdout, otherwise Eclipse will not see any output until done + cmdArgs.add(org.python.pydev.ui.InterpreterEditor.isJython(interpreter) ? "-i" : "-u"); + + if(isProfile){ + cmdArgs.add(profileScript); + cmdArgs.add("-r"); + cmdArgs.add("-m"); + }else{ + throw new RuntimeException("Can only get profile script in profile mode."); + } + + cmdArgs.add(file.toOSString()); + + String[] retVal = new String[cmdArgs.size()]; + cmdArgs.toArray(retVal); + return retVal; + } + public String getCommandLineAsString() { String[] args = getCommandLine(); Index: LaunchShortcut.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.debug/src/org/python/pydev/debug/ui/launching/LaunchShortcut.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** LaunchShortcut.java 20 Sep 2004 13:19:42 -0000 1.6 --- LaunchShortcut.java 8 Oct 2004 16:44:40 -0000 1.7 *************** *** 77,81 **** protected boolean verifyMode(String mode) { boolean ok = mode.equals(ILaunchManager.RUN_MODE) || ! mode.equals(ILaunchManager.DEBUG_MODE); if (!ok) reportError("Unknown launch mode: " + mode, null); --- 77,82 ---- protected boolean verifyMode(String mode) { boolean ok = mode.equals(ILaunchManager.RUN_MODE) || ! mode.equals(ILaunchManager.DEBUG_MODE) || ! mode.equals(ILaunchManager.PROFILE_MODE); if (!ok) reportError("Unknown launch mode: " + mode, null); *************** *** 223,227 **** if (fShowDialog) { IStatus status = new Status(IStatus.INFO, Constants.PLUGIN_ID, 0, "Hmm", null); //$NON-NLS-1$ ! String groupID = mode.equals("run") ? Constants.PYTHON_RUN_LAUNCH_GROUP : Constants.PYTHON_DEBUG_LAUNCH_GROUP; DebugUITools.openLaunchConfigurationDialog(PydevDebugPlugin.getActiveWorkbenchWindow().getShell(), conf, groupID, null); } else { --- 224,237 ---- if (fShowDialog) { IStatus status = new Status(IStatus.INFO, Constants.PLUGIN_ID, 0, "Hmm", null); //$NON-NLS-1$ ! String groupID = ""; ! ! if(mode.equals("run")) { ! groupID = Constants.PYTHON_RUN_LAUNCH_GROUP; ! }else if (mode.equals("debug")){ ! groupID = Constants.PYTHON_DEBUG_LAUNCH_GROUP; ! }else if (mode.equals("profile")){ ! groupID = Constants.PYTHON_COVERAGE_LAUNCH_GROUP; ! } ! DebugUITools.openLaunchConfigurationDialog(PydevDebugPlugin.getActiveWorkbenchWindow().getShell(), conf, groupID, null); } else { |