diff --git a/launch/org.eclipse.cdt.launch/ChangeLog b/launch/org.eclipse.cdt.launch/ChangeLog index f0e26e97b66..6ade94654a1 100644 --- a/launch/org.eclipse.cdt.launch/ChangeLog +++ b/launch/org.eclipse.cdt.launch/ChangeLog @@ -1,3 +1,23 @@ +2003-10-27 Mikhail Khodjaiants + Changed the initialization of 'SourceLookupBlock'. + * CSourceLookupTab.java + +2003-10-27 Mikhail Khodjaiants + Moved the 'org.eclipse.debug.core.sourceLocators' extension from the launcher. + * plugin.xml + * plugin.properties + +2003-10-27 Mikhail Khodjaiants + Removed the dependency to 'org.apache.xerces'. + * plugin.xml + * .classpath + * .project + +2003-10-27 Mikhail Khodjaiants + Moved 'DefaultSourceLocator' from the 'org.eclipse.cdt.launch' plugin and merge it with 'CUISourceLocator'. + Removed the 'org.eclipse.cdt.launch.internal.ui.sourcelookup' package. + * DefaultSourceLocator.java: moved to the 'org.eclipse.cdt.debug.ui' plugin. + 2003-11-22 Mikhail Khodjaiants src/org/eclipse/cdt/launch/ui/CSourceLookupTab.java: Dispose 'SourceLookupBlock' when disposing 'CSourceLookupTab'. diff --git a/launch/org.eclipse.cdt.launch/plugin.properties b/launch/org.eclipse.cdt.launch/plugin.properties index edc1deedb5e..de0ff3f8491 100644 --- a/launch/org.eclipse.cdt.launch/plugin.properties +++ b/launch/org.eclipse.cdt.launch/plugin.properties @@ -13,5 +13,3 @@ providerName=Eclipse.org LocalCDTLaunch.name= C/C++ Local CoreFileCDTLaunch.name= C/C++ Postmortem debugger - -DefaultSourceLocator.name=Default C/C++ Source Locator diff --git a/launch/org.eclipse.cdt.launch/plugin.xml b/launch/org.eclipse.cdt.launch/plugin.xml index c668ee70dfa..9d61e8bbe75 100644 --- a/launch/org.eclipse.cdt.launch/plugin.xml +++ b/launch/org.eclipse.cdt.launch/plugin.xml @@ -20,7 +20,6 @@ - @@ -83,13 +82,5 @@ - - - - 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 0a157010c6e..79186371531 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,11 +17,11 @@ import java.util.Map.Entry; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.model.ICProject; -import org.eclipse.cdt.debug.core.*; import org.eclipse.cdt.debug.core.CDebugCorePlugin; +import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; import org.eclipse.cdt.debug.core.ICDebugConfiguration; +import org.eclipse.cdt.debug.ui.CDebugUIPlugin; import org.eclipse.cdt.launch.internal.ui.LaunchUIPlugin; -import org.eclipse.cdt.launch.sourcelookup.DefaultSourceLocator; import org.eclipse.cdt.utils.spawner.EnvironmentReader; import org.eclipse.core.resources.IContainer; import org.eclipse.core.resources.IFile; @@ -297,7 +297,7 @@ abstract public class AbstractCLaunchDelegate implements ILaunchConfigurationDel if (cProject == null) { abort("Project does not exist", null, ICDTLaunchConfigurationConstants.ERR_NOT_A_C_PROJECT); } - sourceLocator = new DefaultSourceLocator(); + sourceLocator = CDebugUIPlugin.createDefaultSourceLocator(); sourceLocator.initializeDefaults(configuration); } else { sourceLocator = DebugPlugin.getDefault().getLaunchManager().newSourceLocator(id); diff --git a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/sourcelookup/DefaultSourceLocator.java b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/sourcelookup/DefaultSourceLocator.java deleted file mode 100644 index 0a2e38dc9cd..00000000000 --- a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/sourcelookup/DefaultSourceLocator.java +++ /dev/null @@ -1,257 +0,0 @@ -/* - *(c) Copyright QNX Software Systems Ltd. 2002. - * All Rights Reserved. - * - */ -package org.eclipse.cdt.launch.sourcelookup; - -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.debug.core.CDebugUtils; -import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; -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.internal.ui.LaunchUIPlugin; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResourceChangeListener; -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; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; - -/** - * The wrapper for the CUISourceLocator class. - * - * @since: Dec 11, 2002 - */ -public class DefaultSourceLocator implements IPersistableSourceLocator, IAdaptable -{ - private static final String ELEMENT_NAME = "PromptingSourceLocator"; - private static final String ATTR_PROJECT = "project"; - private static final String ATTR_MEMENTO = "memento"; - - /** - * Identifier for the 'Default C/C++ Source Locator' extension - * (value "org.eclipse.cdt.launch.DefaultSourceLocator"). - */ - 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() - { - } - - /** - * Constructor for DefaultSourceLocator. - */ - public DefaultSourceLocator( CUISourceLocator locator ) - { - fSourceLocator = locator; - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IPersistableSourceLocator#getMemento() - */ - public String getMemento() throws CoreException - { - if ( fSourceLocator != null ) - { - Document doc = new DocumentImpl(); - Element node = doc.createElement( ELEMENT_NAME ); - doc.appendChild( node ); - node.setAttribute( ATTR_PROJECT, fSourceLocator.getProject().getName() ); - - IPersistableSourceLocator psl = getPersistableSourceLocator(); - if ( psl != null ) - { - node.setAttribute( ATTR_MEMENTO, psl.getMemento() ); - } - try - { - return CDebugUtils.serializeDocument( doc, " " ); - } - catch( IOException e ) - { - abort( "Unable to create memento for C/C++ source locator.", e ); - } - } - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IPersistableSourceLocator#initializeFromMemento(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 prompting source locator - invalid format.", null ); - } - - String projectName = root.getAttribute( ATTR_PROJECT ); - String data = root.getAttribute( ATTR_MEMENTO ); - if ( isEmpty( projectName ) ) - { - abort( "Unable to restore prompting source locator - invalid format.", null ); - } - IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject( projectName ); - if ( project == null ) - { - abort( MessageFormat.format( "Unable to restore prompting source locator - project {0} not found.", new String[] { projectName } ), null ); - } - ICSourceLocator locator = getCSourceLocator(); - if ( locator == null ) - { - fSourceLocator = new CUISourceLocator( project ); - } - else if ( locator.getProject() != null && !project.equals( locator.getProject() ) ) - { - return; - } - IPersistableSourceLocator psl = getPersistableSourceLocator(); - if ( psl != null ) - { - psl.initializeFromMemento( data ); - } - else - { - abort( "Unable to restore C/C++ source locator - invalid format.", null ); - } - return; - } - catch( ParserConfigurationException e ) - { - ex = e; - } - catch( SAXException e ) - { - ex = e; - } - catch( IOException e ) - { - ex = e; - } - abort( "Exception occurred initializing source locator.", ex ); - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IPersistableSourceLocator#initializeDefaults(ILaunchConfiguration) - */ - public void initializeDefaults( ILaunchConfiguration configuration ) throws CoreException - { - fSourceLocator = new CUISourceLocator( getProject( configuration ) ); - String memento = configuration.getAttribute( ILaunchConfiguration.ATTR_SOURCE_LOCATOR_MEMENTO, "" ); - if ( !isEmpty( memento ) ) - initializeFromMemento( memento ); - } - - /* (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 ( !isEmpty( projectName ) ) - { - IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject( projectName ); - if ( project.exists() ) - { - return project; - } - } - abort( MessageFormat.format( "Project \"{0}\" does not exist.", new String[] { projectName } ), null ); - return 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( IResourceChangeListener.class ) ) - { - return fSourceLocator.getAdapter( adapter ); - } - if ( adapter.equals( ISourceMode.class ) ) - { - return fSourceLocator.getAdapter( adapter ); - } - } - return null; - } - - private ICSourceLocator getCSourceLocator() - { - if ( fSourceLocator != null ) - { - return (ICSourceLocator)fSourceLocator.getAdapter( ICSourceLocator.class ); - } - return null; - } - - private IPersistableSourceLocator getPersistableSourceLocator() - { - ICSourceLocator sl = getCSourceLocator(); - return ( sl instanceof IPersistableSourceLocator ) ? (IPersistableSourceLocator)sl : null; - } - - /** - * Throws an internal error exception - */ - private void abort( String message, Throwable e ) throws CoreException - { - IStatus s = new Status( IStatus.ERROR, - LaunchUIPlugin.getUniqueIdentifier(), - ERROR, - message, - e ); - throw new CoreException( s ); - } - - - private boolean isEmpty( String string ) - { - return string == null || string.length() == 0; - } -} diff --git a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/ui/CSourceLookupTab.java b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/ui/CSourceLookupTab.java index 30f0cdd2d33..ec7cc355dd2 100644 --- a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/ui/CSourceLookupTab.java +++ b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/ui/CSourceLookupTab.java @@ -6,10 +6,9 @@ package org.eclipse.cdt.launch.ui; import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; -import org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocator; +import org.eclipse.cdt.debug.ui.CDebugUIPlugin; import org.eclipse.cdt.debug.ui.sourcelookup.SourceLookupBlock; import org.eclipse.cdt.launch.internal.ui.LaunchImages; -import org.eclipse.cdt.launch.sourcelookup.DefaultSourceLocator; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; @@ -51,7 +50,7 @@ public class CSourceLookupTab extends CLaunchConfigurationTab */ public void setDefaults( ILaunchConfigurationWorkingCopy configuration ) { - configuration.setAttribute( ILaunchConfiguration.ATTR_SOURCE_LOCATOR_ID, DefaultSourceLocator.ID_DEFAULT_SOURCE_LOCATOR ); + configuration.setAttribute( ILaunchConfiguration.ATTR_SOURCE_LOCATOR_ID, CDebugUIPlugin.getDefaultSourceLocatorID() ); } /* (non-Javadoc) @@ -59,35 +58,7 @@ public class CSourceLookupTab extends CLaunchConfigurationTab */ public void initializeFrom( ILaunchConfiguration configuration ) { - IProject project = getProject( configuration ); - IProject oldProject = fBlock.getProject(); - fBlock.setProject( getProject( configuration ) ); - if ( project != null ) - { - try - { - String id = configuration.getAttribute( ILaunchConfiguration.ATTR_SOURCE_LOCATOR_ID, "" ); - if ( isEmpty( id ) || DefaultSourceLocator.ID_DEFAULT_SOURCE_LOCATOR.equals( id ) ) - { - DefaultSourceLocator locator = new DefaultSourceLocator(); - String memento = configuration.getAttribute( ILaunchConfiguration.ATTR_SOURCE_LOCATOR_MEMENTO, "" ); - if ( project.equals( oldProject ) && !isEmpty( memento ) ) - { - locator.initializeFromMemento( memento ); - } - else - { - locator.initializeDefaults( configuration ); - } - ICSourceLocator clocator = (ICSourceLocator)locator.getAdapter( ICSourceLocator.class ); - if ( clocator != null ) - fBlock.initialize( clocator ); - } - } - catch( CoreException e ) - { - } - } + fBlock.initialize( configuration ); } /* (non-Javadoc) @@ -95,28 +66,10 @@ public class CSourceLookupTab extends CLaunchConfigurationTab */ public void performApply( ILaunchConfigurationWorkingCopy configuration ) { - configuration.setAttribute( ILaunchConfiguration.ATTR_SOURCE_LOCATOR_ID, DefaultSourceLocator.ID_DEFAULT_SOURCE_LOCATOR ); + configuration.setAttribute( ILaunchConfiguration.ATTR_SOURCE_LOCATOR_ID, CDebugUIPlugin.getDefaultSourceLocatorID() ); IProject project = getProject( configuration ); if ( project != null ) - { - DefaultSourceLocator locator = new DefaultSourceLocator(); - try - { - locator.initializeDefaults( configuration ); - ICSourceLocator clocator = (ICSourceLocator)locator.getAdapter( ICSourceLocator.class ); - if ( clocator != null ) - { - if ( !project.equals( fBlock.getProject() ) ) - fBlock.initialize( clocator ); - clocator.setSourceLocations( fBlock.getSourceLocations() ); - clocator.setSearchForDuplicateFiles( fBlock.searchForDuplicateFiles() ); - } - configuration.setAttribute( ILaunchConfiguration.ATTR_SOURCE_LOCATOR_MEMENTO, locator.getMemento() ); - } - catch( CoreException e ) - { - } - } + fBlock.performApply( configuration ); } /* (non-Javadoc)