1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-04 23:05:47 +02:00

169668: add unit tests + fix bugs

This commit is contained in:
Andrew Ferguson 2007-03-22 18:50:26 +00:00
parent 6047a73ed7
commit 250d34926b
13 changed files with 419 additions and 51 deletions

View file

@ -0,0 +1,283 @@
/*******************************************************************************
* Copyright (c) 2007 Symbian Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Andrew Ferguson (Symbian) - Initial implementation
*******************************************************************************/
package org.eclipse.cdt.internal.pdom.tests;
import java.io.File;
import java.net.URI;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
import junit.framework.Test;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.IPDOMManager;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.index.IIndexLocationConverter;
import org.eclipse.cdt.core.index.IIndexerStateEvent;
import org.eclipse.cdt.core.index.IIndexerStateListener;
import org.eclipse.cdt.core.index.IndexFilter;
import org.eclipse.cdt.core.index.ResourceContainerRelativeLocationConverter;
import org.eclipse.cdt.core.index.URIRelativeLocationConverter;
import org.eclipse.cdt.core.index.export.ExternalExportProjectProvider;
import org.eclipse.cdt.core.index.export.IExportProjectProvider;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.testplugin.CProjectHelper;
import org.eclipse.cdt.core.testplugin.CTestPlugin;
import org.eclipse.cdt.internal.core.index.IIndexFragment;
import org.eclipse.cdt.internal.core.pdom.WritablePDOM;
import org.eclipse.cdt.internal.core.pdom.export.GeneratePDOMApplication;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.equinox.app.IApplicationContext;
import org.osgi.framework.Bundle;
/**
* Tests the GeneratePDOMApplication
*/
public class GeneratePDOMApplicationTest extends PDOMTestBase {
private static final String SDK_VERSION = "com.acme.sdk.version";
private static final String ACME_SDK_ID= "com.acme.sdk.4.0.1";
private static List toDeleteOnTearDown= new ArrayList();
private final static String s= "resources/pdomtests/generatePDOMTests/project1";
private URI baseURI;
public static Test suite() {
return suite(GeneratePDOMApplicationTest.class);
}
protected void setUp() throws Exception {
toDeleteOnTearDown.clear();
baseURI= new URI("file:///base/"); // unimportant what the value is
}
protected void tearDown() throws Exception {
for(Iterator i= toDeleteOnTearDown.iterator(); i.hasNext(); ) {
ICProject cproject= (ICProject) i.next();
cproject.getProject().delete(true, new NullProgressMonitor());
}
}
public void testBrokenExportProjectProvider1() throws Exception {
try {
File target= File.createTempFile("test", "pdom");
doGenerate(new String[] {
GeneratePDOMApplication.OPT_TARGET, target.getAbsolutePath(),
GeneratePDOMApplication.OPT_PROJECTPROVIDER, TestProjectProvider1.class.getName()
});
fail("Expected exception - IExportProjectProvider implementation returns null for createProject");
} catch(CoreException ce) {
// correct behaviour
}
}
public void testBrokenExportProjectProvider2() throws Exception {
try {
File target= File.createTempFile("test", "pdom");
doGenerate(new String[] {
GeneratePDOMApplication.OPT_TARGET, target.getAbsolutePath(),
GeneratePDOMApplication.OPT_PROJECTPROVIDER, TestProjectProvider2.class.getName()
});
fail("Expected exception - IExportProjectProvider implementation returns null for getLocationConverter");
} catch(CoreException ce) {
// correct behaviour
}
}
public void testSimpleExportProjectProvider1() throws Exception {
File target= File.createTempFile("test", "pdom");
doGenerate(new String[] {
GeneratePDOMApplication.OPT_TARGET, target.getAbsolutePath(),
GeneratePDOMApplication.OPT_PROJECTPROVIDER, TestProjectProvider3.class.getName()
});
assertTrue(target.exists());
WritablePDOM wpdom= new WritablePDOM(target, new URIRelativeLocationConverter(baseURI));
verifyProject1Content(wpdom);
String fid= wpdom.getProperty(IIndexFragment.PROPERTY_FRAGMENT_ID);
assertNotNull(fid);
assertTrue(fid.startsWith("export")); // check for default export id
}
public void testSimpleExportProjectProvider2() throws Exception {
File target= File.createTempFile("test", "pdom");
doGenerate(new String[] {
GeneratePDOMApplication.OPT_TARGET, target.getAbsolutePath(),
GeneratePDOMApplication.OPT_PROJECTPROVIDER, TestProjectProvider4.class.getName()
});
assertTrue(target.exists());
WritablePDOM wpdom= new WritablePDOM(target, new URIRelativeLocationConverter(baseURI));
verifyProject1Content(wpdom);
String fid= wpdom.getProperty(IIndexFragment.PROPERTY_FRAGMENT_ID);
assertNotNull(fid);
assertEquals(ACME_SDK_ID, fid); // check for default export id
String sdkVer= wpdom.getProperty(SDK_VERSION);
assertNotNull(sdkVer);
assertEquals("4.0.1", sdkVer); // check for default export id
}
public void testExternalExportProjectProvider_BadCmdLine1() throws Exception {
File target= File.createTempFile("test", "pdom");
try {
doGenerate(new String[] {
GeneratePDOMApplication.OPT_TARGET, target.getAbsolutePath(),
GeneratePDOMApplication.OPT_PROJECTPROVIDER, ExternalExportProjectProvider.class.getName()
});
assertTrue(target.exists());
fail("Expected failure: -source must be specified");
} catch(CoreException ce) {
// correct behaviour
}
}
public void testExternalExportProjectProvider_BadCmdLine2() throws Exception {
File target= File.createTempFile("test", "pdom");
TestProjectProvider4 tpp4= new TestProjectProvider4();
ICProject cproject= tpp4.createProject();
try {
doGenerate(new String[] {
GeneratePDOMApplication.OPT_TARGET, target.getAbsolutePath(),
GeneratePDOMApplication.OPT_PROJECTPROVIDER, ExternalExportProjectProvider.class.getName(),
ExternalExportProjectProvider.OPT_SOURCE, cproject.getProject().getLocation().toFile().getAbsolutePath()
});
assertTrue(target.exists());
fail("Expected failure: -id must be specified");
} catch(CoreException ce) {
// correct behaviour
}
}
public void testExternalExportProjectProvider() throws Exception {
File target= File.createTempFile("test", "pdom");
final int[] stateCount = new int[1];
IIndexerStateListener listener= new IIndexerStateListener() {
public void indexChanged(IIndexerStateEvent event) {
stateCount[0]++;
}
};
CCorePlugin.getIndexManager().addIndexerStateListener(listener);
URL url= FileLocator.find(CTestPlugin.getDefault().getBundle(), new Path(s), null);
String baseDir= FileLocator.toFileURL(url).getFile();
doGenerate(new String[] {
GeneratePDOMApplication.OPT_TARGET, target.getAbsolutePath(),
GeneratePDOMApplication.OPT_PROJECTPROVIDER, ExternalExportProjectProvider.class.getName(),
ExternalExportProjectProvider.OPT_SOURCE, baseDir,
ExternalExportProjectProvider.OPT_FRAGMENT_ID, "hello.world"
});
assertTrue(target.exists());
WritablePDOM wpdom= new WritablePDOM(target, new URIRelativeLocationConverter(baseURI));
verifyProject1Content(wpdom);
String fid= wpdom.getProperty(IIndexFragment.PROPERTY_FRAGMENT_ID);
assertNotNull(fid);
assertEquals("hello.world", fid); // check for default export id
assertTrue(stateCount[0] == 2);
}
public void verifyProject1Content(WritablePDOM wpdom) throws CoreException {
IBinding[] bindings= wpdom.findBindings(Pattern.compile(".*foo.*"), false, IndexFilter.ALL, PROGRESS);
assertEquals(1, bindings.length);
bindings= wpdom.findBindings(Pattern.compile(".*bar.*"), false, IndexFilter.ALL, PROGRESS);
assertEquals(1, bindings.length);
}
private void doGenerate(String[] args) throws CoreException {
GeneratePDOMApplication app = new GeneratePDOMApplication();
IApplicationContext ac= new MockApplicationContext(args);
app.start(ac);
}
/*
* IExportProjectProvider test implementations
*/
public static class TestProjectProvider1 implements IExportProjectProvider {
public ICProject createProject() throws CoreException {return null;}
public Map getExportProperties() {return null;}
public IIndexLocationConverter getLocationConverter(ICProject cproject) {return null;}
public void setApplicationArguments(String[] arguments) {}
}
public static class TestProjectProvider2 implements IExportProjectProvider {
public ICProject createProject() throws CoreException {
ICProject cproject= CProjectHelper.createCCProject("test"+System.currentTimeMillis(), null, IPDOMManager.ID_NO_INDEXER);
toDeleteOnTearDown.add(cproject);
CProjectHelper.importSourcesFromPlugin(cproject, CTestPlugin.getDefault().getBundle(), s);
return cproject;
}
public Map getExportProperties() {return null;}
public IIndexLocationConverter getLocationConverter(ICProject cproject) {return null;}
public void setApplicationArguments(String[] arguments) {}
}
public static class TestProjectProvider3 implements IExportProjectProvider {
public ICProject createProject() throws CoreException {
ICProject cproject= CProjectHelper.createCCProject("test"+System.currentTimeMillis(), null, IPDOMManager.ID_NO_INDEXER);
toDeleteOnTearDown.add(cproject);
CProjectHelper.importSourcesFromPlugin(cproject, CTestPlugin.getDefault().getBundle(), s);
return cproject;
}
public Map getExportProperties() {return null;}
public IIndexLocationConverter getLocationConverter(ICProject cproject) {
return new ResourceContainerRelativeLocationConverter(cproject.getProject());
}
public void setApplicationArguments(String[] arguments) {}
}
public static class TestProjectProvider4 implements IExportProjectProvider {
public ICProject createProject() throws CoreException {
ICProject cproject= CProjectHelper.createCCProject("test"+System.currentTimeMillis(), null, IPDOMManager.ID_NO_INDEXER);
toDeleteOnTearDown.add(cproject);
CProjectHelper.importSourcesFromPlugin(cproject, CTestPlugin.getDefault().getBundle(), s);
return cproject;
}
public Map getExportProperties() {
Map map= new HashMap();
map.put(SDK_VERSION, "4.0.1");
map.put(IIndexFragment.PROPERTY_FRAGMENT_ID, ACME_SDK_ID);
return map;
}
public IIndexLocationConverter getLocationConverter(ICProject cproject) {
return new ResourceContainerRelativeLocationConverter(cproject.getProject());
}
public void setApplicationArguments(String[] arguments) {}
}
}
class MockApplicationContext implements IApplicationContext {
Map arguments;
MockApplicationContext(String[] appArgs) {
arguments= new HashMap();
arguments.put(APPLICATION_ARGS, appArgs);
}
public void applicationRunning() {}
public Map getArguments() {return arguments;}
public String getBrandingApplication() {return null;}
public Bundle getBrandingBundle() {return null;}
public String getBrandingDescription() {return null;}
public String getBrandingId() {return null;}
public String getBrandingName() {return null;}
public String getBrandingProperty(String key) {return null;}
}

