[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[cdt-patch] Indexer patch
|
This patch:
- refactors the indexer to make proper
use of the CDescriptor service to manage the indexer extension point persistance/creation
- corrects some synchronization problems
between the IndexManager and the TypeCacheManager
- Updates the Indexer UI to make use
of the CDescriptor service
- Updates the tests
- Updates the Make/Managed Make projects
to handle Indexer setting persistance (a la Binary Parser)
Since it has Make and Managed Make components,
I need someone with commit privileges in all areas to apply these changes.
(Hi Doug!)
Thanks,
Bogdan
Index: src/org/eclipse/cdt/make/internal/core/MakeProject.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/MakeProject.java,v
retrieving revision 1.11
diff -u -r1.11 MakeProject.java
--- src/org/eclipse/cdt/make/internal/core/MakeProject.java 25 Jun 2004 14:49:42 -0000 1.11
+++ src/org/eclipse/cdt/make/internal/core/MakeProject.java 21 Mar 2005 04:57:51 -0000
@@ -26,12 +26,17 @@
cDescriptor.remove(CCorePlugin.BUILD_SCANNER_INFO_UNIQ_ID);
cDescriptor.remove(CCorePlugin.BUILDER_MODEL_ID);
updateBinaryParsers(cDescriptor);
+ updateIndexers(cDescriptor);
}
public void update(ICDescriptor cDescriptor, String extensionID) throws CoreException {
if (extensionID.equals(CCorePlugin.BINARY_PARSER_UNIQ_ID)) {
updateBinaryParsers(cDescriptor);
}
+
+ if (extensionID.equals(CCorePlugin.INDEXER_UNIQ_ID)) {
+ updateIndexers(cDescriptor);
+ }
}
private void updateBinaryParsers(ICDescriptor cDescriptor) throws CoreException {
@@ -45,7 +50,18 @@
}
}
}
-
+
+ private void updateIndexers(ICDescriptor cDescriptor) throws CoreException {
+ cDescriptor.remove(CCorePlugin.INDEXER_UNIQ_ID);
+ Preferences corePrefs = CCorePlugin.getDefault().getPluginPreferences();
+ String id = corePrefs.getString(CCorePlugin.PREF_INDEXER);
+ if (id != null && id.length() != 0) {
+ String[] ids = parseStringToArray(id);
+ for (int i = 0; i < ids.length; i++) {
+ cDescriptor.create(CCorePlugin.INDEXER_UNIQ_ID, ids[i]);
+ }
+ }
+ }
private String[] parseStringToArray(String syms) {
if (syms != null && syms.length() > 0) {
Index: indexer/org/eclipse/cdt/core/indexer/tests/DependencyTests.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-core/org.eclipse.cdt.core.tests/indexer/org/eclipse/cdt/core/indexer/tests/DependencyTests.java,v
retrieving revision 1.20
diff -u -r1.20 DependencyTests.java
--- indexer/org/eclipse/cdt/core/indexer/tests/DependencyTests.java 15 Mar 2005 03:35:28 -0000 1.20
+++ indexer/org/eclipse/cdt/core/indexer/tests/DependencyTests.java 21 Mar 2005 04:57:32 -0000
@@ -106,7 +106,7 @@
indexFile.delete();
testProject.setSessionProperty(IndexManager.indexerIDKey, SourceIndexerTests.sourceIndexerID);
- testProject.setSessionProperty(SourceIndexer.activationKey,new Boolean(true));
+ testProject.setSessionProperty(SourceIndexer.activationKey,new Boolean(true));
if (testProject==null)
fail("Unable to create project");
Index: search/org/eclipse/cdt/core/search/tests/BaseSearchTest.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-core/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/BaseSearchTest.java,v
retrieving revision 1.22
diff -u -r1.22 BaseSearchTest.java
--- search/org/eclipse/cdt/core/search/tests/BaseSearchTest.java 15 Mar 2005 03:35:28 -0000 1.22
+++ search/org/eclipse/cdt/core/search/tests/BaseSearchTest.java 21 Mar 2005 04:57:32 -0000
@@ -18,6 +18,8 @@
import junit.framework.TestCase;
import org.eclipse.cdt.core.CCorePlugin;
+import org.eclipse.cdt.core.ICDescriptor;
+import org.eclipse.cdt.core.ICExtensionReference;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.search.BasicSearchResultCollector;
import org.eclipse.cdt.core.search.ICSearchConstants;
@@ -55,13 +57,14 @@
static protected SearchEngine searchEngine;
static protected FileManager fileManager;
static final String sourceIndexerID = "org.eclipse.cdt.core.originalsourceindexer"; //$NON-NLS-1$
-
+ static protected SourceIndexer sourceIndexer;
{
//(CCorePlugin.getDefault().getCoreModel().getIndexManager()).reset();
monitor = new NullProgressMonitor();
workspace = ResourcesPlugin.getWorkspace();
+ CCorePlugin.getDefault().getPluginPreferences().setValue(CCorePlugin.PREF_INDEXER, CCorePlugin.DEFAULT_INDEXER_UNIQ_ID);
try {
//Create temp project
@@ -71,7 +74,9 @@
//Set the id of the source indexer extension point as a session property to allow
//index manager to instantiate it
- testProject.setSessionProperty(IndexManager.indexerIDKey, sourceIndexerID);
+ //testProject.setSessionProperty(IndexManager.indexerIDKey, sourceIndexerID);
+ sourceIndexer = (SourceIndexer) CCorePlugin.getDefault().getCoreModel().getIndexManager().getIndexerForProject(testProject);
+ int x=0;
} catch (CoreException e) {}
@@ -107,7 +112,6 @@
}
protected void setUp() throws Exception {
-
}
protected void tearDown() {
Index: suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java,v
retrieving revision 1.39
diff -u -r1.39 AutomatedIntegrationSuite.java
--- suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java 18 Mar 2005 19:17:42 -0000 1.39
+++ suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java 21 Mar 2005 04:57:33 -0000
@@ -50,9 +50,6 @@
public static Test suite() {
final AutomatedIntegrationSuite suite = new AutomatedIntegrationSuite();
- //TODO: BOG Take this out once null indexer id added to suite project creation
- CCorePlugin.getDefault().getCoreModel().getIndexManager().setEnableUpdates(false);
-
// Add all success tests
suite.addTest(CDescriptorTests.suite());
//suite.addTest(GCCErrorParserTests.suite());
Index: plugin.xml
===================================================================
RCS file: /home/tools/org.eclipse.cdt-core/org.eclipse.cdt.core/plugin.xml,v
retrieving revision 1.75
diff -u -r1.75 plugin.xml
--- plugin.xml 18 Mar 2005 20:25:58 -0000 1.75
+++ plugin.xml 21 Mar 2005 04:57:03 -0000
@@ -529,24 +529,14 @@
<initializer class="org.eclipse.cdt.internal.core.CCorePreferenceInitializer"/>
</extension>
<extension
+ name="Original C/C++ Indexer"
+ id="originalsourceindexer"
point="org.eclipse.cdt.core.CIndexer">
- <indexer
- class="org.eclipse.cdt.internal.core.index.sourceindexer.SourceIndexer"
- name="Original C/C++ Indexer"
- id="org.eclipse.cdt.core.originalsourceindexer">
- </indexer>
+ <cextension>
+ <run
+ class="org.eclipse.cdt.internal.core.index.sourceindexer.SourceIndexer">
+ </run>
+ </cextension>
</extension>
-
-<!-- =================================================================================== -->
-<!-- Dynamic Variables -->
-<!-- =================================================================================== -->
- <extension
- point="org.eclipse.core.variables.dynamicVariables">
- <variable
- name="cdt_pathentry_var"
- resolver="org.eclipse.cdt.internal.core.PathEntryVariableResolver"
- description="%cdt_pathentry_var.description">
- </variable>
- </extension>
-
+
</plugin>
Index: index/org/eclipse/cdt/internal/core/index/sourceindexer/SourceIndexer.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/SourceIndexer.java,v
retrieving revision 1.1
diff -u -r1.1 SourceIndexer.java
--- index/org/eclipse/cdt/internal/core/index/sourceindexer/SourceIndexer.java 14 Mar 2005 05:32:06 -0000 1.1
+++ index/org/eclipse/cdt/internal/core/index/sourceindexer/SourceIndexer.java 21 Mar 2005 04:57:04 -0000
@@ -16,8 +16,10 @@
import java.util.HashSet;
import java.util.List;
+import org.eclipse.cdt.core.AbstractCExtension;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.ICDescriptor;
+import org.eclipse.cdt.core.ICExtensionReference;
import org.eclipse.cdt.core.ICLogConstants;
import org.eclipse.cdt.core.index.ICDTIndexer;
import org.eclipse.cdt.core.index.IIndexChangeListener;
@@ -49,13 +51,11 @@
import org.eclipse.core.runtime.QualifiedName;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
/**
* @author Bogdan Gheorghe
*/
-public class SourceIndexer implements ICDTIndexer {
+public class SourceIndexer extends AbstractCExtension implements ICDTIndexer {
public static boolean VERBOSE = false;
@@ -73,21 +73,27 @@
public final static QualifiedName activationKey = new QualifiedName(INDEX_MODEL_ID, ACTIVATION);
public final static QualifiedName problemsActivationKey = new QualifiedName( INDEX_MODEL_ID, PROBLEM_ACTIVATION );
- public static final String INDEXER_ENABLED = "indexEnabled"; //$NON-NLS-1$
+ /*public static final String INDEXER_ENABLED = "indexEnabled"; //$NON-NLS-1$
public static final String INDEXER_PROBLEMS_ENABLED = "indexerProblemsEnabled"; //$NON-NLS-1$
public static final String SOURCE_INDEXER = "cdt_source_indexer"; //$NON-NLS-1$
public static final String INDEXER_VALUE = "indexValue"; //$NON-NLS-1$
public static final String INDEXER_PROBLEMS_VALUE = "indexProblemsValue"; //$NON-NLS-1$
-
+ */
public static final int PREPROCESSOR_PROBLEMS_BIT = 1;
public static final int SEMANTIC_PROBLEMS_BIT = 1 << 1;
public static final int SYNTACTIC_PROBLEMS_BIT = 1 << 2;
+ public static final String SOURCE_INDEXER_ID = "originalsourceindexer"; //$NON-NLS-1$
+ public static final String SOURCE_INDEXER_UNIQUE_ID = CCorePlugin.PLUGIN_ID + "." + SOURCE_INDEXER_ID; //$NON-NLS-1$;
+
+
private CIndexStorage indexStorage = null;
public ReadWriteMonitor storageMonitor = null;
private IndexManager indexManager = null;
private HashSet jobSet = null;
+ private boolean indexEnabled = false;
+
public SourceIndexer(){
this.indexManager = CCorePlugin.getDefault().getCoreModel().getIndexManager();
@@ -211,10 +217,6 @@
}
}
-
-
-
-
/**
* @param project
* @return
@@ -227,59 +229,65 @@
try {
indexValue = (Boolean) project.getSessionProperty(activationKey);
- } catch (CoreException e) {
- }
+ } catch (CoreException e) {}
if (indexValue != null)
return indexValue.booleanValue();
try {
- //Load value for project
- indexValue = loadIndexerEnabledFromCDescriptor(project);
- if (indexValue != null){
- project.setSessionProperty(SourceIndexer.activationKey, indexValue);
- return indexValue.booleanValue();
+ ICDescriptor cdesc = CCorePlugin.getDefault().getCProjectDescription(project, false);
+ if (cdesc == null)
+ return false;
+
+ ICExtensionReference[] cext = cdesc.get(CCorePlugin.INDEXER_UNIQ_ID);
+ if (cext.length > 0) {
+ //initializeIndexerId();
+ for (int i = 0; i < cext.length; i++) {
+ String id = cext[i].getID();
+ String orig = cext[i].getExtensionData("indexenabled"); //$NON-NLS-1$
+ if (orig != null){
+ Boolean tempBool = new Boolean(orig);
+ indexEnabled = tempBool.booleanValue();
+ }
+ }
}
+
-// TODO: Indexer Block Place holder for Managed Make - take out
- indexValue = new Boolean(true);
- project.setSessionProperty(SourceIndexer.activationKey, indexValue);
- return indexValue.booleanValue();
- } catch (CoreException e1) {
- }
+ } catch (CoreException e) {}
- return false;
+ return indexEnabled;
}
public int indexProblemsEnabled(IProject project) {
- Integer value = null;
- try {
- value = (Integer) project.getSessionProperty(problemsActivationKey);
- } catch (CoreException e) {
- }
-
- if (value != null)
- return value.intValue();
+ if( project == null || !project.exists() || !project.isOpen() )
+ return 0;
+ int indexProblemsEnabled = 0;
try {
- //Load value for project
- value = loadIndexerProblemsEnabledFromCDescriptor(project);
- if (value != null){
- project.setSessionProperty(SourceIndexer.problemsActivationKey, value);
- return value.intValue();
+ ICDescriptor cdesc = CCorePlugin.getDefault().getCProjectDescription(project, false);
+ if (cdesc == null)
+ return 0;
+
+ ICExtensionReference[] cext = cdesc.get(CCorePlugin.INDEXER_UNIQ_ID);
+ if (cext.length > 0) {
+ //initializeIndexerId();
+ for (int i = 0; i < cext.length; i++) {
+ String id = cext[i].getID();
+ String orig = cext[i].getExtensionData("indexmarkers"); //$NON-NLS-1$
+ if (orig != null){
+ Integer tempInt = new Integer(orig);
+ indexProblemsEnabled = tempInt.intValue();
+ }
+ }
}
+
- //TODO: Indexer Block Place holder for Managed Make - take out
- value = new Integer(0);
- project.setSessionProperty(SourceIndexer.problemsActivationKey, value);
- return value.intValue();
- } catch (CoreException e1) {
- }
+ } catch (CoreException e) {}
- return 0;
+ return indexProblemsEnabled;
}
/**
* Index the content of the given source folder.
@@ -332,56 +340,6 @@
public void jobFinishedNotification(IIndexJob job) {
this.indexJobFinishedNotification(job);
- }
-
-
-
- private Boolean loadIndexerEnabledFromCDescriptor(IProject project) throws CoreException {
- // Check if we have the property in the descriptor
- // We pass false since we do not want to create the descriptor if it does not exists.
- ICDescriptor descriptor = CCorePlugin.getDefault().getCProjectDescription(project, false);
- Boolean strBool = null;
- if (descriptor != null) {
- Node child = descriptor.getProjectData(SOURCE_INDEXER).getFirstChild();
-
- while (child != null) {
- if (child.getNodeName().equals(INDEXER_ENABLED))
- strBool = Boolean.valueOf(((Element)child).getAttribute(INDEXER_VALUE));
-
-
- child = child.getNextSibling();
- }
- }
-
- return strBool;
- }
- private Integer loadIndexerProblemsEnabledFromCDescriptor(IProject project) throws CoreException {
- // we are only checking for the settings do not create the descriptor.
- ICDescriptor descriptor = CCorePlugin.getDefault().getCProjectDescription(project, false);
- Integer strInt = null;
- if( descriptor != null ){
- Node child = descriptor.getProjectData(SourceIndexer.SOURCE_INDEXER).getFirstChild();
-
- while (child != null) {
- if (child.getNodeName().equals(INDEXER_PROBLEMS_ENABLED)){
- String val = ((Element)child).getAttribute(INDEXER_PROBLEMS_VALUE);
- try{
- strInt = Integer.valueOf( val );
- } catch( NumberFormatException e ){
- //some old projects might have a boolean stored, translate that into just preprocessors
- Boolean bool = Boolean.valueOf( val );
- if( bool.booleanValue() )
- strInt = new Integer( SourceIndexer.PREPROCESSOR_PROBLEMS_BIT );
- else
- strInt = new Integer( 0 );
- }
- break;
- }
- child = child.getNextSibling();
- }
- }
-
- return strInt;
}
static private class RemoveIndexMarkersJob extends Job{
Index: index/org/eclipse/cdt/internal/core/search/indexing/IndexManager.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/IndexManager.java,v
retrieving revision 1.41
diff -u -r1.41 IndexManager.java
--- index/org/eclipse/cdt/internal/core/search/indexing/IndexManager.java 18 Mar 2005 19:06:22 -0000 1.41
+++ index/org/eclipse/cdt/internal/core/search/indexing/IndexManager.java 21 Mar 2005 04:57:04 -0000
@@ -16,6 +16,7 @@
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.ICDescriptor;
+import org.eclipse.cdt.core.ICExtensionReference;
import org.eclipse.cdt.core.index.ICDTIndexer;
import org.eclipse.cdt.core.index.IIndexStorage;
import org.eclipse.cdt.core.model.ICElement;
@@ -27,21 +28,16 @@
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceDelta;
-import org.eclipse.core.resources.IWorkspaceRunnable;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtension;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.QualifiedName;
import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.jobs.Job;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
/**
* @author Bogdan Gheorghe
@@ -60,198 +56,30 @@
public static boolean VERBOSE = false;
- //Map of Contributed Indexers; keyed by project
- private HashMap contributedIndexerMap = null;
-
//Map of Persisted Indexers; keyed by project
private HashMap indexerMap = null;
-
- //Upgrade index version
- private boolean upgradeIndexEnabled = false;
- private int upgradeIndexProblems = 0;
-
- private ReadWriteMonitor monitor = new ReadWriteMonitor();
- private boolean enableUpdates = true;
-
- /**
- * Create an indexer only on request
- */
- protected static class CDTIndexer {
- IConfigurationElement element;
- ICDTIndexer indexer;
-
- public CDTIndexer(IConfigurationElement _element) {
- element = _element;
- }
-
- public ICDTIndexer getIndexer() throws CoreException {
- if (indexer == null) {
- indexer = (ICDTIndexer) element.createExecutableExtension("class"); //$NON-NLS-1$
- }
- return indexer;
- }
-
- public String getName() {
- return element.getAttribute("name"); //$NON-NLS-1$
- }
-
- }
-
- private class UpdateIndexVersionJob extends Job{
- private final IProject project;
- public UpdateIndexVersionJob( IProject project, String name ){
- super( name );
- this.project = project;
- }
+ private ReadWriteMonitor monitor = new ReadWriteMonitor();
- protected IStatus run(IProgressMonitor monitor) {
- IWorkspaceRunnable job = new IWorkspaceRunnable( ){
- public void run(IProgressMonitor monitor){
- doProjectUpgrade(project);
- doSourceIndexerUpgrade(project);
- }
- };
- try {
- CCorePlugin.getWorkspace().run(job, project, 0, null);
- } catch (CoreException e) {
- }
- return Status.OK_STATUS;
- }
- }
-
-
-
/**
* Flush current state
*/
- public synchronized void reset() {
- super.reset();
-
- initializeIndexersMap();
- this.indexerMap = new HashMap(5);
+ public void reset() {
try{
- monitor.enterWrite();
- initializeIndexerID();
- } finally {
- monitor.exitWrite();
- }
- }
-
-
-
-
- /**
- *
- */
- private void initializeIndexerID() {
- IProject[] projects = CCorePlugin.getWorkspace().getRoot().getProjects();
- //Make sure that all projects are added to the indexer map and updated
- //where neccesary
- for (int i=0; i<projects.length; i++){
- try {
- if (projects[i].isAccessible())
- initializeIndexer(projects[i]);
- } catch (CoreException e) {}
- }
-
- }
-
- private ICDTIndexer initializeIndexer(IProject project) throws CoreException {
-
- ICDTIndexer indexer = null;
- indexer = (ICDTIndexer) indexerMap.get(project);
-
- if (indexer == null){
- String indexerID = null;
- try {
- //Indexer has not been created yet for this session
- //Check to see if the indexer has been set in a session property
- indexerID = (String) project.getSessionProperty(indexerIDKey);
- } catch (CoreException e) {}
-
- if (indexerID == null){
- try{
- //Need to load the indexer from descriptor
- indexerID = loadIndexerIDFromCDescriptor(project);
- } catch (CoreException e){}
- }
-
- //Make sure that we have an indexer ID
- if (indexerID == null &&
- enableUpdates) {
- //No persisted info on file? Must be old project - run temp. upgrade
- UpdateIndexVersionJob job = new UpdateIndexVersionJob(project, "Update Index Version" ); //$NON-NLS-1$
-
- IProgressMonitor group = this.getIndexJobProgressGroup();
-
- job.setRule( project );
- if( group != null )
- job.setProgressGroup( group, 0 );
- job.setPriority( Job.SHORT );
- job.schedule();
- }
-
- //If we're asking for the null indexer,return null
- if (indexerID == null ||
- indexerID.equals(nullIndexerID))
- return null;
-
- //Create the indexer and store it
- indexer = getIndexer(indexerID);
- indexerMap.put(project,indexer);
-
- }
- return indexer;
- }
-
- /**
- * Loads indexerID from .cdtproject file
- * @param project
- * @param includes
- * @param symbols
- * @throws CoreException
- */
- private String loadIndexerIDFromCDescriptor(IProject project) throws CoreException {
- ICDescriptor descriptor = CCorePlugin.getDefault().getCProjectDescription(project, true);
-
- Node child = descriptor.getProjectData(CDT_INDEXER).getFirstChild();
-
- String indexerID = null;
-
- while (child != null) {
- if (child.getNodeName().equals(INDEXER_ID))
- indexerID = ((Element)child).getAttribute(INDEXER_ID_VALUE);
-
- child = child.getNextSibling();
+ monitor.enterWrite();
+ super.reset();
+ //Set default upgrade values
+ CCorePlugin.getDefault().getPluginPreferences().setValue(CCorePlugin.PREF_INDEXER, CCorePlugin.DEFAULT_INDEXER_UNIQ_ID);
+ this.indexerMap = new HashMap(5);
+ } finally{
+ monitor.exitWrite();
}
-
- return indexerID;
}
-
-
- /**
- * Adds all the contributed Indexer Pages to a map
- */
- private void initializeIndexersMap() {
-
- contributedIndexerMap = new HashMap(5);
-
- IExtensionPoint extensionPoint = Platform.getExtensionRegistry().getExtensionPoint(CCorePlugin.PLUGIN_ID, "CIndexer"); //$NON-NLS-1$
- IConfigurationElement[] infos = extensionPoint.getConfigurationElements();
- for (int i = 0; i < infos.length; i++) {
- if (infos[i].getName().equals("indexer")) { //$NON-NLS-1$
- String id = infos[i].getAttribute("id"); //$NON-NLS-1$
- contributedIndexerMap.put(id, new CDTIndexer(infos[i]));
- }
- }
- }
-
- /**
+ /**
* Notify indexer which scheduled this job that the job has completed
*
*/
- protected synchronized void jobFinishedNotification(IIndexJob job) {
+ protected void jobFinishedNotification(IIndexJob job) {
if (job instanceof IndexRequest ){
IndexRequest indexRequest = (IndexRequest) job;
IPath path = indexRequest.getIndexPath();
@@ -262,10 +90,6 @@
indexer.indexJobFinishedNotification(job);
}
}
-
-
-
-
/**
* @param project
* @param element
@@ -277,13 +101,6 @@
if (indexer != null)
indexer.addRequest(element, delta);
- else{
- //Maybe indexer hasn't been created for this project yet
- //Scenarios:
- //1) New Project created - UI has set env var telling which indexer to use
- //2) Existing Project - the indexer has been persisted to file, need to load it up from CCorePlugin
-
- }
}
/**
@@ -375,26 +192,21 @@
return new CIndexStorage(indexer);
}
- public synchronized int getJobStart(){
+ public int getJobStart(){
return jobStart;
}
- public synchronized int getJobEnd(){
+ public int getJobEnd(){
return jobEnd;
}
-
/**
* Returns the job at position in the awaiting job queue
* @param position
* @return
*/
- public synchronized IIndexJob getAwaitingJobAt(int position){
+ public IIndexJob getAwaitingJobAt(int position){
return this.awaitingJobs[position];
}
-
-
-
-
/**
* Check to see if the indexer associated with this project
* requires dependency update notifications
@@ -408,238 +220,95 @@
}
- public synchronized ICDTIndexer getIndexerForProject(IProject project){
- //Make sure we're not updating list
- monitor.enterRead();
- //All indexers that were previously persisted should have been loaded at
- //this point
+ public ICDTIndexer getIndexerForProject(IProject project){
ICDTIndexer indexer = null;
- indexer = (ICDTIndexer) indexerMap.get(project);
try {
- if (indexer == null){
- String indexerID = null;
+ //Make sure we're not updating list
+ monitor.enterRead();
+
+ //See if indexer exists already
+ indexer = (ICDTIndexer) indexerMap.get(project);
+
+ //Create the indexer and store it
+ if (indexer == null) {
+ monitor.exitRead();
try {
- //Indexer has not been created yet for this session
- //Check to see if the indexer has been set in a session property
- indexerID = (String) project.getSessionProperty(indexerIDKey);
- } catch (CoreException e) {}
-
- //Project was either closed at startup or imported
- if (indexerID == null &&
- project.isAccessible()){
- try {
- indexer=initializeIndexer(project);
- } catch (CoreException e1) {}
- }
- else{
- //Create the indexer and store it
- indexer = getIndexer(indexerID);
+ monitor.enterWrite();
+ indexer = getIndexer(project);
+ //Make sure we're not putting null in map
+ if (indexer != null)
+ indexerMap.put(project,indexer);
+ } finally{
+ monitor.exitWriteEnterRead();
}
+ }
+ return indexer;
- //Make sure we're not putting null in map
- if (indexer != null)
- indexerMap.put(project,indexer);
+ }finally {
+ monitor.exitRead();
}
- } finally {
- monitor.exitRead();
- }
-
- return indexer;
}
- /**
- * @param project
- */
- private synchronized void doSourceIndexerUpgrade(IProject project) {
- ICDescriptor descriptor = null;
- Element rootElement = null;
- IProject newProject = null;
-
- try {
- newProject = project;
- descriptor = CCorePlugin.getDefault().getCProjectDescription(newProject, true);
- rootElement = descriptor.getProjectData(SourceIndexer.SOURCE_INDEXER);
-
- // Clear out all current children
- Node child = rootElement.getFirstChild();
- while (child != null) {
- rootElement.removeChild(child);
- child = rootElement.getFirstChild();
- }
- Document doc = rootElement.getOwnerDocument();
-
-
- saveIndexerEnabled(upgradeIndexEnabled, rootElement, doc);
- saveIndexerProblemsEnabled( upgradeIndexProblems, rootElement, doc );
-
- descriptor.saveProjectData();
-
- //Update project session property
-
- project.setSessionProperty(SourceIndexer.activationKey,new Boolean(upgradeIndexEnabled));
- project.setSessionProperty(SourceIndexer.problemsActivationKey, new Integer( upgradeIndexProblems ));
-
- } catch (CoreException e) {}
- }
-
- private static void saveIndexerEnabled (boolean indexerEnabled, Element rootElement, Document doc ) {
-
- Element indexEnabled = doc.createElement(SourceIndexer.INDEXER_ENABLED);
- Boolean tempValue= new Boolean(indexerEnabled);
-
- indexEnabled.setAttribute(SourceIndexer.INDEXER_VALUE,tempValue.toString());
- rootElement.appendChild(indexEnabled);
-
- }
- private static void saveIndexerProblemsEnabled ( int problemValues, Element rootElement, Document doc ) {
-
- Element enabled = doc.createElement(SourceIndexer.INDEXER_PROBLEMS_ENABLED);
- Integer tempValue= new Integer( problemValues );
-
- enabled.setAttribute(SourceIndexer.INDEXER_PROBLEMS_VALUE, tempValue.toString());
- rootElement.appendChild(enabled);
- }
-
-/**
- * @return
- */
- private synchronized String doProjectUpgrade(IProject project) {
- ICDescriptor descriptor = null;
- Element rootElement = null;
- IProject newProject = null;
-
- try {
- //Get the old values from .cdtproject before upgrading
- Boolean tempEnabled = loadIndexerEnabledFromCDescriptor(project);
- if (tempEnabled != null)
- upgradeIndexEnabled = tempEnabled.booleanValue();
-
- Integer tempProblems = loadIndexerProblemsEnabledFromCDescriptor(project);
- if (tempProblems != null)
- upgradeIndexProblems = tempProblems.intValue();
-
- } catch (CoreException e1) {}
-
-
- //For now all upgrades will be to the old source indexer
- String indexerPageID = "org.eclipse.cdt.ui.originalSourceIndexerUI"; //$NON-NLS-1$
- String indexerID = "org.eclipse.cdt.core.originalsourceindexer"; //$NON-NLS-1$
-
- try {
- newProject = project;
- descriptor = CCorePlugin.getDefault().getCProjectDescription(newProject, true);
- rootElement = descriptor.getProjectData(IndexManager.CDT_INDEXER);
-
- // Clear out all current children
- Node child = rootElement.getFirstChild();
- while (child != null) {
- rootElement.removeChild(child);
- child = rootElement.getFirstChild();
- }
- Document doc = rootElement.getOwnerDocument();
-
- saveIndexerInfo(indexerID, indexerPageID, rootElement, doc);
-
- descriptor.saveProjectData();
-
- //Update project session property
-
- project.setSessionProperty(IndexManager.indexerIDKey, indexerID);
- //project.setSessionProperty(indexerUIIDKey, indexerPageID);
-
- } catch (CoreException e) {}
-
- return indexerID;
- }
-
-
- private static void saveIndexerInfo (String indexerID, String indexerUIID, Element rootElement, Document doc ) {
-
- //Save the indexer id
- Element indexerIDElement = doc.createElement(IndexManager.INDEXER_ID);
- indexerIDElement.setAttribute(IndexManager.INDEXER_ID_VALUE,indexerID);
- rootElement.appendChild(indexerIDElement);
-
- //Save the indexer UI id
- Element indexerUIIDElement = doc.createElement("indexerUI"); //$NON-NLS-1$
- indexerUIIDElement.setAttribute("indexerUIValue",indexerUIID); //$NON-NLS-1$
- rootElement.appendChild(indexerUIIDElement);
- }
-
- private Boolean loadIndexerEnabledFromCDescriptor(IProject project) throws CoreException {
- // Check if we have the property in the descriptor
- // We pass false since we do not want to create the descriptor if it does not exists.
- ICDescriptor descriptor = CCorePlugin.getDefault().getCProjectDescription(project, false);
- Boolean strBool = null;
- if (descriptor != null) {
- Node child = descriptor.getProjectData(CDT_INDEXER).getFirstChild();
-
- while (child != null) {
- if (child.getNodeName().equals(SourceIndexer.INDEXER_ENABLED))
- strBool = Boolean.valueOf(((Element)child).getAttribute(SourceIndexer.INDEXER_VALUE));
-
-
- child = child.getNextSibling();
- }
+ public ICDTIndexer getDefaultIndexer(IProject project) throws CoreException {
+ ICDTIndexer indexer = null;
+ String id = CCorePlugin.getDefault().getPluginPreferences().getDefaultString(CCorePlugin.PREF_INDEXER);
+ if (id == null || id.length() == 0) {
+ id = CCorePlugin.DEFAULT_INDEXER_UNIQ_ID;
}
- return strBool;
- }
- private Integer loadIndexerProblemsEnabledFromCDescriptor(IProject project) throws CoreException {
- // we are only checking for the settings do not create the descriptor.
- ICDescriptor descriptor = CCorePlugin.getDefault().getCProjectDescription(project, false);
- Integer strInt = null;
- if( descriptor != null ){
- Node child = descriptor.getProjectData(CDT_INDEXER).getFirstChild();
-
- while (child != null) {
- if (child.getNodeName().equals(SourceIndexer.INDEXER_PROBLEMS_ENABLED)){
- String val = ((Element)child).getAttribute(SourceIndexer.INDEXER_PROBLEMS_VALUE);
- try{
- strInt = Integer.valueOf( val );
- } catch( NumberFormatException e ){
- //some old projects might have a boolean stored, translate that into just preprocessors
- Boolean bool = Boolean.valueOf( val );
- if( bool.booleanValue() )
- strInt = new Integer( SourceIndexer.PREPROCESSOR_PROBLEMS_BIT );
- else
- strInt = new Integer( 0 );
- }
+ IExtensionPoint extensionPoint = Platform.getExtensionRegistry().getExtensionPoint(CCorePlugin.PLUGIN_ID, CCorePlugin.INDEXER_SIMPLE_ID);
+ IExtension extension = extensionPoint.getExtension(id);
+ if (extension != null) {
+ IConfigurationElement element[] = extension.getConfigurationElements();
+ for (int i = 0; i < element.length; i++) {
+ if (element[i].getName().equalsIgnoreCase("cextension")) { //$NON-NLS-1$
+ indexer = (ICDTIndexer) element[i].createExecutableExtension("run"); //$NON-NLS-1$
break;
}
- child = child.getNextSibling();
}
+ } else {
+ IStatus s = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, -1,"No Indexer Found", null); //$NON-NLS-1$
+ throw new CoreException(s);
}
-
- return strInt;
+ return indexer;
}
-
-protected ICDTIndexer getIndexer(String indexerId) {
- CDTIndexer configElement = (CDTIndexer) contributedIndexerMap.get(indexerId);
- if (configElement != null) {
- try {
- return configElement.getIndexer();
- } catch (CoreException e) {}
- }
- return null;
+
+ protected ICDTIndexer getIndexer(IProject project) {
+ ICDTIndexer indexer = null;
+ try{
+ ICDescriptor cdesc = CCorePlugin.getDefault().getCProjectDescription(project,true);
+ ICExtensionReference[] cextensions = cdesc.get(CCorePlugin.INDEXER_UNIQ_ID, true);
+
+ if (cextensions != null && cextensions.length > 0)
+ indexer = (ICDTIndexer) cextensions[0].createExtension();
+
+ } catch (CoreException e){}
+
+ if (indexer == null)
+ try {
+ indexer = getDefaultIndexer(project);
+ } catch (CoreException e1) {}
+
+ return indexer;
}
protected void notifyIdle(long idlingTime) {
//Notify all indexers
- if (indexerMap == null)
- return;
-
- Set mapKeys = indexerMap.keySet();
- Iterator i = mapKeys.iterator();
- while (i.hasNext()){
- IProject tempProject = (IProject) i.next();
- ICDTIndexer indexer = (ICDTIndexer) indexerMap.get(tempProject);
- if (indexer != null)
- indexer.notifyIdle(idlingTime);
+ monitor.enterRead();
+ try{
+ if (indexerMap == null)
+ return;
+
+ Set mapKeys = indexerMap.keySet();
+ Iterator i = mapKeys.iterator();
+ while (i.hasNext()){
+ IProject tempProject = (IProject) i.next();
+ ICDTIndexer indexer = (ICDTIndexer) indexerMap.get(tempProject);
+ if (indexer != null)
+ indexer.notifyIdle(idlingTime);
+ }
+ } finally{
+ monitor.exitRead();
}
}
-
- public void setEnableUpdates(boolean enableUpdates) {
- this.enableUpdates = enableUpdates;
- }
}
Index: src/org/eclipse/cdt/core/CCorePlugin.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CCorePlugin.java,v
retrieving revision 1.77
diff -u -r1.77 CCorePlugin.java
--- src/org/eclipse/cdt/core/CCorePlugin.java 15 Mar 2005 19:55:34 -0000 1.77
+++ src/org/eclipse/cdt/core/CCorePlugin.java 21 Mar 2005 04:57:07 -0000
@@ -76,6 +76,12 @@
public final static String DEFAULT_BINARY_PARSER_UNIQ_ID = PLUGIN_ID + "." + DEFAULT_BINARY_PARSER_SIMPLE_ID; //$NON-NLS-1$
public final static String PREF_USE_STRUCTURAL_PARSE_MODE = "useStructualParseMode"; //$NON-NLS-1$
+ public static final String INDEXER_SIMPLE_ID = "CIndexer"; //$NON-NLS-1$
+ public static final String INDEXER_UNIQ_ID = PLUGIN_ID + "." + INDEXER_SIMPLE_ID; //$NON-NLS-1$
+ public final static String PREF_INDEXER = "indexer"; //$NON-NLS-1$
+ public final static String DEFAULT_INDEXER_SIMPLE_ID = "originalsourceindexer"; //$NON-NLS-1$
+ public final static String DEFAULT_INDEXER_UNIQ_ID = PLUGIN_ID + "." + DEFAULT_INDEXER_SIMPLE_ID; //$NON-NLS-1$
+
public final static String ERROR_PARSER_SIMPLE_ID = "ErrorParser"; //$NON-NLS-1$
// default store for pathentry
Index: src/org/eclipse/cdt/internal/ui/CUIMessages.properties
===================================================================
RCS file: /home/tools/org.eclipse.cdt-core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CUIMessages.properties,v
retrieving revision 1.15
diff -u -r1.15 CUIMessages.properties
--- src/org/eclipse/cdt/internal/ui/CUIMessages.properties 24 Jan 2005 18:49:21 -0000 1.15
+++ src/org/eclipse/cdt/internal/ui/CUIMessages.properties 21 Mar 2005 04:59:08 -0000
@@ -62,6 +62,7 @@
IndexerOptions.enablePreprocessor = Report &preprocessor problems
IndexerOptions.enableSemantic = Report &semantic problems
IndexerOptions.enableSyntactic = Report s&yntactic problems
+IndexerOptiosn.task.savingAttributes = Saving Attributes
StatusBarUpdater.num_elements_selected={0} items selected
Index: src/org/eclipse/cdt/ui/dialogs/IndexerBlock.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/IndexerBlock.java,v
retrieving revision 1.9
diff -u -r1.9 IndexerBlock.java
--- src/org/eclipse/cdt/ui/dialogs/IndexerBlock.java 14 Mar 2005 21:08:20 -0000 1.9
+++ src/org/eclipse/cdt/ui/dialogs/IndexerBlock.java 21 Mar 2005 04:59:10 -0000
@@ -17,7 +17,8 @@
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.ICDescriptor;
-import org.eclipse.cdt.internal.core.search.indexing.IndexManager;
+import org.eclipse.cdt.core.ICDescriptorOperation;
+import org.eclipse.cdt.internal.ui.CUIMessages;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.index.AbstractIndexerPage;
import org.eclipse.cdt.utils.ui.controls.ControlFactory;
@@ -27,8 +28,11 @@
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.Preferences;
import org.eclipse.core.runtime.QualifiedName;
+import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Font;
@@ -37,9 +41,6 @@
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
/**
* @author Bogdan Gheorghe
@@ -71,7 +72,8 @@
private Composite parentComposite;
private ICOptionPage currentPage;
-
+ String initialSelected;
+
public IndexerBlock(){
super(INDEXER_LABEL);
setDescription(INDEXER_DESCRIPTION);
@@ -104,10 +106,6 @@
}
}
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
- */
public void createControl(Composite parent) {
@@ -147,9 +145,6 @@
}
parent.layout(true);
}
-
-
-
/**
*
*/
@@ -176,7 +171,6 @@
setCurrentPage(page);
}
-
/**
* @param page
*/
@@ -184,15 +178,15 @@
currentPage = page;
}
-
-
protected String getCurrentIndexPageId() {
String selectedIndexPageName = getSelectedIndexerID();
if (selectedIndexPageName == null)
return null;
+
String selectedIndexPageId = getIndexerPageId(selectedIndexPageName);
+
return selectedIndexPageId;
}
/**
@@ -239,9 +233,6 @@
return true;
}
-
-
-
/**
* Adds all the contributed Indexer Pages to a map
*/
@@ -252,7 +243,7 @@
IConfigurationElement[] infos = extensionPoint.getConfigurationElements();
for (int i = 0; i < infos.length; i++) {
if (infos[i].getName().equals("indexerUI")) { //$NON-NLS-1$
- String id = infos[i].getAttribute("id"); //$NON-NLS-1$
+ String id = infos[i].getAttribute("indexerID"); //$NON-NLS-1$
indexerPageMap.put(id, new IndexerPageConfiguration(infos[i]));
}
}
@@ -322,10 +313,77 @@
}
public void performApply(IProgressMonitor monitor) throws CoreException {
- IProject newProject = null;
- newProject = getContainer().getProject();
+ //Get the currently selected indexer from the UI
+ String indexerName = getSelectedIndexerID();
+ //If no indexer has been selected, return
+ if (indexerName == null)
+ return;
+
+ //Match up the selected indexer in the UI to a corresponding
+ //contributed Indexer Page ID
+ String indexerPageID = getIndexerPageId(indexerName);
+
+ if (indexerPageID == null)
+ return;
- persistIndexerSettings(newProject, monitor);
+ //Get the id of the indexer that goes along with this UI page - this gets persisted
+ final String indexerID = getIndexerIdName(indexerPageID);
+ //
+ if (monitor == null) {
+ monitor = new NullProgressMonitor();
+ }
+ monitor.beginTask(CUIMessages.getString("IndexerOptions.task.savingAttributes"), 2); //$NON-NLS-1$
+ final String selected = indexerID;
+
+ if (indexerID != null) {
+ ICOptionContainer container = getContainer();
+ IProject project = null;
+ if (container != null){
+ project=container.getProject();
+ } else {
+ project = ((AbstractIndexerPage) currentPage).getCurrentProject();
+ }
+
+ if ( project != null) {
+ ICDescriptorOperation op = new ICDescriptorOperation() {
+
+ public void execute(ICDescriptor descriptor, IProgressMonitor monitor) throws CoreException {
+ if (initialSelected == null || !selected.equals(initialSelected)) {
+ descriptor.remove(CCorePlugin.INDEXER_UNIQ_ID);
+ descriptor.create(CCorePlugin.INDEXER_UNIQ_ID,indexerID);
+ }
+ monitor.worked(1);
+ // Give a chance to the contributions to save.
+ // We have to do it last to make sure the indexer id
+ // is saved in .cdtproject
+ ICOptionPage page = currentPage; //egetBinaryParserPage(((BinaryParserConfiguration) selected.get(i)).getID());
+ if (page != null && page.getControl() != null) {
+ page.performApply(new SubProgressMonitor(monitor, 1));
+ }
+
+ }
+ };
+ CCorePlugin.getDefault().getCDescriptorManager().runDescriptorOperation(project, op, monitor);
+ } else {
+ if (initialSelected == null || !selected.equals(initialSelected)) {
+ if (container != null){
+ Preferences store = container.getPreferences();
+ if (store != null) {
+ store.setValue(CCorePlugin.PREF_INDEXER, indexerID);
+ }
+ }
+ }
+ monitor.worked(1);
+ // Give a chance to the contributions to save.
+ ICOptionPage page = currentPage;
+ if (page != null && page.getControl() != null) {
+ page.performApply(new SubProgressMonitor(monitor, 1));
+ }
+
+ }
+ initialSelected = selected;
+ }
+ monitor.done();
}
/**
@@ -334,21 +392,18 @@
* property page.
*/
public void persistIndexerSettings(IProject project, IProgressMonitor monitor) throws CoreException{
-
- persistIndexerValues(project);
-
if (currentPage instanceof AbstractIndexerPage)
((AbstractIndexerPage)currentPage).setCurrentProject(project);
- //Give the chosen indexer a chance to persist its values
+ this.performApply(monitor);
+ /*//Give the chosen indexer a chance to persist its values
if (currentPage != null){
- currentPage.performApply(monitor);
- }
+ currentPage.performApply(monitor);*/
+
}
-
+
public void performDefaults() {
- // TODO Auto-generated method stub
-
+ // TODO Auto-generated method stub
}
/**
@@ -359,56 +414,6 @@
return false;
}
- //Storage section
-
- public void persistIndexerValues(IProject project){
- ICDescriptor descriptor = null;
- Element rootElement = null;
- IProject newProject = null;
-
- //Get the currently selected indexer from the UI
- String indexerName = getSelectedIndexerID();
- //If no indexer has been selected, return
- if (indexerName == null)
- return;
-
- //Match up the selected indexer in the UI to a corresponding
- //contributed Indexer Page ID
- String indexerPageID = getIndexerPageId(indexerName);
-
- if (indexerPageID == null)
- return;
-
- //Get the id of the indexer that goes along with this UI page - this gets persisted
- String indexerID = getIndexerIdName(indexerPageID);
-
- try {
- newProject = project;
- descriptor = CCorePlugin.getDefault().getCProjectDescription(newProject, true);
- rootElement = descriptor.getProjectData(IndexManager.CDT_INDEXER);
-
- // Clear out all current children
- Node child = rootElement.getFirstChild();
- while (child != null) {
- rootElement.removeChild(child);
- child = rootElement.getFirstChild();
- }
- Document doc = rootElement.getOwnerDocument();
-
- saveIndexerInfo(indexerID, indexerPageID, rootElement, doc);
-
- descriptor.saveProjectData();
-
- //Update project session property
-
- project.setSessionProperty(IndexManager.indexerIDKey, indexerID);
- project.setSessionProperty(indexerUIIDKey, indexerPageID);
-
- } catch (CoreException e) {
- e.printStackTrace();
- }
- }
-
/**
* @param oldIndexerID
* @param project
@@ -416,7 +421,12 @@
public void setIndexerID(String oldIndexerID, IProject project) {
//Get the corresponding text for the given indexer id
selectedIndexerId = getIndexerPageName(oldIndexerID);
-
+
+ if (selectedIndexerId == null){
+ CCorePlugin.getDefault().getPluginPreferences().setValue(CCorePlugin.PREF_INDEXER, CCorePlugin.DEFAULT_INDEXER_UNIQ_ID);
+ selectedIndexerId = CCorePlugin.DEFAULT_INDEXER_UNIQ_ID;
+ }
+
//Set the appropriate indexer in the combo box
indexersComboBox.setText(selectedIndexerId);
//Load the appropriate page
@@ -428,19 +438,6 @@
}
- private static void saveIndexerInfo (String indexerID, String indexerUIID, Element rootElement, Document doc ) {
-
- //Save the indexer id
- Element indexerIDElement = doc.createElement(IndexManager.INDEXER_ID);
- indexerIDElement.setAttribute(IndexManager.INDEXER_ID_VALUE,indexerID);
- rootElement.appendChild(indexerIDElement);
-
- //Save the indexer UI id
- Element indexerUIIDElement = doc.createElement(INDEXER_UI);
- indexerUIIDElement.setAttribute(INDEXER_UI_VALUE,indexerUIID);
- rootElement.appendChild(indexerUIIDElement);
- }
-
public String getSelectedIndexerID(){
String indexerID = null;
Index: src/org/eclipse/cdt/ui/dialogs/IndexerOptionPropertyPage.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/IndexerOptionPropertyPage.java,v
retrieving revision 1.9
diff -u -r1.9 IndexerOptionPropertyPage.java
--- src/org/eclipse/cdt/ui/dialogs/IndexerOptionPropertyPage.java 14 Mar 2005 05:31:50 -0000 1.9
+++ src/org/eclipse/cdt/ui/dialogs/IndexerOptionPropertyPage.java 21 Mar 2005 04:59:10 -0000
@@ -13,6 +13,7 @@
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.ICDescriptor;
+import org.eclipse.cdt.core.ICExtensionReference;
import org.eclipse.cdt.internal.core.search.indexing.IndexManager;
import org.eclipse.cdt.internal.ui.ICHelpContextIds;
import org.eclipse.core.resources.IProject;
@@ -116,23 +117,13 @@
}
public String getIndexerID(IProject project) throws CoreException {
- //See if there's already one associated with the resource for this session
- String indexerID = (String) project.getSessionProperty(IndexerBlock.indexerUIIDKey);
-
- if (indexerID != null)
- return indexerID;
-
- // Try to load one for the project
- indexerID = loadIndexerIDFromCDescriptor(project);
-
- // There is nothing persisted for the session, or saved in a file so
- // create a build info object
- if (indexerID != null) {
- project.setSessionProperty(IndexerBlock.indexerUIIDKey, indexerID);
- }
- else{
- //Hmm, no persisted indexer value. Could be an old project - need to run project
- //update code here
+
+
+ ICDescriptor desc = CCorePlugin.getDefault().getCProjectDescription(project, true);
+ ICExtensionReference[] ref = desc.get(CCorePlugin.INDEXER_UNIQ_ID);
+ String indexerID = null;
+ for (int i = 0; i < ref.length; i++) {
+ indexerID = ref[i].getID();
}
return indexerID;
Index: src/org/eclipse/cdt/ui/dialogs/SourceIndexerBlock.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/SourceIndexerBlock.java,v
retrieving revision 1.2
diff -u -r1.2 SourceIndexerBlock.java
--- src/org/eclipse/cdt/ui/dialogs/SourceIndexerBlock.java 14 Mar 2005 21:08:20 -0000 1.2
+++ src/org/eclipse/cdt/ui/dialogs/SourceIndexerBlock.java 21 Mar 2005 04:59:10 -0000
@@ -13,25 +13,29 @@
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.ICDescriptor;
+import org.eclipse.cdt.core.ICExtensionReference;
import org.eclipse.cdt.core.index.ICDTIndexer;
import org.eclipse.cdt.internal.core.index.sourceindexer.SourceIndexer;
import org.eclipse.cdt.internal.ui.CUIMessages;
+import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.index.AbstractIndexerPage;
import org.eclipse.cdt.utils.ui.controls.ControlFactory;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Preferences;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
public class SourceIndexerBlock extends AbstractIndexerPage {
+ public final static String PREF_INDEX_ENABLED = CUIPlugin.PLUGIN_ID + ".indexenabled"; //$NON-NLS-1$
+ public final static String PREF_INDEX_MARKERS = CUIPlugin.PLUGIN_ID + ".indexmarkers"; //$NON-NLS-1$
+
private static final String ENABLE_PREPROCESSOR_PROBLEMS = CUIMessages.getString( "IndexerOptions.enablePreprocessor" ); //$NON-NLS-1$
private static final String ENABLE_SEMANTIC_PROBLEMS = CUIMessages.getString( "IndexerOptions.enableSemantic" ); //$NON-NLS-1$
private static final String ENABLE_SYNTACTIC_PROBLEMS = CUIMessages.getString( "IndexerOptions.enableSyntactic" ); //$NON-NLS-1$
@@ -44,15 +48,63 @@
private Button syntacticProblemsEnabled;
private Button semanticProblemsEnabled;
- private boolean oldIndexerValue;
- private int oldIndexerProblemsValue;
+ private boolean oldIndexerValue = false;
+ private int oldIndexerProblemsValue = 0;
/* (non-Javadoc)
* @see org.eclipse.cdt.ui.dialogs.ICOptionPage#performApply(org.eclipse.core.runtime.IProgressMonitor)
*/
public void performApply(IProgressMonitor monitor) throws CoreException {
- this.persistIndexerValues(currentProject);
+ if (monitor == null) {
+ monitor = new NullProgressMonitor();
+ }
+
+ monitor.beginTask(CUIMessages.getString("IndexerOptiosn.task.savingAttributes "), 1); //$NON-NLS-1$
+ ICOptionContainer container = getContainer();
+ IProject proj = null;
+
+ if (container != null){
+ proj = container.getProject();
+ }
+ else{
+ proj = currentProject;
+ }
+
+ if (proj != null) {
+ ICDescriptor cdesc = CCorePlugin.getDefault().getCProjectDescription(proj, false);
+ ICExtensionReference[] cext = cdesc.get(CCorePlugin.INDEXER_UNIQ_ID);
+ if (cext.length > 0) {
+ //initializeIndexerId();
+ for (int i = 0; i < cext.length; i++) {
+ String id = cext[i].getID();
+ //if (cext[i].getID().equals(parserID)) {
+ String orig = cext[i].getExtensionData("indexenabled"); //$NON-NLS-1$
+ String indexEnabled = getIndexerEnabledString();
+ if (orig == null || !orig.equals(indexEnabled)) {
+ cext[i].setExtensionData("indexenabled", indexEnabled); //$NON-NLS-1$
+ }
+ orig = cext[i].getExtensionData("indexmarkers"); //$NON-NLS-1$
+ String indexProblems = getIndexerProblemsValuesString();
+ if (orig == null || !orig.equals(indexProblems)) {
+ cext[i].setExtensionData("indexmarkers", indexProblems); //$NON-NLS-1$
+ }
+ //}
+ }
+ }
+ } else {
+ Preferences store = null;
+ if (container != null){
+ store = container.getPreferences();
+ }
+
+ if (store != null) {
+ String indexEnabled = getIndexerEnabledString();
+ String indexMarkers = getIndexerProblemsValuesString();
+ store.setValue(PREF_INDEX_ENABLED, indexEnabled);
+ store.setValue(PREF_INDEX_MARKERS, indexMarkers);
+ }
+ }
boolean indexProject = getIndexerValue();
@@ -102,82 +154,35 @@
}
- public void persistIndexerValues(IProject project){
- ICDescriptor descriptor = null;
- Element rootElement = null;
- IProject newProject = null;
-
- try {
- newProject = project;
- descriptor = CCorePlugin.getDefault().getCProjectDescription(newProject, true);
- rootElement = descriptor.getProjectData(SourceIndexer.SOURCE_INDEXER);
-
- // Clear out all current children
- Node child = rootElement.getFirstChild();
- while (child != null) {
- rootElement.removeChild(child);
- child = rootElement.getFirstChild();
- }
- Document doc = rootElement.getOwnerDocument();
-
- boolean indexProject = getIndexerValue();
- int problemValues = getIndexerProblemsValues();
-
- saveIndexerEnabled(indexProject, rootElement, doc);
- saveIndexerProblemsEnabled( problemValues, rootElement, doc );
-
- descriptor.saveProjectData();
-
- //Update project session property
-
- project.setSessionProperty(SourceIndexer.activationKey,new Boolean(indexProject));
- project.setSessionProperty(SourceIndexer.problemsActivationKey, new Integer( problemValues ));
-
- } catch (CoreException e) {
- e.printStackTrace();
- }
- }
-
-
public boolean getIndexerValue(){
return indexerEnabled.getSelection();
}
- public int getIndexerProblemsValues(){
+ public String getIndexerProblemsValuesString(){
int result = 0;
result |= preprocessorProblemsEnabled.getSelection() ? SourceIndexer.PREPROCESSOR_PROBLEMS_BIT : 0;
if( syntacticProblemsEnabled != null )
result |= syntacticProblemsEnabled.getSelection() ? SourceIndexer.SYNTACTIC_PROBLEMS_BIT : 0;
result |= semanticProblemsEnabled.getSelection() ? SourceIndexer.SEMANTIC_PROBLEMS_BIT : 0;
- return result;
+ Integer tempInt = new Integer(result);
+
+ return tempInt.toString();
}
- private static void saveIndexerEnabled (boolean indexerEnabled, Element rootElement, Document doc ) {
-
- Element indexEnabled = doc.createElement(SourceIndexer.INDEXER_ENABLED);
- Boolean tempValue= new Boolean(indexerEnabled);
+ private String getIndexerEnabledString(){
+ if (indexerEnabled.getSelection())
+ return "true"; //$NON-NLS-1$
- indexEnabled.setAttribute(SourceIndexer.INDEXER_VALUE,tempValue.toString());
- rootElement.appendChild(indexEnabled);
-
+ return "false"; //$NON-NLS-1$
}
- private static void saveIndexerProblemsEnabled ( int problemValues, Element rootElement, Document doc ) {
-
- Element enabled = doc.createElement(SourceIndexer.INDEXER_PROBLEMS_ENABLED);
- Integer tempValue= new Integer( problemValues );
- enabled.setAttribute(SourceIndexer.INDEXER_PROBLEMS_VALUE, tempValue.toString());
- rootElement.appendChild(enabled);
- }
-
/* (non-Javadoc)
* @see org.eclipse.cdt.ui.index2.AbstractIndexerPage#initialize(org.eclipse.core.resources.IProject)
*/
public void initialize(IProject project) {
try {
- oldIndexerValue = getIndexerEnabled(project);
- oldIndexerProblemsValue = getIndexerProblemsEnabled( project );
+ loadPersistedValues(project);
this.currentProject = project;
} catch (CoreException e) {
e.printStackTrace();
@@ -190,53 +195,30 @@
setIndexerProblemValues(oldIndexerProblemsValue);
}
- public boolean getIndexerEnabled(IProject project) throws CoreException {
- // See if there's already one associated with the resource for this
- // session
- Boolean indexValue = (Boolean) project.getSessionProperty(SourceIndexer.activationKey);
-
- // Try to load one for the project
- if (indexValue == null) {
- indexValue = loadIndexerEnabledFromCDescriptor(project);
- }
-
- // There is nothing persisted for the session, or saved in a file so
- // create a build info object
- if (indexValue != null) {
- project.setSessionProperty(SourceIndexer.activationKey, indexValue);
- }
- else{
- //Hmm, no persisted indexer value. Could be an old project - set to true and persist
- indexValue = new Boolean(true);
- setIndexerValue(true);
- persistIndexerValues(project);
- }
+ public void loadPersistedValues(IProject project) throws CoreException {
- return indexValue.booleanValue();
- }
-
- public int getIndexerProblemsEnabled( IProject project ) throws CoreException
- {
- // See if there's already one associated with the resource for this session
- Integer value = (Integer) project.getSessionProperty( SourceIndexer.problemsActivationKey );
-
- // Try to load one for the project
- if (value == null) {
- value = loadIndexerProblemsEnabledFromCDescriptor(project);
+ ICDescriptor cdesc = CCorePlugin.getDefault().getCProjectDescription(project, false);
+ ICExtensionReference[] cext = cdesc.get(CCorePlugin.INDEXER_UNIQ_ID);
+ if (cext.length > 0) {
+ //initializeIndexerId();
+ for (int i = 0; i < cext.length; i++) {
+ String id = cext[i].getID();
+ //if (cext[i].getID().equals(parserID)) {
+ String orig = cext[i].getExtensionData("indexenabled"); //$NON-NLS-1$
+ if (orig != null){
+ Boolean tempBool = new Boolean(orig);
+ oldIndexerValue = tempBool.booleanValue();
+ }
+
+ orig = cext[i].getExtensionData("indexmarkers"); //$NON-NLS-1$
+ if (orig != null){
+ Integer tempInt = new Integer(orig);
+ oldIndexerProblemsValue = tempInt.intValue();
+ }
+ //}
+ }
}
- // There is nothing persisted for the session, or saved in a file so
- // create a build info object
- if (value != null) {
- project.setSessionProperty(SourceIndexer.problemsActivationKey, value);
- } else {
- //Hmm, no persisted indexer value. Could be an old project - set all to false and persist
- value = new Integer( 0 );
- setIndexerProblemValues( 0 );
- persistIndexerValues(project);
- }
-
- return value.intValue();
}
public void setIndexerValue(boolean value){
@@ -250,55 +232,4 @@
semanticProblemsEnabled.setSelection( (value & SourceIndexer.SEMANTIC_PROBLEMS_BIT) != 0 );
}
- /**
- * Loads dis from .cdtproject file
- * @param project
- * @param includes
- * @param symbols
- * @throws CoreException
- */
- private Boolean loadIndexerEnabledFromCDescriptor(IProject project) throws CoreException {
- ICDescriptor descriptor = CCorePlugin.getDefault().getCProjectDescription(project, true);
-
- Node child = descriptor.getProjectData(SourceIndexer.SOURCE_INDEXER).getFirstChild();
- Boolean strBool = null;
-
- while (child != null) {
- if (child.getNodeName().equals(SourceIndexer.INDEXER_ENABLED))
- strBool = Boolean.valueOf(((Element)child).getAttribute(SourceIndexer.INDEXER_VALUE));
-
-
- child = child.getNextSibling();
- }
-
- return strBool;
- }
-
- private Integer loadIndexerProblemsEnabledFromCDescriptor( IProject project ) throws CoreException
- {
- ICDescriptor descriptor = CCorePlugin.getDefault().getCProjectDescription(project, true);
-
- Node child = descriptor.getProjectData(SourceIndexer.SOURCE_INDEXER).getFirstChild();
- Integer strInt = null;
-
- while (child != null) {
- if (child.getNodeName().equals(SourceIndexer.INDEXER_PROBLEMS_ENABLED)) {
- String val = ((Element)child).getAttribute(SourceIndexer.INDEXER_PROBLEMS_VALUE);
- try{
- strInt = Integer.valueOf( val );
- } catch( NumberFormatException e ){
- //some old projects might have a boolean stored, translate that into just preprocessors
- Boolean bool = Boolean.valueOf( val );
- if( bool.booleanValue() )
- strInt = new Integer( SourceIndexer.PREPROCESSOR_PROBLEMS_BIT );
- else
- strInt = new Integer( 0 );
- }
- break;
- }
-
- child = child.getNextSibling();
- }
- return strInt;
- }
}
Index: src/org/eclipse/cdt/managedbuilder/internal/core/ManagedMakeProject.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ManagedMakeProject.java,v
retrieving revision 1.1
diff -u -r1.1 ManagedMakeProject.java
--- src/org/eclipse/cdt/managedbuilder/internal/core/ManagedMakeProject.java 24 Jun 2004 15:57:05 -0000 1.1
+++ src/org/eclipse/cdt/managedbuilder/internal/core/ManagedMakeProject.java 21 Mar 2005 04:58:54 -0000
@@ -11,10 +11,14 @@
package org.eclipse.cdt.managedbuilder.internal.core;
+import java.util.ArrayList;
+import java.util.StringTokenizer;
+
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.ICDescriptor;
import org.eclipse.cdt.core.ICOwner;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.Preferences;
/**
* @since 2.0
@@ -36,6 +40,8 @@
cproject.remove(CCorePlugin.BUILD_SCANNER_INFO_UNIQ_ID);
cproject.remove(CCorePlugin.BUILDER_MODEL_ID);
cproject.remove(CCorePlugin.BINARY_PARSER_UNIQ_ID);
+
+ updateIndexers(cproject);
}
/* (non-Javadoc)
@@ -43,10 +49,37 @@
*/
public void update(ICDescriptor cproject, String extensionID)
throws CoreException {
- // TODO Auto-generated method stub
+
+ if (extensionID.equals(CCorePlugin.INDEXER_UNIQ_ID)) {
+ updateIndexers(cproject);
+ }
}
private void updateBinaryParsers(ICDescriptor cproject) throws CoreException {
+ }
+
+ private void updateIndexers(ICDescriptor cDescriptor) throws CoreException {
+ cDescriptor.remove(CCorePlugin.INDEXER_UNIQ_ID);
+ Preferences corePrefs = CCorePlugin.getDefault().getPluginPreferences();
+ String id = corePrefs.getString(CCorePlugin.PREF_INDEXER);
+ if (id != null && id.length() != 0) {
+ String[] ids = parseStringToArray(id);
+ for (int i = 0; i < ids.length; i++) {
+ cDescriptor.create(CCorePlugin.INDEXER_UNIQ_ID, ids[i]);
+ }
+ }
+ }
+
+ private String[] parseStringToArray(String syms) {
+ if (syms != null && syms.length() > 0) {
+ StringTokenizer tok = new StringTokenizer(syms, ";"); //$NON-NLS-1$
+ ArrayList list = new ArrayList(tok.countTokens());
+ while (tok.hasMoreElements()) {
+ list.add(tok.nextToken());
+ }
+ return (String[]) list.toArray(new String[list.size()]);
+ }
+ return new String[0];
}
}