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

- serialize/deserialize to/from C project description
- fix stack overflow issue on load
- move ResourceExclusion and friends to internal packages
This commit is contained in:
Chris Recoskie 2011-05-10 16:53:37 +00:00
parent 2fab85bf17
commit b609ec68ba
14 changed files with 275 additions and 331 deletions

View file

@ -161,7 +161,7 @@ public class RefreshPolicyTab extends AbstractCPropertyTab {
public Object[] getChildren() {
if (isExclusion()) {
List children = new ArrayList(exclusion_instances);
List<Object> children = new ArrayList<Object>(exclusion_instances);
if (exceptions_node != null)
children.add(exceptions_node);
return children.toArray();
@ -603,7 +603,7 @@ public class RefreshPolicyTab extends AbstractCPropertyTab {
}
try {
fManager.persistSettings();
fManager.persistSettings(getResDesc().getConfiguration().getProjectDescription());
} catch (CoreException e) {
// TODO Auto-generated catch block
e.printStackTrace();

View file

@ -19,16 +19,19 @@ import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.eclipse.cdt.core.CProjectNature;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.IPDOMManager;
import org.eclipse.cdt.core.model.ICProject;
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.RefreshScopeManager;
import org.eclipse.cdt.core.resources.ResourceExclusion;
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
import org.eclipse.cdt.core.testplugin.CProjectHelper;
import org.eclipse.cdt.core.testplugin.CTestPlugin;
import org.eclipse.cdt.internal.core.resources.ResourceExclusion;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.IWorkspaceRunnable;
@ -60,20 +63,8 @@ public class RefreshScopeTests extends TestCase {
// create project
CTestPlugin.getWorkspace().run(new IWorkspaceRunnable() {
public void run(IProgressMonitor monitor) throws CoreException {
IWorkspaceRoot root = CTestPlugin.getWorkspace().getRoot();
IProject project = root.getProject("testRefreshScope");
if (!project.exists()) {
project.create(null);
} else {
project.refreshLocal(IResource.DEPTH_INFINITE, null);
}
if (!project.isOpen()) {
project.open(null);
}
if (!project.hasNature(CProjectNature.C_NATURE_ID)) {
addNatureToProject(project, CProjectNature.C_NATURE_ID, null);
}
fProject = project;
ICProject cProject = CProjectHelper.createNewStileCProject("testRefreshScope", IPDOMManager.ID_NO_INDEXER, false);
fProject = cProject.getProject();
}
}, null);
@ -120,16 +111,6 @@ public class RefreshScopeTests extends TestCase {
}
private static void addNatureToProject(IProject proj, String natureId, IProgressMonitor monitor) throws CoreException {
IProjectDescription description = proj.getDescription();
String[] prevNatures = description.getNatureIds();
String[] newNatures = new String[prevNatures.length + 1];
System.arraycopy(prevNatures, 0, newNatures, 0, prevNatures.length);
newNatures[prevNatures.length] = natureId;
description.setNatureIds(newNatures);
proj.setDescription(description, monitor);
}
/* (non-Javadoc)
* @see junit.framework.TestCase#tearDown()
*/
@ -248,8 +229,11 @@ public class RefreshScopeTests extends TestCase {
instance.setParentExclusion(exclusion2);
exclusion2.addExclusionInstance(instance);
ICProjectDescription projectDescription = CCorePlugin.getDefault().getProjectDescription(fProject, true);
try {
manager.persistSettings();
manager.persistSettings(projectDescription);
CCorePlugin.getDefault().setProjectDescription(fProject, projectDescription);
} catch (CoreException e) {
fail();
}
@ -273,7 +257,7 @@ public class RefreshScopeTests extends TestCase {
// there should be 2 top-level exclusions
List<RefreshExclusion> exclusions = manager.getExclusions(fProject);
assertEquals(exclusions.size(), 2);
assertEquals(2, exclusions.size());
RefreshExclusion[] exclusionsArray = exclusions.toArray(new RefreshExclusion[0]);
// both exclusions should have parent resource set to the project
@ -434,9 +418,11 @@ public class RefreshScopeTests extends TestCase {
List<RefreshExclusion> exclusions = manager.getExclusions(fProject);
assertEquals(0, exclusions.size());
ICProjectDescription projectDescription = CCorePlugin.getDefault().getProjectDescription(fProject);
// now try persisting the data and loading it
try {
manager.persistSettings();
manager.persistSettings(projectDescription);
} catch (CoreException e) {
fail();
}

View file

@ -40,7 +40,12 @@ Export-Package: org.eclipse.cdt.core,
org.eclipse.cdt.core.templateengine,
org.eclipse.cdt.core.templateengine.process,
org.eclipse.cdt.core.templateengine.process.processes,
org.eclipse.cdt.internal.core;x-friends:="org.eclipse.cdt.ui,org.eclipse.cdt.debug.core,org.eclipse.cdt.managedbuilder.core,org.eclipse.cdt.make.core,org.eclipse.cdt.make.ui",
org.eclipse.cdt.internal.core;
x-friends:="org.eclipse.cdt.ui,
org.eclipse.cdt.debug.core,
org.eclipse.cdt.managedbuilder.core,
org.eclipse.cdt.make.core,
org.eclipse.cdt.make.ui",
org.eclipse.cdt.internal.core.browser;x-friends:="org.eclipse.cdt.ui",
org.eclipse.cdt.internal.core.cdtvariables;x-internal:=true,
org.eclipse.cdt.internal.core.dom;x-internal:=true,

View file

@ -743,5 +743,12 @@
version="5.0.0">
</CProjectStorageType>
</extension>
<extension
point="org.eclipse.cdt.core.RefreshExclusionFactory">
<exclusionFactory
exclusionClass="org.eclipse.cdt.internal.core.resources.ResourceExclusion"
factoryClass="org.eclipse.cdt.internal.core.resources.ResourceExclusionFactory">
</exclusionFactory>
</extension>
</plugin>

View file

@ -10,10 +10,9 @@
*******************************************************************************/
package org.eclipse.cdt.core.resources;
import org.eclipse.cdt.core.settings.model.ICStorageElement;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
/**
* Represents a particular instance of an exclusion. E.g., if an exclusion allowed
@ -100,9 +99,9 @@ public class ExclusionInstance {
fDisplayString = displayString;
}
public synchronized void persistInstanceData(Document doc, Element exclusionElement) {
public synchronized void persistInstanceData(ICStorageElement exclusionElement) {
Element instanceElement = doc.createElement(INSTANCE_ELEMENT_NAME);
ICStorageElement instanceElement = exclusionElement.createChild(INSTANCE_ELEMENT_NAME);
// persist the type of the object we are
instanceElement.setAttribute(CLASS_ATTRIBUTE_NAME, this.getClass().getName());
@ -137,25 +136,22 @@ public class ExclusionInstance {
instanceElement.setAttribute(DISPLAY_STRING_ATTRIBUTE_NAME, fDisplayString);
}
exclusionElement.appendChild(instanceElement);
// persist any data from extenders
persistExtendedInstanceData(doc, instanceElement);
persistExtendedInstanceData(instanceElement);
}
protected synchronized void persistExtendedInstanceData(Document doc, Element instanceElement) {
protected synchronized void persistExtendedInstanceData(ICStorageElement instanceElement) {
// override to provide extension specific behaviour if desired
}
public synchronized static ExclusionInstance loadInstanceData(Element instanceElement) {
public synchronized static ExclusionInstance loadInstanceData(ICStorageElement instanceElement, RefreshScopeManager manager) {
String className = instanceElement.getAttribute(CLASS_ATTRIBUTE_NAME);
ExclusionInstance newInstance = null;
// see if there is a custom instance class
RefreshScopeManager manager = RefreshScopeManager.getInstance();
newInstance = manager.getInstanceForClassName(className);
if(newInstance == null) {
@ -200,7 +196,7 @@ public class ExclusionInstance {
return newInstance;
}
protected synchronized void loadExtendedInstanceData(Element instanceElement) {
protected synchronized void loadExtendedInstanceData(ICStorageElement child) {
// override to provide extension specific behaviour if desired
}
}

View file

@ -15,12 +15,9 @@ import java.util.LinkedList;
import java.util.List;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.settings.model.ICStorageElement;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import com.ibm.icu.text.MessageFormat;
@ -207,9 +204,9 @@ public abstract class RefreshExclusion {
fNestedExclusions.remove(exclusion);
}
public synchronized void persistData(Document doc, Element parentElement) {
public synchronized void persistData(ICStorageElement parentElement) {
// persist the common data that all RefreshExclusions have
Element exclusionElement = doc.createElement(EXCLUSION_ELEMENT_NAME);
ICStorageElement exclusionElement = parentElement.createChild(EXCLUSION_ELEMENT_NAME);
// persist the type of the object we are
exclusionElement.setAttribute(CLASS_ATTRIBUTE_NAME, this.getClass().getName());
@ -238,145 +235,113 @@ public abstract class RefreshExclusion {
// the structure of the XML tree
exclusionElement.setAttribute(CONTRIBUTOR_ID_ATTRIBUTE_NAME, getContributorId());
parentElement.appendChild(exclusionElement);
// persist instances
for(ExclusionInstance instance : fExclusionInstanceList) {
instance.persistInstanceData(doc, exclusionElement);
instance.persistInstanceData(exclusionElement);
}
// provide a place for extenders to store their own data
Element extensionElement = doc.createElement(EXTENSION_DATA_ELEMENT_NAME);
exclusionElement.appendChild(extensionElement);
ICStorageElement extensionElement = exclusionElement.createChild(EXTENSION_DATA_ELEMENT_NAME);
// call extender to store any extender-specific data
persistExtendedData(doc, extensionElement);
persistExtendedData(extensionElement);
// persist nested exclusions
for(RefreshExclusion exclusion : fNestedExclusions) {
exclusion.persistData(doc, exclusionElement);
exclusion.persistData(exclusionElement);
}
}
protected synchronized void persistExtendedData(Document doc, Element extensionElement) {
protected synchronized void persistExtendedData(ICStorageElement extensionElement) {
// override to provide extension specific behaviour if desired
}
protected synchronized void loadExtendedData(Element parentElement) {
protected synchronized void loadExtendedData(ICStorageElement grandchild) {
// override to provide extension specific behaviour if desired
}
public synchronized static List<RefreshExclusion> loadData(Element parentElement, RefreshExclusion parentExclusion, IResource parentResource) throws CoreException {
public synchronized static List<RefreshExclusion> loadData(ICStorageElement parentElement,
RefreshExclusion parentExclusion, IResource parentResource, RefreshScopeManager manager) throws CoreException {
List<RefreshExclusion> exclusions = new LinkedList<RefreshExclusion>();
// the parent element might contain any number of exclusions... iterate through the list
NodeList childNodes = parentElement.getChildNodes();
ICStorageElement[] children = parentElement.getChildren();
for (int i = 0; i < childNodes.getLength(); i++) {
Node node = childNodes.item(i);
for (ICStorageElement child : children) {
// node should be an element
if (node instanceof Element) {
Element exclusionElement = (Element) node;
if (child.getName().equals(EXCLUSION_ELEMENT_NAME)) {
if (exclusionElement.getNodeName().equals(EXCLUSION_ELEMENT_NAME)) {
// create an object of the proper type
String className = child.getAttribute(CLASS_ATTRIBUTE_NAME);
RefreshExclusion newExclusion = manager.getExclusionForClassName(className);
// 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)));
}
// 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
}
}
// set parent if nested
newExclusion.fParentExclusion = parentExclusion;
// 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);
if (newExclusion == null) {
throw new CoreException(CCorePlugin.createStatus(MessageFormat.format(
Messages.RefreshExclusion_0, className)));
}
// load the exclusion type
String exclusionTypeString = child.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
}
}
// set parent if nested
newExclusion.fParentExclusion = parentExclusion;
// set parent resource if there is one
newExclusion.fParentResource = parentResource;
newExclusion.fContributorId = child.getAttribute(CONTRIBUTOR_ID_ATTRIBUTE_NAME);
// get the extension element
ICStorageElement[] grandchildren = child.getChildren();
for (ICStorageElement grandchild : grandchildren) {
if (grandchild.getName().equals(RefreshExclusion.EXTENSION_DATA_ELEMENT_NAME)) {
// load the extension's data
newExclusion.loadExtendedData(grandchild);
}
else if (grandchild.getName().equals(INSTANCE_ELEMENT_NAME)) {
// load the instance data
ExclusionInstance instance = ExclusionInstance.loadInstanceData(grandchild, manager);
newExclusion.fExclusionInstanceList.add(instance);
}
}
// load nested exclusions
List<RefreshExclusion> nestedExclusions = loadData(child, newExclusion, null, manager);
// add to parent
for (RefreshExclusion nestedExclusion : nestedExclusions) {
newExclusion.addNestedExclusion(nestedExclusion);
}
// add the new exclusion to the list of exclusions to return
exclusions.add(newExclusion);
}
}
return exclusions;
}

View file

@ -10,26 +10,16 @@
*******************************************************************************/
package org.eclipse.cdt.core.resources;
import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;
import java.text.MessageFormat;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.CProjectNature;
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
import org.eclipse.cdt.core.settings.model.ICStorageElement;
import org.eclipse.cdt.internal.core.settings.model.CProjectDescriptionManager;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
@ -46,13 +36,6 @@ import org.eclipse.core.runtime.IExtension;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.QualifiedName;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
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
@ -71,12 +54,12 @@ import org.xml.sax.SAXException;
*
*/
public class RefreshScopeManager {
public static final String WORKSPACE_PATH_ATTRIBUTE_NAME = "workspacePath"; //$NON-NLS-1$
public static final String RESOURCE_ELEMENT_NAME = "resource"; //$NON-NLS-1$
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 REFRESH_SCOPE_STORAGE_NAME = "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$
@ -89,6 +72,8 @@ public class RefreshScopeManager {
private HashMap<String, RefreshExclusionFactory> fClassnameToExclusionFactoryMap;
private static RefreshScopeManager fInstance;
private boolean fIsLoading = false;
private boolean fIsLoaded = false;
private RefreshScopeManager(){
fClassnameToExclusionFactoryMap = new HashMap<String, RefreshExclusionFactory>();
@ -288,12 +273,14 @@ public class RefreshScopeManager {
}
public synchronized void clearAllResourcesToRefresh() {
getProjectToResourcesMap();
fProjectToResourcesMap.clear();
}
public synchronized void clearAllData() {
clearAllResourcesToRefresh();
clearAllExclusions();
fIsLoaded = false;
}
private HashMap<IProject, LinkedHashSet<IResource>> getProjectToResourcesMap() {
@ -346,82 +333,58 @@ public class RefreshScopeManager {
exclusions.remove(exclusion);
}
public synchronized void persistSettings() throws CoreException {
public synchronized void persistSettings(ICProjectDescription projectDescription) throws CoreException {
getProjectToResourcesMap();
getResourcesToExclusionsMap();
for(IProject project : fProjectToResourcesMap.keySet()) {
for (IProject project : fProjectToResourcesMap.keySet()) {
if (!project.exists()) {
continue;
}
// serialize all settings for the project to an XML document which we will use to persist
// the data to a persistent resource property
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = null;
try {
docBuilder = docBuilderFactory.newDocumentBuilder();
} catch (ParserConfigurationException e) {
throw new CoreException(CCorePlugin.createStatus(Messages.RefreshScopeManager_0, e));
}
// create document root
Document doc = docBuilder.newDocument();
Element root = doc.createElement("root"); //$NON-NLS-1$
doc.appendChild(root);
Element versionElement = doc.createElement(VERSION_ELEMENT_NAME);
versionElement.setAttribute(VERSION_NUMBER_ATTRIBUTE_NAME, Integer.toString(fVersion));
root.appendChild(versionElement);
for(IResource resource : fProjectToResourcesMap.get(project)) {
// create a resource node
Element resourceElement = doc.createElement(RESOURCE_ELEMENT_NAME);
resourceElement.setAttribute(WORKSPACE_PATH_ATTRIBUTE_NAME, resource.getFullPath().toString());
root.appendChild(resourceElement);
// populate the node with any exclusions
List<RefreshExclusion> exclusions = fResourceToExclusionsMap.get(resource);
if (exclusions != null) {
for(RefreshExclusion exclusion : exclusions) {
exclusion.persistData(doc, resourceElement);
}
}
}
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer;
try {
transformer = transformerFactory.newTransformer();
} catch (TransformerConfigurationException e) {
throw new CoreException(CCorePlugin.createStatus(Messages.RefreshScopeManager_1, e));
}
//transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); //$NON-NLS-1$
//create a string from xml tree
StringWriter stringWriter = new StringWriter();
StreamResult result = new StreamResult(stringWriter);
DOMSource source = new DOMSource(doc);
try {
transformer.transform(source, result);
} catch (TransformerException e) {
throw new CoreException(CCorePlugin.createStatus(Messages.RefreshScopeManager_2, e));
}
String xmlString = stringWriter.toString();
// use the string as a value for a persistent resource property on the project
project.setPersistentProperty(REFRESH_SCOPE_PROPERTY_NAME, xmlString);
// serialize all settings for the project to the C Project Description
if (project.isOpen()) {
if (project.hasNature(CProjectNature.C_NATURE_ID)) {
ICStorageElement storageElement = projectDescription.getStorage(REFRESH_SCOPE_STORAGE_NAME, true);
storageElement.clear();
storageElement.setAttribute(VERSION_NUMBER_ATTRIBUTE_NAME, Integer.toString(fVersion));
for (IResource resource : fProjectToResourcesMap.get(project)) {
// create a resource node
ICStorageElement resourceElement = storageElement.createChild(RESOURCE_ELEMENT_NAME);
resourceElement.setAttribute(WORKSPACE_PATH_ATTRIBUTE_NAME, resource
.getFullPath().toString());
// populate the node with any exclusions
List<RefreshExclusion> exclusions = fResourceToExclusionsMap.get(resource);
if (exclusions != null) {
for (RefreshExclusion exclusion : exclusions) {
exclusion.persistData(resourceElement);
}
}
}
}
}
}
}
public synchronized 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();
if(!fIsLoaded && !fIsLoading) {
fIsLoading = true;
// 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()) {
loadSettings(workspaceRoot, project);
for (IProject project : workspaceRoot.getProjects()) {
loadSettings(workspaceRoot, project);
}
fIsLoaded = true;
fIsLoading = false;
}
}
@ -430,95 +393,57 @@ public class RefreshScopeManager {
* @param project
* @throws CoreException
*/
private synchronized void loadSettings(IWorkspaceRoot workspaceRoot, IProject project) throws CoreException {
private synchronized void loadSettings(IWorkspaceRoot workspaceRoot, IProject project)
throws CoreException {
if (project.isOpen()) {
if (project.hasNature(CProjectNature.C_NATURE_ID)) {
String xmlString = project.getPersistentProperty(REFRESH_SCOPE_PROPERTY_NAME);
ICProjectDescription projectDescription = CProjectDescriptionManager.getInstance()
.getProjectDescription(project, false);
ICStorageElement storageElement = projectDescription.getStorage(
REFRESH_SCOPE_STORAGE_NAME, true);
// if there are no settings, then configure the default behaviour of refreshing the entire
// project,
// with no exclusions
if (xmlString == null) {
addResourceToRefresh(project, project);
}
// walk the tree and load the settings
else {
// convert the XML string to a DOM model
// for now ignore the version attribute, as we only have version 1 at this time
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory
.newInstance();
DocumentBuilder docBuilder = null;
try {
docBuilder = docBuilderFactory.newDocumentBuilder();
} catch (ParserConfigurationException e) {
throw new CoreException(CCorePlugin.createStatus(
Messages.RefreshScopeManager_0, e));
}
// iterate through the child nodes
ICStorageElement[] children = storageElement.getChildren();
Document doc = null;
for (ICStorageElement child : children) {
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));
}
if (child.getName().equals(RESOURCE_ELEMENT_NAME)) {
// walk the DOM and load the settings
// get the resource path
String resourcePath = child.getAttribute(WORKSPACE_PATH_ATTRIBUTE_NAME);
// for now ignore the version attribute, as we only have version 1 at this time
if (resourcePath == null) {
// error
// 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);
else {
// find the resource
IResource resource = workspaceRoot.findMember(resourcePath);
// node will be an element
if (node instanceof Element) {
Element resourceElement = (Element) node;
if (resource == null) {
// error
}
if (resourceElement.getNodeName().equals(RESOURCE_ELEMENT_NAME)) {
else {
addResourceToRefresh(project, resource);
// get the resource path
String resourcePath = resourceElement
.getAttribute(WORKSPACE_PATH_ATTRIBUTE_NAME);
// load any exclusions
List<RefreshExclusion> exclusions = RefreshExclusion.loadData(
child, null, resource, this);
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, resource);
// add them
for (RefreshExclusion exclusion : exclusions) {
addExclusion(resource, exclusion);
}
}
// add them
for (RefreshExclusion exclusion : exclusions) {
addExclusion(resource, exclusion);
}
}
}
}
}
}
}
}

View file

@ -9,11 +9,14 @@
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.resources;
package org.eclipse.cdt.internal.core.resources;
import java.util.LinkedList;
import java.util.List;
import org.eclipse.cdt.core.resources.ExclusionInstance;
import org.eclipse.cdt.core.resources.Messages;
import org.eclipse.cdt.core.resources.RefreshExclusion;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IResource;

View file

@ -0,0 +1,64 @@
/*******************************************************************************
* 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.internal.core.resources;
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 ResourceExclusionFactory extends RefreshExclusionFactory {
/**
*
*/
public ResourceExclusionFactory() {
// TODO Auto-generated constructor stub
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.resources.RefreshExclusionFactory#createNewExclusion()
*/
@Override
public RefreshExclusion createNewExclusion() {
return new ResourceExclusion();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.resources.RefreshExclusionFactory#createNewExclusionInstance()
*/
@Override
public ExclusionInstance createNewExclusionInstance() {
// TODO Auto-generated method stub
return null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.resources.RefreshExclusionFactory#getExclusionClassname()
*/
@Override
public String getExclusionClassname() {
return ResourceExclusion.class.getName();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.resources.RefreshExclusionFactory#getInstanceClassname()
*/
@Override
public String getInstanceClassname() {
// TODO Auto-generated method stub
return null;
}
}

View file

@ -44,6 +44,7 @@ Export-Package: org.eclipse.cdt.internal.corext;x-internal:=true,
org.eclipse.cdt.internal.ui.refactoring.rename;x-friends:="org.eclipse.cdt.ui.tests",
org.eclipse.cdt.internal.ui.refactoring.togglefunction;x-friends:="org.eclipse.cdt.ui.tests",
org.eclipse.cdt.internal.ui.refactoring.utils;x-friends:="org.eclipse.cdt.ui.tests",
org.eclipse.cdt.internal.ui.resources,
org.eclipse.cdt.internal.ui.search;x-internal:=true,
org.eclipse.cdt.internal.ui.search.actions;x-internal:=true,
org.eclipse.cdt.internal.ui.text;x-internal:=true,

View file

@ -606,3 +606,5 @@ transfer.EditorBehavior.description = Preference related to how the editor proce
# Refresh Exclusion Contributors
RefreshExclusionContributor.name = Resources
extension-point.name = Refresh Exclusion Contributor

View file

@ -26,7 +26,7 @@
<extension-point id="quickAssistProcessors" name="%quickAssistProcessorExtensionPoint" schema="schema/quickAssistProcessors.exsd"/>
<extension-point id="DocCommentOwner" name="%DocCommentOwner.name" schema="schema/DocCommentOwner.exsd"/>
<extension-point id="workingSetConfigurations" name="%workingSetConfigurationsExtensionPoint" schema="schema/workingSetConfigurations.exsd"/>
<extension-point id="RefreshExclusionContributor" name="Refresh Exclusion Contributor" schema="schema/RefreshExclusionContributor.exsd"/>
<extension-point id="RefreshExclusionContributor" name="%extension-point.name" schema="schema/RefreshExclusionContributor.exsd"/>
<extension
point="org.eclipse.core.runtime.adapters">
@ -3977,7 +3977,7 @@
<extension
point="org.eclipse.cdt.ui.RefreshExclusionContributor">
<exclusionContributor
class="org.eclipse.cdt.ui.resources.ResourceExclusionContributor"
class="org.eclipse.cdt.internal.ui.resources.ResourceExclusionContributor"
id="org.eclipse.cdt.ui.ResourceExclusionContributor"
name="%RefreshExclusionContributor.name">
</exclusionContributor>

View file

@ -9,7 +9,7 @@
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.ui.resources;
package org.eclipse.cdt.internal.ui.resources;
import java.util.ArrayList;
import java.util.Arrays;
@ -37,12 +37,14 @@ import org.eclipse.swt.widgets.List;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.dialogs.CheckedTreeSelectionDialog;
import org.eclipse.ui.model.WorkbenchLabelProvider;
import org.w3c.dom.Element;
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.ResourceExclusion;
import org.eclipse.cdt.ui.resources.Messages;
import org.eclipse.cdt.ui.resources.RefreshExclusionContributor;
import org.eclipse.cdt.internal.core.resources.ResourceExclusion;
/**
* <strong>EXPERIMENTAL</strong>. This class or interface has been added as
@ -278,13 +280,4 @@ public class ResourceExclusionContributor extends RefreshExclusionContributor {
});
}
/* (non-Javadoc)
* @see org.eclipse.cdt.ui.resources.RefreshExclusionContributor#createExclusionFromXML(org.w3c.dom.Element)
*/
@Override
public RefreshExclusion createExclusionFromXML(Element exclusionElement) {
// TODO Auto-generated method stub
return null;
}
}

View file

@ -11,7 +11,6 @@
package org.eclipse.cdt.ui.resources;
import org.eclipse.swt.widgets.Composite;
import org.w3c.dom.Element;
import org.eclipse.cdt.core.resources.RefreshExclusion;
@ -68,7 +67,5 @@ public abstract class RefreshExclusionContributor {
* @param exclusion - the RefreshExclusion to be modified
*/
abstract public void createProperiesUI(Composite parent, RefreshExclusion exclusion);
abstract public RefreshExclusion createExclusionFromXML(Element exclusionElement);
}