[Pydev-cvs] org.python.pydev.debug/src/org/python/pydev/debug/ui/launching AbstractLaunchShortcut.
Brought to you by:
fabioz
From: Fabio Z. <fa...@us...> - 2008-09-27 20:03:45
|
Update of /cvsroot/pydev/org.python.pydev.debug/src/org/python/pydev/debug/ui/launching In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20604/src/org/python/pydev/debug/ui/launching Modified Files: AbstractLaunchShortcut.java PythonRunnerConfig.java PythonRunner.java Log Message: Synching to latest changes: Pydev <ul> <li><strong>Editor</strong>: Cursor settings no longer overridden</li> <li><strong>Code-completion</strong>: If __all__ is defined with runtime elements (and not only in a single assign statement), it's ignored for code-completion purposes</li> <li><strong>Debugger</strong>: Pythonpath the same in debug and regular modes (sys.path[0] is the same directory as the file run)</li> <li><strong>Debugger</strong>: Persist choices done in the debugger when files from the debugger are not found</li> <li><strong>Interpreter config</strong>: "email" automatically added to the "forced builtins"</li> <li><strong>Parser</strong>: Correctly recognizing absolute import with 3 or more levels</li> <li><strong>Syntax check</strong>: Option to do only on active editor</li> </ul> Also: tabs changed for spaces Index: PythonRunner.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.debug/src/org/python/pydev/debug/ui/launching/PythonRunner.java,v retrieving revision 1.38 retrieving revision 1.39 diff -C2 -d -r1.38 -r1.39 *** PythonRunner.java 17 Aug 2008 00:26:56 -0000 1.38 --- PythonRunner.java 27 Sep 2008 19:59:08 -0000 1.39 *************** *** 65,74 **** ! /** ! * Launches the configuration * * The code is modeled after Ant launching example. ! */ ! public static void run(final PythonRunnerConfig config, ILaunch launch, IProgressMonitor monitor) throws CoreException, IOException { //let's check if the interpreter is valid. final IInterpreterManager interpreterManager = PythonNature.getPythonNature(config.project).getRelatedInterpreterManager(); --- 65,74 ---- ! /** ! * Launches the configuration * * The code is modeled after Ant launching example. ! */ ! public static void run(final PythonRunnerConfig config, ILaunch launch, IProgressMonitor monitor) throws CoreException, IOException { //let's check if the interpreter is valid. final IInterpreterManager interpreterManager = PythonNature.getPythonNature(config.project).getRelatedInterpreterManager(); *************** *** 93,105 **** try{ ! if (config.isDebug) { ! runDebug(config, launch, monitor); ! }else if (config.isUnittest()) { ! runUnitTest(config, launch, monitor); ! }else { //default - just configured by command line (the others need special attention) ! doIt(config, monitor, config.envp, config.getCommandLine(true), config.workingDirectory, launch); ! } }catch (final JDTNotAvailableException e) { PydevPlugin.log(e); --- 93,105 ---- try{ ! if (config.isDebug) { ! runDebug(config, launch, monitor); ! }else if (config.isUnittest()) { ! runUnitTest(config, launch, monitor); ! }else { //default - just configured by command line (the others need special attention) ! doIt(config, monitor, config.envp, config.getCommandLine(true), config.workingDirectory, launch); ! } }catch (final JDTNotAvailableException e) { PydevPlugin.log(e); *************** *** 113,175 **** }); } ! } ! /** ! * Launches the config in the debug mode. ! * ! * Loosely modeled upon Ant launcher. ! * @throws JDTNotAvailableException ! */ ! private static void runDebug(PythonRunnerConfig config, ILaunch launch, IProgressMonitor monitor) throws CoreException, IOException, JDTNotAvailableException { ! if (monitor == null) ! monitor = new NullProgressMonitor(); ! IProgressMonitor subMonitor = new SubProgressMonitor(monitor, 5); ! subMonitor.beginTask("Launching python", 1); ! ! // Launch & connect to the debugger ! RemoteDebugger debugger = new RemoteDebugger(config); ! debugger.startConnect(subMonitor); ! subMonitor.subTask("Constructing command_line..."); ! String[] cmdLine = config.getCommandLine(true); ! Process p = createProcess(launch, config.envp, cmdLine, config.workingDirectory); ! checkProcess(p); ! ! IProcess process = registerWithDebugPlugin(config, launch, p); checkProcess(p, process); ! subMonitor.subTask("Waiting for connection..."); ! try { ! boolean userCanceled = debugger.waitForConnect(subMonitor, p, process); ! if (userCanceled) { ! debugger.dispose(); ! return; ! } ! } ! catch (Exception ex) { ! process.terminate(); ! p.destroy(); ! String message = "Unexpected error setting up the debugger"; ! if (ex instanceof SocketTimeoutException) ! message = "Timed out after " + Float.toString(config.acceptTimeout/1000) + " seconds while waiting for python script to connect."; ! throw new CoreException(PydevDebugPlugin.makeStatus(IStatus.ERROR, message, ex)); ! } ! subMonitor.subTask("Done"); ! // hook up debug model, and we are off & running ! PyDebugTarget t = new PyDebugTarget(launch, process, config.resource, debugger); ! launch.setSourceLocator(new PySourceLocator()); ! debugger.startTransmission(); // this starts reading/writing from sockets ! t.initialize(); ! t.addConsoleInputListener(); ! } private static IProcess doIt(PythonRunnerConfig config, IProgressMonitor monitor, String [] envp, String[] cmdLine, File workingDirectory, ILaunch launch) 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 commandLineAsString = SimpleRunner.getArgumentsAsStr(cmdLine); --- 113,175 ---- }); } ! } ! /** ! * Launches the config in the debug mode. ! * ! * Loosely modeled upon Ant launcher. ! * @throws JDTNotAvailableException ! */ ! private static void runDebug(PythonRunnerConfig config, ILaunch launch, IProgressMonitor monitor) throws CoreException, IOException, JDTNotAvailableException { ! if (monitor == null) ! monitor = new NullProgressMonitor(); ! IProgressMonitor subMonitor = new SubProgressMonitor(monitor, 5); ! subMonitor.beginTask("Launching python", 1); ! ! // Launch & connect to the debugger ! RemoteDebugger debugger = new RemoteDebugger(config); ! debugger.startConnect(subMonitor); ! subMonitor.subTask("Constructing command_line..."); ! String[] cmdLine = config.getCommandLine(true); ! Process p = createProcess(launch, config.envp, cmdLine, config.workingDirectory); ! checkProcess(p); ! ! IProcess process = registerWithDebugPlugin(config, launch, p); checkProcess(p, process); ! subMonitor.subTask("Waiting for connection..."); ! try { ! boolean userCanceled = debugger.waitForConnect(subMonitor, p, process); ! if (userCanceled) { ! debugger.dispose(); ! return; ! } ! } ! catch (Exception ex) { ! process.terminate(); ! p.destroy(); ! String message = "Unexpected error setting up the debugger"; ! if (ex instanceof SocketTimeoutException) ! message = "Timed out after " + Float.toString(config.acceptTimeout/1000) + " seconds while waiting for python script to connect."; ! throw new CoreException(PydevDebugPlugin.makeStatus(IStatus.ERROR, message, ex)); ! } ! subMonitor.subTask("Done"); ! // hook up debug model, and we are off & running ! PyDebugTarget t = new PyDebugTarget(launch, process, config.resource, debugger); ! launch.setSourceLocator(new PySourceLocator()); ! debugger.startTransmission(); // this starts reading/writing from sockets ! t.initialize(); ! t.addConsoleInputListener(); ! } private static IProcess doIt(PythonRunnerConfig config, IProgressMonitor monitor, String [] envp, String[] cmdLine, File workingDirectory, ILaunch launch) 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 commandLineAsString = SimpleRunner.getArgumentsAsStr(cmdLine); *************** *** 182,186 **** //it was dying before register, so, I made this faster to see if this fixes it ! Process p = createProcess(launch, envp, cmdLine, workingDirectory); checkProcess(p); --- 182,186 ---- //it was dying before register, so, I made this faster to see if this fixes it ! Process p = createProcess(launch, envp, cmdLine, workingDirectory); checkProcess(p); *************** *** 189,193 **** if(config.isJython()) { if(config.isInteractive){ ! throw new RuntimeException("Interactive not supported here!"); } process = registerWithDebugPluginForProcessType(label, launch, p, processAttributes, "java"); --- 189,193 ---- if(config.isJython()) { if(config.isInteractive){ ! throw new RuntimeException("Interactive not supported here!"); } process = registerWithDebugPluginForProcessType(label, launch, p, processAttributes, "java"); *************** *** 197,201 **** //in the debug plugin (the communication is all done through xml-rpc). if(config.isInteractive){ ! throw new RuntimeException("Interactive not supported here!"); } process = registerWithDebugPlugin(label, launch, p, processAttributes); --- 197,201 ---- //in the debug plugin (the communication is all done through xml-rpc). if(config.isInteractive){ ! throw new RuntimeException("Interactive not supported here!"); } process = registerWithDebugPlugin(label, launch, p, processAttributes); *************** *** 212,216 **** */ private static Process createProcess(ILaunch launch, String[] envp, String[] cmdLine, File workingDirectory) throws CoreException { ! //Not using DebugPlugin.ATTR_CONSOLE_ENCODING to provide backward compatibility for eclipse 3.2 String encoding = launch.getAttribute(IDebugUIConstants.ATTR_CONSOLE_ENCODING); if(encoding != null && encoding.trim().length() > 0){ --- 212,216 ---- */ private static Process createProcess(ILaunch launch, String[] envp, String[] cmdLine, File workingDirectory) throws CoreException { ! //Not using DebugPlugin.ATTR_CONSOLE_ENCODING to provide backward compatibility for eclipse 3.2 String encoding = launch.getAttribute(IDebugUIConstants.ATTR_CONSOLE_ENCODING); if(encoding != null && encoding.trim().length() > 0){ *************** *** 225,241 **** private static void runUnitTest(PythonRunnerConfig config, ILaunch launch, IProgressMonitor monitor) throws CoreException, JDTNotAvailableException{ ! doIt(config, monitor, config.envp, config.getCommandLine(true), config.workingDirectory, launch); } /** ! * The debug plugin needs to be notified about our process. ! * It'll then display the appropriate UI. * @throws JDTNotAvailableException ! */ ! private static IProcess registerWithDebugPlugin(PythonRunnerConfig config, ILaunch launch, Process p) throws JDTNotAvailableException { ! HashMap<Object, Object> processAttributes = new HashMap<Object, Object>(); ! processAttributes.put(IProcess.ATTR_CMDLINE, config.getCommandLineAsString()); ! return registerWithDebugPlugin(config.getRunningName(), launch,p, processAttributes); ! } --- 225,241 ---- private static void runUnitTest(PythonRunnerConfig config, ILaunch launch, IProgressMonitor monitor) throws CoreException, JDTNotAvailableException{ ! doIt(config, monitor, config.envp, config.getCommandLine(true), config.workingDirectory, launch); } /** ! * The debug plugin needs to be notified about our process. ! * It'll then display the appropriate UI. * @throws JDTNotAvailableException ! */ ! private static IProcess registerWithDebugPlugin(PythonRunnerConfig config, ILaunch launch, Process p) throws JDTNotAvailableException { ! HashMap<Object, Object> processAttributes = new HashMap<Object, Object>(); ! processAttributes.put(IProcess.ATTR_CMDLINE, config.getCommandLineAsString()); ! return registerWithDebugPlugin(config.getRunningName(), launch,p, processAttributes); ! } *************** *** 247,263 **** return registerWithDebugPluginForProcessType(label, launch, p, processAttributes, Constants.PROCESS_TYPE); } ! ! /** ! * The debug plugin needs to be notified about our process. ! * It'll then display the appropriate UI. ! */ private static IProcess registerWithDebugPluginForProcessType(String label, ILaunch launch, Process p, Map<Object, Object> processAttributes, String processType) { ! processAttributes.put(IProcess.ATTR_PROCESS_TYPE, processType); ! processAttributes.put(IProcess.ATTR_PROCESS_LABEL, label); processAttributes.put(DebugPlugin.ATTR_CAPTURE_OUTPUT, "true"); ! return DebugPlugin.newProcess(launch,p, label, processAttributes); ! } } --- 247,263 ---- return registerWithDebugPluginForProcessType(label, launch, p, processAttributes, Constants.PROCESS_TYPE); } ! ! /** ! * The debug plugin needs to be notified about our process. ! * It'll then display the appropriate UI. ! */ private static IProcess registerWithDebugPluginForProcessType(String label, ILaunch launch, Process p, Map<Object, Object> processAttributes, String processType) { ! processAttributes.put(IProcess.ATTR_PROCESS_TYPE, processType); ! processAttributes.put(IProcess.ATTR_PROCESS_LABEL, label); processAttributes.put(DebugPlugin.ATTR_CAPTURE_OUTPUT, "true"); ! return DebugPlugin.newProcess(launch,p, label, processAttributes); ! } } Index: PythonRunnerConfig.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.debug/src/org/python/pydev/debug/ui/launching/PythonRunnerConfig.java,v retrieving revision 1.67 retrieving revision 1.68 diff -C2 -d -r1.67 -r1.68 *** PythonRunnerConfig.java 17 Aug 2008 00:26:56 -0000 1.67 --- PythonRunnerConfig.java 27 Sep 2008 19:59:08 -0000 1.68 *************** *** 59,78 **** public static final String RUN_JYTHON = "jython regular run"; ! public IProject project; ! public IPath[] resource; ! public IPath interpreter; ! public String interpreterLocation; ! private String arguments; ! public File workingDirectory; ! public String pythonpathUsed; ! // debugging ! public boolean isDebug; ! public boolean isInteractive; ! private int debugPort = 0; // use getDebugPort ! public int acceptTimeout = 5000; // miliseconds ! public String[] envp = null; ! private String run; ! private ILaunchConfiguration configuration; public boolean isCoverage(){ --- 59,81 ---- public static final String RUN_JYTHON = "jython regular run"; ! public final IProject project; ! public final IPath[] resource; ! public final IPath interpreter; ! public final String interpreterLocation; ! private final String arguments; ! public final File workingDirectory; ! public String pythonpathUsed; ! // debugging ! public final boolean isDebug; ! public final boolean isInteractive; ! private int debugPort = 0; // use getDebugPort ! public int acceptTimeout = 5000; // miliseconds ! public String[] envp = null; ! private final boolean useUnittestWrapper; ! ! /** One of RUN_ enums */ ! private final String run; ! private final ILaunchConfiguration configuration; public boolean isCoverage(){ *************** *** 94,129 **** ! /** ! * Expands and returns the location attribute of the given launch ! * configuration. The location is ! * verified to point to an existing file, in the local file system. * * @param configuration launch configuration ! * @return an absolute path to a file in the local file system ! * @throws CoreException if unable to retrieve the associated launch ! * configuration attribute, if unable to resolve any variables, or if the ! * resolved location does not point to an existing file in the local file ! * system */ public static IPath[] getLocation(ILaunchConfiguration configuration) throws CoreException { ! String locationsStr = configuration.getAttribute(Constants.ATTR_LOCATION, (String) null); ! if (locationsStr == null) { throw new CoreException(PydevDebugPlugin.makeStatus(IStatus.ERROR, "Unable to get location for run", null)); - } else { - String[] locations = StringUtils.split(locationsStr, '|'); - Path[] ret = new Path[locations.length]; - int i=0; - for(String location:locations){ - String expandedLocation = getStringVariableManager().performStringSubstitution(location); - if (expandedLocation == null || expandedLocation.length() == 0) { - throw new CoreException(PydevDebugPlugin.makeStatus(IStatus.ERROR, "Unable to get expanded location for run", null)); - } else { - ret[i] = new Path(expandedLocation); - } - i++; - } - return ret; } } --- 97,134 ---- ! /* ! * Expands and returns the location attribute of the given launch configuration. The location is verified to point ! * to an existing file, in the local file system. * * @param configuration launch configuration ! * ! * @return an absolute path to a file in the local file system ! * ! * @throws CoreException if unable to retrieve the associated launch configuration attribute, if unable to resolve ! * any variables, or if the resolved location does not point to an existing file in the local file system */ public static IPath[] getLocation(ILaunchConfiguration configuration) throws CoreException { ! String locationsStr = configuration.getAttribute(Constants.ATTR_ALTERNATE_LOCATION, (String) null); ! if (locationsStr == null) { ! locationsStr = configuration.getAttribute(Constants.ATTR_LOCATION, (String) null); ! } if (locationsStr == null) { throw new CoreException(PydevDebugPlugin.makeStatus(IStatus.ERROR, "Unable to get location for run", null)); } + + String[] locations = StringUtils.split(locationsStr, '|'); + Path[] ret = new Path[locations.length]; + int i = 0; + for (String location : locations) { + String expandedLocation = getStringVariableManager().performStringSubstitution(location); + if (expandedLocation == null || expandedLocation.length() == 0) { + throw new CoreException(PydevDebugPlugin.makeStatus(IStatus.ERROR, + "Unable to get expanded location for run", null)); + } else { + ret[i] = new Path(expandedLocation); + } + i++; + } + return ret; } *************** *** 141,146 **** String arguments = configuration.getAttribute(Constants.ATTR_PROGRAM_ARGUMENTS, ""); if(makeArgumentsVariableSubstitution){ ! return VariablesPlugin.getDefault().getStringVariableManager() ! .performStringSubstitution(arguments); }else{ return arguments; --- 146,151 ---- String arguments = configuration.getAttribute(Constants.ATTR_PROGRAM_ARGUMENTS, ""); if(makeArgumentsVariableSubstitution){ ! return VariablesPlugin.getDefault().getStringVariableManager() ! .performStringSubstitution(arguments); }else{ return arguments; *************** *** 207,227 **** */ public static String getInterpreterLocation(ILaunchConfiguration conf, IPythonNature nature) throws InvalidRunException, CoreException { ! IInterpreterManager interpreterManager = PydevPlugin.getInterpreterManager(nature); String location = conf.getAttribute(Constants.ATTR_INTERPRETER, Constants.ATTR_INTERPRETER_DEFAULT); ! if (location != null && location.equals(Constants.ATTR_INTERPRETER_DEFAULT)){ ! location = interpreterManager.getDefaultInterpreter(); ! }else if(interpreterManager.hasInfoOnInterpreter(location) == false){ ! File file = new File(location); ! if(!file.exists()){ ! throw new InvalidRunException("Error. The interprer: "+location+" does not exist"); ! ! }else{ ! throw new InvalidRunException("Error. The interprer: "+location+" is not configured in the pydev preferences as a valid '"+nature.getVersion()+"' interpreter."); ! } } ! return location; ! } --- 212,232 ---- */ public static String getInterpreterLocation(ILaunchConfiguration conf, IPythonNature nature) throws InvalidRunException, CoreException { ! IInterpreterManager interpreterManager = PydevPlugin.getInterpreterManager(nature); String location = conf.getAttribute(Constants.ATTR_INTERPRETER, Constants.ATTR_INTERPRETER_DEFAULT); ! if (location != null && location.equals(Constants.ATTR_INTERPRETER_DEFAULT)){ ! location = interpreterManager.getDefaultInterpreter(); ! }else if(interpreterManager.hasInfoOnInterpreter(location) == false){ ! File file = new File(location); ! if(!file.exists()){ ! throw new InvalidRunException("Error. The interprer: "+location+" does not exist"); ! ! }else{ ! throw new InvalidRunException("Error. The interprer: "+location+" is not configured in the pydev preferences as a valid '"+nature.getVersion()+"' interpreter."); ! } } ! return location; ! } *************** *** 295,310 **** } ! /** ! * Sets defaults. ! * @throws InvalidRunException ! */ ! @SuppressWarnings("unchecked") public PythonRunnerConfig(ILaunchConfiguration conf, String mode, String run, boolean makeArgumentsVariableSubstitution) throws CoreException, InvalidRunException { ! //1st thing, see if this is a valid run. project = getProjectFromConfiguration(conf); if(project == null){ //Ok, we could not find it out ! CoreException e = PydevPlugin.log("Could not get project for resource: "+resource); ! throw e; } --- 300,314 ---- } ! /** ! * Sets defaults. ! * @throws InvalidRunException ! */ ! @SuppressWarnings("unchecked") public PythonRunnerConfig(ILaunchConfiguration conf, String mode, String run, boolean makeArgumentsVariableSubstitution) throws CoreException, InvalidRunException { ! //1st thing, see if this is a valid run. project = getProjectFromConfiguration(conf); if(project == null){ //Ok, we could not find it out ! throw PydevPlugin.log("Could not get project for configuration: " + conf); } *************** *** 316,321 **** } - - if(pythonNature.isJython()){ if(!run.equals(RUN_JYTHON) && !run.equals(RUN_JYTHON_UNITTEST)){ --- 320,323 ---- *************** *** 334,356 **** } ! ! ! //now, go on configuring other things ! this.configuration = conf; this.run = run; ! isDebug = mode.equals(ILaunchManager.DEBUG_MODE); ! isInteractive = mode.equals("interactive"); ! resource = getLocation(conf); ! arguments = getArguments(conf, makeArgumentsVariableSubstitution); ! IPath workingPath = getWorkingDirectory(conf); ! workingDirectory = workingPath == null ? null : workingPath.toFile(); ! acceptTimeout = PydevPrefs.getPreferences().getInt(PydevPrefs.CONNECT_TIMEOUT); interpreterLocation = getInterpreterLocation(conf, pythonNature); ! interpreter = getInterpreter(conf, pythonNature); //make the environment ! ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager(); envp = launchManager.getEnvironment(conf); --- 336,360 ---- } ! ! ! //now, go on configuring other things ! this.configuration = conf; this.run = run; ! isDebug = mode.equals(ILaunchManager.DEBUG_MODE); ! isInteractive = mode.equals("interactive"); ! useUnittestWrapper = !run.equals(RUN_UNITTEST) || ! !conf.getAttribute(Constants.ATTR_NO_UNITTEST_WRAPPER, false); ! resource = getLocation(conf); ! arguments = getArguments(conf, makeArgumentsVariableSubstitution); ! IPath workingPath = getWorkingDirectory(conf); ! workingDirectory = workingPath == null ? null : workingPath.toFile(); ! acceptTimeout = PydevPrefs.getPreferences().getInt(PydevPrefs.CONNECT_TIMEOUT); interpreterLocation = getInterpreterLocation(conf, pythonNature); ! interpreter = getInterpreter(conf, pythonNature); //make the environment ! ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager(); envp = launchManager.getEnvironment(conf); *************** *** 361,476 **** pythonpathUsed = SimpleRunner.makePythonPathEnvString(pythonNature, interpreterLocation); }else{ ! boolean win32= Platform.getOS().equals(org.eclipse.osgi.service.environment.Constants.OS_WIN32); ! //ok, the user has done something to configure it, so, just add the pythonpath to the //current env (if he still didn't do so) ! Map envMap = conf.getAttribute(ILaunchManager.ATTR_ENVIRONMENT_VARIABLES, (Map)null); ! if(!specifiedPythonpath(envMap)){ ! ! String pythonpath = SimpleRunner.makePythonPathEnvString(pythonNature, interpreterLocation); pythonpathUsed = pythonpath; ! //override it if it was the ambient pythonpath ! for (int i = 0; i < envp.length; i++) { ! if(win32){ //case insensitive ! if(envp[i].toUpperCase().startsWith("PYTHONPATH")){ ! //OK, finish it. ! envp[i] = "PYTHONPATH="+pythonpath; ! return; ! } ! }else{ ! if(envp[i].startsWith("PYTHONPATH")){ ! //OK, finish it. ! envp[i] = "PYTHONPATH="+pythonpath; ! return; ! } ! } ! ! } ! ! //there was no pythonpath, let's set it ! String[] s = new String[envp.length+1]; ! System.arraycopy(envp, 0, s, 0, envp.length); ! s[s.length-1] = "PYTHONPATH="+pythonpath; ! envp = s; ! ! } } ! } ! /** ! * @param envMap ! * @return */ private boolean specifiedPythonpath(Map<String, String> envMap) { ! if(envMap == null){ return false; ! ! }else{ ! boolean win32= Platform.getOS().equals(org.eclipse.osgi.service.environment.Constants.OS_WIN32); ! ! for (Iterator<String> iter = envMap.keySet().iterator(); iter.hasNext();) { ! String s = iter.next(); ! if(win32){ ! if(s.toUpperCase().equals("PYTHONPATH")){ ! return true; ! } ! }else{ ! if(s.equals("PYTHONPATH")){ ! return true; ! } ! } ! } } - return false; } public int getDebugPort() throws CoreException { ! if (debugPort == 0) { ! debugPort= SocketUtil.findUnusedLocalPort(); ! if (debugPort == -1) ! throw new CoreException(PydevDebugPlugin.makeStatus(IStatus.ERROR, "Could not find a free socket for debugger", null)); ! } ! return debugPort; ! } public static String getRunningName(IPath[] paths) { ! FastStringBuffer buf = new FastStringBuffer(20*paths.length); ! for(IPath p:paths){ ! if(buf.length() > 0){ ! buf.append(" - "); ! } ! buf.append(p.lastSegment()); ! } ! return buf.toString(); ! } ! public String getRunningName() { ! return getRunningName(resource); ! } ! /** ! * @throws CoreException if arguments are inconsistent ! */ ! public void verify() throws CoreException { ! if (resource == null || interpreter == null){ ! throw new CoreException(PydevDebugPlugin.makeStatus(IStatus.ERROR, "Invalid PythonRunnerConfig",null)); } ! if (isDebug && ( acceptTimeout < 0|| debugPort < 0) ){ ! throw new CoreException(PydevDebugPlugin.makeStatus(IStatus.ERROR, "Invalid PythonRunnerConfig",null)); } ! } ! /** * @return ! * @throws CoreException */ public static String getCoverageScript() throws CoreException { --- 365,476 ---- pythonpathUsed = SimpleRunner.makePythonPathEnvString(pythonNature, interpreterLocation); }else{ ! boolean win32= Platform.getOS().equals(org.eclipse.osgi.service.environment.Constants.OS_WIN32); ! //ok, the user has done something to configure it, so, just add the pythonpath to the //current env (if he still didn't do so) ! Map envMap = conf.getAttribute(ILaunchManager.ATTR_ENVIRONMENT_VARIABLES, (Map)null); ! if(!specifiedPythonpath(envMap)){ ! ! String pythonpath = SimpleRunner.makePythonPathEnvString(pythonNature, interpreterLocation); pythonpathUsed = pythonpath; ! //override it if it was the ambient pythonpath ! for (int i = 0; i < envp.length; i++) { ! if(win32){ //case insensitive ! if(envp[i].toUpperCase().startsWith("PYTHONPATH")){ ! //OK, finish it. ! envp[i] = "PYTHONPATH="+pythonpath; ! return; ! } ! }else{ ! if(envp[i].startsWith("PYTHONPATH")){ ! //OK, finish it. ! envp[i] = "PYTHONPATH="+pythonpath; ! return; ! } ! } ! ! } ! ! //there was no pythonpath, let's set it ! String[] s = new String[envp.length+1]; ! System.arraycopy(envp, 0, s, 0, envp.length); ! s[s.length-1] = "PYTHONPATH="+pythonpath; ! envp = s; ! ! } } ! } ! /** ! * Check if map contains PYTHONPATH key. ! * ! * Variables names are considered not case sensitive on Windows. ! * ! * @param envMap mapping of env variables and their values ! * @return {@code true} if passed map contain PYTHONPATH key. */ private boolean specifiedPythonpath(Map<String, String> envMap) { ! if (envMap == null) { return false; ! } ! boolean win32 = Platform.getOS().equals(org.eclipse.osgi.service.environment.Constants.OS_WIN32); ! if (!win32) { ! return envMap.containsKey("PYTHONPATH"); ! } ! for (Iterator<String> iter = envMap.keySet().iterator(); iter.hasNext();) { ! String s = iter.next(); ! if (s.toUpperCase().equals("PYTHONPATH")) { ! return true; } } return false; } public int getDebugPort() throws CoreException { ! if (debugPort == 0) { ! debugPort= SocketUtil.findUnusedLocalPort(); ! if (debugPort == -1) ! throw new CoreException(PydevDebugPlugin.makeStatus(IStatus.ERROR, "Could not find a free socket for debugger", null)); ! } ! return debugPort; ! } public static String getRunningName(IPath[] paths) { ! FastStringBuffer buf = new FastStringBuffer(20*paths.length); ! for(IPath p:paths){ ! if(buf.length() > 0){ ! buf.append(" - "); ! } ! buf.append(p.lastSegment()); ! } ! return buf.toString(); ! } ! public String getRunningName() { ! return getRunningName(resource); ! } ! /** ! * @throws CoreException if arguments are inconsistent ! */ ! public void verify() throws CoreException { ! if (resource == null || interpreter == null){ ! throw new CoreException(PydevDebugPlugin.makeStatus(IStatus.ERROR, "Invalid PythonRunnerConfig",null)); } ! if (isDebug && ( acceptTimeout < 0|| debugPort < 0) ){ ! throw new CoreException(PydevDebugPlugin.makeStatus(IStatus.ERROR, "Invalid PythonRunnerConfig",null)); } ! } ! /** * @return ! * @throws CoreException */ public static String getCoverageScript() throws CoreException { *************** *** 478,505 **** } - public static String getUnitTestScript() throws CoreException { - return REF.getFileAbsolutePath(PydevDebugPlugin.getScriptWithinPySrc("SocketTestRunner.py")); - } - /** ! * gets location of jpydaemon.py ! */ ! public static String getDebugScript() throws CoreException { ! return REF.getFileAbsolutePath(PydevDebugPlugin.getScriptWithinPySrc("pydevd.py")); ! } ! private String getRunFilesScript() throws CoreException { return REF.getFileAbsolutePath(PydevDebugPlugin.getScriptWithinPySrc("runfiles.py")); } ! /** ! * Create a command line for launching. ! * @return command line ready to be exec'd ! * @throws CoreException ! * @throws JDTNotAvailableException ! */ ! public String[] getCommandLine(boolean makeVariableSubstitution) throws CoreException, JDTNotAvailableException { ! List<String> cmdArgs = new ArrayList<String>(); if(isJython()){ --- 478,501 ---- } /** ! * gets location of jpydaemon.py ! */ ! public static String getDebugScript() throws CoreException { ! return REF.getFileAbsolutePath(PydevDebugPlugin.getScriptWithinPySrc("pydevd.py")); ! } ! public static String getRunFilesScript() throws CoreException { return REF.getFileAbsolutePath(PydevDebugPlugin.getScriptWithinPySrc("runfiles.py")); } ! /** ! * Create a command line for launching. ! * @return command line ready to be exec'd ! * @throws CoreException ! * @throws JDTNotAvailableException ! */ ! public String[] getCommandLine(boolean makeVariableSubstitution) throws CoreException, JDTNotAvailableException { ! List<String> cmdArgs = new ArrayList<String>(); if(isJython()){ *************** *** 519,608 **** // if (project.getNature(Constants.JAVA_NATURE) != null){ ! // cpath = getClasspath(JavaCore.create(project)); // } else { ! cpath = interpreter + SimpleRunner.getPythonPathSeparator() + pythonpathUsed; // } cmdArgs.add(cpath); cmdArgs.add("-Dpython.path="+pythonpathUsed); //will be added to the env variables in the run (check if this works on all platforms...) ! addVmArgs(cmdArgs); ! if (isDebug) { ! cmdArgs.add("-Dpython.security.respectJavaAccessibility=false"); //TODO: the user should configure this -- we use it so that ! //we can access the variables during debugging. ! cmdArgs.add("org.python.util.jython"); ! ! cmdArgs.add(getDebugScript()); ! cmdArgs.add("--vm_type"); ! cmdArgs.add("jython"); ! cmdArgs.add("--client"); ! cmdArgs.add("localhost"); ! cmdArgs.add("--port"); ! cmdArgs.add(Integer.toString(debugPort)); ! cmdArgs.add("--file"); ! }else{ ! cmdArgs.add("org.python.util.jython"); ! } ! ! if(isUnittest()){ ! cmdArgs.add(getRunFilesScript()); ! cmdArgs.add("--verbosity"); ! cmdArgs.add( PydevPrefs.getPreferences().getString(PyunitPrefsPage.PYUNIT_VERBOSITY) ); ! ! String filter = PydevPrefs.getPreferences().getString(PyunitPrefsPage.PYUNIT_TEST_FILTER); ! if (filter.length() > 0) { ! cmdArgs.add("--filter"); ! cmdArgs.add( filter ); ! } ! } }else{ ! cmdArgs.add(interpreter.toOSString()); ! // Next option is for unbuffered stdout, otherwise Eclipse will not see any output until done cmdArgs.add("-u"); addVmArgs(cmdArgs); ! if (isDebug) { ! cmdArgs.add(getDebugScript()); ! cmdArgs.add("--vm_type"); ! cmdArgs.add("python"); ! cmdArgs.add("--client"); ! cmdArgs.add("localhost"); ! cmdArgs.add("--port"); ! cmdArgs.add(Integer.toString(debugPort)); ! cmdArgs.add("--file"); ! } ! ! if(isCoverage()){ ! cmdArgs.add(getCoverageScript()); ! String coverageFileLocation = PyCoverage.getCoverageFileLocation(); cmdArgs.add(coverageFileLocation); ! cmdArgs.add("-x"); ! if (!isFile()){ ! //run all testcases cmdArgs.add(getRunFilesScript()); } ! } ! if(isUnittest()){ ! cmdArgs.add(getRunFilesScript()); ! cmdArgs.add("--verbosity"); ! cmdArgs.add( PydevPrefs.getPreferences().getString(PyunitPrefsPage.PYUNIT_VERBOSITY) ); ! ! String filter = PydevPrefs.getPreferences().getString(PyunitPrefsPage.PYUNIT_TEST_FILTER); ! if (filter.length() > 0) { ! cmdArgs.add("--filter"); ! cmdArgs.add( filter ); ! } ! } } for(IPath p:resource){ ! cmdArgs.add(p.toOSString()); } --- 515,564 ---- // if (project.getNature(Constants.JAVA_NATURE) != null){ ! // cpath = getClasspath(JavaCore.create(project)); // } else { ! cpath = interpreter + SimpleRunner.getPythonPathSeparator() + pythonpathUsed; // } cmdArgs.add(cpath); cmdArgs.add("-Dpython.path="+pythonpathUsed); //will be added to the env variables in the run (check if this works on all platforms...) ! addVmArgs(cmdArgs); ! if (isDebug) { ! cmdArgs.add("-Dpython.security.respectJavaAccessibility=false"); //TODO: the user should configure this -- we use it so that ! //we can access the variables during debugging. ! cmdArgs.add("org.python.util.jython"); ! addDebugArgs(cmdArgs, "jython"); }else{ ! cmdArgs.add("org.python.util.jython"); } ! addUnittestArgs(cmdArgs); }else{ ! cmdArgs.add(interpreter.toOSString()); ! // Next option is for unbuffered stdout, otherwise Eclipse will not see any output until done cmdArgs.add("-u"); addVmArgs(cmdArgs); ! addDebugArgs(cmdArgs, "python"); ! ! if(isCoverage()){ ! cmdArgs.add(getCoverageScript()); ! String coverageFileLocation = PyCoverage.getCoverageFileLocation(); cmdArgs.add(coverageFileLocation); ! cmdArgs.add("-x"); ! if (!isFile()){ ! //run all testcases cmdArgs.add(getRunFilesScript()); } ! } ! addUnittestArgs(cmdArgs); } for(IPath p:resource){ ! cmdArgs.add(p.toOSString()); } *************** *** 617,624 **** } ! String[] retVal = new String[cmdArgs.size()]; ! cmdArgs.toArray(retVal); ! return retVal; ! } /** --- 573,613 ---- } ! String[] retVal = new String[cmdArgs.size()]; ! cmdArgs.toArray(retVal); ! return retVal; ! } ! ! /** ! * Adds a set of arguments used to wrap executed file with unittest runner. ! */ ! private void addUnittestArgs(List<String> cmdArgs) throws CoreException { ! if (isUnittest() && useUnittestWrapper) { ! cmdArgs.add(getRunFilesScript()); ! cmdArgs.add("--verbosity"); ! cmdArgs.add(PydevPrefs.getPreferences().getString(PyunitPrefsPage.PYUNIT_VERBOSITY)); ! ! String filter = PydevPrefs.getPreferences().getString(PyunitPrefsPage.PYUNIT_TEST_FILTER); ! if (filter.length() > 0) { ! cmdArgs.add("--filter"); ! cmdArgs.add(filter); ! } ! } ! } ! ! /** ! * Adds a set of arguments needed for debugging. ! */ ! private void addDebugArgs(List<String> cmdArgs, String vmType) throws CoreException { ! if (isDebug) { ! cmdArgs.add(getDebugScript()); ! cmdArgs.add("--vm_type"); ! cmdArgs.add(vmType); ! cmdArgs.add("--client"); ! cmdArgs.add("localhost"); ! cmdArgs.add("--port"); ! cmdArgs.add(Integer.toString(debugPort)); ! cmdArgs.add("--file"); ! } ! } /** *************** *** 630,645 **** if(vmArguments != null){ for (int i = 0; i < vmArguments.length; i++){ ! cmdArgs.add(vmArguments[i]); } } } ! ! /** ! * @return an array with the vm arguments in the given configuration. ! * @throws CoreException ! */ private String[] getVMArguments(ILaunchConfiguration configuration) throws CoreException { ! String args = configuration.getAttribute(Constants.ATTR_VM_ARGUMENTS, (String) null); if (args != null && args.trim().length() > 0) { String expanded = getStringVariableManager().performStringSubstitution(args); --- 619,634 ---- if(vmArguments != null){ for (int i = 0; i < vmArguments.length; i++){ ! cmdArgs.add(vmArguments[i]); } } } ! ! /** ! * @return an array with the vm arguments in the given configuration. ! * @throws CoreException ! */ private String[] getVMArguments(ILaunchConfiguration configuration) throws CoreException { ! String args = configuration.getAttribute(Constants.ATTR_VM_ARGUMENTS, (String) null); if (args != null && args.trim().length() > 0) { String expanded = getStringVariableManager().performStringSubstitution(args); *************** *** 647,651 **** } return null; ! } /** --- 636,640 ---- } return null; ! } /** *************** *** 654,659 **** * @throws JDTNotAvailableException */ ! public String getCommandLineAsString() throws JDTNotAvailableException { ! String[] args; try { args = getCommandLine(false); --- 643,648 ---- * @throws JDTNotAvailableException */ ! public String getCommandLineAsString() throws JDTNotAvailableException { ! String[] args; try { args = getCommandLine(false); *************** *** 662,666 **** throw new RuntimeException(e); } ! } } --- 651,655 ---- throw new RuntimeException(e); } ! } } Index: AbstractLaunchShortcut.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.debug/src/org/python/pydev/debug/ui/launching/AbstractLaunchShortcut.java,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** AbstractLaunchShortcut.java 17 Aug 2008 00:26:56 -0000 1.18 --- AbstractLaunchShortcut.java 27 Sep 2008 19:59:08 -0000 1.19 *************** *** 224,229 **** } return buffer.toString(); ! // E3 IStringVariableManager varManager = VariablesPlugin.getDefault().getStringVariableManager(); ! // E3 return varManager.generateVariableExpression("workspace_loc", file.getFullPath().toString()); } --- 224,229 ---- } return buffer.toString(); ! // E3 IStringVariableManager varManager = VariablesPlugin.getDefault().getStringVariableManager(); ! // E3 return varManager.generateVariableExpression("workspace_loc", file.getFullPath().toString()); } *************** *** 342,351 **** FastStringBuffer moduleFile = new FastStringBuffer(80*resource.length); for(IResource r:resource){ ! String m = r.getFullPath().makeRelative().toString(); ! m = varManager.generateVariableExpression("workspace_loc", m); ! if(moduleFile.length() > 0){ ! moduleFile.append("|"); ! } ! moduleFile.append(m); } return moduleFile.toString(); --- 342,351 ---- FastStringBuffer moduleFile = new FastStringBuffer(80*resource.length); for(IResource r:resource){ ! String m = r.getFullPath().makeRelative().toString(); ! m = varManager.generateVariableExpression("workspace_loc", m); ! if(moduleFile.length() > 0){ ! moduleFile.append("|"); ! } ! moduleFile.append(m); } return moduleFile.toString(); |