diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/MakeProject.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/MakeProject.java index 5be42ad2929..6c49829f53b 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/MakeProject.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/MakeProject.java @@ -26,12 +26,17 @@ public class MakeProject implements ICOwner { 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 @@ public class MakeProject implements ICOwner { } } } - + + 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) { diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ManagedMakeProject.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ManagedMakeProject.java index bc1d7e2fd15..e42a117c498 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ManagedMakeProject.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ManagedMakeProject.java @@ -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 @@ public class ManagedMakeProject implements ICOwner { 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 class ManagedMakeProject implements ICOwner { */ 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]; + } } 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; -// 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) { - } + 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(); + } + } + } - return false; + + } catch (CoreException e) {} + + return indexEnabled; } public int indexProblemsEnabled(IProject project) { - Integer value = null; + if( project == null || !project.exists() || !project.isOpen() ) + return 0; + + int indexProblemsEnabled = 0; try { - value = (Integer) project.getSessionProperty(problemsActivationKey); - } catch (CoreException e) { - } - - if (value != null) - return value.intValue(); - - 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; - //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) { - } + 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(); + } + } + } - return 0; + + } catch (CoreException e) {} + + 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; - } - - 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(); + 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(); } } - - - - - /** - * - */ - 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 0) + indexer = (ICDTIndexer) cextensions[0].createExtension(); - - 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; - + } catch (CoreException e){} + + if (indexer == 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(); - + indexer = getDefaultIndexer(project); } 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(); - } - } - - 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 ); - } - break; - } - child = child.getNextSibling(); - } - } - - return strInt; - } - -protected ICDTIndexer getIndexer(String indexerId) { - CDTIndexer configElement = (CDTIndexer) contributedIndexerMap.get(indexerId); - if (configElement != null) { - try { - return configElement.getIndexer(); - } catch (CoreException e) {} - } - return null; + 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 @@ - + @@ -528,13 +528,15 @@ - - - + + + + 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 @@ - - - - - - - - - a unique name for this indexer - - - - - - - a name that will be used for this indexer in the UI - - - - - - - the class that implements <code>org.eclipse.cdt.core.index2.IIndexer</code> - - - - - - - - - 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,50 +313,6 @@ public class IndexerBlock extends AbstractCOptionPage { } public void performApply(IProgressMonitor monitor) throws CoreException { - IProject newProject = null; - newProject = getContainer().getProject(); - - persistIndexerSettings(newProject, monitor); - } - - /** - * Persists BasicIndexerBlock settings to disk and allows current indexer page to persist settings - * This is needed since we need to pass in the project if we are trying to save changes made to the - * 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 - if (currentPage != null){ - currentPage.performApply(monitor); - } - } - - public void performDefaults() { - // TODO Auto-generated method stub - - } - - /** - * @return - */ - public boolean isIndexEnabled() { - // TODO Auto-generated method stub - 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 @@ -380,33 +327,91 @@ public class IndexerBlock extends AbstractCOptionPage { 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(); + 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(); + } + + /** + * Persists BasicIndexerBlock settings to disk and allows current indexer page to persist settings + * This is needed since we need to pass in the project if we are trying to save changes made to the + * property page. + */ + public void persistIndexerSettings(IProject project, IProgressMonitor monitor) throws CoreException{ + if (currentPage instanceof AbstractIndexerPage) + ((AbstractIndexerPage)currentPage).setCurrentProject(project); + + this.performApply(monitor); + /*//Give the chosen indexer a chance to persist its values + if (currentPage != null){ + currentPage.performApply(monitor);*/ + + } + + public void performDefaults() { + // TODO Auto-generated method stub + } + + /** + * @return + */ + public boolean isIndexEnabled() { + // TODO Auto-generated method stub + return false; } /** @@ -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); - } + public void loadPersistedValues(IProject project) throws CoreException { - return indexValue.booleanValue(); - } + 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(); + } - 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); + 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; - } }