1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Bug 133881 - Make refreshing after building optional

Work in progress.
This commit is contained in:
Chris Recoskie 2011-04-15 20:17:54 +00:00
parent 60487e7a57
commit 4cb96045d3
10 changed files with 359 additions and 102 deletions

View file

@ -5,9 +5,12 @@ Bundle-SymbolicName: org.eclipse.cdt.core.tests; singleton:=true
Bundle-Version: 5.3.0.qualifier Bundle-Version: 5.3.0.qualifier
Bundle-Activator: org.eclipse.cdt.core.testplugin.CTestPlugin Bundle-Activator: org.eclipse.cdt.core.testplugin.CTestPlugin
Export-Package: org.eclipse.cdt.core.cdescriptor.tests, Export-Package: org.eclipse.cdt.core.cdescriptor.tests,
org.eclipse.cdt.core.envvar,
org.eclipse.cdt.core.internal.efsextension.tests,
org.eclipse.cdt.core.internal.errorparsers.tests;x-internal:=true, org.eclipse.cdt.core.internal.errorparsers.tests;x-internal:=true,
org.eclipse.cdt.core.internal.index.provider.test;x-internal:=true, org.eclipse.cdt.core.internal.index.provider.test;x-internal:=true,
org.eclipse.cdt.core.internal.tests;x-internal:=true, org.eclipse.cdt.core.internal.tests;x-internal:=true,
org.eclipse.cdt.core.internal.tests.filesystem.ram,
org.eclipse.cdt.core.language, org.eclipse.cdt.core.language,
org.eclipse.cdt.core.model.tests, org.eclipse.cdt.core.model.tests,
org.eclipse.cdt.core.parser.tests, org.eclipse.cdt.core.parser.tests,
@ -22,6 +25,7 @@ Export-Package: org.eclipse.cdt.core.cdescriptor.tests,
org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.replace, org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.replace,
org.eclipse.cdt.core.parser.tests.rewrite.comenthandler, org.eclipse.cdt.core.parser.tests.rewrite.comenthandler,
org.eclipse.cdt.core.parser.tests.scanner, org.eclipse.cdt.core.parser.tests.scanner,
org.eclipse.cdt.core.resources.tests,
org.eclipse.cdt.core.settings.model, org.eclipse.cdt.core.settings.model,
org.eclipse.cdt.core.suite, org.eclipse.cdt.core.suite,
org.eclipse.cdt.core.testplugin, org.eclipse.cdt.core.testplugin,
@ -30,7 +34,8 @@ Export-Package: org.eclipse.cdt.core.cdescriptor.tests,
org.eclipse.cdt.core.tests.templateengine, org.eclipse.cdt.core.tests.templateengine,
org.eclipse.cdt.core.winreg.tests, org.eclipse.cdt.core.winreg.tests,
org.eclipse.cdt.internal.index.tests;x-internal:=true, org.eclipse.cdt.internal.index.tests;x-internal:=true,
org.eclipse.cdt.internal.pdom.tests;x-internal:=true org.eclipse.cdt.internal.pdom.tests;x-internal:=true,
org.eclipse.cdt.utils
Require-Bundle: org.eclipse.core.resources, Require-Bundle: org.eclipse.core.resources,
org.eclipse.cdt.core, org.eclipse.cdt.core,
org.junit, org.junit,

View file

