mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-09-07 10:33:26 +02:00
verify project/program in launch
This commit is contained in:
parent
76151921f1
commit
52246c044f
4 changed files with 66 additions and 31 deletions
|
@ -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;
|
||||
|
|
|
@ -119,13 +119,38 @@ public interface ICDTLaunchConfigurationConstants {
|
|||
* </p>
|
||||
*/
|
||||
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
|
||||
* <p>
|
||||
|
@ -133,10 +158,17 @@ public interface ICDTLaunchConfigurationConstants {
|
|||
* and should return a String indicating which debugger to use.
|
||||
* </p>
|
||||
*/
|
||||
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.
|
||||
|
|
|
@ -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 ) {
|
||||
|
|
|
@ -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());
|
||||
|
|
Loading…
Add table
Reference in a new issue