[Pydev-cvs] org.python.pydev.debug/src/org/python/pydev/debug/ui/launching InvalidRunException.jav
Brought to you by:
fabioz
From: Fabio Z. <fa...@us...> - 2008-04-13 16:55:13
|
Update of /cvsroot/pydev/org.python.pydev.debug/src/org/python/pydev/debug/ui/launching In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13464/src/org/python/pydev/debug/ui/launching Modified Files: PythonRunnerConfig.java AbstractLaunchConfigurationDelegate.java Added Files: InvalidRunException.java Log Message: Better error message when launch config is not valid. --- NEW FILE: InvalidRunException.java --- package org.python.pydev.debug.ui.launching; public class InvalidRunException extends Exception { public InvalidRunException(String message) { super(message); } } Index: PythonRunnerConfig.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.debug/src/org/python/pydev/debug/ui/launching/PythonRunnerConfig.java,v retrieving revision 1.64 retrieving revision 1.65 diff -C2 -d -r1.64 -r1.65 *** PythonRunnerConfig.java 18 Mar 2008 02:55:02 -0000 1.64 --- PythonRunnerConfig.java 13 Apr 2008 16:55:17 -0000 1.65 *************** *** 31,34 **** --- 31,35 ---- import org.python.pydev.core.IPythonNature; import org.python.pydev.core.REF; + import org.python.pydev.core.docutils.StringUtils; import org.python.pydev.debug.codecoverage.PyCoverage; import org.python.pydev.debug.core.Constants; *************** *** 51,59 **** public class PythonRunnerConfig { ! public static final String RUN_COVERAGE = "RUN_COVERAGE"; ! public static final String RUN_REGULAR = "RUN_REGULAR"; ! public static final String RUN_UNITTEST = "RUN_UNITTEST"; ! public static final String RUN_JYTHON_UNITTEST = "RUN_JYTHON_UNITTEST"; ! public static final String RUN_JYTHON = "RUN_JYTHON"; public IProject project; --- 52,60 ---- public class PythonRunnerConfig { ! public static final String RUN_COVERAGE = "python code coverage run"; ! public static final String RUN_REGULAR = "python regular run"; ! public static final String RUN_UNITTEST = "pyton unittest run"; ! public static final String RUN_JYTHON_UNITTEST = "jython unittest run"; ! public static final String RUN_JYTHON = "jython regular run"; public IProject project; *************** *** 196,200 **** * resolve the default interpreter. */ ! public static String getInterpreterLocation(ILaunchConfiguration conf, IPythonNature nature) throws CoreException { IInterpreterManager interpreterManager = PydevPlugin.getInterpreterManager(nature); String location = conf.getAttribute(Constants.ATTR_INTERPRETER, Constants.ATTR_INTERPRETER_DEFAULT); --- 197,201 ---- * resolve the default interpreter. */ ! 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); *************** *** 204,208 **** }else if(interpreterManager.hasInfoOnInterpreter(location) == false){ ! throw new CoreException(PydevPlugin.makeStatus(IStatus.ERROR, "Error. The interprer: "+location+" is not configured in the pydev preferences as a '"+nature.getVersion()+"' interpreter (as required by the project:"+nature.getProject().getName()+").", null)); } return location; --- 205,215 ---- }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; *************** *** 221,226 **** * resolved location does not point to an existing directory in the local * file system */ ! public static IPath getInterpreter(ILaunchConfiguration configuration, IPythonNature nature) throws CoreException { String location = getInterpreterLocation(configuration, nature); if (location == null) { --- 228,234 ---- * resolved location does not point to an existing directory in the local * file system + * @throws InvalidRunException */ ! public static IPath getInterpreter(ILaunchConfiguration configuration, IPythonNature nature) throws CoreException, InvalidRunException { String location = getInterpreterLocation(configuration, nature); if (location == null) { *************** *** 262,267 **** * @return a string with the pythonpath used (with | as a separator) * @throws CoreException */ ! public static String getPythonpathFromConfiguration(ILaunchConfiguration conf) throws CoreException{ IProject p = getProjectFromConfiguration(conf); PythonNature pythonNature = PythonNature.getPythonNature(p); --- 270,276 ---- * @return a string with the pythonpath used (with | as a separator) * @throws CoreException + * @throws InvalidRunException */ ! public static String getPythonpathFromConfiguration(ILaunchConfiguration conf) throws CoreException, InvalidRunException{ IProject p = getProjectFromConfiguration(conf); PythonNature pythonNature = PythonNature.getPythonNature(p); *************** *** 270,277 **** } String l = getInterpreterLocation(conf, pythonNature); ! return SimpleRunner.makePythonPathEnvString(p, l); } ! public PythonRunnerConfig(ILaunchConfiguration conf, String mode, String run) throws CoreException { this(conf, mode, run, true); } --- 279,286 ---- } String l = getInterpreterLocation(conf, pythonNature); ! return SimpleRunner.makePythonPathEnvString(pythonNature, l); } ! public PythonRunnerConfig(ILaunchConfiguration conf, String mode, String run) throws CoreException, InvalidRunException { this(conf, mode, run, true); } *************** *** 279,296 **** /** * Sets defaults. */ @SuppressWarnings("unchecked") ! public PythonRunnerConfig(ILaunchConfiguration conf, String mode, String run, boolean makeArgumentsVariableSubstitution) throws CoreException { ! 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); ! project = getProjectFromConfiguration(conf); --- 288,296 ---- /** * 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); *************** *** 307,310 **** --- 307,342 ---- } + + + if(pythonNature.isJython()){ + if(!run.equals(RUN_JYTHON) && !run.equals(RUN_JYTHON_UNITTEST)){ + throw new InvalidRunException(StringUtils.format( + "Cannot make a '%s' for the project '%s' because the project is configured as %s\n\n" + + "To fix this, configure '%s' as python or run it as jython", + run, project.getName(), pythonNature.getVersion(), project.getName())); + } + }else if(pythonNature.isPython()){ + if(!run.equals(RUN_REGULAR) && !run.equals(RUN_COVERAGE) && !run.equals(RUN_UNITTEST)){ + throw new InvalidRunException(StringUtils.format( + "Cannot make a '%s' for the project '%s' because the project is configured as %s\n\n" + + "To fix this, configure '%s' as jython or run it as python", + run, project.getName(), pythonNature.getVersion(), project.getName())); + } + } + + + + //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); *************** *** 317,322 **** //ok, the user has done nothing to the environment, just get all the default environment and //put the pythonpath in it ! envp = new SimplePythonRunner().getEnvironment(project, interpreterLocation); ! pythonpathUsed = SimpleRunner.makePythonPathEnvString(project, interpreterLocation); }else{ boolean win32= Platform.getOS().equals(org.eclipse.osgi.service.environment.Constants.OS_WIN32); --- 349,354 ---- //ok, the user has done nothing to the environment, just get all the default environment and //put the pythonpath in it ! envp = new SimplePythonRunner().getEnvironment(pythonNature, interpreterLocation); ! pythonpathUsed = SimpleRunner.makePythonPathEnvString(pythonNature, interpreterLocation); }else{ boolean win32= Platform.getOS().equals(org.eclipse.osgi.service.environment.Constants.OS_WIN32); *************** *** 328,332 **** if(!specifiedPythonpath(envMap)){ ! String pythonpath = SimpleRunner.makePythonPathEnvString(project, interpreterLocation); pythonpathUsed = pythonpath; //override it if it was the ambient pythonpath --- 360,364 ---- if(!specifiedPythonpath(envMap)){ ! String pythonpath = SimpleRunner.makePythonPathEnvString(pythonNature, interpreterLocation); pythonpathUsed = pythonpath; //override it if it was the ambient pythonpath Index: AbstractLaunchConfigurationDelegate.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.debug/src/org/python/pydev/debug/ui/launching/AbstractLaunchConfigurationDelegate.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** AbstractLaunchConfigurationDelegate.java 11 Dec 2007 21:18:25 -0000 1.6 --- AbstractLaunchConfigurationDelegate.java 13 Apr 2008 16:55:18 -0000 1.7 *************** *** 14,24 **** --- 14,33 ---- import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.NullProgressMonitor; + import org.eclipse.debug.core.DebugPlugin; import org.eclipse.debug.core.ILaunch; import org.eclipse.debug.core.ILaunchConfiguration; + import org.eclipse.debug.core.ILaunchManager; import org.eclipse.debug.core.model.ILaunchConfigurationDelegate; import org.eclipse.debug.core.model.LaunchConfigurationDelegate; + import org.eclipse.debug.internal.core.LaunchConfiguration; + import org.eclipse.debug.internal.core.LaunchManager; + import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationManager; + import org.eclipse.jface.dialogs.ErrorDialog; + import org.eclipse.swt.widgets.Display; import org.python.pydev.core.log.Log; import org.python.pydev.debug.core.Constants; import org.python.pydev.debug.core.PydevDebugPlugin; + import org.python.pydev.editor.actions.PyAction; + import org.python.pydev.plugin.PydevPlugin; /** *************** *** 85,96 **** monitor.beginTask("Preparing configuration", 3); - PythonRunnerConfig runConfig = new PythonRunnerConfig(conf, mode, getRunnerConfigRun()); - - monitor.worked(1); try { ! PythonRunner.run(runConfig, launch, monitor); ! } catch (IOException e) { ! Log.log(e); ! throw new CoreException(PydevDebugPlugin.makeStatus(IStatus.ERROR, "Unexpected IO Exception in Pydev debugger", null)); } } --- 94,129 ---- monitor.beginTask("Preparing configuration", 3); try { ! PythonRunnerConfig runConfig = new PythonRunnerConfig(conf, mode, getRunnerConfigRun()); ! ! monitor.worked(1); ! try { ! PythonRunner.run(runConfig, launch, monitor); ! } catch (IOException e) { ! Log.log(e); ! finishLaunchWithError(launch); ! throw new CoreException(PydevDebugPlugin.makeStatus(IStatus.ERROR, "Unexpected IO Exception in Pydev debugger", null)); ! } ! }catch(final InvalidRunException e){ ! Display.getDefault().asyncExec(new Runnable(){ ! ! public void run() { ! ErrorDialog.openError(PyAction.getShell(), "Invalid launch configuration", ! "Unable to make launch because launch configuration is not valid", ! PydevPlugin.makeStatus(IStatus.ERROR, e.getMessage(), e)); ! } ! }); ! finishLaunchWithError(launch); ! } ! } ! ! private void finishLaunchWithError(ILaunch launch) { ! try{ ! launch.terminate(); ! ! ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager(); ! launchManager.removeLaunch(launch); ! }catch(Throwable x){ ! PydevPlugin.log(x); } } |