From acda777315f69483c4066c356557661b7555325d Mon Sep 17 00:00:00 2001 From: Marc Khouzam Date: Fri, 24 Apr 2015 11:33:53 -0400 Subject: [PATCH] Bug 464078 - Support project-less Run Change-Id: I69e655a65533e4cb835df59c9ff6ffa8152b92ff Signed-off-by: Marc Khouzam --- .../cdt/launch/AbstractCLaunchDelegate2.java | 40 +++++++++++++++++++ .../internal/LocalRunLaunchDelegate.java | 17 +++++++- 2 files changed, 55 insertions(+), 2 deletions(-) diff --git a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/AbstractCLaunchDelegate2.java b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/AbstractCLaunchDelegate2.java index 729b30dfb40..7fd2b46caef 100644 --- a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/AbstractCLaunchDelegate2.java +++ b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/AbstractCLaunchDelegate2.java @@ -34,6 +34,7 @@ import org.eclipse.cdt.launch.internal.ui.LaunchMessages; import org.eclipse.cdt.launch.internal.ui.LaunchUIPlugin; import org.eclipse.core.resources.ICommand; import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IMarker; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; @@ -642,6 +643,45 @@ public abstract class AbstractCLaunchDelegate2 extends LaunchConfigurationDelega return null; } + /** + * Verify that the program name of the configuration can be found as a file. + * This method supports a program name without a corresponding project, + * as long as the program name is specified with an absolute path. + * + * @return Absolute path of the program location + * @since 7.3 + */ + protected IPath verifyProgramPath(ILaunchConfiguration configuration, ICProject cproject) throws CoreException { + String programName = configuration.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, (String)null); + if (programName == null) { + abort(LaunchMessages.AbstractCLaunchDelegate_Program_file_not_specified, null, + ICDTLaunchConfigurationConstants.ERR_UNSPECIFIED_PROGRAM); + } + programName = VariablesPlugin.getDefault().getStringVariableManager().performStringSubstitution(programName); + + IPath programPath = new Path(programName); + if (programPath.isEmpty()) { + abort(LaunchMessages.AbstractCLaunchDelegate_Program_file_does_not_exist, null, + ICDTLaunchConfigurationConstants.ERR_PROGRAM_NOT_EXIST); + } + + if (!programPath.isAbsolute() && cproject != null) { + // Find the specified program within the specified project + IFile wsProgramPath = cproject.getProject().getFile(programPath); + programPath = wsProgramPath.getLocation(); + } + + if (!programPath.toFile().exists()) { + abort(LaunchMessages.AbstractCLaunchDelegate_Program_file_does_not_exist, + new FileNotFoundException( + NLS.bind(LaunchMessages.AbstractCLaunchDelegate_PROGRAM_PATH_not_found, + programPath.toOSString())), + ICDTLaunchConfigurationConstants.ERR_PROGRAM_NOT_EXIST); + } + + return programPath; + } + /** * @return the ID of the plugin hosting the launch delegate. It's used to * create {@link IStatus} objects. diff --git a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/internal/LocalRunLaunchDelegate.java b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/internal/LocalRunLaunchDelegate.java index 57219d3dc37..eef9929e3d7 100644 --- a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/internal/LocalRunLaunchDelegate.java +++ b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/internal/LocalRunLaunchDelegate.java @@ -17,7 +17,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Date; -import org.eclipse.cdt.debug.core.CDebugUtils; +import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; import org.eclipse.cdt.launch.AbstractCLaunchDelegate2; import org.eclipse.cdt.launch.internal.ui.LaunchMessages; @@ -43,6 +43,7 @@ import com.ibm.icu.text.DateFormat; public class LocalRunLaunchDelegate extends AbstractCLaunchDelegate2 { public LocalRunLaunchDelegate() { + // We support project-less run super(false); } @@ -66,7 +67,7 @@ public class LocalRunLaunchDelegate extends AbstractCLaunchDelegate2 } monitor.worked(1); try { - IPath exePath = CDebugUtils.verifyProgramPath(config); + IPath exePath = checkBinaryDetails(config); File wd = verifyWorkingDirectory(config); if (wd == null) { @@ -97,6 +98,18 @@ public class LocalRunLaunchDelegate extends AbstractCLaunchDelegate2 } } + /** + * Method used to check that the project and program are correct. + * Can be overridden to avoid checking certain things. + */ + protected IPath checkBinaryDetails(final ILaunchConfiguration config) throws CoreException { + // First verify we are dealing with a proper project. + ICProject project = verifyCProject(config); + // Now verify we know the program to run. + IPath exePath = verifyProgramPath(config, project); + return exePath; + } + /** * Performs a runtime exec on the given command line in the context of the * specified working directory, and returns the resulting process.