1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-09-10 12:03:16 +02:00

Bug 133881 - Make refreshing after building optional

Work in progress.
This commit is contained in:
Chris Recoskie 2011-04-21 19:15:20 +00:00
parent eca2f20595
commit ff9885b6e4
13 changed files with 517 additions and 170 deletions

View file

@ -204,6 +204,7 @@ public class RefreshScopeTests extends TestCase {
instance.setResource(fFolder2);
instance.setExclusionType(ExclusionType.RESOURCE);
instance.setParentExclusion(exclusion2);
exclusion2.addExclusionInstance(instance);
try {
manager.persistSettings();
@ -234,8 +235,8 @@ public class RefreshScopeTests extends TestCase {
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);
assertEquals(fProject, exclusionsArray[0].getParentResource());
assertEquals(fProject, exclusionsArray[1].getParentResource());
// the first exclusion should have one nested exclusion
List<RefreshExclusion> nestedExclusions1 = exclusionsArray[0].getNestedExclusions();
@ -250,12 +251,11 @@ public class RefreshScopeTests extends TestCase {
// the second exclusion should have an instance
List<ExclusionInstance> instances = exclusionsArray[1].getExclusionInstances();
assertEquals(instances.size(), 1);
assertEquals(1, instances.size());
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());

View file

@ -0,0 +1,56 @@
/*******************************************************************************
* Copyright (c) 2011 IBM Corporation 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:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.resources.tests;
import org.eclipse.cdt.core.resources.ExclusionInstance;
import org.eclipse.cdt.core.resources.RefreshExclusion;
import org.eclipse.cdt.core.resources.RefreshExclusionFactory;
/**
* @author crecoskie
*
*/
public class TestExclusionFactory extends RefreshExclusionFactory {
/**
*
*/
public TestExclusionFactory() {
// TODO Auto-generated constructor stub
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.resources.RefreshExclusionFactory#createNewExclusion()
*/
@Override
public RefreshExclusion createNewExclusion() {
return new TestExclusion();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.resources.RefreshExclusionFactory#getExclusionClassname()
*/
@Override
public String getExclusionClassname() {
return TestExclusion.class.getName();
}
@Override
public ExclusionInstance createNewExclusionInstance() {
return new ExclusionInstance();
}
@Override
public String getInstanceClassname() {
return ExclusionInstance.class.getName();
}
}

View file

@ -183,4 +183,11 @@
scheme="EFSExtensionProviderTestsScheme">
</EFSExtensionProvider>
</extension>
<extension
point="org.eclipse.cdt.core.RefreshExclusionFactory">
<exclusionFactory
exclusionClass="org.eclipse.cdt.core.resources.tests.TestExclusion"
factoryClass="org.eclipse.cdt.core.resources.tests.TestExclusionFactory">
</exclusionFactory>
</extension>
</plugin>

View file

@ -638,6 +638,7 @@
<extension-point id="templateAssociations" name="%templateAssociations.name" schema="schema/templateAssociations.exsd"/>
<extension-point id="ScannerInfoProvider2" name="%scannerInfoProvider2.name" schema="schema/ScannerInfoProvider2.exsd"/>
<extension-point id="EFSExtensionProvider" name="EFSExtensionProvider" schema="schema/EFSExtensionProvider.exsd"/>
<extension-point id="RefreshExclusionFactory" name="Refresh Exclusion Factory" schema="schema/RefreshExclusionFactory.exsd"/>
<extension
point="org.eclipse.cdt.core.templateProcessTypes">

View file

@ -0,0 +1,134 @@
<?xml version='1.0' encoding='UTF-8'?>
<!-- Schema file written by PDE -->
<schema targetNamespace="org.eclipse.cdt.core" xmlns="http://www.w3.org/2001/XMLSchema">
<annotation>
<appInfo>
<meta.schema plugin="org.eclipse.cdt.core" id="RefreshExclusionFactory" name="Refresh Exclusion Factory"/>
</appInfo>
<documentation>
This extension point allows ISVs to contribute factory classes that know how to instantiate a given type of RefreshExclusion. Usage of this extension point is mandatory when contributing new types of RefreshExclusions as otherwise CDT cannot instantiate the proper exclusions when loading persisted settings relating to the refresh policy for a given project.
</documentation>
</annotation>
<element name="extension">
<annotation>
<appInfo>
<meta.element />
</appInfo>
</annotation>
<complexType>
<sequence minOccurs="1" maxOccurs="unbounded">
<element ref="exclusionFactory"/>
</sequence>
<attribute name="point" type="string" use="required">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="id" type="string">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="name" type="string">
<annotation>
<documentation>
</documentation>
<appInfo>
<meta.attribute translatable="true"/>
</appInfo>
</annotation>
</attribute>
</complexType>
</element>
<element name="exclusionFactory">
<complexType>
<attribute name="factoryClass" type="string" use="required">
<annotation>
<documentation>
The factory that is used to create objects of the type specified in the exclusionClass and/or the instanceClass attribute.
</documentation>
<appInfo>
<meta.attribute kind="java" basedOn="org.eclipse.cdt.core.resources.RefreshExclusionFactory:"/>
</appInfo>
</annotation>
</attribute>
<attribute name="exclusionClass" type="string">
<annotation>
<documentation>
Optionally specifies the fully qualified typename of a RefreshExclusion that this factory creates objects for.
</documentation>
<appInfo>
<meta.attribute kind="java" basedOn="org.eclipse.cdt.core.resources.RefreshExclusion:"/>
</appInfo>
</annotation>
</attribute>
<attribute name="instanceClass" type="string">
<annotation>
<documentation>
Optionally specifies the fully qualified typename of a RefreshExclusion that this factory creates objects for.
</documentation>
<appInfo>
<meta.attribute kind="java" basedOn="org.eclipse.cdt.core.resources.ExclusionInstance:"/>
</appInfo>
</annotation>
</attribute>
</complexType>
</element>
<annotation>
<appInfo>
<meta.section type="since"/>
</appInfo>
<documentation>
5.3.0
</documentation>
</annotation>
<annotation>
<appInfo>
<meta.section type="examples"/>
</appInfo>
<documentation>
[Enter extension point usage example here.]
</documentation>
</annotation>
<annotation>
<appInfo>
<meta.section type="apiinfo"/>
</appInfo>
<documentation>
[Enter API information here.]
</documentation>
</annotation>
<annotation>
<appInfo>
<meta.section type="implementation"/>
</appInfo>
<documentation>
[Enter information about supplied implementation of this extension point.]
</documentation>
</annotation>
<annotation>
<appInfo>
<meta.section type="copyright"/>
</appInfo>
<documentation>
Copyright (c) 2011 IBM Corporation and others.&lt;br&gt;
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 &lt;a
href=&quot;http://www.eclipse.org/legal/epl-v10.html&quot;&gt;http://www.eclipse.org/legal/epl-v10.html&lt;/a&gt;
</documentation>
</annotation>
</schema>

View file

@ -10,8 +10,6 @@
*******************************************************************************/
package org.eclipse.cdt.core.resources;
import java.lang.reflect.Constructor;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.w3c.dom.Document;
@ -102,12 +100,12 @@ public class ExclusionInstance {
fDisplayString = displayString;
}
public void persistInstanceData(Document doc, Element extensionElement) {
public void persistInstanceData(Document doc, Element exclusionElement) {
Element instanceElement = doc.createElement(INSTANCE_ELEMENT_NAME);
// persist the type of the object we are
extensionElement.setAttribute(CLASS_ATTRIBUTE_NAME, this.getClass().getName());
Element instanceElement = doc.createElement(INSTANCE_ELEMENT_NAME);
instanceElement.setAttribute(CLASS_ATTRIBUTE_NAME, this.getClass().getName());
// persist the exclusion type
String exclusionType = null;
@ -139,6 +137,8 @@ public class ExclusionInstance {
instanceElement.setAttribute(DISPLAY_STRING_ATTRIBUTE_NAME, fDisplayString);
}
exclusionElement.appendChild(instanceElement);
// persist any data from extenders
persistExtendedInstanceData(doc, instanceElement);
@ -148,22 +148,18 @@ public class ExclusionInstance {
// override to provide extension specific behaviour if desired
}
@SuppressWarnings("rawtypes")
public static ExclusionInstance loadInstanceData(Element instanceElement) {
String classname = instanceElement.getAttribute(CLASS_ATTRIBUTE_NAME);
String className = instanceElement.getAttribute(CLASS_ATTRIBUTE_NAME);
ExclusionInstance newInstance = null;
Class instanceClass;
try {
instanceClass = Class.forName(classname);
Class[] parameterTypes = new Class[0];
Constructor constructor = instanceClass.getConstructor(parameterTypes);
newInstance = (ExclusionInstance) constructor.newInstance((Object[]) null);
} catch (Exception e) {
e.printStackTrace();
return null;
// see if there is a custom instance class
RefreshScopeManager manager = RefreshScopeManager.getInstance();
newInstance = manager.getInstanceForClassName(className);
if(newInstance == null) {
newInstance = new ExclusionInstance();
}
// load the exclusion type

View file

@ -18,6 +18,7 @@ import org.eclipse.osgi.util.NLS;
*/
public class Messages extends NLS {
private static final String BUNDLE_NAME = "org.eclipse.cdt.core.resources.messages"; //$NON-NLS-1$
public static String RefreshExclusion_0;
public static String RefreshScopeManager_0;
public static String RefreshScopeManager_1;
public static String RefreshScopeManager_2;

View file

@ -10,11 +10,11 @@
*******************************************************************************/
package org.eclipse.cdt.core.resources;
import java.lang.reflect.Constructor;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.w3c.dom.Document;
@ -22,6 +22,8 @@ import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import com.ibm.icu.text.MessageFormat;
/**
* A RefreshExclusion represents a rule for excluding certain resources from being refreshed.
*
@ -205,15 +207,15 @@ public abstract class RefreshExclusion {
exclusionElement.setAttribute(CONTRIBUTOR_ID_ATTRIBUTE_NAME, getContributorId());
parentElement.appendChild(exclusionElement);
// persist instances
for(ExclusionInstance instance : fExclusionInstanceList) {
instance.persistInstanceData(doc, exclusionElement);
}
// provide a place for extenders to store their own data
Element extensionElement = doc.createElement(EXTENSION_DATA_ELEMENT_NAME);
exclusionElement.appendChild(extensionElement);
// persist instances
for(ExclusionInstance instance : fExclusionInstanceList) {
instance.persistInstanceData(doc, extensionElement);
}
// call extender to store any extender-specific data
persistExtendedData(doc, extensionElement);
@ -232,102 +234,111 @@ public abstract class RefreshExclusion {
// override to provide extension specific behaviour if desired
}
@SuppressWarnings("rawtypes")
public static List<RefreshExclusion> loadData(Element parentElement, RefreshExclusion parent) throws CoreException {
public static List<RefreshExclusion> loadData(Element parentElement, RefreshExclusion parentExclusion, IResource parentResource) 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);
NodeList childNodes = parentElement.getChildNodes();
for (int i = 0; i < childNodes.getLength(); i++) {
Node node = childNodes.item(i);
// node should be an element
if(node instanceof Element) {
if (node instanceof Element) {
Element exclusionElement = (Element) node;
// create an object of the proper type using zero-argument constructor
RefreshExclusion newExclusion = null;
String classname = exclusionElement.getAttribute(CLASS_ATTRIBUTE_NAME);
Class extensionClass;
try {
extensionClass = Class.forName(classname);
Class[] parameterTypes = new Class[0];
Constructor constructor = extensionClass.getConstructor(parameterTypes);
newExclusion = (RefreshExclusion) constructor.newInstance((Object[]) null);
} catch (Exception e) {
// error
e.printStackTrace();
return null;
}
// load the exclusion type
String exclusionTypeString = exclusionElement.getAttribute(EXCLUSION_TYPE_ATTRIBUTE_NAME);
if (exclusionTypeString != null) {
if (exclusionTypeString.equals(FILE_VALUE)) {
newExclusion.fExclusionType = org.eclipse.cdt.core.resources.ExclusionType.FILE;
if (exclusionElement.getNodeName().equals(EXCLUSION_ELEMENT_NAME)) {
// create an object of the proper type
String className = exclusionElement.getAttribute(CLASS_ATTRIBUTE_NAME);
RefreshScopeManager manager = RefreshScopeManager.getInstance();
RefreshExclusion newExclusion = manager.getExclusionForClassName(className);
if (newExclusion == null) {
throw new CoreException(CCorePlugin.createStatus(MessageFormat.format(
Messages.RefreshExclusion_0, className)));
}
else if (exclusionTypeString.equals(FOLDER_VALUE)) {
newExclusion.fExclusionType = org.eclipse.cdt.core.resources.ExclusionType.FOLDER;
// load the exclusion type
String exclusionTypeString = exclusionElement
.getAttribute(EXCLUSION_TYPE_ATTRIBUTE_NAME);
if (exclusionTypeString != null) {
if (exclusionTypeString.equals(FILE_VALUE)) {
newExclusion.fExclusionType = org.eclipse.cdt.core.resources.ExclusionType.FILE;
}
else if (exclusionTypeString.equals(FOLDER_VALUE)) {
newExclusion.fExclusionType = org.eclipse.cdt.core.resources.ExclusionType.FOLDER;
}
else if (exclusionTypeString.equals(RESOURCE_VALUE)) {
newExclusion.fExclusionType = org.eclipse.cdt.core.resources.ExclusionType.RESOURCE;
}
else {
// error
}
}
else if (exclusionTypeString.equals(RESOURCE_VALUE)) {
newExclusion.fExclusionType = org.eclipse.cdt.core.resources.ExclusionType.RESOURCE;
}
else {
// error
}
}
// set parent
newExclusion.fParentExclusion = parent;
newExclusion.fContributorId = exclusionElement.getAttribute(CONTRIBUTOR_ID_ATTRIBUTE_NAME);
// get the extension element
NodeList extensionList = exclusionElement.getElementsByTagName(EXTENSION_DATA_ELEMENT_NAME);
for(int k = 0; k < extensionList.getLength(); k++) {
Node node1 = extensionList.item(k);
// the node will be an Element
if(node1 instanceof Element) {
Element extensionElement = (Element) node1;
// load the extension's data
newExclusion.loadExtendedData(extensionElement);
}
}
// load instances
NodeList instanceList = exclusionElement.getElementsByTagName(INSTANCE_ELEMENT_NAME);
for(int k = 0; k < instanceList.getLength(); k++) {
Node node1 = instanceList.item(k);
// set parent if nested
newExclusion.fParentExclusion = parentExclusion;
// the node will be an element
if(node1 instanceof Element) {
Element instanceElement = (Element) node1;
// load the instance data
ExclusionInstance instance = ExclusionInstance.loadInstanceData(instanceElement);
newExclusion.fExclusionInstanceList.add(instance);
// set parent resource if there is one
newExclusion.fParentResource = parentResource;
newExclusion.fContributorId = exclusionElement
.getAttribute(CONTRIBUTOR_ID_ATTRIBUTE_NAME);
// get the extension element
NodeList extensionList = exclusionElement
.getElementsByTagName(EXTENSION_DATA_ELEMENT_NAME);
for (int k = 0; k < extensionList.getLength(); k++) {
Node node1 = extensionList.item(k);
// the node will be an Element
if (node1 instanceof Element) {
Element extensionElement = (Element) node1;
// load the extension's data
newExclusion.loadExtendedData(extensionElement);
}
}
// load instances
NodeList exclusionChildNodes = exclusionElement.getChildNodes();
for (int k = 0; k < exclusionChildNodes.getLength(); k++) {
Node node1 = exclusionChildNodes.item(k);
// the node will be an element
if (node1 instanceof Element) {
Element instanceElement = (Element) node1;
// is the node an instance?
if (instanceElement.getNodeName().equals(INSTANCE_ELEMENT_NAME)) {
// load the instance data
ExclusionInstance instance = ExclusionInstance
.loadInstanceData(instanceElement);
newExclusion.fExclusionInstanceList.add(instance);
}
}
}
// load nested exclusions
List<RefreshExclusion> nestedExclusions = loadData(exclusionElement,
newExclusion, null);
// add to parent
for (RefreshExclusion nestedExclusion : nestedExclusions) {
newExclusion.addNestedExclusion(nestedExclusion);
}
// add the new exclusion to the list of exclusions to return
exclusions.add(newExclusion);
}
// load nested exclusions
List<RefreshExclusion> nestedExclusions = loadData(exclusionElement, newExclusion);
// add to parent
for(RefreshExclusion nestedExclusion : nestedExclusions) {
newExclusion.addNestedExclusion(nestedExclusion);
}
// add the new exclusion to the list of exclusions to return
exclusions.add(newExclusion);
}
}

View file

@ -0,0 +1,55 @@
/*******************************************************************************
* Copyright (c) 2011 IBM Corporation 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:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.resources;
/**
* Responsible for manufacturing a given type of RefreshExclusion. Called by the
* RefreshScopeManager when loading persisted settings to instantiate exclusion objects.
*
* @author crecoskie
* @since 5.3
*
*/
public abstract class RefreshExclusionFactory {
/**
* Creates a new RefreshExclusion.
*
* @return RefreshExclusion
*/
abstract public RefreshExclusion createNewExclusion();
/**
* Creates a new ExclusionInstance
*
* @return ExclusionInstance
*/
abstract public ExclusionInstance createNewExclusionInstance();
/**
* Returns the fully qualified classname of the type of the object that will
* be returned by org.eclipse.cdt.core.resources.RefreshExclusionFactory.createNewExclusion()
*
* @return String
*/
abstract public String getExclusionClassname();
/**
* Returns the fully qualified classname of the type of the object that will
* be returned by org.eclipse.cdt.core.resources.RefreshExclusionFactory.createNewExclusionInstance()
*
* @return String
*/
abstract public String getInstanceClassname();
}

View file

@ -36,6 +36,10 @@ 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.IConfigurationElement;
import org.eclipse.core.runtime.IExtension;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.QualifiedName;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@ -67,17 +71,62 @@ public class RefreshScopeManager {
public static final String VERSION_NUMBER_ATTRIBUTE_NAME = "versionNumber"; //$NON-NLS-1$
public static final String VERSION_ELEMENT_NAME = "version"; //$NON-NLS-1$
public static final QualifiedName REFRESH_SCOPE_PROPERTY_NAME = new QualifiedName(CCorePlugin.PLUGIN_ID, "refreshScope"); //$NON-NLS-1$
public static final String EXTENSION_ID = "RefreshExclusionFactory"; //$NON-NLS-1$
public static final Object EXCLUSION_FACTORY = "exclusionFactory"; //$NON-NLS-1$
public static final String EXCLUSION_CLASS = "exclusionClass"; //$NON-NLS-1$
public static final String FACTORY_CLASS = "factoryClass"; //$NON-NLS-1$
public static final String INSTANCE_CLASS = "instanceClass"; //$NON-NLS-1$
private int fVersion = 1;
private RefreshScopeManager(){
}
private HashMap<IProject, LinkedHashSet<IResource>> fProjectToResourcesMap;
private HashMap<IResource, List<RefreshExclusion>> fResourceToExclusionsMap;
private HashMap<String, RefreshExclusionFactory> fClassnameToExclusionFactoryMap;
private static RefreshScopeManager fInstance;
private RefreshScopeManager(){
fClassnameToExclusionFactoryMap = new HashMap<String, RefreshExclusionFactory>();
loadExtensions();
}
public synchronized void loadExtensions() {
IExtensionPoint extension = Platform.getExtensionRegistry().getExtensionPoint(CCorePlugin.PLUGIN_ID,
EXTENSION_ID);
if (extension != null) {
IExtension[] extensions = extension.getExtensions();
for (IExtension extension2 : extensions) {
IConfigurationElement[] configElements = extension2.getConfigurationElements();
for (IConfigurationElement configElement : configElements) {
if (configElement.getName().equals(EXCLUSION_FACTORY)) {
String exclusionClassName = configElement.getAttribute(EXCLUSION_CLASS);
String factoryClassName = configElement.getAttribute(FACTORY_CLASS);
String instanceClassName = configElement.getAttribute(INSTANCE_CLASS);
if (factoryClassName != null) {
try {
Object execExt = configElement.createExecutableExtension(FACTORY_CLASS);
if ((execExt instanceof RefreshExclusionFactory)) {
RefreshExclusionFactory exclusionFactory = (RefreshExclusionFactory) execExt;
if(exclusionClassName != null) {
fClassnameToExclusionFactoryMap.put(exclusionClassName, exclusionFactory);
}
if(instanceClassName != null) {
fClassnameToExclusionFactoryMap.put(instanceClassName, exclusionFactory);
}
}
} catch (CoreException e) {
CCorePlugin.log(e);
}
}
}
}
}
}
}
public static synchronized RefreshScopeManager getInstance() {
if(fInstance == null) {
fInstance = new RefreshScopeManager();
@ -90,6 +139,22 @@ public class RefreshScopeManager {
return fVersion;
}
public RefreshExclusionFactory getFactoryForClassName(String className) {
RefreshExclusionFactory factory = fClassnameToExclusionFactoryMap.get(className);
return factory;
}
public RefreshExclusion getExclusionForClassName(String className) {
RefreshExclusionFactory factory = getFactoryForClassName(className);
if(factory == null) {
return null;
}
return factory.createNewExclusion();
}
/**
* Returns the set of resources that should be refreshed for a project.
@ -276,87 +341,99 @@ public class RefreshScopeManager {
}
public void loadSettings() throws CoreException {
// iterate through all projects in the workspace. If they are C projects, attempt to load settings from them.
// 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)) {
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,
// 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;
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory
.newInstance();
DocumentBuilder docBuilder = null;
try {
docBuilder = docBuilderFactory.newDocumentBuilder();
} catch (ParserConfigurationException e) {
throw new CoreException(CCorePlugin.createStatus(Messages.RefreshScopeManager_0, 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));
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));
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++) {
// iterate through the child nodes
NodeList nodeList = doc.getDocumentElement().getChildNodes(); // child of the doc is the root
for (int k = 0; k < nodeList.getLength(); k++) {
Node node = nodeList.item(k);
// node will be an element
if(node instanceof 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) {
if (resourceElement.getNodeName().equals(RESOURCE_ELEMENT_NAME)) {
// get the resource path
String resourcePath = resourceElement
.getAttribute(WORKSPACE_PATH_ATTRIBUTE_NAME);
if (resourcePath == 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);
// 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, resource);
// add them
for (RefreshExclusion exclusion : exclusions) {
addExclusion(resource, exclusion);
}
}
}
}
}
}
}
}
}
}
}
@ -381,4 +458,14 @@ public class RefreshScopeManager {
fResourceToExclusionsMap.clear();
}
public ExclusionInstance getInstanceForClassName(String className) {
RefreshExclusionFactory factory = getFactoryForClassName(className);
if(factory == null) {
return null;
}
return factory.createNewExclusionInstance();
}
}

View file

@ -8,6 +8,7 @@
# Contributors:
# IBM Corporation - initial API and implementation
###############################################################################
RefreshExclusion_0=Error creating class {0} from project refresh settings
RefreshScopeManager_0=Error instantiating XML document builder.
RefreshScopeManager_1=Error instantiating XML transformer.
RefreshScopeManager_2=Error transforming XML.

View file

@ -10,11 +10,9 @@
*******************************************************************************/
package org.eclipse.cdt.ui.resources;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
@ -67,14 +65,14 @@ public class RefreshExclusionContributionManager {
String id = configElement.getAttribute("id"); //$NON-NLS-1$
String name = configElement.getAttribute("name"); //$NON-NLS-1$
String utility = configElement.getAttribute("class"); //$NON-NLS-1$
String contributorClassName = configElement.getAttribute("class"); //$NON-NLS-1$
boolean isTest = false;
String isTestString = configElement.getAttribute("isTest");
String isTestString = configElement.getAttribute("isTest"); //$NON-NLS-1$
if(isTestString != null) {
isTest = Boolean.getBoolean(isTestString);
}
if (utility != null) {
if (contributorClassName != null) {
try {
Object execExt = configElement.createExecutableExtension("class"); //$NON-NLS-1$
if ((execExt instanceof RefreshExclusionContributor) && id != null) {

View file

@ -50,7 +50,7 @@ public abstract class RefreshExclusionContributor {
/**
* Returns the human-readable name of this exclusion type.
*
* @return
* @return String.
*/
public String getName() {
return fName;