[Pydev-cvs] org.python.pydev.debug/src/org/python/pydev/debug/ui/actions PythonRunSubsetActionDelega
Brought to you by:
fabioz
From: Fabio Z. <fa...@us...> - 2004-10-18 19:13:25
|
Update of /cvsroot/pydev/org.python.pydev.debug/src/org/python/pydev/debug/ui/actions In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5079/src/org/python/pydev/debug/ui/actions Modified Files: PythonRunSubsetActionDelegate.java Log Message: Index: PythonRunSubsetActionDelegate.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.debug/src/org/python/pydev/debug/ui/actions/PythonRunSubsetActionDelegate.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** PythonRunSubsetActionDelegate.java 15 Oct 2004 19:53:28 -0000 1.1 --- PythonRunSubsetActionDelegate.java 18 Oct 2004 19:13:14 -0000 1.2 *************** *** 13,17 **** --- 13,29 ---- import org.eclipse.core.resources.IFolder; + import org.eclipse.core.runtime.CoreException; + import org.eclipse.core.runtime.IStatus; + import org.eclipse.core.runtime.Status; + import org.eclipse.debug.core.ILaunchConfiguration; + import org.eclipse.debug.core.ILaunchConfigurationType; + import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; + import org.eclipse.debug.core.ILaunchManager; + import org.eclipse.debug.core.Launch; + import org.eclipse.debug.ui.CommonTab; + import org.eclipse.debug.ui.DebugUITools; + import org.eclipse.debug.ui.IDebugUIConstants; import org.eclipse.jface.action.IAction; + import org.eclipse.jface.dialogs.ErrorDialog; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; *************** *** 22,25 **** --- 34,40 ---- import org.python.pydev.debug.codecoverage.PyCoverage; import org.python.pydev.debug.codecoverage.RunManyDialog; + import org.python.pydev.debug.core.Constants; + import org.python.pydev.debug.core.PydevDebugPlugin; + import org.python.pydev.debug.ui.launching.PythonRunnerConfig; /** *************** *** 32,54 **** public void run(IAction action) { ! if (part != null && selectedFolder != null) { ! // figure out run or debug mode ! ! RunManyDialog dialog = new RunManyDialog(part.getSite().getShell(), selectedFolder.getLocation().toString()); ! if(dialog.open() == Window.OK){ ! String root = dialog.rootFolder; ! String files = dialog.files; ! ! String interpreter = dialog.interpreter; ! String workingDir = dialog.working; ! ! List list = listFilesThatMatch(root, files); ! for (Iterator iter = list.iterator(); iter.hasNext();) { ! System.out.println(iter.next()); ! //TODO: execute those files with the coverage script. ! //we have to get the output for the user.. ! } ! } ! } } --- 47,110 ---- public void run(IAction action) { ! try { ! if (part != null && selectedFolder != null) { ! ! String runMode = ""; ! if(action.getId().endsWith("PythonRunSubset")){ ! runMode = ILaunchManager.RUN_MODE; ! ! } else if(action.getId().endsWith("PythonCoverageSubset")){ ! runMode = ILaunchManager.PROFILE_MODE; ! ! } else{ ! throw new RuntimeException("Unknown "); ! } ! ! ! ! RunManyDialog dialog = new RunManyDialog(part.getSite().getShell(), selectedFolder.getLocation().toString()); ! if(dialog.open() == Window.OK){ ! String root = dialog.rootFolder; ! String files = dialog.files; ! ! String interpreter = dialog.interpreter; ! String workingDir = dialog.working; ! String scriptArgs = dialog.scriptArgs; ! String scriptLocation = dialog.scriptLocation; ! boolean scriptSelected = dialog.scriptSelected; ! ! String arguments= ""; //no arguments for multiple run... ! if(scriptSelected){ ! arguments += root+" "; ! arguments += scriptArgs; ! ILaunchConfiguration configuration = createDefaultLaunchConfiguration(selectedFolder, scriptLocation, workingDir, arguments, interpreter); ! Launch launch = new Launch(configuration,runMode, null ); ! ! PythonRunnerConfig config = new PythonRunnerConfig(configuration, runMode); ! ! DebugUITools.launch(configuration, runMode); ! ! }else{ ! List list = listFilesThatMatch(root, files); ! ! for (Iterator iter = list.iterator(); iter.hasNext();) { ! Object n = iter.next(); ! System.out.println("Executing:"+n); ! ILaunchConfiguration configuration = createDefaultLaunchConfiguration(selectedFolder, n.toString(), workingDir, arguments, interpreter); ! Launch launch = new Launch(configuration,runMode, null ); ! ! PythonRunnerConfig config = new PythonRunnerConfig(configuration, runMode); ! ! DebugUITools.launch(configuration, runMode); ! ! } ! } ! } ! } ! } catch (Exception e) { ! // TODO Auto-generated catch block ! e.printStackTrace(); ! throw new RuntimeException(e); ! } } *************** *** 70,74 **** }; ! l = PyCoverage.getPyFilesBelow(file, filter)[0]; } --- 126,130 ---- }; ! l = PyCoverage.getPyFilesBelow(file, filter, null)[0]; } *************** *** 97,100 **** --- 153,214 ---- } } + + + /** + * COPIED/MODIFIED from AntLaunchShortcut + */ + public static ILaunchConfiguration createDefaultLaunchConfiguration(IFolder folder, String location, String baseDirectory, String arguments, String interpreter) { + ILaunchManager manager = org.eclipse.debug.core.DebugPlugin.getDefault().getLaunchManager(); + ILaunchConfigurationType type = manager.getLaunchConfigurationType(Constants.ID_PYTHON_LAUNCH_CONFIGURATION_TYPE); + if (type == null) { + reportError("Python launch configuration not found", null); + return null; + } + StringBuffer buffer = new StringBuffer(folder.getProject().getName()); + buffer.append(" "); + buffer.append(folder.getName()); + String name = buffer.toString().trim(); + // name= manager.generateUniqueLaunchConfigurationNameFrom(name); + try { + + ILaunchConfigurationWorkingCopy workingCopy = type.newInstance(null, name); + workingCopy.setAttribute(IDebugUIConstants.ATTR_LAUNCH_IN_BACKGROUND, false); + workingCopy.setAttribute(Constants.ATTR_LOCATION,location); + workingCopy.setAttribute(Constants.ATTR_WORKING_DIRECTORY,baseDirectory); + workingCopy.setAttribute(Constants.ATTR_PROGRAM_ARGUMENTS,arguments); + workingCopy.setAttribute(Constants.ATTR_INTERPRETER,interpreter); + + // Common Tab Arguments + CommonTab tab = new CommonTab(); + tab.setDefaults(workingCopy); + tab.dispose(); + return workingCopy.doSave(); + } catch (CoreException e) { + reportError(null, e); + return null; + } + } + + /** + * + * @param folder + * @return + */ + static String getDefaultLocation (IFolder folder) { + return folder.getRawLocation().toString(); + } + + protected static void reportError(String message, Throwable throwable) { + if (message == null) + message = "Unexpected error"; + IStatus status = null; + if (throwable instanceof CoreException) { + status = ((CoreException)throwable).getStatus(); + } else { + status = new Status(IStatus.ERROR, "org.python.pydev.debug", 0, message, throwable); + } + ErrorDialog.openError(PydevDebugPlugin.getActiveWorkbenchWindow().getShell(), + "Python pydev.debug error", "Python launch subset failed", status); + } } \ No newline at end of file |