View file

@ -39,6 +39,7 @@ public class PDOMTests extends TestSuite {
suite.addTest(OverloadsWithinCommonHeaderTests.suite()); suite.addTest(OverloadsWithinCommonHeaderTests.suite());
suite.addTest(BTreeTests.suite()); suite.addTest(BTreeTests.suite());
suite.addTest(FilesOnReindexTests.suite()); suite.addTest(FilesOnReindexTests.suite());
suite.addTest(GeneratePDOMApplicationTest.suite());
suite.addTest(CPPFieldTests.suite()); suite.addTest(CPPFieldTests.suite());
suite.addTest(CPPFunctionTests.suite()); suite.addTest(CPPFunctionTests.suite());

View file

@ -32,6 +32,18 @@
<ReadOnlyPDOMProvider <ReadOnlyPDOMProvider
class="org.eclipse.cdt.core.internal.index.provider.test.DummyProvider1"> class="org.eclipse.cdt.core.internal.index.provider.test.DummyProvider1">
</ReadOnlyPDOMProvider> </ReadOnlyPDOMProvider>
<ExportProjectProvider
class="org.eclipse.cdt.internal.pdom.tests.GeneratePDOMApplicationTest$TestProjectProvider1">
</ExportProjectProvider>
<ExportProjectProvider
class="org.eclipse.cdt.internal.pdom.tests.GeneratePDOMApplicationTest$TestProjectProvider2">
</ExportProjectProvider>
<ExportProjectProvider
class="org.eclipse.cdt.internal.pdom.tests.GeneratePDOMApplicationTest$TestProjectProvider3">
</ExportProjectProvider>
<ExportProjectProvider
class="org.eclipse.cdt.internal.pdom.tests.GeneratePDOMApplicationTest$TestProjectProvider4">
</ExportProjectProvider>
</extension> </extension>
</plugin> </plugin>

View file

@ -0,0 +1,7 @@
class A {
public:
class B {};
int c;
A* foo(B b) {};
};

View file

@ -0,0 +1,7 @@
#include "a/b/c/d e/this.h"
void bar() {
A a;
a.foo(*new A::B());
}

View file

@ -65,6 +65,7 @@ Export-Package: org.eclipse.cdt.core,
org.eclipse.cdt.internal.core.pdom.dom;x-friends:="org.eclipse.cdt.ui", org.eclipse.cdt.internal.core.pdom.dom;x-friends:="org.eclipse.cdt.ui",
org.eclipse.cdt.internal.core.pdom.dom.c;x-internal:=true, org.eclipse.cdt.internal.core.pdom.dom.c;x-internal:=true,
org.eclipse.cdt.internal.core.pdom.dom.cpp;x-internal:=true, org.eclipse.cdt.internal.core.pdom.dom.cpp;x-internal:=true,
org.eclipse.cdt.internal.core.pdom.export,
org.eclipse.cdt.internal.core.pdom.indexer;x-friends:="org.eclipse.cdt.ui", org.eclipse.cdt.internal.core.pdom.indexer;x-friends:="org.eclipse.cdt.ui",
org.eclipse.cdt.internal.core.pdom.indexer.fast;x-internal:=true, org.eclipse.cdt.internal.core.pdom.indexer.fast;x-internal:=true,
org.eclipse.cdt.internal.core.pdom.indexer.full;x-internal:=true, org.eclipse.cdt.internal.core.pdom.indexer.full;x-internal:=true,

View file

@ -31,6 +31,9 @@ import org.eclipse.cdt.core.index.ResourceContainerRelativeLocationConverter;
import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.IPathEntry; import org.eclipse.cdt.core.model.IPathEntry;
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
import org.eclipse.cdt.core.settings.model.extension.impl.CDefaultConfigurationData;
import org.eclipse.cdt.internal.core.index.IIndexFragment; import org.eclipse.cdt.internal.core.index.IIndexFragment;
import org.eclipse.cdt.internal.core.pdom.indexer.IndexerPreferences; import org.eclipse.cdt.internal.core.pdom.indexer.IndexerPreferences;
import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.IFolder;
@ -58,9 +61,9 @@ import org.eclipse.core.runtime.Path;
public class ExternalExportProjectProvider extends AbstractExportProjectProvider implements IExportProjectProvider { public class ExternalExportProjectProvider extends AbstractExportProjectProvider implements IExportProjectProvider {
private static final String ORG_ECLIPSE_CDT_CORE_INDEX_EXPORT_DATESTAMP = "org.eclipse.cdt.core.index.export.datestamp"; //$NON-NLS-1$ private static final String ORG_ECLIPSE_CDT_CORE_INDEX_EXPORT_DATESTAMP = "org.eclipse.cdt.core.index.export.datestamp"; //$NON-NLS-1$
private static final String CONTENT = "content"; //$NON-NLS-1$ private static final String CONTENT = "content"; //$NON-NLS-1$
protected static final String ARG_SOURCE = "-source"; //$NON-NLS-1$ public static final String OPT_SOURCE = "-source"; //$NON-NLS-1$
protected static final String ARG_INCLUDE = "-include"; //$NON-NLS-1$ public static final String OPT_INCLUDE = "-include"; //$NON-NLS-1$
protected static final String ARG_FRAGMENT_ID = "-id"; //$NON-NLS-1$ public static final String OPT_FRAGMENT_ID = "-id"; //$NON-NLS-1$
private IFolder content; private IFolder content;
private String fragmentId; private String fragmentId;
@ -75,21 +78,21 @@ public class ExternalExportProjectProvider extends AbstractExportProjectProvider
*/ */
public ICProject createProject() throws CoreException { public ICProject createProject() throws CoreException {
// -source // -source
File source= new File(getSingleString(ARG_SOURCE)); File source= new File(getSingleString(OPT_SOURCE));
if(!source.exists()) { if(!source.exists()) {
fail(MessageFormat.format(Messages.ExternalContentPEM_LocationToIndexNonExistent, new Object[] {source})); fail(MessageFormat.format(Messages.ExternalContentPEM_LocationToIndexNonExistent, new Object[] {source}));
} }
// -include // -include
List includeFiles= new ArrayList(); List includeFiles= new ArrayList();
if(isPresent(ARG_INCLUDE)) { if(isPresent(OPT_INCLUDE)) {
includeFiles.addAll(getParameters(ARG_INCLUDE)); includeFiles.addAll(getParameters(OPT_INCLUDE));
} }
// -id // -id
fragmentId= getSingleString(ARG_FRAGMENT_ID); fragmentId= getSingleString(OPT_FRAGMENT_ID);
return createCProject("__"+System.currentTimeMillis(), source, IPDOMManager.ID_FAST_INDEXER, includeFiles); //$NON-NLS-1$ return createCCProject("__"+System.currentTimeMillis(), source, includeFiles); //$NON-NLS-1$
} }
/** /**
@ -109,10 +112,9 @@ public class ExternalExportProjectProvider extends AbstractExportProjectProvider
* @return a new project * @return a new project
* @throws CoreException * @throws CoreException
*/ */
private ICProject createCProject( private ICProject createCCProject(
final String projectName, final String projectName,
final File location, final File location,
final String indexerID,
final List includeFiles final List includeFiles
) throws CoreException { ) throws CoreException {
final IWorkspace ws = ResourcesPlugin.getWorkspace(); final IWorkspace ws = ResourcesPlugin.getWorkspace();
@ -159,16 +161,26 @@ public class ExternalExportProjectProvider extends AbstractExportProjectProvider
new NullProgressMonitor() new NullProgressMonitor()
); );
ICProjectDescription pd= CoreModel.getDefault().createProjectDescription(cproject.getProject(), false); // create the description
newCfg(pd, project.getName(), "cfg1"); //$NON-NLS-1$
CoreModel.getDefault().setProjectDescription(cproject.getProject(), pd, true, new NullProgressMonitor());
newProject[0]= cproject; newProject[0]= cproject;
IndexerPreferences.set(newProject[0].getProject(), IndexerPreferences.KEY_INDEX_ALL_FILES, Boolean.TRUE.toString());
IndexerPreferences.set(newProject[0].getProject(), IndexerPreferences.KEY_INDEXER_ID, IPDOMManager.ID_NO_INDEXER);
} }
}, null); }, null);
if (indexerID != null) { return newProject[0];
IndexerPreferences.set(newProject[0].getProject(), IndexerPreferences.KEY_INDEX_ALL_FILES, Boolean.TRUE.toString());
IndexerPreferences.set(newProject[0].getProject(), IndexerPreferences.KEY_INDEXER_ID, indexerID);
} }
return newProject[0]; private ICConfigurationDescription newCfg(ICProjectDescription des, String project, String config) throws CoreException {
CDefaultConfigurationData data= new CDefaultConfigurationData(project+"."+config, project+" "+config+" name", null); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
data.initEmptyData();
String ID= CCorePlugin.PLUGIN_ID + ".defaultConfigDataProvider"; //$NON-NLS-1$
return des.createConfiguration(ID, data);
} }
/* /*

View file

@ -41,7 +41,8 @@ public interface IExportProjectProvider {
public void setApplicationArguments(String[] arguments); public void setApplicationArguments(String[] arguments);
/** /**
* Creates, configures and returns a project for the indexer to index * Creates, configures and returns a project for the indexer to index. This routine should
* not itself index the project, as a reindex will be performed by the framework.
* May not return null. * May not return null.
* @return * @return
*/ */

