From d7b288068e97c784c84029bcfda0ce27bf7d6677 Mon Sep 17 00:00:00 2001 From: Mikhail Khodjaiants Date: Tue, 18 Feb 2003 19:24:08 +0000 Subject: [PATCH] Added persistency to the source locator. --- debug/org.eclipse.cdt.debug.core/.classpath | 5 +- debug/org.eclipse.cdt.debug.core/.project | 2 + debug/org.eclipse.cdt.debug.core/ChangeLog | 10 + debug/org.eclipse.cdt.debug.core/plugin.xml | 1 + .../core/sourcelookup/ICSourceLocation.java | 18 ++ .../cdt/debug/internal/core/CDebugUtils.java | 45 ++++ .../CDirectorySourceLocation.java | 138 ++++++++++++ .../sourcelookup/CProjectSourceLocation.java | 108 ++++++++++ .../core/sourcelookup/CSourceLocator.java | 197 +++++++++++++++++- .../core/sourcelookup/CSourceManager.java | 43 +++- 10 files changed, 564 insertions(+), 3 deletions(-) diff --git a/debug/org.eclipse.cdt.debug.core/.classpath b/debug/org.eclipse.cdt.debug.core/.classpath index dfcc15b5539..0afb6011f5c 100644 --- a/debug/org.eclipse.cdt.debug.core/.classpath +++ b/debug/org.eclipse.cdt.debug.core/.classpath @@ -1,9 +1,12 @@ - + + + + diff --git a/debug/org.eclipse.cdt.debug.core/.project b/debug/org.eclipse.cdt.debug.core/.project index f22a8a7909a..1b6c0fc1547 100644 --- a/debug/org.eclipse.cdt.debug.core/.project +++ b/debug/org.eclipse.cdt.debug.core/.project @@ -3,7 +3,9 @@ org.eclipse.cdt.debug.core + org.apache.xerces org.eclipse.cdt.core + org.eclipse.cdt.core.win32 org.eclipse.core.boot org.eclipse.core.resources org.eclipse.core.runtime diff --git a/debug/org.eclipse.cdt.debug.core/ChangeLog b/debug/org.eclipse.cdt.debug.core/ChangeLog index 1c34f8cc5a6..b5525b50959 100644 --- a/debug/org.eclipse.cdt.debug.core/ChangeLog +++ b/debug/org.eclipse.cdt.debug.core/ChangeLog @@ -1,3 +1,13 @@ +2003-02-18 Mikhail Khodjaiants + Added persistency to the source locator. + * plugin.xml: added dependency on the 'org.apache.xerces' plugin + * ICSourceLocation.java + * CDebugUtils.java + * CDirectorySourceLocation.java + * CProjectSourceLocation.java + * CSourceLocator.java + * CSourceManager.java + 2003-02-13 Mikhail Khodjaiants Undo changes because the 'asyncExec' method of the 'DebugPlugin' class has added since version 2.1. * IAsyncExecutor.java: removed diff --git a/debug/org.eclipse.cdt.debug.core/plugin.xml b/debug/org.eclipse.cdt.debug.core/plugin.xml index ac13203cab9..fbdb62c984c 100644 --- a/debug/org.eclipse.cdt.debug.core/plugin.xml +++ b/debug/org.eclipse.cdt.debug.core/plugin.xml @@ -15,6 +15,7 @@ + diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/sourcelookup/ICSourceLocation.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/sourcelookup/ICSourceLocation.java index d407324c9fc..e88d8161a99 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/sourcelookup/ICSourceLocation.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/sourcelookup/ICSourceLocation.java @@ -43,4 +43,22 @@ public interface ICSourceLocation extends IAdaptable * @return the paths associated with this location */ IPath[] getPaths(); + + /** + * Returns a memento for this source location from which this + * source location can be reconstructed. + * + * @return a memento for this source location + * @exception CoreException if unable to create a memento + */ + public String getMemento() throws CoreException; + + /** + * Initializes this source location from the given memento. + * + * @param memento a memento generated by this source location + * @exception CoreException if unable to initialize this source + * location + */ + public void initializeFrom( String memento ) throws CoreException; } diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CDebugUtils.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CDebugUtils.java index b2c69ed7496..a6d45d0d5d9 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CDebugUtils.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CDebugUtils.java @@ -5,13 +5,21 @@ */ package org.eclipse.cdt.debug.internal.core; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.OutputStreamWriter; import java.util.Arrays; +import org.apache.xml.serialize.Method; +import org.apache.xml.serialize.OutputFormat; +import org.apache.xml.serialize.Serializer; +import org.apache.xml.serialize.SerializerFactory; import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IStatus; import org.eclipse.debug.core.DebugPlugin; import org.eclipse.debug.core.IStatusHandler; +import org.w3c.dom.Document; /** * @@ -244,4 +252,41 @@ public class CDebugUtils } return false; } + + /** + * Serializes a XML document into a string - encoded in UTF8 format, + * with given line separators. + * + * @param doc document to serialize + * @param lineSeparator line separator + * @return the document as a string + */ + public static String serializeDocument( Document doc, String lineSeparator ) throws IOException + { + ByteArrayOutputStream s = new ByteArrayOutputStream(); + OutputFormat format = new OutputFormat(); + format.setIndenting( true ); + format.setLineSeparator( lineSeparator ); //$NON-NLS-1$ + Serializer serializer = SerializerFactory.getSerializerFactory( Method.XML ).makeSerializer( new OutputStreamWriter( s, "UTF8" ), format ); + serializer.asDOMSerializer().serialize( doc ); + return s.toString( "UTF8" ); //$NON-NLS-1$ + } + + /** + * Serializes a XML document into a string - encoded in UTF8 format, + * with platform line separators. + * + * @param doc document to serialize + * @return the document as a string + */ + public static String serializeDocument( Document doc) throws IOException + { + ByteArrayOutputStream s = new ByteArrayOutputStream(); + OutputFormat format = new OutputFormat(); + format.setIndenting( true ); + format.setLineSeparator( System.getProperty( "line.separator" ) ); //$NON-NLS-1$ + Serializer serializer = SerializerFactory.getSerializerFactory( Method.XML ).makeSerializer( new OutputStreamWriter( s, "UTF8" ), format ); + serializer.asDOMSerializer().serialize( doc ); + return s.toString( "UTF8" ); //$NON-NLS-1$ + } } diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CDirectorySourceLocation.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CDirectorySourceLocation.java index 8dc59455ac2..93d0b289964 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CDirectorySourceLocation.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CDirectorySourceLocation.java @@ -6,16 +6,32 @@ package org.eclipse.cdt.debug.internal.core.sourcelookup; import java.io.File; +import java.io.IOException; +import java.io.StringReader; +import java.text.MessageFormat; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; + +import org.apache.xerces.dom.DocumentImpl; import org.eclipse.cdt.core.resources.FileStorage; +import org.eclipse.cdt.debug.core.CDebugCorePlugin; import org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocation; import org.eclipse.cdt.debug.core.sourcelookup.IDirectorySourceLocation; +import org.eclipse.cdt.debug.internal.core.CDebugUtils; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IStorage; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Status; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; /** * @@ -26,6 +42,10 @@ import org.eclipse.core.runtime.Path; */ public class CDirectorySourceLocation implements IDirectorySourceLocation { + private static final String ELEMENT_NAME = "cDirectorySourceLocation"; + private static final String ATTR_DIRECTORY = "directory"; + private static final String ATTR_ASSOCIATION = "association"; + /** * The root directory of this source location */ @@ -36,6 +56,13 @@ public class CDirectorySourceLocation implements IDirectorySourceLocation */ private IPath fAssociation = null; + /** + * Constructor for CDirectorySourceLocation. + */ + public CDirectorySourceLocation() + { + } + /** * Constructor for CDirectorySourceLocation. */ @@ -103,6 +130,11 @@ public class CDirectorySourceLocation implements IDirectorySourceLocation return fDirectory; } + public void getDirectory( IPath path ) + { + fDirectory = path; + } + private void setAssociation( IPath association ) { fAssociation = association; @@ -177,4 +209,110 @@ public class CDirectorySourceLocation implements IDirectorySourceLocation { return new IPath[] { fDirectory }; } + + /* (non-Javadoc) + * @see org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocation#getMemento() + */ + public String getMemento() throws CoreException + { + Document doc = new DocumentImpl(); + Element node = doc.createElement( ELEMENT_NAME ); + doc.appendChild( node ); + node.setAttribute( ATTR_DIRECTORY, getDirectory().toOSString() ); + if ( getAssociation() != null ) + node.setAttribute( ATTR_ASSOCIATION, getAssociation().toOSString() ); + try + { + return CDebugUtils.serializeDocument( doc, " " ); + } + catch( IOException e ) + { + abort( MessageFormat.format( "Unable to create memento for C/C++ directory source location {0}", new String[] { getDirectory().toOSString() } ), e ); + } + // execution will not reach here + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocation#initializeFrom(java.lang.String) + */ + public void initializeFrom( String memento ) throws CoreException + { + Exception ex = null; + try + { + Element root = null; + DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder(); + StringReader reader = new StringReader( memento ); + InputSource source = new InputSource( reader ); + root = parser.parse( source ).getDocumentElement(); + + String dir = root.getAttribute( ATTR_DIRECTORY ); + if ( isEmpty( dir ) ) + { + abort( "Unable to initialize source location - missing directory path", null ); + } + else + { + IPath path = new Path( dir ); + if ( path.isValidPath( dir ) && path.toFile().isDirectory() ) + { + setDirectory( path ); + } + else + { + abort( MessageFormat.format( "Unable to initialize source location - invalid directory path {0}", new String[] { dir } ), null ); + } + } + dir = root.getAttribute( ATTR_ASSOCIATION ); + if ( isEmpty( dir ) ) + { + setAssociation( null ); + } + else + { + IPath path = new Path( dir ); + if ( path.isValidPath( dir ) ) + { + setAssociation( path ); + } + else + { + setAssociation( null ); + } + } + return; + } + catch( ParserConfigurationException e ) + { + ex = e; + } + catch( SAXException e ) + { + ex = e; + } + catch( IOException e ) + { + ex = e; + } + abort( "Exception occurred initializing source location.", ex ); + } + + /** + * Throws an internal error exception + */ + private void abort( String message, Throwable e ) throws CoreException + { + IStatus s = new Status( IStatus.ERROR, + CDebugCorePlugin.getUniqueIdentifier(), + CDebugCorePlugin.INTERNAL_ERROR, + message, + e ); + throw new CoreException( s ); + } + + private boolean isEmpty( String string ) + { + return string == null || string.length() == 0; + } } diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CProjectSourceLocation.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CProjectSourceLocation.java index c450fe8ea2f..1103cd5fbaa 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CProjectSourceLocation.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CProjectSourceLocation.java @@ -6,19 +6,36 @@ package org.eclipse.cdt.debug.internal.core.sourcelookup; import java.io.File; +import java.io.IOException; +import java.io.StringReader; +import java.text.MessageFormat; import java.util.HashMap; import java.util.HashSet; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; + +import org.apache.xerces.dom.DocumentImpl; +import org.eclipse.cdt.debug.core.CDebugCorePlugin; import org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocation; import org.eclipse.cdt.debug.core.sourcelookup.IProjectSourceLocation; +import org.eclipse.cdt.debug.internal.core.CDebugUtils; import org.eclipse.core.resources.IContainer; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Status; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; /** * @@ -28,6 +45,9 @@ import org.eclipse.core.runtime.Path; */ public class CProjectSourceLocation implements IProjectSourceLocation { + private static final String ELEMENT_NAME = "cProjectSourceLocation"; + private static final String ATTR_PROJECT = "project"; + /** * The project associated with this source location */ @@ -37,6 +57,13 @@ public class CProjectSourceLocation implements IProjectSourceLocation private HashSet fNotFoundCache = new HashSet( 20 ); + /** + * Constructor for CProjectSourceLocation. + */ + public CProjectSourceLocation() + { + } + /** * Constructor for CProjectSourceLocation. */ @@ -220,4 +247,85 @@ public class CProjectSourceLocation implements IProjectSourceLocation fCache.clear(); fNotFoundCache.clear(); } + + /* (non-Javadoc) + * @see org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocation#getMemento() + */ + public String getMemento() throws CoreException + { + Document doc = new DocumentImpl(); + Element node = doc.createElement( ELEMENT_NAME ); + doc.appendChild( node ); + node.setAttribute( ATTR_PROJECT, getProject().getName() ); + + try + { + return CDebugUtils.serializeDocument( doc, " " ); + } + catch( IOException e ) + { + abort( MessageFormat.format( "Unable to create memento for C/C++ project source location {0}.", new String[] { getProject().getName() } ), e ); + } + // execution will not reach here + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocation#initializeFrom(java.lang.String) + */ + public void initializeFrom( String memento ) throws CoreException + { + Exception ex = null; + try + { + Element root = null; + DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder(); + StringReader reader = new StringReader( memento ); + InputSource source = new InputSource( reader ); + root = parser.parse( source ).getDocumentElement(); + + String name = root.getAttribute( ATTR_PROJECT ); + if ( isEmpty( name ) ) + { + abort( "Unable to initialize source location - missing project name", null ); + } + else + { + IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject( name ); + setProject( project ); + } + return; + } + catch( ParserConfigurationException e ) + { + ex = e; + } + catch( SAXException e ) + { + ex = e; + } + catch( IOException e ) + { + ex = e; + } + abort( "Exception occurred initializing source location.", ex ); + } + + /** + * Throws an internal error exception + */ + private void abort( String message, Throwable e ) throws CoreException + { + IStatus s = new Status( IStatus.ERROR, + CDebugCorePlugin.getUniqueIdentifier(), + CDebugCorePlugin.INTERNAL_ERROR, + message, + e ); + throw new CoreException( s ); + } + + private boolean isEmpty( String string ) + { + return string == null || string.length() == 0; + } } diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourceLocator.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourceLocator.java index 803cd4925b0..7f81f6bb8da 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourceLocator.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourceLocator.java @@ -6,20 +6,41 @@ package org.eclipse.cdt.debug.internal.core.sourcelookup; +import java.io.IOException; +import java.io.StringReader; +import java.text.MessageFormat; import java.util.ArrayList; import java.util.List; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; + +import org.apache.xerces.dom.DocumentImpl; import org.eclipse.cdt.core.resources.FileStorage; +import org.eclipse.cdt.debug.core.CDebugCorePlugin; +import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; import org.eclipse.cdt.debug.core.model.IStackFrameInfo; import org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocation; import org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocator; +import org.eclipse.cdt.debug.internal.core.CDebugUtils; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Path; +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; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; /** * @@ -27,8 +48,14 @@ import org.eclipse.debug.core.model.IStackFrame; * * @since Aug 19, 2002 */ -public class CSourceLocator implements ICSourceLocator + +public class CSourceLocator implements ICSourceLocator, IPersistableSourceLocator { + private static final String ELEMENT_NAME = "cSourceLocator"; + private static final String CHILD_NAME = "cSourceLocation"; + private static final String ATTR_CLASS = "class"; + private static final String ATTR_MEMENTO = "memento"; + /** * The array of source locations associated with this locator. */ @@ -246,4 +273,172 @@ public class CSourceLocator implements ICSourceLocator } return result; } + + /* (non-Javadoc) + * @see org.eclipse.debug.core.model.IPersistableSourceLocator#getMemento() + */ + public String getMemento() throws CoreException + { + Document doc = new DocumentImpl(); + Element node = doc.createElement( ELEMENT_NAME ); + doc.appendChild( node ); + + ICSourceLocation[] locations = getSourceLocations(); + for ( int i = 0; i < locations.length; i++ ) + { + Element child = doc.createElement( CHILD_NAME ); + child.setAttribute( ATTR_CLASS, locations[i].getClass().getName() ); + child.setAttribute( ATTR_MEMENTO, locations[i].getMemento() ); + node.appendChild( child ); + } + try + { + return CDebugUtils.serializeDocument( doc, " " ); + } + catch( IOException e ) + { + abort( "Unable to create memento for C/C++ source locator.", e ); + } + // execution will not reach here + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.debug.core.model.IPersistableSourceLocator#initializeDefaults(org.eclipse.debug.core.ILaunchConfiguration) + */ + public void initializeDefaults( ILaunchConfiguration configuration ) throws CoreException + { + IProject project = getProject( configuration ); + if ( project != null ) + { + setSourceLocations( getDefaultSourceLocations( project ) ); + } + else + { + setSourceLocations( new ICSourceLocation[0] ); + } + } + + /* (non-Javadoc) + * @see org.eclipse.debug.core.model.IPersistableSourceLocator#initializeFromMemento(java.lang.String) + */ + public void initializeFromMemento( String memento ) throws CoreException + { + Exception ex = null; + try + { + Element root = null; + DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder(); + StringReader reader = new StringReader( memento ); + InputSource source = new InputSource( reader ); + root = parser.parse( source ).getDocumentElement(); + + if ( !root.getNodeName().equalsIgnoreCase( ELEMENT_NAME ) ) + { + abort( "Unable to restore C/C++ source locator - invalid format.", null ); + } + + List sourceLocations = new ArrayList(); + ClassLoader classLoader = CDebugCorePlugin.getDefault() .getDescriptor().getPluginClassLoader(); + + NodeList list = root.getChildNodes(); + int length = list.getLength(); + for ( int i = 0; i < length; ++i ) + { + Node node = list.item( i ); + short type = node.getNodeType(); + if ( type == Node.ELEMENT_NODE ) + { + Element entry = (Element)node; + if ( entry.getNodeName().equalsIgnoreCase( CHILD_NAME ) ) + { + String className = entry.getAttribute( ATTR_CLASS ); + String data = entry.getAttribute( ATTR_MEMENTO ); + if ( isEmpty( className ) ) + { + abort( "Unable to restore C/C++ source locator - invalid format.", null ); + } + Class clazz = null; + try + { + clazz = classLoader.loadClass( className ); + } + catch( ClassNotFoundException e ) + { + abort( MessageFormat.format( "Unable to restore source location - class not found {0}", new String[] { className } ), e ); + } + + ICSourceLocation location = null; + try + { + location = (ICSourceLocation)clazz.newInstance(); + } + catch( IllegalAccessException e ) + { + abort( "Unable to restore source location.", e ); + } + catch( InstantiationException e ) + { + abort( "Unable to restore source location.", e ); + } + location.initializeFrom( data ); + sourceLocations.add( location ); + } + else + { + abort( "Unable to restore C/C++ source locator - invalid format.", null ); + } + } + } + setSourceLocations( (ICSourceLocation[])sourceLocations.toArray( new ICSourceLocation[sourceLocations.size()] ) ); + return; + } + catch( ParserConfigurationException e ) + { + ex = e; + } + catch( SAXException e ) + { + ex = e; + } + catch( IOException e ) + { + ex = e; + } + abort( "Exception occurred initializing source locator.", ex ); + } + + /** + * Throws an internal error exception + */ + private void abort( String message, Throwable e ) throws CoreException + { + IStatus s = new Status( IStatus.ERROR, + CDebugCorePlugin.getUniqueIdentifier(), + CDebugCorePlugin.INTERNAL_ERROR, + message, + e ); + throw new CoreException( s ); + } + + + private boolean isEmpty( String string ) + { + return string == null || string.length() == 0; + } + + private IProject getProject( ILaunchConfiguration configuration ) + { + IProject project = null; + try + { + String projectName = configuration.getAttribute( ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, "" ); + if ( !isEmpty( projectName ) ) + project = ResourcesPlugin.getWorkspace().getRoot().getProject( projectName ); + } + catch( CoreException e ) + { + } + return project; + } } diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourceManager.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourceManager.java index 6c6236dd0e0..6215da470f8 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourceManager.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourceManager.java @@ -16,8 +16,11 @@ import org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocation; import org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocator; import org.eclipse.cdt.debug.core.sourcelookup.ISourceMode; import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IAdaptable; import org.eclipse.debug.core.ILaunch; +import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.debug.core.model.IPersistableSourceLocator; import org.eclipse.debug.core.model.ISourceLocator; import org.eclipse.debug.core.model.IStackFrame; @@ -26,7 +29,10 @@ import org.eclipse.debug.core.model.IStackFrame; * * @since: Oct 8, 2002 */ -public class CSourceManager implements ICSourceLocator, ISourceMode, IAdaptable +public class CSourceManager implements ICSourceLocator, + IPersistableSourceLocator, + ISourceMode, + IAdaptable { private ISourceLocator fSourceLocator = null; private int fMode = ISourceMode.MODE_SOURCE; @@ -202,4 +208,39 @@ public class CSourceManager implements ICSourceLocator, ISourceMode, IAdaptable } return null; } + + /* (non-Javadoc) + * @see org.eclipse.debug.core.model.IPersistableSourceLocator#getMemento() + */ + public String getMemento() throws CoreException + { + if ( getPersistableSourceLocator() != null ) + return getPersistableSourceLocator().getMemento(); + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.debug.core.model.IPersistableSourceLocator#initializeDefaults(org.eclipse.debug.core.ILaunchConfiguration) + */ + public void initializeDefaults( ILaunchConfiguration configuration ) throws CoreException + { + if ( getPersistableSourceLocator() != null ) + getPersistableSourceLocator().initializeDefaults( configuration ); + } + + /* (non-Javadoc) + * @see org.eclipse.debug.core.model.IPersistableSourceLocator#initializeFromMemento(java.lang.String) + */ + public void initializeFromMemento( String memento ) throws CoreException + { + if ( getPersistableSourceLocator() != null ) + getPersistableSourceLocator().initializeFromMemento( memento ); + } + + private IPersistableSourceLocator getPersistableSourceLocator() + { + if ( fSourceLocator instanceof IPersistableSourceLocator ) + return (IPersistableSourceLocator)fSourceLocator; + return null; + } }