@ -16,6 +16,8 @@ import java.util.List;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.eclipse.cdt.core.CProjectNature; import org.eclipse.cdt.core.CProjectNature;
import org.eclipse.cdt.core.resources.ExclusionInstance;
import org.eclipse.cdt.core.resources.ExclusionType;
import org.eclipse.cdt.core.resources.RefreshExclusion; import org.eclipse.cdt.core.resources.RefreshExclusion;
import org.eclipse.cdt.core.resources.RefreshScopeManager; import org.eclipse.cdt.core.resources.RefreshScopeManager;
import org.eclipse.cdt.core.testplugin.CTestPlugin; import org.eclipse.cdt.core.testplugin.CTestPlugin;
@ -154,22 +156,6 @@ public class RefreshScopeTests extends TestCase {
} }
public class TestExclusion extends RefreshExclusion {
@Override
public String getName() {
return "TestExclusion";
}
@Override
public boolean testExclusion(IResource resource) {
// if the resource name ends in a 2, then we pass
String name = resource.getName();
return name.endsWith("2");
}
}
public void testAddRemoveExclusion() { public void testAddRemoveExclusion() {
RefreshScopeManager manager = RefreshScopeManager.getInstance(); RefreshScopeManager manager = RefreshScopeManager.getInstance();
manager.addResourceToRefresh(fProject, fProject); manager.addResourceToRefresh(fProject, fProject);
@ -199,5 +185,84 @@ public class RefreshScopeTests extends TestCase {
} }
public void testPersistAndLoad() {
RefreshScopeManager manager = RefreshScopeManager.getInstance();
manager.addResourceToRefresh(fProject, fProject);
RefreshExclusion exclusion1 = new TestExclusion();
manager.addExclusion(fProject, exclusion1);
RefreshExclusion exclusion2 = new TestExclusion();
manager.addExclusion(fProject, exclusion2);
// add a nested exclusion to the first exclusion
RefreshExclusion exclusion3 = new TestExclusion();
exclusion1.addNestedExclusion(exclusion3);
// add an instance to the second exclusion
ExclusionInstance instance = new ExclusionInstance();
instance.setDisplayString("foo");
instance.setResource(fFolder2);
instance.setExclusionType(ExclusionType.RESOURCE);
instance.setParentExclusion(exclusion2);
try {
manager.persistSettings();
} catch (CoreException e) {
fail();
}
// now clear all the settings out of the manager
manager.clearAllData();
// now load the settings
try {
manager.loadSettings();
} catch (CoreException e) {
fail();
}
// make sure we got the same stuff we saved
// the project should be set to refresh its root
List<IResource> resources = manager.getResourcesToRefresh(fProject);
assertEquals(resources.size(), 1);
assertEquals(resources.toArray(new IResource[0])[0], fProject);
// there should be 2 top-level exclusions
List<RefreshExclusion> exclusions = manager.getExclusions(fProject);
assertEquals(exclusions.size(), 2);
RefreshExclusion[] exclusionsArray = exclusions.toArray(new RefreshExclusion[0]);
// both exclusions should have parent resource set to the project
assertEquals(exclusionsArray[0].getParentResource(), fProject);
assertEquals(exclusionsArray[1].getParentResource(), fProject);
// the first exclusion should have one nested exclusion
List<RefreshExclusion> nestedExclusions1 = exclusionsArray[0].getNestedExclusions();
assertEquals(nestedExclusions1.size(), 1);
RefreshExclusion[] nestedExclusionsArray = nestedExclusions1.toArray(new RefreshExclusion[0]);
// the nested exclusion should have its parent exclusion set properly
assertEquals(nestedExclusionsArray[0].getParentExclusion(), exclusionsArray[0]);
// the second exclusion should have no nested exclusions
List<RefreshExclusion> nestedExclusions2 = exclusionsArray[1].getNestedExclusions();
assertEquals(nestedExclusions2.size(), 0);
// the second exclusion should have an instance
List<ExclusionInstance> instances = exclusionsArray[1].getExclusionInstances();
assertEquals(instances.size(), 1);
ExclusionInstance[] instancesArray = instances.toArray(new ExclusionInstance[0]);
ExclusionInstance loadedInstance = instancesArray[0];
// check the contents of the instance
assertEquals(exclusionsArray[1], loadedInstance.getParentExclusion());
assertEquals("foo", loadedInstance.getDisplayString());
assertEquals(fFolder2, loadedInstance.getResource());
assertEquals(ExclusionType.RESOURCE, loadedInstance.getExclusionType());
// cleanup
manager.clearAllData();
}
} }

View file

@ -0,0 +1,20 @@
package org.eclipse.cdt.core.resources.tests;
import org.eclipse.cdt.core.resources.RefreshExclusion;
import org.eclipse.core.resources.IResource;
public class TestExclusion extends RefreshExclusion {
@Override
public String getName() {
return "TestExclusion";
}
@Override
public boolean testExclusion(IResource resource) {
// if the resource name ends in a 2, then we pass
String name = resource.getName();
return name.endsWith("2");
}
}

View file

