mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Core support of the new workbench preferences: 'Source Locations' and 'Search For Duplicate Source Files'.
This commit is contained in:
parent
49d36fc10e
commit
e726ac9355
5 changed files with 215 additions and 2 deletions
|
@ -1,3 +1,10 @@
|
|||
2003-10-23 Mikhail Khodjaiants
|
||||
Core support of the new workbench preferences: 'Source Locations' and 'Search
|
||||
For Duplicate Source Files'.
|
||||
* CDebugCorePlugin.java
|
||||
* ICDebugConstants.java
|
||||
* SourceUtils.java: new
|
||||
|
||||
2003-10-20 Mikhail Khodjaiants
|
||||
Core support of the "Search subfolders" option for directory source locations.
|
||||
* IDirectorySourceLocation.java
|
||||
|
|
|
@ -8,9 +8,11 @@ package org.eclipse.cdt.debug.core;
|
|||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocation;
|
||||
import org.eclipse.cdt.debug.internal.core.DebugConfiguration;
|
||||
import org.eclipse.cdt.debug.internal.core.SessionManager;
|
||||
import org.eclipse.cdt.debug.internal.core.breakpoints.CBreakpoint;
|
||||
import org.eclipse.cdt.debug.internal.core.sourcelookup.SourceUtils;
|
||||
import org.eclipse.core.resources.IWorkspace;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
@ -229,4 +231,14 @@ public class CDebugCorePlugin extends Plugin
|
|||
fSessionManager.dispose();
|
||||
fSessionManager = sm;
|
||||
}
|
||||
|
||||
public void saveCommonSourceLocations( ICSourceLocation[] locations )
|
||||
{
|
||||
CDebugCorePlugin.getDefault().getPluginPreferences().setValue( ICDebugConstants.PREF_SOURCE_LOCATIONS, SourceUtils.getCommonSourceLocationsMemento( locations ) );
|
||||
}
|
||||
|
||||
public ICSourceLocation[] getCommonSourceLocations()
|
||||
{
|
||||
return SourceUtils.getCommonSourceLocationsFromMemento( CDebugCorePlugin.getDefault().getPluginPreferences().getString( ICDebugConstants.PREF_SOURCE_LOCATIONS ) );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,6 +58,17 @@ public interface ICDebugConstants
|
|||
*/
|
||||
public static final String PREF_MAX_NUMBER_OF_INSTRUCTIONS = PLUGIN_ID + "cDebug.max_number_of_instructions"; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* Boolean preference controlling whether the search for duplicate source files
|
||||
* will be performed by debugger.
|
||||
*/
|
||||
public static final String PREF_SEARCH_DUPLICATE_FILES = PLUGIN_ID + "cDebug.Source.search_duplicate_files"; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* The identifier of the common source locations list
|
||||
*/
|
||||
public static final String PREF_SOURCE_LOCATIONS = PLUGIN_ID + "cDebug.Source.source_locations"; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* The default number of instructions displayed in disassembly.
|
||||
*/
|
||||
|
|
|
@ -23,6 +23,7 @@ import javax.xml.parsers.ParserConfigurationException;
|
|||
import org.apache.xerces.dom.DocumentImpl;
|
||||
import org.eclipse.cdt.debug.core.CDebugCorePlugin;
|
||||
import org.eclipse.cdt.debug.core.CDebugUtils;
|
||||
import org.eclipse.cdt.debug.core.ICDebugConstants;
|
||||
import org.eclipse.cdt.debug.core.model.IStackFrameInfo;
|
||||
import org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocation;
|
||||
import org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocator;
|
||||
|
@ -316,7 +317,13 @@ public class CSourceLocator implements ICSourceLocator, IPersistableSourceLocato
|
|||
*/
|
||||
public void initializeDefaults( ILaunchConfiguration configuration ) throws CoreException
|
||||
{
|
||||
setSourceLocations( getDefaultSourceLocations() );
|
||||
ICSourceLocation[] defaultLocations = getDefaultSourceLocations();
|
||||
ICSourceLocation[] commonLocations = CDebugCorePlugin.getDefault().getCommonSourceLocations();
|
||||
List list = new ArrayList( defaultLocations.length + commonLocations.length );
|
||||
list.addAll( Arrays.asList( defaultLocations ) );
|
||||
list.addAll( Arrays.asList( commonLocations ) );
|
||||
setSourceLocations( (ICSourceLocation[])list.toArray( new ICSourceLocation[list.size()] ) );
|
||||
fDuplicateFiles = CDebugCorePlugin.getDefault().getPluginPreferences().getBoolean( ICDebugConstants.PREF_SEARCH_DUPLICATE_FILES );
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
@ -662,7 +669,7 @@ public class CSourceLocator implements ICSourceLocator, IPersistableSourceLocato
|
|||
IProject project = (IProject)it.next();
|
||||
if ( project != null && project.exists() && project.isOpen() )
|
||||
list.add( SourceLocationFactory.createProjectSourceLocation( project ) );
|
||||
}
|
||||
}
|
||||
return (ICSourceLocation[])list.toArray( new ICSourceLocation[list.size()] );
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,176 @@
|
|||
/*
|
||||
*(c) Copyright QNX Software Systems Ltd. 2002.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.eclipse.cdt.debug.internal.core.sourcelookup;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.LinkedList;
|
||||
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.debug.core.CDebugCorePlugin;
|
||||
import org.eclipse.cdt.debug.core.CDebugUtils;
|
||||
import org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocation;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Enter type comment.
|
||||
*
|
||||
* @since Oct 22, 2003
|
||||
*/
|
||||
public class SourceUtils
|
||||
{
|
||||
private static final String NAME_COMMON_SOURCE_LOCATIONS = "commonSourceLocations";
|
||||
private static final String NAME_SOURCE_LOCATION = "sourceLocation";
|
||||
private static final String ATTR_CLASS = "class";
|
||||
private static final String ATTR_MEMENTO = "memento";
|
||||
|
||||
public static String getCommonSourceLocationsMemento( ICSourceLocation[] locations )
|
||||
{
|
||||
Document doc = new DocumentImpl();
|
||||
Element node = doc.createElement( NAME_COMMON_SOURCE_LOCATIONS );
|
||||
doc.appendChild( node );
|
||||
|
||||
saveSourceLocations( doc, node, locations );
|
||||
try
|
||||
{
|
||||
return CDebugUtils.serializeDocument( doc, " " );
|
||||
}
|
||||
catch( IOException e )
|
||||
{
|
||||
CDebugCorePlugin.log( new Status( IStatus.ERROR, CDebugCorePlugin.getUniqueIdentifier(), 0, "Error saving common source settings.", e ) );
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static void saveSourceLocations( Document doc, Element node, ICSourceLocation[] locations )
|
||||
{
|
||||
for ( int i = 0; i < locations.length; i++ )
|
||||
{
|
||||
Element child = doc.createElement( NAME_SOURCE_LOCATION );
|
||||
child.setAttribute( ATTR_CLASS, locations[i].getClass().getName() );
|
||||
try
|
||||
{
|
||||
child.setAttribute( ATTR_MEMENTO, locations[i].getMemento() );
|
||||
}
|
||||
catch( CoreException e )
|
||||
{
|
||||
CDebugCorePlugin.log( e );
|
||||
continue;
|
||||
}
|
||||
node.appendChild( child );
|
||||
}
|
||||
}
|
||||
|
||||
public static ICSourceLocation[] getCommonSourceLocationsFromMemento( String memento )
|
||||
{
|
||||
ICSourceLocation[] result = new ICSourceLocation[0];
|
||||
if ( memento != null )
|
||||
{
|
||||
try
|
||||
{
|
||||
DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
||||
StringReader reader = new StringReader( memento );
|
||||
InputSource source = new InputSource( reader );
|
||||
Element root = parser.parse( source ).getDocumentElement();
|
||||
|
||||
if ( root.getNodeName().equalsIgnoreCase( NAME_COMMON_SOURCE_LOCATIONS ) )
|
||||
result = initializeSourceLocations( root );
|
||||
}
|
||||
catch( ParserConfigurationException e )
|
||||
{
|
||||
CDebugCorePlugin.log( new Status( IStatus.ERROR, CDebugCorePlugin.getUniqueIdentifier(), 0, "Error initializing common source settings.", e ) );
|
||||
}
|
||||
catch( SAXException e )
|
||||
{
|
||||
CDebugCorePlugin.log( new Status( IStatus.ERROR, CDebugCorePlugin.getUniqueIdentifier(), 0, "Error initializing common source settings.", e ) );
|
||||
}
|
||||
catch( IOException e )
|
||||
{
|
||||
CDebugCorePlugin.log( new Status( IStatus.ERROR, CDebugCorePlugin.getUniqueIdentifier(), 0, "Error initializing common source settings.", e ) );
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static ICSourceLocation[] initializeSourceLocations( Element root )
|
||||
{
|
||||
List sourceLocations = new LinkedList();
|
||||
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( NAME_SOURCE_LOCATION ) )
|
||||
{
|
||||
String className = entry.getAttribute( ATTR_CLASS );
|
||||
String data = entry.getAttribute( ATTR_MEMENTO );
|
||||
if ( className == null || className.trim().length() == 0 )
|
||||
{
|
||||
CDebugCorePlugin.log( "Unable to restore common source locations - invalid format." );
|
||||
continue;
|
||||
}
|
||||
Class clazz = null;
|
||||
try
|
||||
{
|
||||
clazz = classLoader.loadClass( className );
|
||||
}
|
||||
catch( ClassNotFoundException e )
|
||||
{
|
||||
CDebugCorePlugin.log( MessageFormat.format( "Unable to restore source location - class not found {0}", new String[] { className } ) );
|
||||
continue;
|
||||
}
|
||||
|
||||
ICSourceLocation location = null;
|
||||
try
|
||||
{
|
||||
location = (ICSourceLocation)clazz.newInstance();
|
||||
}
|
||||
catch( IllegalAccessException e )
|
||||
{
|
||||
CDebugCorePlugin.log( "Unable to restore source location: " + e.getMessage() );
|
||||
continue;
|
||||
}
|
||||
catch( InstantiationException e )
|
||||
{
|
||||
CDebugCorePlugin.log( "Unable to restore source location: " + e.getMessage() );
|
||||
continue;
|
||||
}
|
||||
try
|
||||
{
|
||||
location.initializeFrom( data );
|
||||
sourceLocations.add( location );
|
||||
}
|
||||
catch( CoreException e )
|
||||
{
|
||||
CDebugCorePlugin.log( "Unable to restore source location: " + e.getMessage() );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return (ICSourceLocation[])sourceLocations.toArray( new ICSourceLocation[sourceLocations.size()] );
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue