From 52246c044fa9ef2f4510dc623f0cbc0f406b2353 Mon Sep 17 00:00:00 2001 From: David Inglis Date: Tue, 24 Sep 2002 17:26:12 +0000 Subject: [PATCH] verify project/program in launch --- .../cdt/launch/AbstractCLaunchDelegate.java | 38 ++++++++++++------ .../ICDTLaunchConfigurationConstants.java | 40 +++++++++++++++++-- .../internal/CoreFileLaunchDelegate.java | 10 ++--- .../LocalCLaunchConfigurationDelegate.java | 9 +---- 4 files changed, 66 insertions(+), 31 deletions(-) diff --git a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/AbstractCLaunchDelegate.java b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/AbstractCLaunchDelegate.java index cef8edd90ef..bc48f731a3e 100644 --- a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/AbstractCLaunchDelegate.java +++ b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/AbstractCLaunchDelegate.java @@ -17,12 +17,7 @@ import java.util.Map.Entry; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.debug.core.CDebugCorePlugin; -import org.eclipse.cdt.debug.core.CDebugModel; import org.eclipse.cdt.debug.core.ICDebugConfiguration; -import org.eclipse.cdt.debug.core.ICDebugger; -import org.eclipse.cdt.debug.core.cdi.CDIException; -import org.eclipse.cdt.debug.core.cdi.ICDISession; -import org.eclipse.cdt.debug.core.cdi.model.ICDITarget; import org.eclipse.cdt.launch.internal.ui.LaunchUIPlugin; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; @@ -31,19 +26,12 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.QualifiedName; import org.eclipse.core.runtime.Status; import org.eclipse.debug.core.DebugPlugin; import org.eclipse.debug.core.ILaunch; import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.IStatusHandler; import org.eclipse.debug.core.model.ILaunchConfigurationDelegate; -import org.eclipse.debug.core.model.IProcess; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.FileDialog; -import org.eclipse.swt.widgets.Shell; abstract public class AbstractCLaunchDelegate implements ILaunchConfigurationDelegate { @@ -200,6 +188,32 @@ abstract public class AbstractCLaunchDelegate implements ILaunchConfigurationDel return MessageFormat.format(format, new String[] { commandLine, timestamp }); } + protected ICProject verifyCProject(ILaunchConfiguration config) throws CoreException { + String name = getProjectName(config); + if (name == null) { + abort("C project not specified", null, ICDTLaunchConfigurationConstants.ERR_UNSPECIFIED_PROJECT); + } + ICProject project = getCProject(config); + if (project == null) { + abort("Project does not exist or is not a C/C++ project", null, ICDTLaunchConfigurationConstants.ERR_NOT_A_C_PROJECT); + } + return project; + } + + protected IPath verifyProgramFile(ILaunchConfiguration config) throws CoreException { + ICProject cproject = verifyCProject(config); + String fileName = getProgramName(config); + if ( fileName == null ) { + abort("Program file not specified", null, ICDTLaunchConfigurationConstants.ERR_UNSPECIFIED_PROGRAM); + } + + IFile projectPath = ((IProject) cproject.getResource()).getFile(fileName); + if (projectPath == null || !projectPath.exists()) { + abort("Program file does not exist", null, ICDTLaunchConfigurationConstants.ERR_PROGRAM_NOT_EXIST); + } + return projectPath.getLocation(); + } + private static class ArgumentParser { private String fArgs; private int fIndex = 0; diff --git a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/ICDTLaunchConfigurationConstants.java b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/ICDTLaunchConfigurationConstants.java index 6fcc3c48f55..2773c8ec4c2 100644 --- a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/ICDTLaunchConfigurationConstants.java +++ b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/ICDTLaunchConfigurationConstants.java @@ -119,13 +119,38 @@ public interface ICDTLaunchConfigurationConstants { *

*/ public static final int ERR_WORKING_DIRECTORY_NOT_SUPPORTED = 100; - + /** * Status code indicating the specified working directory * does not exist. */ public static final int ERR_WORKING_DIRECTORY_DOES_NOT_EXIST = 101; + /** + * Status code indicating a launch configuration does not + * specify a project when a project is required. + */ + public static final int ERR_UNSPECIFIED_PROJECT = 102; + + /** + * Status code indicating a launch configuration does not + * specify a vaild project. + */ + public static final int ERR_NOT_A_C_PROJECT = 103; + + /** + * Status code indicating a launch configuration does not + * specify a vaild program. + */ + public static final int ERR_PROGRAM_NOT_EXIST = 104; + + /** + * Status code indicating a launch configuration does not + * specify a program name. + */ + + public static final int ERR_UNSPECIFIED_PROGRAM = 105; + /** * Status code indicating that the CDT debugger is missing *

@@ -133,10 +158,17 @@ public interface ICDTLaunchConfigurationConstants { * and should return a String indicating which debugger to use. *

*/ - public static final int ERR_DEBUGGER_NOT_INSTALLED = 102; + public static final int ERR_DEBUGGER_NOT_INSTALLED = 106; - public static final int ERR_NO_PROCESSID = 103; - public static final int ERR_NO_COREFILE = 104; + /** + * Status code indicating a the user did not specify a process id + */ + public static final int ERR_NO_PROCESSID = 107; + + /** + * Status code indicating a the user did not specify a path to a corefile + */ + public static final int ERR_NO_COREFILE = 108; /** * Status code indicating an unexpected internal error. diff --git a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/internal/CoreFileLaunchDelegate.java b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/internal/CoreFileLaunchDelegate.java index c7ea46137f6..b420292125c 100644 --- a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/internal/CoreFileLaunchDelegate.java +++ b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/internal/CoreFileLaunchDelegate.java @@ -1,13 +1,8 @@ package org.eclipse.cdt.launch.internal; -import java.text.DateFormat; -import java.text.MessageFormat; -import java.util.Date; - import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.debug.core.CDebugModel; import org.eclipse.cdt.debug.core.ICDebugConfiguration; -import org.eclipse.cdt.debug.core.ICDebugger; import org.eclipse.cdt.debug.core.cdi.CDIException; import org.eclipse.cdt.debug.core.cdi.ICDISession; import org.eclipse.cdt.debug.core.cdi.model.ICDITarget; @@ -50,12 +45,13 @@ public class CoreFileLaunchDelegate extends AbstractCLaunchDelegate { if (monitor.isCanceled()) { return; } - ICProject cproject = getCProject(config); - IPath projectPath = ((IProject) cproject.getResource()).getFile(getProgramName(config)).getLocation(); + IPath projectPath = verifyProgramFile(config); ICDebugConfiguration debugConfig = getDebugConfig(config); IFile exe = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(projectPath); ICDISession dsession = null; + + ICProject cproject = getCProject(config); IPath corefile = getCoreFilePath((IProject)cproject.getResource()); if ( corefile == null ) { diff --git a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/internal/LocalCLaunchConfigurationDelegate.java b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/internal/LocalCLaunchConfigurationDelegate.java index e077c0faeac..de362650e1f 100644 --- a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/internal/LocalCLaunchConfigurationDelegate.java +++ b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/internal/LocalCLaunchConfigurationDelegate.java @@ -7,19 +7,14 @@ package org.eclipse.cdt.launch.internal; import java.io.File; import java.io.IOException; -import java.text.DateFormat; -import java.text.MessageFormat; import java.util.ArrayList; import java.util.Arrays; -import java.util.Date; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.IProcessInfo; import org.eclipse.cdt.core.IProcessList; -import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.debug.core.CDebugModel; import org.eclipse.cdt.debug.core.ICDebugConfiguration; -import org.eclipse.cdt.debug.core.ICDebugger; import org.eclipse.cdt.debug.core.cdi.CDIException; import org.eclipse.cdt.debug.core.cdi.ICDIRuntimeOptions; import org.eclipse.cdt.debug.core.cdi.ICDISession; @@ -28,7 +23,6 @@ import org.eclipse.cdt.launch.AbstractCLaunchDelegate; import org.eclipse.cdt.launch.ICDTLaunchConfigurationConstants; import org.eclipse.cdt.launch.internal.ui.LaunchUIPlugin; import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; @@ -64,8 +58,7 @@ public class LocalCLaunchConfigurationDelegate extends AbstractCLaunchDelegate { if (monitor.isCanceled()) { return; } - ICProject cproject = getCProject(config); - IPath projectPath = ((IProject) cproject.getResource()).getFile(getProgramName(config)).getLocation(); + IPath projectPath = verifyProgramFile(config); String arguments[] = getProgramArgumentsArray(config); ArrayList command = new ArrayList(1 + arguments.length); command.add(projectPath.toOSString());