@ -21,6 +21,7 @@ public class Messages extends NLS {
public static String RefreshScopeManager_0; public static String RefreshScopeManager_0;
public static String RefreshScopeManager_1; public static String RefreshScopeManager_1;
public static String RefreshScopeManager_2; public static String RefreshScopeManager_2;
public static String RefreshScopeManager_3;
static { static {
// initialize resource bundle // initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, Messages.class); NLS.initializeMessages(BUNDLE_NAME, Messages.class);

View file

@ -16,6 +16,7 @@ import java.util.LinkedList;
import java.util.List; import java.util.List;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.Element; import org.w3c.dom.Element;
import org.w3c.dom.Node; import org.w3c.dom.Node;
@ -51,12 +52,12 @@ public abstract class RefreshExclusion {
protected List<ExclusionInstance> fExclusionInstanceList = new LinkedList<ExclusionInstance>(); protected List<ExclusionInstance> fExclusionInstanceList = new LinkedList<ExclusionInstance>();
protected List<RefreshExclusion> fNestedExclusions = new LinkedList<RefreshExclusion>(); protected List<RefreshExclusion> fNestedExclusions = new LinkedList<RefreshExclusion>();
protected ExclusionType fExclusionType; protected ExclusionType fExclusionType = ExclusionType.RESOURCE;
protected RefreshExclusion fParentExclusion; protected RefreshExclusion fParentExclusion;
protected IResource fParentResource; protected IResource fParentResource;
protected String fContributorId; protected String fContributorId = ""; //$NON-NLS-1$
/** /**
* If this exclusion is a direct descendant of a resource, returns that resource. * If this exclusion is a direct descendant of a resource, returns that resource.
@ -232,9 +233,19 @@ public abstract class RefreshExclusion {
} }
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
public static RefreshExclusion loadData(Element exclusionElement, RefreshExclusion parent) { public static List<RefreshExclusion> loadData(Element parentElement, RefreshExclusion parent) throws CoreException {
List<RefreshExclusion> exclusions = new LinkedList<RefreshExclusion>();
// the parent element might contain any number of exclusions... iterate through the list
NodeList exclusionsList = parentElement.getElementsByTagName(EXCLUSION_ELEMENT_NAME);
for(int i = 0; i < exclusionsList.getLength(); i++) {
Node node = exclusionsList.item(i);
// node should be an element
if(node instanceof Element) {
Element exclusionElement = (Element) node;
// create an object of the proper type using zero-argument constructor // create an object of the proper type using zero-argument constructor
RefreshExclusion newExclusion = null; RefreshExclusion newExclusion = null;
String classname = exclusionElement.getAttribute(CLASS_ATTRIBUTE_NAME); String classname = exclusionElement.getAttribute(CLASS_ATTRIBUTE_NAME);
@ -280,10 +291,10 @@ public abstract class RefreshExclusion {
NodeList extensionList = exclusionElement.getElementsByTagName(EXTENSION_DATA_ELEMENT_NAME); NodeList extensionList = exclusionElement.getElementsByTagName(EXTENSION_DATA_ELEMENT_NAME);
for(int k = 0; k < extensionList.getLength(); k++) { for(int k = 0; k < extensionList.getLength(); k++) {
Node node = extensionList.item(k); Node node1 = extensionList.item(k);
// the node will be an Element // the node will be an Element
if(node instanceof Element) { if(node1 instanceof Element) {
Element extensionElement = (Element) node; Element extensionElement = (Element) node1;
// load the extension's data // load the extension's data
newExclusion.loadExtendedData(extensionElement); newExclusion.loadExtendedData(extensionElement);
@ -294,11 +305,11 @@ public abstract class RefreshExclusion {
NodeList instanceList = exclusionElement.getElementsByTagName(INSTANCE_ELEMENT_NAME); NodeList instanceList = exclusionElement.getElementsByTagName(INSTANCE_ELEMENT_NAME);
for(int k = 0; k < instanceList.getLength(); k++) { for(int k = 0; k < instanceList.getLength(); k++) {
Node node = instanceList.item(k); Node node1 = instanceList.item(k);
// the node will be an element // the node will be an element
if(node instanceof Element) { if(node1 instanceof Element) {
Element instanceElement = (Element) node; Element instanceElement = (Element) node1;
// load the instance data // load the instance data
ExclusionInstance instance = ExclusionInstance.loadInstanceData(instanceElement); ExclusionInstance instance = ExclusionInstance.loadInstanceData(instanceElement);
@ -307,22 +318,22 @@ public abstract class RefreshExclusion {
} }
// load nested exclusions // load nested exclusions
NodeList nestedExclusionsList = exclusionElement.getElementsByTagName(EXCLUSION_ELEMENT_NAME); List<RefreshExclusion> nestedExclusions = loadData(exclusionElement, newExclusion);
for(int k = 0; k < nestedExclusionsList.getLength(); k++) { // add to parent
Node node = nestedExclusionsList.item(k); for(RefreshExclusion nestedExclusion : nestedExclusions) {
// the node will be an element
if(node instanceof Element) {
Element nestedExclusionElement = (Element) node;
// load the nested exclusion
RefreshExclusion nestedExclusion = loadData(nestedExclusionElement, newExclusion);
newExclusion.addNestedExclusion(nestedExclusion); newExclusion.addNestedExclusion(nestedExclusion);
} }
// add the new exclusion to the list of exclusions to return
exclusions.add(newExclusion);
}
} }
return newExclusion;
return exclusions;
} }
} }

View file

@ -10,7 +10,11 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.resources; package org.eclipse.cdt.core.resources;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringReader;
import java.io.StringWriter; import java.io.StringWriter;
import java.text.MessageFormat;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.LinkedList; import java.util.LinkedList;
@ -27,12 +31,19 @@ import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamResult;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.CProjectNature;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.QualifiedName; import org.eclipse.core.runtime.QualifiedName;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.Element; import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
/** /**
* The RefreshScopeManager provides access to settings pertaining to refreshes performed during * The RefreshScopeManager provides access to settings pertaining to refreshes performed during
@ -140,6 +151,15 @@ public class RefreshScopeManager {
} }
public void clearAllResourcesToRefresh() {
fProjectToResourcesMap.clear();
}
public void clearAllData() {
clearAllResourcesToRefresh();
clearAllExclusions();
}
private HashMap<IProject, LinkedHashSet<IResource>> getProjectToResourcesMap() { private HashMap<IProject, LinkedHashSet<IResource>> getProjectToResourcesMap() {
if(fProjectToResourcesMap == null) { if(fProjectToResourcesMap == null) {
fProjectToResourcesMap = new HashMap<IProject, LinkedHashSet<IResource>>(); fProjectToResourcesMap = new HashMap<IProject, LinkedHashSet<IResource>>();
@ -251,8 +271,101 @@ public class RefreshScopeManager {
} }
} }
public void loadSettings() { public void loadSettings() throws CoreException {
// iterate through all projects in the workspace. If they are C projects, attempt to load settings from them.
IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
for(IProject project : workspaceRoot.getProjects()) {
if(project.isOpen()) {
if(project.hasNature(CProjectNature.C_NATURE_ID)) {
String xmlString = project.getPersistentProperty(REFRESH_SCOPE_PROPERTY_NAME);
// if there are no settings, then configure the default behaviour of refreshing the entire project,
// with no exclusions
if (xmlString == null) {
addResourceToRefresh(project, project);
}
else {
// convert the XML string to a DOM model
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = null;
try {
docBuilder = docBuilderFactory.newDocumentBuilder();
} catch (ParserConfigurationException e) {
throw new CoreException(CCorePlugin.createStatus(Messages.RefreshScopeManager_0, e));
}
Document doc = null;
try {
doc = docBuilder.parse(new InputSource(new StringReader(xmlString)));
} catch (SAXException e) {
throw new CoreException(CCorePlugin.createStatus(MessageFormat.format(Messages.RefreshScopeManager_3, project.getName()), e));
} catch (IOException e) {
throw new CoreException(CCorePlugin.createStatus(MessageFormat.format(Messages.RefreshScopeManager_3, project.getName()), e));
}
// walk the DOM and load the settings
// for now ignore the version attribute, as we only have version 1 at this time
// iterate through the resource element nodes
NodeList nodeList = doc.getElementsByTagName(RESOURCE_ELEMENT_NAME);
for(int k = 0; k < nodeList.getLength(); k++) {
Node node = nodeList.item(k);
// node will be an element
if(node instanceof Element) {
Element resourceElement = (Element) node;
// get the resource path
String resourcePath = resourceElement.getAttribute(WORKSPACE_PATH_ATTRIBUTE_NAME);
if(resourcePath == null) {
// error
} }
else {
// find the resource
IResource resource = workspaceRoot.findMember(resourcePath);
if(resource == null) {
// error
}
else {
addResourceToRefresh(project, resource);
// load any exclusions
List<RefreshExclusion> exclusions = RefreshExclusion.loadData(resourceElement, null);
// add them
for(RefreshExclusion exclusion : exclusions) {
addExclusion(resource, exclusion);
}
}
}
}
}
}
}
}
}
}
public void clearExclusions(IResource resource) {
getResourcesToExclusionsMap();
List<RefreshExclusion> exclusions = fResourceToExclusionsMap.get(resource);
exclusions.clear();
}
public void clearAllExclusions() {
fResourceToExclusionsMap.clear();
}
} }

View file

@ -11,3 +11,5 @@
RefreshScopeManager_0=Error instantiating XML document builder. RefreshScopeManager_0=Error instantiating XML document builder.
RefreshScopeManager_1=Error instantiating XML transformer. RefreshScopeManager_1=Error instantiating XML transformer.
RefreshScopeManager_2=Error transforming XML. RefreshScopeManager_2=Error transforming XML.
RefreshScopeManager_3=Error parsing refresh settings from project {0}

View file

@ -78,6 +78,13 @@
</documentation> </documentation>
</annotation> </annotation>
</attribute> </attribute>
<attribute name="isTest" type="boolean">
<annotation>
<documentation>
Attribute indicating this contribution is for testing purposes and hence the given contributor should not be considered for contributions to the UI.
</documentation>
</annotation>
</attribute>
</complexType> </complexType>
</element> </element>

View file

@ -68,6 +68,11 @@ public class RefreshExclusionContributionManager {
String id = configElement.getAttribute("id"); //$NON-NLS-1$ String id = configElement.getAttribute("id"); //$NON-NLS-1$
String name = configElement.getAttribute("name"); //$NON-NLS-1$ String name = configElement.getAttribute("name"); //$NON-NLS-1$
String utility = configElement.getAttribute("class"); //$NON-NLS-1$ String utility = configElement.getAttribute("class"); //$NON-NLS-1$
boolean isTest = false;
String isTestString = configElement.getAttribute("isTest");
if(isTestString != null) {
isTest = Boolean.getBoolean(isTestString);
}
if (utility != null) { if (utility != null) {
try { try {
@ -76,6 +81,7 @@ public class RefreshExclusionContributionManager {
RefreshExclusionContributor exclusionContributor = (RefreshExclusionContributor) execExt; RefreshExclusionContributor exclusionContributor = (RefreshExclusionContributor) execExt;
exclusionContributor.setID(id); exclusionContributor.setID(id);
exclusionContributor.setName(name); exclusionContributor.setName(name);
exclusionContributor.setIsTest(isTest);
fIDtoContributorsMap.put(id, exclusionContributor); fIDtoContributorsMap.put(id, exclusionContributor);
} }
@ -94,6 +100,24 @@ public class RefreshExclusionContributionManager {
} }
public List<RefreshExclusionContributor> getContributors() { public List<RefreshExclusionContributor> getContributors() {
return getContributors(false);
}
public List<RefreshExclusionContributor> getContributors(boolean returnTestContributors) {
List<RefreshExclusionContributor> retVal = new LinkedList<RefreshExclusionContributor>();
if(!returnTestContributors) {
for(RefreshExclusionContributor contributor : fIDtoContributorsMap.values()) {
if(!contributor.isTest()) {
retVal.add(contributor);
}
}
return retVal;
}
else {
return new LinkedList<RefreshExclusionContributor>(fIDtoContributorsMap.values()); return new LinkedList<RefreshExclusionContributor>(fIDtoContributorsMap.values());
} }
} }
}

View file

@ -29,6 +29,7 @@ public abstract class RefreshExclusionContributor {
protected String fID; protected String fID;
protected String fName; protected String fName;
protected boolean fIsTest;
public String getID() { public String getID() {
return fID; return fID;
@ -38,6 +39,14 @@ public abstract class RefreshExclusionContributor {
fID = id; fID = id;
} }
public boolean isTest() {
return fIsTest;
}
public void setIsTest(boolean isTest) {
fIsTest = isTest;
}
/** /**
* Returns the human-readable name of this exclusion type. * Returns the human-readable name of this exclusion type.
* *