mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-23 17:05:26 +02:00
- upgrade mechanism for old indexer projects
- a new "No Indexer" null indexer used for projects that don't need indexing - temporary modification to the Automated suite to get around TypeCache manager kicking off unwanted upgrades during JUnits
This commit is contained in:
parent
44ccc9fdac
commit
402cb165c3
7 changed files with 308 additions and 15 deletions
|
@ -9,6 +9,7 @@ package org.eclipse.cdt.core.suite;
|
|||
import junit.framework.Test;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.build.managed.tests.StandardBuildTests;
|
||||
import org.eclipse.cdt.core.cdescriptor.tests.CDescriptorTests;
|
||||
import org.eclipse.cdt.core.filetype.tests.ResolverTests;
|
||||
|
@ -50,6 +51,9 @@ public class AutomatedIntegrationSuite extends TestSuite {
|
|||
public static Test suite() {
|
||||
final AutomatedIntegrationSuite suite = new AutomatedIntegrationSuite();
|
||||
|
||||
//TODO: BOG take this out once TypeCache issues resolved
|
||||
disableIndexUpgrades();
|
||||
|
||||
// Add all success tests
|
||||
suite.addTest(CDescriptorTests.suite());
|
||||
//suite.addTest(GCCErrorParserTests.suite());
|
||||
|
@ -75,5 +79,13 @@ public class AutomatedIntegrationSuite extends TestSuite {
|
|||
|
||||
return suite;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static void disableIndexUpgrades() {
|
||||
CCorePlugin.getDefault().getCoreModel().getIndexManager().disableUpgrades();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -34,6 +34,7 @@ import org.eclipse.core.runtime.IExtensionPoint;
|
|||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.Platform;
|
||||
import org.eclipse.core.runtime.QualifiedName;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
|
||||
|
@ -46,6 +47,8 @@ public class IndexManager extends JobManager{
|
|||
public final static String INDEXERID = "indexerID"; //$NON-NLS-1$
|
||||
public final static QualifiedName indexerIDKey = new QualifiedName(INDEX_MODEL_ID, INDEXERID);
|
||||
|
||||
public static final String nullIndexerID = "org.eclipse.cdt.core.nullindexer"; //$NON-NLS-1$
|
||||
|
||||
public static final String CDT_INDEXER = "cdt_indexer"; //$NON-NLS-1$
|
||||
public static final String INDEXER_ID = "indexerID"; //$NON-NLS-1$
|
||||
public static final String INDEXER_ID_VALUE = "indexerIDValue"; //$NON-NLS-1$
|
||||
|
@ -58,6 +61,12 @@ public class IndexManager extends JobManager{
|
|||
//Map of Persisted Indexers; keyed by project
|
||||
private HashMap indexerMap = null;
|
||||
|
||||
//Upgrade index version
|
||||
private boolean upgradeIndexEnabled = false;
|
||||
private int upgradeIndexProblems = 0;
|
||||
private boolean upgradeProjects = true;
|
||||
|
||||
|
||||
/**
|
||||
* Create an indexer only on request
|
||||
*/
|
||||
|
@ -343,7 +352,15 @@ public class IndexManager extends JobManager{
|
|||
}
|
||||
|
||||
//Make sure that we have an indexer ID
|
||||
if (indexerID == null)
|
||||
if (indexerID == null && upgradeProjects) {
|
||||
//No persisted info on file? Must be old project - run temp. upgrade
|
||||
indexerID = doProjectUpgrade(project);
|
||||
doSourceIndexerUpgrade(project);
|
||||
}
|
||||
|
||||
//If we're asking for the null indexer,return null
|
||||
if (indexerID == null ||
|
||||
indexerID.equals(nullIndexerID))
|
||||
return null;
|
||||
|
||||
//Create the indexer and store it
|
||||
|
@ -354,7 +371,178 @@ public class IndexManager extends JobManager{
|
|||
return indexer;
|
||||
}
|
||||
|
||||
protected ICDTIndexer getIndexer(String indexerId) {
|
||||
/**
|
||||
* @param project
|
||||
*/
|
||||
private void doSourceIndexerUpgrade(IProject project) {
|
||||
ICDescriptor descriptor = null;
|
||||
Element rootElement = null;
|
||||
IProject newProject = null;
|
||||
|
||||
try {
|
||||
newProject = project;
|
||||
descriptor = CCorePlugin.getDefault().getCProjectDescription(newProject, true);
|
||||
rootElement = descriptor.getProjectData(SourceIndexer.SOURCE_INDEXER);
|
||||
|
||||
// Clear out all current children
|
||||
Node child = rootElement.getFirstChild();
|
||||
while (child != null) {
|
||||
rootElement.removeChild(child);
|
||||
child = rootElement.getFirstChild();
|
||||
}
|
||||
Document doc = rootElement.getOwnerDocument();
|
||||
|
||||
|
||||
saveIndexerEnabled(upgradeIndexEnabled, rootElement, doc);
|
||||
saveIndexerProblemsEnabled( upgradeIndexProblems, rootElement, doc );
|
||||
|
||||
descriptor.saveProjectData();
|
||||
|
||||
//Update project session property
|
||||
|
||||
project.setSessionProperty(SourceIndexer.activationKey,new Boolean(upgradeIndexEnabled));
|
||||
project.setSessionProperty(SourceIndexer.problemsActivationKey, new Integer( upgradeIndexProblems ));
|
||||
|
||||
} catch (CoreException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
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 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) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
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 {
|
||||
|
@ -377,6 +565,15 @@ public class IndexManager extends JobManager{
|
|||
indexer.notifyIdle(idlingTime);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void disableUpgrades() {
|
||||
upgradeProjects = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1327,6 +1327,11 @@
|
|||
indexerID="org.eclipse.cdt.core.originalsourceindexer"
|
||||
name="Original C/C++ Indexer"
|
||||
id="org.eclipse.cdt.ui.originalSourceIndexerUI"/>
|
||||
<indexerUI
|
||||
class="org.eclipse.cdt.ui.dialogs.NullIndexerBlock"
|
||||
indexerID="org.eclipse.cdt.core.nullindexer"
|
||||
name="No Indexer"
|
||||
id="org.eclipse.cdt.ui.nullindexerUI"/>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.cdt.ui.completionContributors">
|
||||
|
|
|
@ -216,7 +216,7 @@ public class IndexerBlock extends AbstractCOptionPage {
|
|||
}
|
||||
});
|
||||
//Add button
|
||||
ControlFactory.createPushButton(group,"Info ...");
|
||||
ControlFactory.createPushButton(group,"Info ..."); //$NON-NLS-1$
|
||||
|
||||
// fill the combobox and set the initial value
|
||||
for (Iterator items = getIndexerPageIdList().iterator(); items.hasNext();) {
|
||||
|
@ -227,6 +227,15 @@ public class IndexerBlock extends AbstractCOptionPage {
|
|||
}
|
||||
}
|
||||
|
||||
String[] indexerList = indexersComboBox.getItems();
|
||||
int selectedIndex = 0;
|
||||
for (int i=0; i<indexerList.length; i++){
|
||||
if (indexerList[i].equals("No Indexer")) //$NON-NLS-1$
|
||||
selectedIndex = i;
|
||||
}
|
||||
|
||||
indexersComboBox.select(selectedIndex);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -328,6 +337,9 @@ public class IndexerBlock extends AbstractCOptionPage {
|
|||
|
||||
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);
|
||||
|
@ -424,7 +436,7 @@ public class IndexerBlock extends AbstractCOptionPage {
|
|||
rootElement.appendChild(indexerIDElement);
|
||||
|
||||
//Save the indexer UI id
|
||||
Element indexerUIIDElement = doc.createElement(INDEXER_UI);
|
||||
Element indexerUIIDElement = doc.createElement(INDEXER_UI);
|
||||
indexerUIIDElement.setAttribute(INDEXER_UI_VALUE,indexerUIID);
|
||||
rootElement.appendChild(indexerUIIDElement);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
/**********************************************************************
|
||||
* Copyright (c) 2005 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM - Initial API and implementation
|
||||
**********************************************************************/
|
||||
package org.eclipse.cdt.ui.dialogs;
|
||||
|
||||
import org.eclipse.cdt.ui.index.AbstractIndexerPage;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
|
||||
/**
|
||||
* @author Bogdan Gheorghe
|
||||
*/
|
||||
public class NullIndexerBlock extends AbstractIndexerPage {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.ui.index.AbstractIndexerPage#initialize(org.eclipse.core.resources.IProject)
|
||||
*/
|
||||
public void initialize(IProject currentProject) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.ui.dialogs.ICOptionPage#performApply(org.eclipse.core.runtime.IProgressMonitor)
|
||||
*/
|
||||
public void performApply(IProgressMonitor monitor) throws CoreException {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.ui.dialogs.ICOptionPage#performDefaults()
|
||||
*/
|
||||
public void performDefaults() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
|
||||
*/
|
||||
public void createControl(Composite parent) {
|
||||
setControl(parent);
|
||||
}
|
||||
|
||||
}
|
|
@ -13,8 +13,8 @@ package org.eclipse.cdt.ui.dialogs;
|
|||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.ICDescriptor;
|
||||
import org.eclipse.cdt.core.index.ICDTIndexer;
|
||||
import org.eclipse.cdt.internal.core.index.sourceindexer.SourceIndexer;
|
||||
import org.eclipse.cdt.internal.core.search.indexing.IndexManager;
|
||||
import org.eclipse.cdt.internal.ui.CUIMessages;
|
||||
import org.eclipse.cdt.ui.index.AbstractIndexerPage;
|
||||
import org.eclipse.cdt.utils.ui.controls.ControlFactory;
|
||||
|
@ -51,16 +51,18 @@ public class SourceIndexerBlock extends AbstractIndexerPage {
|
|||
* @see org.eclipse.cdt.ui.dialogs.ICOptionPage#performApply(org.eclipse.core.runtime.IProgressMonitor)
|
||||
*/
|
||||
public void performApply(IProgressMonitor monitor) throws CoreException {
|
||||
|
||||
IProject newProject = null;
|
||||
newProject = getContainer().getProject();
|
||||
|
||||
this.persistIndexerValues(newProject);
|
||||
|
||||
this.persistIndexerValues(currentProject);
|
||||
|
||||
boolean indexProject = getIndexerValue();
|
||||
|
||||
//if (indexProject && newProject != null)
|
||||
//SourceIndexer.indexAll()
|
||||
if ((indexProject != oldIndexerValue)
|
||||
&& (currentProject != null)
|
||||
&& indexProject) {
|
||||
ICDTIndexer indexer = CCorePlugin.getDefault().getCoreModel().getIndexManager().getIndexerForProject(currentProject);
|
||||
if (indexer instanceof SourceIndexer)
|
||||
((SourceIndexer) indexer).indexAll(currentProject);
|
||||
}
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.ui.dialogs.ICOptionPage#performDefaults()
|
||||
|
@ -176,6 +178,7 @@ public class SourceIndexerBlock extends AbstractIndexerPage {
|
|||
try {
|
||||
oldIndexerValue = getIndexerEnabled(project);
|
||||
oldIndexerProblemsValue = getIndexerProblemsEnabled( project );
|
||||
this.currentProject = project;
|
||||
} catch (CoreException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ import org.eclipse.core.resources.IProject;
|
|||
*/
|
||||
public abstract class AbstractIndexerPage extends AbstractCOptionPage {
|
||||
|
||||
protected IProject currentProject;
|
||||
|
||||
protected AbstractIndexerPage() {
|
||||
super();
|
||||
|
@ -28,5 +29,13 @@ public abstract class AbstractIndexerPage extends AbstractCOptionPage {
|
|||
* @param currentProject - the project that this page is being created for
|
||||
*/
|
||||
abstract public void initialize(IProject currentProject);
|
||||
|
||||
|
||||
|
||||
|
||||
public IProject getCurrentProject() {
|
||||
return currentProject;
|
||||
}
|
||||
public void setCurrentProject(IProject currentProject) {
|
||||
this.currentProject = currentProject;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue