mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-28 19:35:36 +02:00
174986: make IConfigurationDescription reference utility methods available
This commit is contained in:
parent
c0c96c265c
commit
43e699e18c
4 changed files with 313 additions and 37 deletions
|
@ -35,6 +35,7 @@ import javax.xml.parsers.DocumentBuilderFactory;
|
|||
import org.eclipse.cdt.core.AbstractCExtension;
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.model.CoreModel;
|
||||
import org.eclipse.cdt.core.model.CoreModelUtil;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.core.model.IPathEntry;
|
||||
import org.eclipse.cdt.core.parser.IScannerInfo;
|
||||
|
@ -137,8 +138,8 @@ public class ManagedBuildManager extends AbstractCExtension implements IScannerI
|
|||
private static final String MANIFEST_ERROR_OPTION_CATEGORY = "ManagedBuildManager.error.manifest.option.category"; //$NON-NLS-1$
|
||||
private static final String MANIFEST_ERROR_OPTION_FILTER = "ManagedBuildManager.error.manifest.option.filter"; //$NON-NLS-1$
|
||||
private static final String MANIFEST_ERROR_OPTION_VALUEHANDLER = "ManagedBuildManager.error.manifest.option.valuehandler"; //$NON-NLS-1$
|
||||
private static final String MANIFEST_ERROR_READ_ONLY = "ManagedBuildManager.error.read_only"; //$NON-NLS-1$
|
||||
private static final String MANIFEST_ERROR_WRITE_FAILED = "ManagedBuildManager.error.write_failed"; //$NON-NLS-1$
|
||||
private static final String MANIFEST_ERROR_READ_ONLY = "ManagedBuildManager.error.read_only"; //$NON-NLS-1$
|
||||
private static final String MANIFEST_ERROR_WRITE_FAILED = "ManagedBuildManager.error.write_failed"; //$NON-NLS-1$
|
||||
|
||||
// Error ID's for OptionValidError()
|
||||
public static final int ERROR_CATEGORY = 0;
|
||||
|
@ -4120,48 +4121,28 @@ public class ManagedBuildManager extends AbstractCExtension implements IScannerI
|
|||
return BuildPropertyManager.getInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the configurations referenced by this configuration.
|
||||
* Returns an empty array if there are no referenced configurations.
|
||||
*
|
||||
* @see CoreModelUtil.getReferencedConfigurations()
|
||||
* @return an array of IConfiguration objects referenced by this IConfiguration
|
||||
*/
|
||||
public static IConfiguration[] getReferencedConfigurations(IConfiguration config){
|
||||
IConfiguration[] refConfigs = null;
|
||||
ICConfigurationDescription cfgDes = getDescriptionForConfiguration(config);
|
||||
if(cfgDes != null){
|
||||
Map map = cfgDes.getReferenceInfo();
|
||||
if(map.size() != 0){
|
||||
List list = new ArrayList(map.size());
|
||||
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
|
||||
CoreModel model = CoreModel.getDefault();
|
||||
for(Iterator iter = map.entrySet().iterator(); iter.hasNext();){
|
||||
Map.Entry entry = (Map.Entry)iter.next();
|
||||
String projName = (String)entry.getKey();
|
||||
String cfgId = (String)entry.getValue();
|
||||
IProject project = root.getProject(projName);
|
||||
if(!project.exists())
|
||||
continue;
|
||||
|
||||
ICProjectDescription des = model.getProjectDescription(project, false);
|
||||
if(des == null)
|
||||
continue;
|
||||
|
||||
ICConfigurationDescription refCfgDes = cfgId.length() == 0 ? des.getActiveConfiguration() : des.getConfigurationById(cfgId);
|
||||
if(refCfgDes == null)
|
||||
continue;
|
||||
|
||||
IConfiguration refdCfg = ManagedBuildManager.getConfigurationForDescription(refCfgDes);
|
||||
if(refdCfg == null)
|
||||
continue;
|
||||
|
||||
list.add(refdCfg);
|
||||
}
|
||||
|
||||
if(list.size() != 0){
|
||||
refConfigs = (IConfiguration[])list.toArray(new Configuration[list.size()]);
|
||||
ICConfigurationDescription[] descs= CoreModelUtil.getReferencedConfigurationDescriptions(cfgDes, false);
|
||||
List result = new ArrayList();
|
||||
for(int i=0; i<descs.length; i++) {
|
||||
IConfiguration cfg = getConfigurationForDescription(descs[i]);
|
||||
if(cfg != null) {
|
||||
result.add(cfg);
|
||||
}
|
||||
}
|
||||
return (IConfiguration[]) result.toArray(new IConfiguration[result.size()]);
|
||||
}
|
||||
|
||||
if(refConfigs == null)
|
||||
refConfigs = new Configuration[0];
|
||||
|
||||
return refConfigs;
|
||||
return new Configuration[0];
|
||||
}
|
||||
|
||||
public static void buildConfigurations(IConfiguration[] configs, IProgressMonitor monitor) throws CoreException{
|
||||
|
|
|
@ -14,6 +14,7 @@ import junit.framework.Test;
|
|||
import junit.framework.TestSuite;
|
||||
|
||||
import org.eclipse.cdt.core.model.failedTests.FailedDeclaratorsTest;
|
||||
import org.eclipse.cdt.core.settings.model.CConfigurationDescriptionReferenceTests;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -45,6 +46,7 @@ public class AllCoreTests {
|
|||
suite.addTest(DeclaratorsTests.suite());
|
||||
suite.addTest(FailedDeclaratorsTest.suite());
|
||||
suite.addTest(CPathEntryTest.suite());
|
||||
suite.addTest(CConfigurationDescriptionReferenceTests.suite());
|
||||
|
||||
return suite;
|
||||
|
||||
|
|
|
@ -0,0 +1,196 @@
|
|||
/*******************************************************************************
|
||||
* 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.core.settings.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.model.CoreModel;
|
||||
import org.eclipse.cdt.core.model.CoreModelUtil;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.core.settings.model.extension.impl.CDefaultConfigurationData;
|
||||
import org.eclipse.cdt.core.testplugin.CProjectHelper;
|
||||
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
|
||||
/**
|
||||
* Test ICConfigurationDescription reference behaviours
|
||||
*/
|
||||
public class CConfigurationDescriptionReferenceTests extends BaseTestCase {
|
||||
ICProject p1, p2, p3, p4;
|
||||
ICConfigurationDescription p1cd1, p1cd2, p1cd3;
|
||||
ICConfigurationDescription p2cd1, p2cd2, p2cd3;
|
||||
ICConfigurationDescription p3cd1, p3cd2, p3cd3;
|
||||
ICConfigurationDescription p4cd1, p4cd2, p4cd3;
|
||||
|
||||
public static TestSuite suite() {
|
||||
return suite(CConfigurationDescriptionReferenceTests.class, "_");
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
p1 = CProjectHelper.createCCProject("p1", "bin");
|
||||
p2 = CProjectHelper.createCCProject("p2", "bin");
|
||||
p3 = CProjectHelper.createCCProject("p3", "bin");
|
||||
p4 = CProjectHelper.createCCProject("p4", "bin");
|
||||
|
||||
CoreModel coreModel = CoreModel.getDefault();
|
||||
ICProjectDescription des1 = coreModel.getProjectDescription(p1.getProject());
|
||||
ICProjectDescription des2 = coreModel.getProjectDescription(p2.getProject());
|
||||
ICProjectDescription des3 = coreModel.getProjectDescription(p3.getProject());
|
||||
ICProjectDescription des4 = coreModel.getProjectDescription(p4.getProject());
|
||||
|
||||
p1cd1 = newCfg(des1, "p1", "cd1");
|
||||
p1cd2 = newCfg(des1, "p1", "cd2");
|
||||
p1cd3 = newCfg(des1, "p1", "cd3");
|
||||
|
||||
p2cd1 = newCfg(des2, "p2", "cd1");
|
||||
p2cd2 = newCfg(des2, "p2", "cd2");
|
||||
p2cd3 = newCfg(des2, "p2", "cd3");
|
||||
|
||||
p3cd1 = newCfg(des3, "p3", "cd1");
|
||||
p3cd2 = newCfg(des3, "p3", "cd2");
|
||||
p3cd3 = newCfg(des3, "p3", "cd3");
|
||||
|
||||
p4cd1 = newCfg(des4, "p4", "cd1");
|
||||
p4cd2 = newCfg(des4, "p4", "cd2");
|
||||
p4cd3 = newCfg(des4, "p4", "cd3");
|
||||
|
||||
/*
|
||||
* Setup references:
|
||||
*
|
||||
* p1: cd1 cd2 cd3
|
||||
* \ | /
|
||||
* \|/
|
||||
* *
|
||||
* /|\
|
||||
* / | \
|
||||
* p2: cd1 cd2 cd3
|
||||
* | | |
|
||||
* p3: cd1 cd2 cd3
|
||||
* \ | /
|
||||
* \|/
|
||||
* p4: cd1 cd2 cd3
|
||||
*/
|
||||
|
||||
setRefs(p1cd1, new ICConfigurationDescription[] {p2cd3});
|
||||
setRefs(p1cd2, new ICConfigurationDescription[] {p2cd2});
|
||||
setRefs(p1cd3, new ICConfigurationDescription[] {p2cd1});
|
||||
|
||||
setRefs(p2cd1, new ICConfigurationDescription[] {p3cd1});
|
||||
setRefs(p2cd2, new ICConfigurationDescription[] {p3cd2});
|
||||
setRefs(p2cd3, new ICConfigurationDescription[] {p3cd3});
|
||||
|
||||
setRefs(p3cd1, new ICConfigurationDescription[] {p4cd2});
|
||||
setRefs(p3cd2, new ICConfigurationDescription[] {p4cd2});
|
||||
setRefs(p3cd3, new ICConfigurationDescription[] {p4cd2});
|
||||
|
||||
coreModel.setProjectDescription(p1.getProject(), des1);
|
||||
coreModel.setProjectDescription(p2.getProject(), des2);
|
||||
coreModel.setProjectDescription(p3.getProject(), des3);
|
||||
coreModel.setProjectDescription(p4.getProject(), des4);
|
||||
}
|
||||
|
||||
private void setRefs(ICConfigurationDescription node, ICConfigurationDescription[] refs) {
|
||||
Map p1RefData = new HashMap();
|
||||
for(int i=0; i<refs.length; i++) {
|
||||
String projectName = refs[i].getProjectDescription().getName();
|
||||
p1RefData.put(projectName, refs[i].getId());
|
||||
}
|
||||
node.setReferenceInfo(p1RefData);
|
||||
}
|
||||
|
||||
private ICConfigurationDescription newCfg(ICProjectDescription des, String project, String config) throws CoreException {
|
||||
CDefaultConfigurationData data= new CDefaultConfigurationData(project+"."+config, project+" "+config+" name", null);
|
||||
data.initEmptyData();
|
||||
String ID= CCorePlugin.PLUGIN_ID + ".defaultConfigDataProvider";
|
||||
return des.createConfiguration(ID, data);
|
||||
}
|
||||
|
||||
public void testConfigurationDescriptionReference() throws CoreException {
|
||||
// references
|
||||
|
||||
assertEdges(p1cd1, new ICConfigurationDescription[] {p2cd3}, true);
|
||||
assertEdges(p1cd2, new ICConfigurationDescription[] {p2cd2}, true);
|
||||
assertEdges(p1cd3, new ICConfigurationDescription[] {p2cd1}, true);
|
||||
|
||||
assertEdges(p2cd1, new ICConfigurationDescription[] {p3cd1}, true);
|
||||
assertEdges(p2cd2, new ICConfigurationDescription[] {p3cd2}, true);
|
||||
assertEdges(p2cd3, new ICConfigurationDescription[] {p3cd3}, true);
|
||||
|
||||
assertEdges(p3cd1, new ICConfigurationDescription[] {p4cd2}, true);
|
||||
assertEdges(p3cd2, new ICConfigurationDescription[] {p4cd2}, true);
|
||||
assertEdges(p3cd3, new ICConfigurationDescription[] {p4cd2}, true);
|
||||
|
||||
assertEdges(p4cd1, new ICConfigurationDescription[] {}, true);
|
||||
assertEdges(p4cd2, new ICConfigurationDescription[] {}, true);
|
||||
assertEdges(p4cd3, new ICConfigurationDescription[] {}, true);
|
||||
}
|
||||
|
||||
public void testConfigurationDescriptionReferencing() throws CoreException {
|
||||
// referencing
|
||||
|
||||
assertEdges(p1cd1, new ICConfigurationDescription[] {}, false);
|
||||
assertEdges(p1cd2, new ICConfigurationDescription[] {}, false);
|
||||
assertEdges(p1cd3, new ICConfigurationDescription[] {}, false);
|
||||
|
||||
assertEdges(p2cd1, new ICConfigurationDescription[] {p1cd3}, false);
|
||||
assertEdges(p2cd2, new ICConfigurationDescription[] {p1cd2}, false);
|
||||
assertEdges(p2cd3, new ICConfigurationDescription[] {p1cd1}, false);
|
||||
|
||||
assertEdges(p3cd1, new ICConfigurationDescription[] {p2cd1}, false);
|
||||
assertEdges(p3cd2, new ICConfigurationDescription[] {p2cd2}, false);
|
||||
assertEdges(p3cd3, new ICConfigurationDescription[] {p2cd3}, false);
|
||||
|
||||
assertEdges(p4cd1, new ICConfigurationDescription[] {}, false);
|
||||
assertEdges(p4cd2, new ICConfigurationDescription[] {p3cd1, p3cd2, p3cd3}, false);
|
||||
assertEdges(p4cd3, new ICConfigurationDescription[] {}, false);
|
||||
}
|
||||
|
||||
protected void assertEdges(ICConfigurationDescription cfgDes, ICConfigurationDescription[] expected, boolean references) {
|
||||
ICConfigurationDescription[] actual;
|
||||
|
||||
if(references) {
|
||||
actual= CoreModelUtil.getReferencedConfigurationDescriptions(cfgDes, false);
|
||||
} else {
|
||||
actual= CoreModelUtil.getReferencingConfigurationDescriptions(cfgDes, false);
|
||||
}
|
||||
|
||||
assertEquals(expected.length, actual.length);
|
||||
|
||||
List actualIds = new ArrayList();
|
||||
for(int i=0; i<actual.length; i++) {
|
||||
actualIds.add(actual[i].getId());
|
||||
}
|
||||
// check for each ID, don't use a Set so we detect duplicates
|
||||
for(int i=0; i<expected.length; i++) {
|
||||
assertTrue(expected[i].getId()+" is missing", actualIds.contains(expected[i].getId()));
|
||||
}
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
for(Iterator i = Arrays.asList(new ICProject[]{p1,p2,p3,p4}).iterator(); i.hasNext(); ) {
|
||||
ICProject project = (ICProject) i.next();
|
||||
try {
|
||||
project.getProject().delete(true, NPM);
|
||||
} catch(CoreException ce) {
|
||||
// try next one..
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -11,9 +11,18 @@
|
|||
|
||||
package org.eclipse.cdt.core.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.resources.IWorkspaceRoot;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
|
||||
|
@ -581,4 +590,92 @@ public class CoreModelUtil {
|
|||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the configuration descriptions referenced directly by the specified
|
||||
* configuration description. The result will not contain duplicates. Returns
|
||||
* an empty array if there are no referenced configuration descriptions.
|
||||
*
|
||||
* @param cfgDes
|
||||
* @param writable - specifies whether the returned descriptions should be writable or read-only
|
||||
* @since 4.0
|
||||
* @return a list of configuration descriptions
|
||||
* @see CoreModelUtil#getReferencingConfigurationDescriptions(ICConfigurationDescription, boolean)
|
||||
*/
|
||||
|
||||
public static ICConfigurationDescription[] getReferencedConfigurationDescriptions(ICConfigurationDescription cfgDes, boolean writable){
|
||||
List result = new ArrayList();
|
||||
|
||||
if(cfgDes != null) {
|
||||
Map map = cfgDes.getReferenceInfo();
|
||||
if(map.size() != 0){
|
||||
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
|
||||
CoreModel model = CoreModel.getDefault();
|
||||
for(Iterator iter = map.entrySet().iterator(); iter.hasNext();){
|
||||
Map.Entry entry = (Map.Entry)iter.next();
|
||||
String projName = (String)entry.getKey();
|
||||
String cfgId = (String)entry.getValue();
|
||||
IProject project = root.getProject(projName);
|
||||
if(!project.exists())
|
||||
continue;
|
||||
|
||||
ICProjectDescription des = model.getProjectDescription(project, writable);
|
||||
if(des == null)
|
||||
continue;
|
||||
|
||||
ICConfigurationDescription refCfgDes;
|
||||
if(cfgId!=null && cfgId.length()>0) {
|
||||
refCfgDes= des.getConfigurationById(cfgId);
|
||||
} else {
|
||||
refCfgDes= des.getActiveConfiguration();
|
||||
}
|
||||
if(refCfgDes != null)
|
||||
result.add(refCfgDes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (ICConfigurationDescription[]) result.toArray(new ICConfigurationDescription[result.size()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of all configuration descriptions which directly reference
|
||||
* the specified configuration description. Returns an empty array if there are
|
||||
* no referencing configuration descriptions.
|
||||
*
|
||||
* @since 4.0
|
||||
* @param cfgDes
|
||||
* @param writable - specifies whether the returned descriptions should be writable or read-only
|
||||
* @return a list of configuration descriptions referencing this configuration description
|
||||
* @see CoreModelUtil#getReferencedConfigurationDescriptions(ICConfigurationDescription, boolean)
|
||||
*/
|
||||
public static ICConfigurationDescription[] getReferencingConfigurationDescriptions(ICConfigurationDescription cfgDes, boolean writable) {
|
||||
List result = new ArrayList();
|
||||
|
||||
if(cfgDes!=null) {
|
||||
CoreModel core= CoreModel.getDefault();
|
||||
IProject[] cprojects= ResourcesPlugin.getWorkspace().getRoot().getProjects();
|
||||
|
||||
for (int i=0; i<cprojects.length; i++) {
|
||||
IProject cproject= (IProject) cprojects[i];
|
||||
ICProjectDescription prjDes= core.getProjectDescription(cproject, writable);
|
||||
//in case this is not a CDT project the description will be null, so check for null
|
||||
if(prjDes != null){
|
||||
ICConfigurationDescription[] cfgDscs= prjDes.getConfigurations();
|
||||
for(int j=0; j<cfgDscs.length; j++) {
|
||||
ICConfigurationDescription[] references = getReferencedConfigurationDescriptions(cfgDscs[j], false);
|
||||
for (int k=0; k<references.length; k++) {
|
||||
if(references[k]!=null
|
||||
&& references[k].getId().equals(cfgDes.getId())) {
|
||||
result.add(cfgDscs[j]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (ICConfigurationDescription[]) result.toArray(new ICConfigurationDescription[result.size()]);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue