1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 14:42:11 +02:00

set default source locator method added and called in delegate

This commit is contained in:
David Inglis 2002-12-17 20:38:50 +00:00
parent 5311b76a0f
commit 952ffbce46
8 changed files with 185 additions and 24 deletions

View file

@ -1,3 +1,9 @@
2002-12-17 David Inglis
* src/.../launch/AbstractCLaunchDelegate.java(setDefaultSourceLocator): new method
* src/.../sourcelookup/DefaultSourceLocator.java:new class
add method for delegate to call to set a default source locator.
2002-12-03 Alain Magloire
* src/.../internal/LocalCLaunchConfigurationDelegate.java(exec):

View file

@ -19,6 +19,7 @@ import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.debug.core.CDebugCorePlugin;
import org.eclipse.cdt.debug.core.ICDebugConfiguration;
import org.eclipse.cdt.launch.internal.ui.LaunchUIPlugin;
import org.eclipse.cdt.launch.sourcelookup.DefaultSourceLocator;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
@ -35,6 +36,7 @@ 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.IPersistableSourceLocator;
abstract public class AbstractCLaunchDelegate implements ILaunchConfigurationDelegate {
@ -45,7 +47,8 @@ abstract public class AbstractCLaunchDelegate implements ILaunchConfigurationDel
Map env = null;
try {
env = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_ENVIROMENT_MAP, (Map) null);
} catch (CoreException e) {
}
catch (CoreException e) {
}
if (env == null) {
return new String[0];
@ -125,7 +128,7 @@ abstract public class AbstractCLaunchDelegate implements ILaunchConfigurationDel
*/
protected void abort(String message, Throwable exception, int code) throws CoreException {
String newMessage = message;
if ( exception != null ) {
if (exception != null) {
newMessage = message + " : " + exception.getLocalizedMessage();
}
throw new CoreException(new Status(IStatus.ERROR, getPluginID(), code, newMessage, exception));
@ -137,7 +140,6 @@ abstract public class AbstractCLaunchDelegate implements ILaunchConfigurationDel
abstract protected String getPluginID();
public static ICProject getCProject(ILaunchConfiguration configuration) throws CoreException {
String projectName = getProjectName(configuration);
if (projectName != null) {
@ -161,6 +163,29 @@ abstract public class AbstractCLaunchDelegate implements ILaunchConfigurationDel
return configuration.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, (String) null);
}
/**
* Assigns a default source locator to the given launch if a source locator has not yet been assigned to it, and the associated
* launch configuration does not specify a source locator.
*
* @param launch launch object
* @param configuration configuration being launched
* @exception CoreException if unable to set the source locator
*/
protected void setDefaultSourceLocator(ILaunch launch, ILaunchConfiguration configuration) throws CoreException {
// set default source locator if none specified
if (launch.getSourceLocator() == null) {
String id = configuration.getAttribute(ILaunchConfiguration.ATTR_SOURCE_LOCATOR_ID, (String) null);
if (id == null) {
ICProject cProject = getCProject(configuration);
if (cProject != null) {
IPersistableSourceLocator sourceLocator = new DefaultSourceLocator();
sourceLocator.initializeDefaults(configuration);
launch.setSourceLocator(sourceLocator);
}
}
}
}
/**
* Returns the program arguments as a String.
*
@ -238,7 +263,8 @@ abstract public class AbstractCLaunchDelegate implements ILaunchConfigurationDel
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(name);
if (!project.exists()) {
abort("Project does not exist", null, ICDTLaunchConfigurationConstants.ERR_NOT_A_C_PROJECT);
} else if (!project.isOpen()) {
}
else if (!project.isOpen()) {
abort("Project is closed", null, ICDTLaunchConfigurationConstants.ERR_NOT_A_C_PROJECT);
}
abort("Project is not a C/C++ project", null, ICDTLaunchConfigurationConstants.ERR_NOT_A_C_PROJECT);
@ -249,10 +275,10 @@ abstract public class AbstractCLaunchDelegate implements ILaunchConfigurationDel
protected IPath verifyProgramFile(ILaunchConfiguration config) throws CoreException {
ICProject cproject = verifyCProject(config);
String fileName = getProgramName(config);
if ( fileName == null ) {
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);
@ -269,7 +295,7 @@ abstract public class AbstractCLaunchDelegate implements ILaunchConfigurationDel
* @return the working directory specified by the given
* launch configuration, or <code>null</code> if none
* @exception CoreException if unable to retrieve the attribute
*/
*/
public File verifyWorkingDirectory(ILaunchConfiguration configuration) throws CoreException {
IPath path = getWorkingDirectoryPath(configuration);
if (path == null) {
@ -279,24 +305,34 @@ abstract public class AbstractCLaunchDelegate implements ILaunchConfigurationDel
IProject p = cp.getProject();
return p.getLocation().toFile();
}
} else {
}
else {
if (path.isAbsolute()) {
File dir = new File(path.toOSString());
if (dir.isDirectory()) {
return dir;
} else {
abort("Working directory does not exist", null, ICDTLaunchConfigurationConstants.ERR_WORKING_DIRECTORY_DOES_NOT_EXIST);
}
} else {
else {
abort(
"Working directory does not exist",
null,
ICDTLaunchConfigurationConstants.ERR_WORKING_DIRECTORY_DOES_NOT_EXIST);
}
}
else {
IResource res = ResourcesPlugin.getWorkspace().getRoot().findMember(path);
if (res instanceof IContainer && res.exists()) {
return res.getLocation().toFile();
} else {
abort("Working directory does not exist", null, ICDTLaunchConfigurationConstants.ERR_WORKING_DIRECTORY_DOES_NOT_EXIST);
}
else {
abort(
"Working directory does not exist",
null,
ICDTLaunchConfigurationConstants.ERR_WORKING_DIRECTORY_DOES_NOT_EXIST);
}
}
}
return null;
return null;
}
private static class ArgumentParser {

View file

@ -218,7 +218,7 @@ public class CApplicationLaunchShortcut implements ILaunchShortcut {
dialog.setMultipleSelection(false);
int result = dialog.open();
provider.dispose();
if (result == dialog.OK) {
if (result == ElementListSelectionDialog.OK) {
return (ICDebugConfiguration) dialog.getFirstResult();
}
return null;
@ -242,7 +242,7 @@ public class CApplicationLaunchShortcut implements ILaunchShortcut {
dialog.setMultipleSelection(false);
int result = dialog.open();
labelProvider.dispose();
if (result == dialog.OK) {
if (result == ElementListSelectionDialog.OK) {
return (ILaunchConfiguration) dialog.getFirstResult();
}
return null;
@ -263,7 +263,7 @@ public class CApplicationLaunchShortcut implements ILaunchShortcut {
dialog.setMessage("Choose an application to run"); //$NON-NLS-1$
}
dialog.setMultipleSelection(false);
if (dialog.open() == dialog.OK) {
if (dialog.open() == ElementListSelectionDialog.OK) {
return (IBinary) dialog.getFirstResult();
}
return null;

View file

@ -63,7 +63,7 @@ public class CoreFileLaunchDelegate extends AbstractCLaunchDelegate {
abort("Failed Launching CDI Debugger", e, ICDTLaunchConfigurationConstants.ERR_INTERNAL_ERROR);
}
if ( debugger != null ) {
debuggerProcess = DebugPlugin.getDefault().newProcess(launch, debugger, "Debug Console");
debuggerProcess = DebugPlugin.newProcess(launch, debugger, "Debug Console");
launch.removeProcess(debuggerProcess);
}
CDebugModel.newCoreFileDebugTarget(

View file

@ -136,9 +136,13 @@ public class LocalCLaunchConfigurationDelegate extends AbstractCLaunchDelegate {
wd = new File(System.getProperty("user.home", ".")); //NON-NLS-1;
}
Process process = exec(commandArray, getEnvironmentProperty(config), wd);
DebugPlugin.getDefault().newProcess(launch, process, renderProcessLabel(commandArray[0]));
DebugPlugin.newProcess(launch, process, renderProcessLabel(commandArray[0]));
}
// set the default source locator if required
setDefaultSourceLocator(launch, config);
monitor.done();
}
private int getProcessID() throws CoreException {
@ -164,7 +168,7 @@ public class LocalCLaunchConfigurationDelegate extends AbstractCLaunchDelegate {
return;
}
dialog.setElements(plist.getProcessList());
if (dialog.open() == dialog.OK) {
if (dialog.open() == ElementListSelectionDialog.OK) {
IProcessInfo info = (IProcessInfo) dialog.getFirstResult();
pid[0] = info.getPid();
}

View file

@ -0,0 +1,115 @@
/*
*(c) Copyright QNX Software Systems Ltd. 2002.
* All Rights Reserved.
*
*/
package org.eclipse.cdt.launch.sourcelookup;
import java.text.MessageFormat;
import org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocator;
import org.eclipse.cdt.debug.core.sourcelookup.ISourceMode;
import org.eclipse.cdt.debug.ui.sourcelookup.CUISourceLocator;
import org.eclipse.cdt.launch.ICDTLaunchConfigurationConstants;
import org.eclipse.cdt.launch.internal.ui.LaunchUIPlugin;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.model.IPersistableSourceLocator;
import org.eclipse.debug.core.model.IStackFrame;
/**
* The wrapper for the CUISourceLocator class.
*
* @since: Dec 11, 2002
*/
public class DefaultSourceLocator implements IPersistableSourceLocator, IAdaptable
{
/**
* Identifier for the 'Default C/C++ Source Locator' extension
* (value <code>"org.eclipse.cdt.launch.DefaultSourceLocator"</code>).
*/
public static final String ID_DEFAULT_SOURCE_LOCATOR = LaunchUIPlugin.getUniqueIdentifier() + ".DefaultSourceLocator"; //$NON-NLS-1$
private CUISourceLocator fSourceLocator = null;
private final static int ERROR = 1000; // ????
/**
* Constructor for DefaultSourceLocator.
*/
public DefaultSourceLocator()
{
}
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.IPersistableSourceLocator#getMemento()
*/
public String getMemento() throws CoreException
{
return null;
}
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.IPersistableSourceLocator#initializeFromMemento(String)
*/
public void initializeFromMemento( String memento ) throws CoreException
{
}
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.IPersistableSourceLocator#initializeDefaults(ILaunchConfiguration)
*/
public void initializeDefaults( ILaunchConfiguration configuration ) throws CoreException
{
fSourceLocator = new CUISourceLocator( getProject( configuration ) );
}
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.ISourceLocator#getSourceElement(IStackFrame)
*/
public Object getSourceElement( IStackFrame stackFrame )
{
return ( fSourceLocator != null ) ? fSourceLocator.getSourceElement( stackFrame ) : null;
}
private IProject getProject( ILaunchConfiguration configuration ) throws CoreException
{
String projectName = configuration.getAttribute( ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, (String)null );
if ( projectName != null )
{
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject( projectName );
if ( project.exists() )
{
return project;
}
}
throw new CoreException( new Status( IStatus.ERROR,
LaunchUIPlugin.getUniqueIdentifier(),
ERROR,
MessageFormat.format( "Project \"{0}\" does not exist.", new String[] { projectName } ),
null ) );
}
/* (non-Javadoc)
* @see org.eclipse.core.runtime.IAdaptable#getAdapter(Class)
*/
public Object getAdapter( Class adapter )
{
if ( fSourceLocator != null )
{
if ( adapter.equals( ICSourceLocator.class ) )
{
return fSourceLocator.getAdapter( adapter );
}
if ( adapter.equals( ISourceMode.class ) )
{
return fSourceLocator.getAdapter( adapter );
}
}
return null;
}
}

View file

@ -322,7 +322,7 @@ public class CEnvironmentTab extends CLaunchConfigurationTab {
protected void newEntry() {
EntryDialog dialog = new EntryDialog(new String(), new String(), false);
if (dialog.open() == dialog.OK) {
if (dialog.open() == EntryDialog.OK) {
fElements.setProperty(dialog.getName(), dialog.getValue());
fVariableList.refresh();
}
@ -336,7 +336,7 @@ public class CEnvironmentTab extends CLaunchConfigurationTab {
protected void doEdit(Map.Entry entry) {
EntryDialog dialog = new EntryDialog(entry.getKey().toString(), entry.getValue().toString(), true);
if (dialog.open() == dialog.OK) {
if (dialog.open() == EntryDialog.OK) {
fElements.remove(entry.getKey());
fElements.setProperty(dialog.getName(), dialog.getValue());
fVariableList.refresh();

View file

@ -202,7 +202,7 @@ public class CMainTab extends CLaunchConfigurationTab {
dialog.setElements(executables);
dialog.setMessage("Choose a &program to run");
dialog.setTitle("Program Selection");
if (dialog.open() == dialog.OK) {
if (dialog.open() == ElementListSelectionDialog.OK) {
IBinary binary = (IBinary) dialog.getFirstResult();
try {
fProgText.setText(binary.getResource().getProjectRelativePath().toString());
@ -253,7 +253,7 @@ public class CMainTab extends CLaunchConfigurationTab {
if (cProject != null) {
dialog.setInitialSelections(new Object[] { cProject });
}
if (dialog.open() == dialog.OK) {
if (dialog.open() == ElementListSelectionDialog.OK) {
return (ICProject) dialog.getFirstResult();
}
return null;