View file

@ -29,6 +29,8 @@ import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
import org.eclipse.cdt.internal.core.CCoreInternals;
import org.eclipse.cdt.internal.core.index.provider.IndexProviderManager; import org.eclipse.cdt.internal.core.index.provider.IndexProviderManager;
import org.eclipse.cdt.internal.core.pdom.PDOMManager; import org.eclipse.cdt.internal.core.pdom.PDOMManager;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
@ -56,7 +58,7 @@ public class IndexFactory {
boolean addDependent= (options & ADD_DEPENDENT) != 0; boolean addDependent= (options & ADD_DEPENDENT) != 0;
boolean skipProvided= (options & SKIP_PROVIDED) != 0; boolean skipProvided= (options & SKIP_PROVIDED) != 0;
IndexProviderManager m = ((PDOMManager)CCorePlugin.getPDOMManager()).getIndexProviderManager(); IndexProviderManager m = CCoreInternals.getPDOMManager().getIndexProviderManager();
HashMap map= new HashMap(); HashMap map= new HashMap();
Collection selectedProjects= getProjects(projects, addDependencies, addDependent, map, new Integer(1)); Collection selectedProjects= getProjects(projects, addDependencies, addDependent, map, new Integer(1));
@ -68,7 +70,9 @@ public class IndexFactory {
fragments.put(pdom.getProperty(IIndexFragment.PROPERTY_FRAGMENT_ID), pdom); fragments.put(pdom.getProperty(IIndexFragment.PROPERTY_FRAGMENT_ID), pdom);
if(!skipProvided) { if(!skipProvided) {
ICConfigurationDescription activeCfg= CoreModel.getDefault().getProjectDescription(cproject.getProject()).getActiveConfiguration(); ICProjectDescription pd= CoreModel.getDefault().getProjectDescription(cproject.getProject(), false);
if(pd!=null) {
ICConfigurationDescription activeCfg= pd.getActiveConfiguration();
IIndexFragment[] pFragments= m.getProvidedIndexFragments(activeCfg); IIndexFragment[] pFragments= m.getProvidedIndexFragments(activeCfg);
for(int i=0; i<pFragments.length; i++) { for(int i=0; i<pFragments.length; i++) {
fragments.put(pFragments[i].getProperty(IIndexFragment.PROPERTY_FRAGMENT_ID), pFragments[i]); fragments.put(pFragments[i].getProperty(IIndexFragment.PROPERTY_FRAGMENT_ID), pFragments[i]);
@ -76,6 +80,7 @@ public class IndexFactory {
} }
} }
} }
}
if (fragments.isEmpty()) { if (fragments.isEmpty()) {
return EmptyCIndex.INSTANCE; return EmptyCIndex.INSTANCE;
} }
@ -94,7 +99,9 @@ public class IndexFactory {
fragments.put(pdom.getProperty(IIndexFragment.PROPERTY_FRAGMENT_ID), pdom); fragments.put(pdom.getProperty(IIndexFragment.PROPERTY_FRAGMENT_ID), pdom);
} }
if(!skipProvided) { if(!skipProvided) {
ICConfigurationDescription activeCfg= CoreModel.getDefault().getProjectDescription(cproject.getProject()).getActiveConfiguration(); ICProjectDescription pd= CoreModel.getDefault().getProjectDescription(cproject.getProject(), false);
if(pd!=null) {
ICConfigurationDescription activeCfg= pd.getActiveConfiguration();
IIndexFragment[] pFragments= m.getProvidedIndexFragments(activeCfg); IIndexFragment[] pFragments= m.getProvidedIndexFragments(activeCfg);
for(int i=0; i<pFragments.length; i++) { for(int i=0; i<pFragments.length; i++) {
fragments.put(pFragments[i].getProperty(IIndexFragment.PROPERTY_FRAGMENT_ID), pFragments[i]); fragments.put(pFragments[i].getProperty(IIndexFragment.PROPERTY_FRAGMENT_ID), pFragments[i]);
@ -102,6 +109,7 @@ public class IndexFactory {
} }
} }
} }
}
Collection pdoms= fragments.values(); Collection pdoms= fragments.values();
return new CIndex((IIndexFragment[]) pdoms.toArray(new IIndexFragment[pdoms.size()]), primaryFragmentCount); return new CIndex((IIndexFragment[]) pdoms.toArray(new IIndexFragment[pdoms.size()]), primaryFragmentCount);
@ -169,6 +177,7 @@ public class IndexFactory {
public IWritableIndex getWritableIndex(ICProject project) throws CoreException { public IWritableIndex getWritableIndex(ICProject project) throws CoreException {
// mstodo to support dependent projects: Collection selectedProjects= getSelectedProjects(new ICProject[]{project}, false); // mstodo to support dependent projects: Collection selectedProjects= getSelectedProjects(new ICProject[]{project}, false);
IndexProviderManager m = CCoreInternals.getPDOMManager().getIndexProviderManager();
Collection selectedProjects= Collections.singleton(project); Collection selectedProjects= Collections.singleton(project);
Map readOnlyFrag= new LinkedHashMap(); Map readOnlyFrag= new LinkedHashMap();
@ -178,14 +187,16 @@ public class IndexFactory {
IWritableIndexFragment pdom= (IWritableIndexFragment) fPDOMManager.getPDOM(p); IWritableIndexFragment pdom= (IWritableIndexFragment) fPDOMManager.getPDOM(p);
if (pdom != null) { if (pdom != null) {
fragments.put(pdom.getProperty(IIndexFragment.PROPERTY_FRAGMENT_ID), pdom); fragments.put(pdom.getProperty(IIndexFragment.PROPERTY_FRAGMENT_ID), pdom);
IndexProviderManager m = ((PDOMManager)CCorePlugin.getPDOMManager()).getIndexProviderManager(); ICProjectDescription pd= CoreModel.getDefault().getProjectDescription(p.getProject(), false);
ICConfigurationDescription activeCfg= CoreModel.getDefault().getProjectDescription(p.getProject()).getActiveConfiguration(); if(pd!=null) {
ICConfigurationDescription activeCfg= pd.getActiveConfiguration();
IIndexFragment[] pFragments= m.getProvidedIndexFragments(activeCfg); IIndexFragment[] pFragments= m.getProvidedIndexFragments(activeCfg);
for(int i=0; i<pFragments.length; i++) { for(int i=0; i<pFragments.length; i++) {
readOnlyFrag.put(pFragments[i].getProperty(IIndexFragment.PROPERTY_FRAGMENT_ID), pFragments[i]); readOnlyFrag.put(pFragments[i].getProperty(IIndexFragment.PROPERTY_FRAGMENT_ID), pFragments[i]);
} }
} }
} }
}
selectedProjects= getProjects(new ICProject[] {project}, true, false, new HashMap(), new Integer(1)); selectedProjects= getProjects(new ICProject[] {project}, true, false, new HashMap(), new Integer(1));
selectedProjects.remove(project); selectedProjects.remove(project);

View file

@ -21,6 +21,7 @@ import org.eclipse.cdt.core.index.export.IExportProjectProvider;
import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.internal.core.CCoreInternals; import org.eclipse.cdt.internal.core.CCoreInternals;
import org.eclipse.cdt.internal.core.pdom.WritablePDOM; import org.eclipse.cdt.internal.core.pdom.WritablePDOM;
import org.eclipse.cdt.internal.core.pdom.indexer.IndexerPreferences;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.ISafeRunnable; import org.eclipse.core.runtime.ISafeRunnable;
import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.NullProgressMonitor;
@ -37,21 +38,33 @@ public class GeneratePDOM implements ISafeRunnable {
protected IExportProjectProvider pm; protected IExportProjectProvider pm;
protected String[] applicationArguments; protected String[] applicationArguments;
protected File targetLocation; protected File targetLocation;
protected String indexerID;
public GeneratePDOM(IExportProjectProvider pm, String[] applicationArguments, File targetLocation) { public GeneratePDOM(IExportProjectProvider pm, String[] applicationArguments, File targetLocation, String indexerID) {
this.pm= pm; this.pm= pm;
this.applicationArguments= applicationArguments; this.applicationArguments= applicationArguments;
this.targetLocation= targetLocation; this.targetLocation= targetLocation;
this.indexerID= indexerID;
} }
public final void run() throws CoreException { public final void run() throws CoreException {
pm.setApplicationArguments(applicationArguments); pm.setApplicationArguments(applicationArguments);
final ICProject cproject = pm.createProject(); final ICProject cproject = pm.createProject();
if(cproject==null) { if(cproject==null) {
throw new CoreException(CCorePlugin.createStatus(Messages.GeneratePDOM_ProjectProviderReturnedNullCProject)); fail(MessageFormat.format(Messages.GeneratePDOM_ProjectProviderReturnedNullCProject,
new Object [] {pm.getClass().getName()}));
} }
CCorePlugin.getIndexManager().joinIndexer(Integer.MAX_VALUE, new NullProgressMonitor());
IIndexLocationConverter converter= pm.getLocationConverter(cproject); IIndexLocationConverter converter= pm.getLocationConverter(cproject);
if(converter==null) {
fail(MessageFormat.format(Messages.GeneratePDOM_NullLocationConverter,
new Object [] {pm.getClass().getName()}));
}
// index the project
IndexerPreferences.set(cproject.getProject(), IndexerPreferences.KEY_INDEXER_ID, indexerID);
CCorePlugin.getIndexManager().joinIndexer(Integer.MAX_VALUE, new NullProgressMonitor());
try { try {
CCoreInternals.getPDOMManager().exportProjectPDOM(cproject, targetLocation, converter); CCoreInternals.getPDOMManager().exportProjectPDOM(cproject, targetLocation, converter);
WritablePDOM exportedPDOM= new WritablePDOM(targetLocation, converter); WritablePDOM exportedPDOM= new WritablePDOM(targetLocation, converter);
@ -78,4 +91,8 @@ public class GeneratePDOM implements ISafeRunnable {
// subclass for custom behaviour // subclass for custom behaviour
CCorePlugin.log(exception); CCorePlugin.log(exception);
} }
private void fail(String message) throws CoreException {
throw new CoreException(CCorePlugin.createStatus(message));
}
} }

View file

@ -18,6 +18,7 @@ import java.util.Map;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.IPDOMIndexerTask; import org.eclipse.cdt.core.dom.IPDOMIndexerTask;
import org.eclipse.cdt.core.dom.IPDOMManager;
import org.eclipse.cdt.core.index.export.ExternalExportProjectProvider; import org.eclipse.cdt.core.index.export.ExternalExportProjectProvider;
import org.eclipse.cdt.core.index.export.IExportProjectProvider; import org.eclipse.cdt.core.index.export.IExportProjectProvider;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
@ -39,9 +40,10 @@ import org.eclipse.equinox.app.IApplicationContext;
public class GeneratePDOMApplication implements IApplication { public class GeneratePDOMApplication implements IApplication {
private static final String EXPORT_PROJECT_PROVIDER = "ExportProjectProvider"; //$NON-NLS-1$ private static final String EXPORT_PROJECT_PROVIDER = "ExportProjectProvider"; //$NON-NLS-1$
private static final String DEFAULT_PROJECT_PROVIDER = ExternalExportProjectProvider.class.getName(); private static final String DEFAULT_PROJECT_PROVIDER = ExternalExportProjectProvider.class.getName();
private static final String OPT_PROJECTPROVIDER= "-pprovider"; //$NON-NLS-1$ public static final String OPT_PROJECTPROVIDER= "-pprovider"; //$NON-NLS-1$
private static final String OPT_TARGET= "-target"; //$NON-NLS-1$ public static final String OPT_TARGET= "-target"; //$NON-NLS-1$
private static final String OPT_QUIET= "-quiet"; //$NON-NLS-1$ public static final String OPT_QUIET= "-quiet"; //$NON-NLS-1$
public static final String OPT_INDEXER_ID= "-indexer"; //$NON-NLS-1$
private static Map/*<String,IProjectForExportManager>*/ projectInitializers; private static Map/*<String,IProjectForExportManager>*/ projectInitializers;
@ -49,7 +51,8 @@ public class GeneratePDOMApplication implements IApplication {
* Starts this application * Starts this application
*/ */
public Object start(IApplicationContext context) throws CoreException { public Object start(IApplicationContext context) throws CoreException {
Map arguments= CLIUtil.parseToMap(Platform.getApplicationArgs()); String[] appArgs= (String[]) context.getArguments().get(IApplicationContext.APPLICATION_ARGS);
Map arguments= CLIUtil.parseToMap(appArgs);
output(Messages.GeneratePDOMApplication_Initializing); output(Messages.GeneratePDOMApplication_Initializing);
setupCLIProgressProvider(); setupCLIProgressProvider();
@ -64,6 +67,16 @@ public class GeneratePDOMApplication implements IApplication {
String target= (String) CLIUtil.getArg(arguments, OPT_TARGET, 1).get(0); String target= (String) CLIUtil.getArg(arguments, OPT_TARGET, 1).get(0);
boolean quiet= arguments.get(OPT_QUIET)!=null; boolean quiet= arguments.get(OPT_QUIET)!=null;
String indexerID= IPDOMManager.ID_FAST_INDEXER;
String[] indexerIDs= (String[]) arguments.get(OPT_INDEXER_ID);
if(indexerIDs!=null) {
if(indexerIDs.length==1) {
indexerID= indexerIDs[0];
} else if(indexerIDs.length>1) {
fail(MessageFormat.format(Messages.GeneratePDOMApplication_InvalidIndexerID, new Object[] {OPT_INDEXER_ID}));
}
}
if(!quiet) { if(!quiet) {
System.setProperty(IPDOMIndexerTask.TRACE_ACTIVITY, Boolean.TRUE.toString()); System.setProperty(IPDOMIndexerTask.TRACE_ACTIVITY, Boolean.TRUE.toString());
System.setProperty(IPDOMIndexerTask.TRACE_PROBLEMS, Boolean.TRUE.toString()); System.setProperty(IPDOMIndexerTask.TRACE_PROBLEMS, Boolean.TRUE.toString());
@ -72,12 +85,11 @@ public class GeneratePDOMApplication implements IApplication {
IExportProjectProvider pprovider = getExportProjectProvider(pproviderFQN); IExportProjectProvider pprovider = getExportProjectProvider(pproviderFQN);
if(pprovider==null) { if(pprovider==null) {
output(MessageFormat.format(Messages.GeneratePDOMApplication_CouldNotFindInitializer, new Object[]{pproviderFQN})); fail(MessageFormat.format(Messages.GeneratePDOMApplication_CouldNotFindInitializer, new Object[]{pproviderFQN}));
return null;
} }
File targetLocation = new File(target); File targetLocation = new File(target);
GeneratePDOM generate = new GeneratePDOM(pprovider, Platform.getApplicationArgs(), targetLocation); GeneratePDOM generate = new GeneratePDOM(pprovider, appArgs, targetLocation, indexerID);
output(Messages.GeneratePDOMApplication_GenerationStarts); output(Messages.GeneratePDOMApplication_GenerationStarts);
generate.run(); generate.run();
output(Messages.GeneratePDOMApplication_GenerationEnds); output(Messages.GeneratePDOMApplication_GenerationEnds);
@ -92,6 +104,10 @@ public class GeneratePDOMApplication implements IApplication {
// do nothing // do nothing
} }
private void fail(String message) throws CoreException {
throw new CoreException(CCorePlugin.createStatus(message));
}
/** /**
* Returns the IExportProjectProvider registed in the plug-in registry under the * Returns the IExportProjectProvider registed in the plug-in registry under the
* specified fully qualified class name * specified fully qualified class name
@ -109,20 +125,16 @@ public class GeneratePDOMApplication implements IApplication {
IExtension extension = extensions[i]; IExtension extension = extensions[i];
IConfigurationElement[] ce = extension.getConfigurationElements(); IConfigurationElement[] ce = extension.getConfigurationElements();
IExportProjectProvider pfem = null;
for(int j=0; j<ce.length; j++) { for(int j=0; j<ce.length; j++) {
if(ce[j].getName().equals(EXPORT_PROJECT_PROVIDER)) { if(ce[j].getName().equals(EXPORT_PROJECT_PROVIDER)) {
try { try {
pfem = (IExportProjectProvider) ce[j].createExecutableExtension("class"); //$NON-NLS-1$ IExportProjectProvider epp = (IExportProjectProvider) ce[j].createExecutableExtension("class"); //$NON-NLS-1$
projectInitializers.put(epp.getClass().getName(), epp);
} catch(CoreException cee) { } catch(CoreException cee) {
CCorePlugin.log(cee); CCorePlugin.log(cee);
} }
break;
} }
} }
if(pfem!=null) {
projectInitializers.put(pfem.getClass().getName(), pfem);
}
} }
} }

View file

@ -15,11 +15,13 @@ import org.eclipse.osgi.util.NLS;
public class Messages extends NLS { public class Messages extends NLS {
private static final String BUNDLE_NAME = "org.eclipse.cdt.internal.core.pdom.export.messages"; //$NON-NLS-1$ private static final String BUNDLE_NAME = "org.eclipse.cdt.internal.core.pdom.export.messages"; //$NON-NLS-1$
public static String GeneratePDOM_GenericGenerationFailed; public static String GeneratePDOM_GenericGenerationFailed;
public static String GeneratePDOM_NullLocationConverter;
public static String GeneratePDOM_ProjectProviderReturnedNullCProject; public static String GeneratePDOM_ProjectProviderReturnedNullCProject;
public static String GeneratePDOMApplication_CouldNotFindInitializer; public static String GeneratePDOMApplication_CouldNotFindInitializer;
public static String GeneratePDOMApplication_GenerationEnds; public static String GeneratePDOMApplication_GenerationEnds;
public static String GeneratePDOMApplication_GenerationStarts; public static String GeneratePDOMApplication_GenerationStarts;
public static String GeneratePDOMApplication_Initializing; public static String GeneratePDOMApplication_Initializing;
public static String GeneratePDOMApplication_InvalidIndexerID;
public static String GeneratePDOMApplication_UsingDefaultProjectProvider; public static String GeneratePDOMApplication_UsingDefaultProjectProvider;
static { static {
// initialize resource bundle // initialize resource bundle

View file

@ -1,7 +1,9 @@
GeneratePDOMApplication_Initializing=== Initializing GeneratePDOMApplication_Initializing=== Initializing
GeneratePDOM_GenericGenerationFailed=Generation failed: {0} GeneratePDOM_GenericGenerationFailed=Generation failed: {0}
GeneratePDOM_NullLocationConverter=IExportProjectProvider implementation of getLocationConverter() returned null ({0})
GeneratePDOMApplication_CouldNotFindInitializer=Could not find IExportProjectProvider: {0} GeneratePDOMApplication_CouldNotFindInitializer=Could not find IExportProjectProvider: {0}
GeneratePDOM_ProjectProviderReturnedNullCProject=IExportProjectProvider implementation of createProject({0} returned null GeneratePDOM_ProjectProviderReturnedNullCProject=IExportProjectProvider implementation of createProject() returned null ({0})
GeneratePDOMApplication_UsingDefaultProjectProvider=-pprovider not specified - defaulting to {0} GeneratePDOMApplication_UsingDefaultProjectProvider=-pprovider not specified - defaulting to {0}
GeneratePDOMApplication_GenerationStarts=== Generation starts GeneratePDOMApplication_GenerationStarts=== Generation starts
GeneratePDOMApplication_InvalidIndexerID={0} takes zero or one argument
GeneratePDOMApplication_GenerationEnds=== Generation ends GeneratePDOMApplication_GenerationEnds=== Generation ends