diff options
author | Doug Schaefer | 2005-03-21 15:44:42 +0000 |
---|---|---|
committer | Doug Schaefer | 2005-03-21 15:44:42 +0000 |
commit | ec85b24cb74c0931fbb930008fb30a27f7f7fd73 (patch) | |
tree | 9e3fd5ac8a0fb723bc11b61f0901f40f4486a564 /core | |
parent | c63b26f8dcfd8acd099a2e18554b6f447885fc11 (diff) | |
download | org.eclipse.cdt-ec85b24cb74c0931fbb930008fb30a27f7f7fd73.tar.gz org.eclipse.cdt-ec85b24cb74c0931fbb930008fb30a27f7f7fd73.tar.xz org.eclipse.cdt-ec85b24cb74c0931fbb930008fb30a27f7f7fd73.zip |
Patch for Bog. Update the Index Manager to use the CDescriptor framework to manage which indexer to instantiate for each project.CDT_3_0_M5
Diffstat (limited to 'core')
12 files changed, 349 insertions, 825 deletions
diff --git a/core/org.eclipse.cdt.core.tests/indexer/org/eclipse/cdt/core/indexer/tests/DependencyTests.java b/core/org.eclipse.cdt.core.tests/indexer/org/eclipse/cdt/core/indexer/tests/DependencyTests.java index fd8933c820c..a495b3139dc 100644 --- a/core/org.eclipse.cdt.core.tests/indexer/org/eclipse/cdt/core/indexer/tests/DependencyTests.java +++ b/core/org.eclipse.cdt.core.tests/indexer/org/eclipse/cdt/core/indexer/tests/DependencyTests.java @@ -106,7 +106,7 @@ import org.eclipse.core.runtime.Platform; 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"); diff --git a/core/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/BaseSearchTest.java b/core/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/BaseSearchTest.java index 40b63b32cfe..33c4c6e02c3 100644 --- a/core/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/BaseSearchTest.java +++ b/core/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/BaseSearchTest.java @@ -18,6 +18,8 @@ import java.io.FileInputStream; 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 @@ public class BaseSearchTest extends TestCase implements ICSearchConstants { 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 @@ public class BaseSearchTest extends TestCase implements ICSearchConstants { //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 @@ public class BaseSearchTest extends TestCase implements ICSearchConstants { } protected void setUp() throws Exception { - } protected void tearDown() { diff --git a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java index 05f4cd1fd5a..5348a3f31a3 100644 --- a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java +++ b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java @@ -50,9 +50,6 @@ public class AutomatedIntegrationSuite extends TestSuite { 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()); diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/SourceIndexer.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/SourceIndexer.java index 0e0ccbf8b07..cd25c86e8f8 100644 --- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/SourceIndexer.java +++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/SourceIndexer.java @@ -16,8 +16,10 @@ import java.util.Collections; 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.Platform; 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 class SourceIndexer implements ICDTIndexer { 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 @@ public class SourceIndexer implements ICDTIndexer { } } - - - - /** * @param project * @return @@ -227,59 +229,65 @@ public class SourceIndexer implements ICDTIndexer { 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. @@ -334,56 +342,6 @@ public class SourceIndexer implements ICDTIndexer { } - - - 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{ private final IResource resource; public RemoveIndexMarkersJob( IResource resource, String name ){ diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/IndexManager.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/IndexManager.java index 6fea25aecf1..2adb98264b0 100644 --- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/IndexManager.java +++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/IndexManager.java @@ -16,6 +16,7 @@ import java.util.Set; 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.cdt.internal.core.search.processing.JobManager; 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 class IndexManager extends JobManager{ 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 @@ public class IndexManager extends JobManager{ indexer.indexJobFinishedNotification(job); } } - - - - /** * @param project * @param element @@ -277,13 +101,6 @@ public class IndexManager extends JobManager{ 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 @@ public class IndexManager extends JobManager{ 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 class IndexManager extends JobManager{ } - 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(); } - - //Make sure we're not putting null in map - if (indexer != null) - indexerMap.put(project,indexer); } - } 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(); + return indexer; + + }finally { + monitor.exitRead(); } - 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; - } } diff --git a/core/org.eclipse.cdt.core/plugin.xml b/core/org.eclipse.cdt.core/plugin.xml index 25557ba14a8..ab7e4c900e3 100644 --- a/core/org.eclipse.cdt.core/plugin.xml +++ b/core/org.eclipse.cdt.core/plugin.xml @@ -62,7 +62,7 @@ <!-- =================================================================================== --> <extension-point id="PathEntryContainerInitializer" name="%PathEntryContainerInitializer" schema="schema/PathEntryContainerInitializer.exsd"/> <extension-point id="CodeFormatter" name="%CodeFormatter.name" schema="schema/CodeFormatter.exsd"/> - <extension-point id="CIndexer" name="C/C++ Indexer" schema="schema/CIndexer.exsd"/> + <extension-point id="CIndexer" name="C/C++ Indexer" /> <!-- =================================================================================== --> <!-- Define the list of the Binary Parser provided by the CDT --> <!-- =================================================================================== --> @@ -528,13 +528,15 @@ <extension point="org.eclipse.core.runtime.preferences"> <initializer class="org.eclipse.cdt.internal.core.CCorePreferenceInitializer"/> </extension> - <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> <!-- =================================================================================== --> diff --git a/core/org.eclipse.cdt.core/schema/CIndexer.exsd b/core/org.eclipse.cdt.core/schema/CIndexer.exsd index f5ea1e0a226..c9806ca2d0d 100644 --- a/core/org.eclipse.cdt.core/schema/CIndexer.exsd +++ b/core/org.eclipse.cdt.core/schema/CIndexer.exsd @@ -39,38 +39,6 @@ </complexType>
</element>
- <element name="indexer">
- <complexType>
- <sequence>
- <element ref="indexer" minOccurs="1" maxOccurs="unbounded"/>
- </sequence>
- <attribute name="id" type="string" use="required">
- <annotation>
- <documentation>
- a unique name for this indexer
- </documentation>
- </annotation>
- </attribute>
- <attribute name="name" type="string" use="required">
- <annotation>
- <documentation>
- a name that will be used for this indexer in the UI
- </documentation>
- </annotation>
- </attribute>
- <attribute name="class" type="string" use="required">
- <annotation>
- <documentation>
- the class that implements <code>org.eclipse.cdt.core.index2.IIndexer</code>
- </documentation>
- <appInfo>
- <meta.attribute kind="java" basedOn="org.eclipse.cdt.core.index2.IIndexer"/>
- </appInfo>
- </annotation>
- </attribute>
- </complexType>
- </element>
-
<annotation>
<appInfo>
<meta.section type="since"/>
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CCorePlugin.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CCorePlugin.java index 68374cc19cb..6aafc8bfbde 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CCorePlugin.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CCorePlugin.java @@ -76,6 +76,12 @@ public class CCorePlugin extends Plugin { 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 diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CUIMessages.properties b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CUIMessages.properties index bce31746189..fce98b07d8a 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CUIMessages.properties +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CUIMessages.properties @@ -62,6 +62,7 @@ IndexerOptions.problemReporting = C/C++ Index problem reporting 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 diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/IndexerBlock.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/IndexerBlock.java index cd188c16054..bfc394803f2 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/IndexerBlock.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/IndexerBlock.java @@ -17,7 +17,8 @@ import java.util.List; 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.CoreException; 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.layout.GridLayout; 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 @@ public class IndexerBlock extends AbstractCOptionPage { private Composite parentComposite; private ICOptionPage currentPage; - + String initialSelected; + public IndexerBlock(){ super(INDEXER_LABEL); setDescription(INDEXER_DESCRIPTION); @@ -104,10 +106,6 @@ public class IndexerBlock extends AbstractCOptionPage { } } - - /* (non-Javadoc) - * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite) - */ public void createControl(Composite parent) { @@ -147,9 +145,6 @@ public class IndexerBlock extends AbstractCOptionPage { } parent.layout(true); } - - - /** * */ @@ -176,7 +171,6 @@ public class IndexerBlock extends AbstractCOptionPage { setCurrentPage(page); } - /** * @param page */ @@ -184,15 +178,15 @@ public class IndexerBlock extends AbstractCOptionPage { currentPage = page; } - - protected String getCurrentIndexPageId() { String selectedIndexPageName = getSelectedIndexerID(); if (selectedIndexPageName == null) return null; + String selectedIndexPageId = getIndexerPageId(selectedIndexPageName); + return selectedIndexPageId; } /** @@ -239,9 +233,6 @@ public class IndexerBlock extends AbstractCOptionPage { return true; } - - - /** * Adds all the contributed Indexer Pages to a map */ @@ -252,7 +243,7 @@ public class IndexerBlock extends AbstractCOptionPage { 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 class IndexerBlock extends AbstractCOptionPage { } 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 @@ public class IndexerBlock extends AbstractCOptionPage { * 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 @@ public class IndexerBlock extends AbstractCOptionPage { 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 class IndexerBlock extends AbstractCOptionPage { 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 @@ public class IndexerBlock extends AbstractCOptionPage { } - 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; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/IndexerOptionPropertyPage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/IndexerOptionPropertyPage.java index b485707f048..db7195919ef 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/IndexerOptionPropertyPage.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/IndexerOptionPropertyPage.java @@ -13,6 +13,7 @@ package org.eclipse.cdt.ui.dialogs; 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 class IndexerOptionPropertyPage extends PropertyPage { } 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; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/SourceIndexerBlock.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/SourceIndexerBlock.java index 181197215af..421bc5506f6 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/SourceIndexerBlock.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/SourceIndexerBlock.java @@ -13,25 +13,29 @@ package org.eclipse.cdt.ui.dialogs; 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 @@ public class SourceIndexerBlock extends AbstractIndexerPage { 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 class SourceIndexerBlock extends AbstractIndexerPage { } - 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 ) { + private String getIndexerEnabledString(){ + if (indexerEnabled.getSelection()) + return "true"; //$NON-NLS-1$ - Element indexEnabled = doc.createElement(SourceIndexer.INDEXER_ENABLED); - Boolean tempValue= new Boolean(indexerEnabled); - - 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 @@ public class SourceIndexerBlock extends AbstractIndexerPage { 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); - } - - 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); + public void loadPersistedValues(IProject project) throws CoreException { + + 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 @@ public class SourceIndexerBlock extends AbstractIndexerPage { 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; - } } |