From 95bf88c5a0c734f18e2dcc3e2a9ff9b06418a7e0 Mon Sep 17 00:00:00 2001 From: Chris Recoskie Date: Fri, 27 May 2011 18:36:52 +0000 Subject: [PATCH] Bug 133881 - Make refreshing after building optional Code cleanup. --- .../cdt/core/resources/ExclusionInstance.java | 245 +++--- .../cdt/core/resources/ExclusionType.java | 23 +- .../cdt/core/resources/RefreshExclusion.java | 465 +++++------ .../resources/RefreshExclusionFactory.java | 26 +- .../core/resources/RefreshScopeManager.java | 742 +++++++++--------- .../core/resources/ResourceExclusion.java | 50 +- .../resources/ResourceExclusionFactory.java | 18 +- .../ResourceExclusionContributor.java | 207 ++--- .../RefreshExclusionContributionManager.java | 84 +- .../RefreshExclusionContributor.java | 64 +- 10 files changed, 985 insertions(+), 939 deletions(-) diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/ExclusionInstance.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/ExclusionInstance.java index 192d80bf156..2720428f4dd 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/ExclusionInstance.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/ExclusionInstance.java @@ -15,40 +15,105 @@ import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.ResourcesPlugin; /** - * Represents a particular instance of an exclusion. E.g., if an exclusion allowed - * for the exclusion of a list individual resources, there would be one exclusion instance - * per resource. Each exclusion instance is presented in the user interface as a child of the exclusion. + * Represents a particular instance of an exclusion. E.g., if an exclusion allowed for the exclusion of a list + * individual resources, there would be one exclusion instance per resource. Each exclusion instance is + * presented in the user interface as a child of the exclusion. * * Clients may extend this class to provide custom implementations for their exclusion type. * - * EXPERIMENTAL. This class or interface has been added as - * part of a work in progress. There is no guarantee that this API will work or - * that it will remain the same. Please do not use this API without consulting - * with the CDT team. + * EXPERIMENTAL. This class or interface has been added as part of a work in progress. There + * is no guarantee that this API will work or that it will remain the same. Please do not use this API without + * consulting with the CDT team. * * @author crecoskie * @since 5.3 - * + * */ public class ExclusionInstance { - + public static final String CLASS_ATTRIBUTE_NAME = "class"; //$NON-NLS-1$ - public static final String EXTENSION_DATA_ELEMENT_NAME = "extensionData"; //$NON-NLS-1$ public static final String CONTRIBUTOR_ID_ATTRIBUTE_NAME = "contributorId"; //$NON-NLS-1$ - public static final String INSTANCE_ELEMENT_NAME = "instance"; //$NON-NLS-1$ - public static final String WORKSPACE_PATH_ATTRIBUTE_NAME = "workspacePath"; //$NON-NLS-1$ - public static final String EXCLUSION_TYPE_ATTRIBUTE_NAME = "exclusionType"; //$NON-NLS-1$ - public static final String EXCLUSION_ELEMENT_NAME = "exclusion"; //$NON-NLS-1$ - public static final String RESOURCE_VALUE = "RESOURCE"; //$NON-NLS-1$ - public static final String FOLDER_VALUE = "FOLDER"; //$NON-NLS-1$ - public static final String FILE_VALUE = "FILE"; //$NON-NLS-1$ public static final String DISPLAY_STRING_ATTRIBUTE_NAME = "displayString"; //$NON-NLS-1$ - - protected ExclusionType fInstanceExclusionType; - protected IResource fResource; + public static final String EXCLUSION_ELEMENT_NAME = "exclusion"; //$NON-NLS-1$ + public static final String EXCLUSION_TYPE_ATTRIBUTE_NAME = "exclusionType"; //$NON-NLS-1$ + public static final String EXTENSION_DATA_ELEMENT_NAME = "extensionData"; //$NON-NLS-1$ + public static final String FILE_VALUE = "FILE"; //$NON-NLS-1$ + public static final String FOLDER_VALUE = "FOLDER"; //$NON-NLS-1$ + public static final String INSTANCE_ELEMENT_NAME = "instance"; //$NON-NLS-1$ + public static final String RESOURCE_VALUE = "RESOURCE"; //$NON-NLS-1$ + public static final String WORKSPACE_PATH_ATTRIBUTE_NAME = "workspacePath"; //$NON-NLS-1$ + + 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 + newInstance = manager.getInstanceForClassName(className); + + if (newInstance == null) { + newInstance = new ExclusionInstance(); + } + + // load the exclusion type + String exclusionTypeString = instanceElement.getAttribute(EXCLUSION_TYPE_ATTRIBUTE_NAME); + if (exclusionTypeString != null) { + if (exclusionTypeString.equals(FILE_VALUE)) { + newInstance.fInstanceExclusionType = org.eclipse.cdt.core.resources.ExclusionType.FILE; + } + + else if (exclusionTypeString.equals(FOLDER_VALUE)) { + newInstance.fInstanceExclusionType = org.eclipse.cdt.core.resources.ExclusionType.FOLDER; + } + + else if (exclusionTypeString.equals(RESOURCE_VALUE)) { + newInstance.fInstanceExclusionType = org.eclipse.cdt.core.resources.ExclusionType.RESOURCE; + } + + else { + // error + return null; + } + } + + // load resource path, use it to get the corresponding resource + String resourcePath = instanceElement.getAttribute(WORKSPACE_PATH_ATTRIBUTE_NAME); + + if (resourcePath != null) { + newInstance.fResource = ResourcesPlugin.getWorkspace().getRoot() + .findMember(resourcePath); + } + + // load display string + newInstance.fDisplayString = instanceElement.getAttribute(DISPLAY_STRING_ATTRIBUTE_NAME); + + // load any data from extenders + newInstance.loadExtendedInstanceData(instanceElement); + + return newInstance; + } + protected String fDisplayString; + protected ExclusionType fInstanceExclusionType; protected RefreshExclusion fParent; + protected IResource fResource; + + /** + * @return a String corresponding to the human-readable name for this exclusion instance. Examples of this + * would be the resource name for a resource based exclusion, or the file extension excluded by a + * file extension exclusion. + */ + public synchronized String getDisplayString() { + return fDisplayString; + } + + public synchronized ExclusionType getExclusionType() { + return fInstanceExclusionType; + } + /** * Returns the parent exclusion of this exclusion instance. * @@ -58,21 +123,6 @@ public class ExclusionInstance { return fParent; } - /** - * @param parent the RefreshExclusion to set as the parent. - */ - public synchronized void setParentExclusion(RefreshExclusion parent) { - fParent = parent; - } - - public synchronized ExclusionType getExclusionType() { - return fInstanceExclusionType; - } - - public synchronized void setExclusionType(ExclusionType type) { - fInstanceExclusionType = type; - } - /** * If there is a resource directly associated with this exclusion instance, returns the resource. * @@ -81,122 +131,75 @@ public class ExclusionInstance { public synchronized IResource getResource() { return fResource; } - - public synchronized void setResource(IResource resource) { - fResource = resource; + + protected synchronized void loadExtendedInstanceData(ICStorageElement child) { + // override to provide extension specific behaviour if desired } - - /** - * @return a String corresponding to the human-readable name for this exclusion instance. - * Examples of this would be the resource name for a resource based exclusion, or the file extension - * excluded by a file extension exclusion. - */ - public synchronized String getDisplayString() { - return fDisplayString; - } - - public synchronized void setDisplayString(String displayString) { - fDisplayString = displayString; + + protected synchronized void persistExtendedInstanceData(ICStorageElement instanceElement) { + // override to provide extension specific behaviour if desired } public synchronized void persistInstanceData(ICStorageElement exclusionElement) { - + ICStorageElement instanceElement = exclusionElement.createChild(INSTANCE_ELEMENT_NAME); - + // persist the type of the object we are instanceElement.setAttribute(CLASS_ATTRIBUTE_NAME, this.getClass().getName()); - + // persist the exclusion type String exclusionType = null; - switch(getExclusionType()) { + switch (getExclusionType()) { case FILE: exclusionType = FILE_VALUE; break; - + case FOLDER: exclusionType = FOLDER_VALUE; break; - + case RESOURCE: exclusionType = RESOURCE_VALUE; break; } - - if(exclusionType != null) { + + if (exclusionType != null) { instanceElement.setAttribute(EXCLUSION_TYPE_ATTRIBUTE_NAME, exclusionType); } - + // persist resource path - if(fResource != null) { - instanceElement.setAttribute(WORKSPACE_PATH_ATTRIBUTE_NAME, fResource.getFullPath().toString()); + if (fResource != null) { + instanceElement.setAttribute(WORKSPACE_PATH_ATTRIBUTE_NAME, fResource.getFullPath() + .toString()); } - + // persist display string - if(fDisplayString != null) { + if (fDisplayString != null) { instanceElement.setAttribute(DISPLAY_STRING_ATTRIBUTE_NAME, fDisplayString); } - + // persist any data from extenders persistExtendedInstanceData(instanceElement); - - } - - protected synchronized void persistExtendedInstanceData(ICStorageElement instanceElement) { - // override to provide extension specific behaviour if desired + } - 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 - newInstance = manager.getInstanceForClassName(className); - - if(newInstance == null) { - newInstance = new ExclusionInstance(); - } - - // load the exclusion type - String exclusionTypeString = instanceElement.getAttribute(EXCLUSION_TYPE_ATTRIBUTE_NAME); - if(exclusionTypeString != null) { - if(exclusionTypeString.equals(FILE_VALUE)) { - newInstance.fInstanceExclusionType = org.eclipse.cdt.core.resources.ExclusionType.FILE; - } - - else if(exclusionTypeString.equals(FOLDER_VALUE)) { - newInstance.fInstanceExclusionType = org.eclipse.cdt.core.resources.ExclusionType.FOLDER; - } - - else if(exclusionTypeString.equals(RESOURCE_VALUE)) { - newInstance.fInstanceExclusionType = org.eclipse.cdt.core.resources.ExclusionType.RESOURCE; - } - - else { - // error - return null; - } - } - - // load resource path, use it to get the corresponding resource - String resourcePath = instanceElement.getAttribute(WORKSPACE_PATH_ATTRIBUTE_NAME); - - if(resourcePath != null) { - newInstance.fResource = ResourcesPlugin.getWorkspace().getRoot().findMember(resourcePath); - } - - // load display string - newInstance.fDisplayString = instanceElement.getAttribute(DISPLAY_STRING_ATTRIBUTE_NAME); - - - // load any data from extenders - newInstance.loadExtendedInstanceData(instanceElement); - - return newInstance; + public synchronized void setDisplayString(String displayString) { + fDisplayString = displayString; } - - protected synchronized void loadExtendedInstanceData(ICStorageElement child) { - // override to provide extension specific behaviour if desired + + public synchronized void setExclusionType(ExclusionType type) { + fInstanceExclusionType = type; + } + + /** + * @param parent + * the RefreshExclusion to set as the parent. + */ + public synchronized void setParentExclusion(RefreshExclusion parent) { + fParent = parent; + } + + public synchronized void setResource(IResource resource) { + fResource = resource; } } \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/ExclusionType.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/ExclusionType.java index f98d6cbfb85..8bff9a51436 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/ExclusionType.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/ExclusionType.java @@ -12,31 +12,28 @@ package org.eclipse.cdt.core.resources; /** - * Indicates the type of resources that this exclusion can exclude. Used to determine which type of icon is displayed in - * the exclusion UI when this exclusion is present. + * Indicates the type of resources that this exclusion can exclude. Used to determine which type of icon is + * displayed in the exclusion UI when this exclusion is present. * - * EXPERIMENTAL. This class or interface has been added as - * part of a work in progress. There is no guarantee that this API will work or - * that it will remain the same. Please do not use this API without consulting - * with the CDT team. + * EXPERIMENTAL. This class or interface has been added as part of a work in progress. There + * is no guarantee that this API will work or that it will remain the same. Please do not use this API without + * consulting with the CDT team. * * @author crecoskie * @since 5.3 - * + * */ public enum ExclusionType { /** * Constant indicating that this exclusion only excludes folders. */ - FOLDER, - - + FILE, + /** * Constant indicating that this exclusion only excludes folders. */ - FILE, - - + FOLDER, + /** * Constant indicating that this exclusion can exclude any resource. */ diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/RefreshExclusion.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/RefreshExclusion.java index 5497c45c970..09d0345b4cc 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/RefreshExclusion.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/RefreshExclusion.java @@ -26,243 +26,31 @@ import com.ibm.icu.text.MessageFormat; * * Clients should extend this class to provide support for their own custom exclusions. * - * EXPERIMENTAL. This class or interface has been added as - * part of a work in progress. There is no guarantee that this API will work or - * that it will remain the same. Please do not use this API without consulting - * with the CDT team. + * EXPERIMENTAL. This class or interface has been added as part of a work in progress. There + * is no guarantee that this API will work or that it will remain the same. Please do not use this API without + * consulting with the CDT team. * * @author crecoskie * @since 5.3 - * + * */ public abstract class RefreshExclusion { - + public static final String CLASS_ATTRIBUTE_NAME = "class"; //$NON-NLS-1$ - public static final String EXTENSION_DATA_ELEMENT_NAME = "extensionData"; //$NON-NLS-1$ public static final String CONTRIBUTOR_ID_ATTRIBUTE_NAME = "contributorId"; //$NON-NLS-1$ - public static final String INSTANCE_ELEMENT_NAME = "instance"; //$NON-NLS-1$ - public static final String WORKSPACE_PATH_ATTRIBUTE_NAME = "workspacePath"; //$NON-NLS-1$ - public static final String EXCLUSION_TYPE_ATTRIBUTE_NAME = "exclusionType"; //$NON-NLS-1$ - public static final String EXCLUSION_ELEMENT_NAME = "exclusion"; //$NON-NLS-1$ - public static final String RESOURCE_VALUE = "RESOURCE"; //$NON-NLS-1$ - public static final String FOLDER_VALUE = "FOLDER"; //$NON-NLS-1$ - public static final String FILE_VALUE = "FILE"; //$NON-NLS-1$ public static final String DISPLAY_STRING_ATTRIBUTE_NAME = "displayString"; //$NON-NLS-1$ - - protected List fExclusionInstanceList = new LinkedList(); - protected List fNestedExclusions = new LinkedList(); - protected ExclusionType fExclusionType = ExclusionType.RESOURCE; - protected RefreshExclusion fParentExclusion; - protected IResource fParentResource; - - - protected String fContributorId = ""; //$NON-NLS-1$ - - /** - * If this exclusion is a direct descendant of a resource, returns that resource. - * Otherwise, returns null; - * - * @return IResource - */ - public synchronized IResource getParentResource() { - return fParentResource; - } - - /** - * Sets the parent resource of this exclusion. - * - * @param parentResource the parent resource to set - */ - public synchronized void setParentResource(IResource parentResource) { - this.fParentResource = parentResource; - } - - /** - * @return a String corresponding to the ID of the RefreshExclusionContributor that was used to create - * this exclusion. - */ - public synchronized String getContributorId() { - return fContributorId; - } - - public synchronized void setContributorId(String id) { - fContributorId = id; - } - - /** - * If this is a nested exclusion, returns the exclusion which is the direct parent of this one. - * - * @return RefreshExclusion - */ - public synchronized RefreshExclusion getParentExclusion() { - return fParentExclusion; - } - - public synchronized void setParentExclusion(RefreshExclusion parent) { - fParentExclusion = parent; - } - - public synchronized ExclusionType getExclusionType() { - return fExclusionType; - } - - public synchronized void setExclusionType(ExclusionType exclusionType) { - fExclusionType = exclusionType; - } - - /** - * @return a String corresponding to the human-readable name for this exclusion. - */ - public abstract String getName(); - - /** - * Tests a given resource to see if this exclusion applies to it. - * - * @param resource the resource to be tested. - * @return true if the resource triggers the exclusion, false otherwise (including if this - * exclusion does not apply). - */ - public abstract boolean testExclusion(IResource resource); - - /** - * Tests this exclusion and recursively test all of its nested exclusions to determine whether this - * exclusion should be triggered or not. - * - * @param resource the resource to be tested - * @return true if the exclusion is triggered, false otherwise (including if this exclusion does not apply) - */ - public synchronized boolean testExclusionChain(IResource resource) { - // first check and see if this exclusion would be triggered in the first place - boolean currentValue = testExclusion(resource); - - if (currentValue) { - List nestedExclusions = getNestedExclusions(); - for (RefreshExclusion exclusion : nestedExclusions) { - - boolean nestedValue = exclusion.testExclusionChain(resource); - - if(nestedValue) { - // the nested exclusion says to do the opposite of what we originally thought, so negate the current value - currentValue = (!currentValue); - - // since the first exclusion chain to trump us wins, then, break out of the loop - break; - } - - } - } - - return currentValue; - - } - - /** - * @return an unmodifiable list of all the instance of this exclusion - */ - public synchronized List getExclusionInstances() { - return Collections.unmodifiableList(fExclusionInstanceList); - } - - /** - * Adds an instance to the list of instances of this exclusion. - * - * @param exclusionInstance - */ - public synchronized void addExclusionInstance(ExclusionInstance exclusionInstance) { - exclusionInstance.setParentExclusion(this); - fExclusionInstanceList.add(exclusionInstance); - } - - /** - * Removes an exclusion instance from the list of instances of this exclusion. - * - * @param exclusionInstance - */ - public synchronized void removeExclusionInstance(ExclusionInstance exclusionInstance) { - fExclusionInstanceList.remove(exclusionInstance); - } - - /** - * - * @return an unmodifiable list of exclusions to this exclusion. - */ - public synchronized List getNestedExclusions() { - return Collections.unmodifiableList(fNestedExclusions); - } - - public synchronized void addNestedExclusion(RefreshExclusion exclusion) { - fNestedExclusions.add(exclusion); - exclusion.setParentExclusion(this); - } - - /** - * Removes the given nested exclusion. The exclusion must be a direct child of this exclusion. - * - * @param exclusion - */ - public synchronized void removeNestedExclusion(RefreshExclusion exclusion) { - fNestedExclusions.remove(exclusion); - } - - public synchronized void persistData(ICStorageElement parentElement) { - // persist the common data that all RefreshExclusions have - ICStorageElement exclusionElement = parentElement.createChild(EXCLUSION_ELEMENT_NAME); - - // persist the type of the object we are - exclusionElement.setAttribute(CLASS_ATTRIBUTE_NAME, this.getClass().getName()); - - // persist the exclusion type - String exclusionType = null; - switch(getExclusionType()) { - case FILE: - exclusionType = FILE_VALUE; - break; - - case FOLDER: - exclusionType = FOLDER_VALUE; - break; - - case RESOURCE: - exclusionType = RESOURCE_VALUE; - break; - } - - if(exclusionType != null) { - exclusionElement.setAttribute(EXCLUSION_TYPE_ATTRIBUTE_NAME, exclusionType); - } - - // note: no need to persist parent, the parent relationship will be determined on load by - // the structure of the XML tree - - exclusionElement.setAttribute(CONTRIBUTOR_ID_ATTRIBUTE_NAME, getContributorId()); - - // persist instances - for(ExclusionInstance instance : fExclusionInstanceList) { - instance.persistInstanceData(exclusionElement); - } - - // provide a place for extenders to store their own data - ICStorageElement extensionElement = exclusionElement.createChild(EXTENSION_DATA_ELEMENT_NAME); - - // call extender to store any extender-specific data - persistExtendedData(extensionElement); - - // persist nested exclusions - for(RefreshExclusion exclusion : fNestedExclusions) { - exclusion.persistData(exclusionElement); - } - } - - protected synchronized void persistExtendedData(ICStorageElement extensionElement) { - // override to provide extension specific behaviour if desired - } - - protected synchronized void loadExtendedData(ICStorageElement grandchild) { - // override to provide extension specific behaviour if desired - } + public static final String EXCLUSION_ELEMENT_NAME = "exclusion"; //$NON-NLS-1$ + public static final String EXCLUSION_TYPE_ATTRIBUTE_NAME = "exclusionType"; //$NON-NLS-1$ + public static final String EXTENSION_DATA_ELEMENT_NAME = "extensionData"; //$NON-NLS-1$ + public static final String FILE_VALUE = "FILE"; //$NON-NLS-1$ + public static final String FOLDER_VALUE = "FOLDER"; //$NON-NLS-1$ + public static final String INSTANCE_ELEMENT_NAME = "instance"; //$NON-NLS-1$ + public static final String RESOURCE_VALUE = "RESOURCE"; //$NON-NLS-1$ + public static final String WORKSPACE_PATH_ATTRIBUTE_NAME = "workspacePath"; //$NON-NLS-1$ public synchronized static List loadData(ICStorageElement parentElement, - RefreshExclusion parentExclusion, IResource parentResource, RefreshScopeManager manager) throws CoreException { + RefreshExclusion parentExclusion, IResource parentResource, RefreshScopeManager manager) + throws CoreException { List exclusions = new LinkedList(); @@ -324,13 +112,15 @@ public abstract class RefreshExclusion { else if (grandchild.getName().equals(INSTANCE_ELEMENT_NAME)) { // load the instance data - ExclusionInstance instance = ExclusionInstance.loadInstanceData(grandchild, manager); + ExclusionInstance instance = ExclusionInstance.loadInstanceData(grandchild, + manager); newExclusion.fExclusionInstanceList.add(instance); } } // load nested exclusions - List nestedExclusions = loadData(child, newExclusion, null, manager); + List nestedExclusions = loadData(child, newExclusion, null, + manager); // add to parent for (RefreshExclusion nestedExclusion : nestedExclusions) { @@ -345,9 +135,226 @@ public abstract class RefreshExclusion { return exclusions; } + protected String fContributorId = ""; //$NON-NLS-1$ + protected List fExclusionInstanceList = new LinkedList(); + protected ExclusionType fExclusionType = ExclusionType.RESOURCE; + protected List fNestedExclusions = new LinkedList(); + + protected RefreshExclusion fParentExclusion; + + protected IResource fParentResource; + + /** + * Adds an instance to the list of instances of this exclusion. + * + * @param exclusionInstance + */ + public synchronized void addExclusionInstance(ExclusionInstance exclusionInstance) { + exclusionInstance.setParentExclusion(this); + fExclusionInstanceList.add(exclusionInstance); + } + + public synchronized void addNestedExclusion(RefreshExclusion exclusion) { + fNestedExclusions.add(exclusion); + exclusion.setParentExclusion(this); + } + + /** + * @return a String corresponding to the ID of the RefreshExclusionContributor that was used to create + * this exclusion. + */ + public synchronized String getContributorId() { + return fContributorId; + } + + /** + * @return an unmodifiable list of all the instance of this exclusion + */ + public synchronized List getExclusionInstances() { + return Collections.unmodifiableList(fExclusionInstanceList); + } + + public synchronized ExclusionType getExclusionType() { + return fExclusionType; + } + + /** + * @return a String corresponding to the human-readable name for this exclusion. + */ + public abstract String getName(); + + /** + * + * @return an unmodifiable list of exclusions to this exclusion. + */ + public synchronized List getNestedExclusions() { + return Collections.unmodifiableList(fNestedExclusions); + } + + /** + * If this is a nested exclusion, returns the exclusion which is the direct parent of this one. + * + * @return RefreshExclusion + */ + public synchronized RefreshExclusion getParentExclusion() { + return fParentExclusion; + } + + /** + * If this exclusion is a direct descendant of a resource, returns that resource. Otherwise, returns null; + * + * @return IResource + */ + public synchronized IResource getParentResource() { + return fParentResource; + } + + protected synchronized void loadExtendedData(ICStorageElement grandchild) { + // override to provide extension specific behaviour if desired + } + + public synchronized void persistData(ICStorageElement parentElement) { + // persist the common data that all RefreshExclusions have + ICStorageElement exclusionElement = parentElement.createChild(EXCLUSION_ELEMENT_NAME); + + // persist the type of the object we are + exclusionElement.setAttribute(CLASS_ATTRIBUTE_NAME, this.getClass().getName()); + + // persist the exclusion type + String exclusionType = null; + switch (getExclusionType()) { + case FILE: + exclusionType = FILE_VALUE; + break; + + case FOLDER: + exclusionType = FOLDER_VALUE; + break; + + case RESOURCE: + exclusionType = RESOURCE_VALUE; + break; + } + + if (exclusionType != null) { + exclusionElement.setAttribute(EXCLUSION_TYPE_ATTRIBUTE_NAME, exclusionType); + } + + // note: no need to persist parent, the parent relationship will be determined on load by + // the structure of the XML tree + + exclusionElement.setAttribute(CONTRIBUTOR_ID_ATTRIBUTE_NAME, getContributorId()); + + // persist instances + for (ExclusionInstance instance : fExclusionInstanceList) { + instance.persistInstanceData(exclusionElement); + } + + // provide a place for extenders to store their own data + ICStorageElement extensionElement = exclusionElement + .createChild(EXTENSION_DATA_ELEMENT_NAME); + + // call extender to store any extender-specific data + persistExtendedData(extensionElement); + + // persist nested exclusions + for (RefreshExclusion exclusion : fNestedExclusions) { + exclusion.persistData(exclusionElement); + } + } + + protected synchronized void persistExtendedData(ICStorageElement extensionElement) { + // override to provide extension specific behaviour if desired + } + + /** + * Removes an exclusion instance from the list of instances of this exclusion. + * + * @param exclusionInstance + */ + public synchronized void removeExclusionInstance(ExclusionInstance exclusionInstance) { + fExclusionInstanceList.remove(exclusionInstance); + } + + /** + * Removes the given nested exclusion. The exclusion must be a direct child of this exclusion. + * + * @param exclusion + */ + public synchronized void removeNestedExclusion(RefreshExclusion exclusion) { + fNestedExclusions.remove(exclusion); + } + + public synchronized void setContributorId(String id) { + fContributorId = id; + } + + public synchronized void setExclusionType(ExclusionType exclusionType) { + fExclusionType = exclusionType; + } + + public synchronized void setParentExclusion(RefreshExclusion parent) { + fParentExclusion = parent; + } + + /** + * Sets the parent resource of this exclusion. + * + * @param parentResource + * the parent resource to set + */ + public synchronized void setParentResource(IResource parentResource) { + this.fParentResource = parentResource; + } + /** * @return true if this exclusion supports exclusion instances */ public abstract boolean supportsExclusionInstances(); + /** + * Tests a given resource to see if this exclusion applies to it. + * + * @param resource + * the resource to be tested. + * @return true if the resource triggers the exclusion, false otherwise (including if this exclusion does + * not apply). + */ + public abstract boolean testExclusion(IResource resource); + + /** + * Tests this exclusion and recursively test all of its nested exclusions to determine whether this + * exclusion should be triggered or not. + * + * @param resource + * the resource to be tested + * @return true if the exclusion is triggered, false otherwise (including if this exclusion does not + * apply) + */ + public synchronized boolean testExclusionChain(IResource resource) { + // first check and see if this exclusion would be triggered in the first place + boolean currentValue = testExclusion(resource); + + if (currentValue) { + List nestedExclusions = getNestedExclusions(); + for (RefreshExclusion exclusion : nestedExclusions) { + + boolean nestedValue = exclusion.testExclusionChain(resource); + + if (nestedValue) { + // the nested exclusion says to do the opposite of what we originally thought, so negate + // the current value + currentValue = (!currentValue); + + // since the first exclusion chain to trump us wins, then, break out of the loop + break; + } + + } + } + + return currentValue; + + } + } diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/RefreshExclusionFactory.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/RefreshExclusionFactory.java index 4f3c1adfab4..2516509ebe4 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/RefreshExclusionFactory.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/RefreshExclusionFactory.java @@ -11,45 +11,43 @@ 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. + * 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() + * 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() + * 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(); - - + } diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/RefreshScopeManager.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/RefreshScopeManager.java index 951b093d16f..723b8155a34 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/RefreshScopeManager.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/RefreshScopeManager.java @@ -43,48 +43,55 @@ import org.eclipse.core.runtime.jobs.ISchedulingRule; import org.eclipse.core.runtime.jobs.MultiRule; /** - * The RefreshScopeManager provides access to settings pertaining to refreshes performed during - * a build. Each project may have a set of resources associated with it that are the set of resources - * to be refreshed. An exclusion mechanism exists that allows for one to specify arbitrarily complicated, - * nested logic that determines whether or not a given resource is refreshed according to previously - * specified rules. + * The RefreshScopeManager provides access to settings pertaining to refreshes performed during a build. Each + * project may have a set of resources associated with it that are the set of resources to be refreshed. An + * exclusion mechanism exists that allows for one to specify arbitrarily complicated, nested logic that + * determines whether or not a given resource is refreshed according to previously specified rules. * - * EXPERIMENTAL. This class or interface has been added as - * part of a work in progress. There is no guarantee that this API will work or - * that it will remain the same. Please do not use this API without consulting - * with the CDT team. + * EXPERIMENTAL. This class or interface has been added as part of a work in progress. There + * is no guarantee that this API will work or that it will remain the same. Please do not use this API without + * consulting with the CDT team. * * @author crecoskie * @since 5.3 - * + * */ public class RefreshScopeManager { - public static final String PROJECT_VALUE = "PROJECT"; //$NON-NLS-1$ - public static final String FOLDER_VALUE = "FOLDER"; //$NON-NLS-1$ - public static final String FILE_VALUE = "FILE"; //$NON-NLS-1$ - public static final String RESOURCE_TYPE_ATTRIBUTE_NAME = "resourceType"; //$NON-NLS-1$ - 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 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$ + public static final Object EXCLUSION_FACTORY = "exclusionFactory"; //$NON-NLS-1$ + public static final String EXTENSION_ID = "RefreshExclusionFactory"; //$NON-NLS-1$ public static final String FACTORY_CLASS = "factoryClass"; //$NON-NLS-1$ + public static final String FILE_VALUE = "FILE"; //$NON-NLS-1$ + private static RefreshScopeManager fInstance; + public static final String FOLDER_VALUE = "FOLDER"; //$NON-NLS-1$ public static final String INSTANCE_CLASS = "instanceClass"; //$NON-NLS-1$ public static final String OTHER_VALUE = "OTHER"; //$NON-NLS-1$ - private int fVersion = 1; - + public static final String PROJECT_VALUE = "PROJECT"; //$NON-NLS-1$ + public static final String REFRESH_SCOPE_STORAGE_NAME = "refreshScope"; //$NON-NLS-1$ + public static final String RESOURCE_ELEMENT_NAME = "resource"; //$NON-NLS-1$ + public static final String RESOURCE_TYPE_ATTRIBUTE_NAME = "resourceType"; //$NON-NLS-1$ + public static final String VERSION_ELEMENT_NAME = "version"; //$NON-NLS-1$ + public static final String VERSION_NUMBER_ATTRIBUTE_NAME = "versionNumber"; //$NON-NLS-1$ + public static final String WORKSPACE_PATH_ATTRIBUTE_NAME = "workspacePath"; //$NON-NLS-1$ + + public static synchronized RefreshScopeManager getInstance() { + if (fInstance == null) { + fInstance = new RefreshScopeManager(); + } + + return fInstance; + } + + private HashMap fClassnameToExclusionFactoryMap; + private boolean fIsLoaded = false; + + private boolean fIsLoading = false; private HashMap> fProjectToResourcesMap; private HashMap> fResourceToExclusionsMap; - private HashMap fClassnameToExclusionFactoryMap; - - private static RefreshScopeManager fInstance; - private boolean fIsLoading = false; - private boolean fIsLoaded = false; - + + private int fVersion = 1; + private RefreshScopeManager() { fClassnameToExclusionFactoryMap = new HashMap(); loadExtensions(); @@ -128,11 +135,13 @@ public class RefreshScopeManager { IProject project = (IProject) delta.getResource(); if (delta.getKind() == IResourceDelta.ADDED - || (delta.getKind() == IResourceDelta.CHANGED && ((delta.getFlags() & IResourceDelta.OPEN) != 0) ) ) { - - loadSettings(ResourcesPlugin.getWorkspace().getRoot(), project); + || (delta.getKind() == IResourceDelta.CHANGED && ((delta + .getFlags() & IResourceDelta.OPEN) != 0))) { + + loadSettings(ResourcesPlugin.getWorkspace() + .getRoot(), project); return false; - + } } @@ -140,7 +149,7 @@ public class RefreshScopeManager { else if (delta.getResource() instanceof IWorkspaceRoot) { return true; } - + return false; } @@ -157,10 +166,220 @@ public class RefreshScopeManager { IResourceChangeEvent.POST_CHANGE | IResourceChangeEvent.PRE_CLOSE | IResourceChangeEvent.PRE_DELETE); } - + + public synchronized void addExclusion(IResource resource, RefreshExclusion exclusion) { + getResourcesToExclusionsMap(); + + List exclusions = fResourceToExclusionsMap.get(resource); + if (exclusions == null) { + exclusions = new LinkedList(); + fResourceToExclusionsMap.put(resource, exclusions); + } + + exclusions.add(exclusion); + } + + public synchronized void addResourceToRefresh(IProject project, IResource resource) { + getProjectToResourcesMap(); + LinkedHashSet resourceSet = fProjectToResourcesMap.get(project); + + if (resourceSet == null) { + resourceSet = new LinkedHashSet(); + fProjectToResourcesMap.put(project, resourceSet); + } + + resourceSet.add(resource); + + } + + public synchronized void clearAllData() { + clearAllResourcesToRefresh(); + clearAllExclusions(); + fIsLoaded = false; + } + + public synchronized void clearAllExclusions() { + if (fResourceToExclusionsMap != null) + fResourceToExclusionsMap.clear(); + } + + public synchronized void clearAllResourcesToRefresh() { + getProjectToResourcesMap(); + fProjectToResourcesMap.clear(); + } + + private synchronized void clearDataForProject(IProject project) { + clearResourcesToRefresh(project); + clearExclusionsForProject(project); + } + + public synchronized void clearExclusions(IResource resource) { + getResourcesToExclusionsMap(); + List exclusions = fResourceToExclusionsMap.get(resource); + if (exclusions != null) { + exclusions.clear(); + } + } + + public synchronized void clearExclusionsForProject(IProject project) { + getResourcesToExclusionsMap(); + List resourcesToRemove = new LinkedList(); + + for (IResource resource : fResourceToExclusionsMap.keySet()) { + IProject project2 = resource.getProject(); + if (project2.equals(project)) { + resourcesToRemove.add(resource); + } + } + + for (IResource resource : resourcesToRemove) { + fResourceToExclusionsMap.remove(resource); + } + } + + public synchronized void clearResourcesToRefresh(IProject project) { + getProjectToResourcesMap(); + LinkedHashSet resourceSet = null; + + fProjectToResourcesMap.put(project, resourceSet); + } + + public synchronized void deleteResourceToRefresh(IProject project, IResource resource) { + getProjectToResourcesMap(); + LinkedHashSet resourceSet = fProjectToResourcesMap.get(project); + + if (resourceSet == null) { + resourceSet = new LinkedHashSet(); + return; + } + + resourceSet.remove(resource); + } + + public synchronized RefreshExclusion getExclusionForClassName(String className) { + RefreshExclusionFactory factory = getFactoryForClassName(className); + + if (factory == null) { + return null; + } + + return factory.createNewExclusion(); + } + + public synchronized List getExclusions(IResource resource) { + getResourcesToExclusionsMap(); + List exclusions = fResourceToExclusionsMap.get(resource); + if (exclusions == null) { + exclusions = new LinkedList(); + fResourceToExclusionsMap.put(resource, exclusions); + } + + return exclusions; + } + + public synchronized RefreshExclusionFactory getFactoryForClassName(String className) { + RefreshExclusionFactory factory = fClassnameToExclusionFactoryMap.get(className); + + return factory; + } + + public synchronized ExclusionInstance getInstanceForClassName(String className) { + RefreshExclusionFactory factory = getFactoryForClassName(className); + + if (factory == null) { + return null; + } + + return factory.createNewExclusionInstance(); + } + + private HashMap> getProjectToResourcesMap() { + if (fProjectToResourcesMap == null) { + fProjectToResourcesMap = new HashMap>(); + } + + return fProjectToResourcesMap; + } + + public IWorkspaceRunnable getRefreshRunnable(final IProject project) { + + IWorkspaceRunnable runnable = new IWorkspaceRunnable() { + + /** + * @param q + * @param resource + * @throws CoreException + */ + private void refreshResources(IResource resource, List exclusions, + IProgressMonitor monitor) throws CoreException { + if (resource instanceof IContainer) { + IContainer container = (IContainer) resource; + + if (shouldResourceBeRefreshed(resource)) { + resource.refreshLocal(IResource.DEPTH_ONE, monitor); + + } + + for (IResource child : container.members()) { + refreshResources(child, exclusions, monitor); + } + } + } + + public void run(IProgressMonitor monitor) throws CoreException { + + List resourcesToRefresh = getResourcesToRefresh(project); + for (IResource resource : resourcesToRefresh) { + List exclusions = getExclusions(resource); + refreshResources(resource, exclusions, monitor); + } + + } + }; + + return runnable; + } + + public synchronized ISchedulingRule getRefreshSchedulingRule(IProject project) { + return new MultiRule(getResourcesToRefresh(project).toArray(new ISchedulingRule[0])); + } + + private HashMap> getResourcesToExclusionsMap() { + if (fResourceToExclusionsMap == null) { + fResourceToExclusionsMap = new HashMap>(); + } + + return fResourceToExclusionsMap; + } + + /** + * Returns the set of resources that should be refreshed for a project. These resources might have + * associated exclusions. + * + * @param project + * @return List + */ + public synchronized List getResourcesToRefresh(IProject project) { + getProjectToResourcesMap(); + LinkedHashSet resources = fProjectToResourcesMap.get(project); + + if (resources == null) { + // there are no settings yet for the project, setup the defaults + resources = new LinkedHashSet(); + resources.add(project); + fProjectToResourcesMap.put(project, resources); + } + + return new LinkedList(resources); + } + + public int getVersion() { + return fVersion; + } + public synchronized void loadExtensions() { - IExtensionPoint extension = Platform.getExtensionRegistry().getExtensionPoint(CCorePlugin.PLUGIN_ID, - EXTENSION_ID); + IExtensionPoint extension = Platform.getExtensionRegistry().getExtensionPoint( + CCorePlugin.PLUGIN_ID, EXTENSION_ID); if (extension != null) { IExtension[] extensions = extension.getExtensions(); for (IExtension extension2 : extensions) { @@ -174,16 +393,19 @@ public class RefreshScopeManager { if (factoryClassName != null) { try { - Object execExt = configElement.createExecutableExtension(FACTORY_CLASS); + Object execExt = configElement + .createExecutableExtension(FACTORY_CLASS); if ((execExt instanceof RefreshExclusionFactory)) { RefreshExclusionFactory exclusionFactory = (RefreshExclusionFactory) execExt; - - if(exclusionClassName != null) { - fClassnameToExclusionFactoryMap.put(exclusionClassName, exclusionFactory); + + if (exclusionClassName != null) { + fClassnameToExclusionFactoryMap.put(exclusionClassName, + exclusionFactory); } - - if(instanceClassName != null) { - fClassnameToExclusionFactoryMap.put(instanceClassName, exclusionFactory); + + if (instanceClassName != null) { + fClassnameToExclusionFactoryMap.put(instanceClassName, + exclusionFactory); } } } catch (CoreException e) { @@ -195,222 +417,9 @@ public class RefreshScopeManager { } } } - - public static synchronized RefreshScopeManager getInstance() { - if(fInstance == null) { - fInstance = new RefreshScopeManager(); - } - - return fInstance; - } - - public int getVersion() { - return fVersion; - } - - public synchronized RefreshExclusionFactory getFactoryForClassName(String className) { - RefreshExclusionFactory factory = fClassnameToExclusionFactoryMap.get(className); - - return factory; - } - - public synchronized 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. - * These resources might have associated exclusions. - * - * @param project - * @return List - */ - public synchronized List getResourcesToRefresh(IProject project) { - getProjectToResourcesMap(); - LinkedHashSet resources = fProjectToResourcesMap.get(project); - - if (resources == null) { - // there are no settings yet for the project, setup the defaults - resources = new LinkedHashSet(); - resources.add(project); - fProjectToResourcesMap.put(project, resources); - } - - return new LinkedList(resources); - } - - public synchronized void setResourcesToRefresh(IProject project, List resources) { - getProjectToResourcesMap(); - LinkedHashSet resourceSet = new LinkedHashSet(resources); - - fProjectToResourcesMap.put(project, resourceSet); - } - - public synchronized void addResourceToRefresh(IProject project, IResource resource) { - getProjectToResourcesMap(); - LinkedHashSet resourceSet = fProjectToResourcesMap.get(project); - - if(resourceSet == null) { - resourceSet = new LinkedHashSet(); - fProjectToResourcesMap.put(project, resourceSet); - } - - resourceSet.add(resource); - - } - - public synchronized void deleteResourceToRefresh(IProject project, IResource resource) { - getProjectToResourcesMap(); - LinkedHashSet resourceSet = fProjectToResourcesMap.get(project); - - if(resourceSet == null) { - resourceSet = new LinkedHashSet(); - return; - } - - resourceSet.remove(resource); - } - - public synchronized void clearResourcesToRefresh(IProject project) { - getProjectToResourcesMap(); - LinkedHashSet resourceSet = null; - - fProjectToResourcesMap.put(project, resourceSet); - } - - public synchronized void clearAllResourcesToRefresh() { - getProjectToResourcesMap(); - fProjectToResourcesMap.clear(); - } - - public synchronized void clearAllData() { - clearAllResourcesToRefresh(); - clearAllExclusions(); - fIsLoaded = false; - } - private HashMap> getProjectToResourcesMap() { - if(fProjectToResourcesMap == null) { - fProjectToResourcesMap = new HashMap>(); - } - - return fProjectToResourcesMap; - } - - public synchronized List getExclusions(IResource resource) { - getResourcesToExclusionsMap(); - List exclusions = fResourceToExclusionsMap.get(resource); - if(exclusions == null) { - exclusions = new LinkedList(); - fResourceToExclusionsMap.put(resource, exclusions); - } - - return exclusions; - } - - public synchronized void addExclusion(IResource resource, RefreshExclusion exclusion) { - getResourcesToExclusionsMap(); - - List exclusions = fResourceToExclusionsMap.get(resource); - if(exclusions == null) { - exclusions = new LinkedList(); - fResourceToExclusionsMap.put(resource, exclusions); - } - - exclusions.add(exclusion); - } - - private HashMap> getResourcesToExclusionsMap() { - if(fResourceToExclusionsMap == null) { - fResourceToExclusionsMap = new HashMap>(); - } - - return fResourceToExclusionsMap; - } - - public synchronized void removeExclusion(IResource resource, RefreshExclusion exclusion) { - getResourcesToExclusionsMap(); - List exclusions = fResourceToExclusionsMap.get(resource); - if(exclusions == null) { - exclusions = new LinkedList(); - fResourceToExclusionsMap.put(resource, exclusions); - } - - exclusions.remove(exclusion); - } - - public synchronized void persistSettings(ICProjectDescription projectDescription) - throws CoreException { - getProjectToResourcesMap(); - getResourcesToExclusionsMap(); - IProject project = projectDescription.getProject(); - - if (!project.exists()) { - return; - } - - // 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()); - - String resourceTypeString = null; - - if(resource instanceof IFile) { - resourceTypeString = FILE_VALUE; - } - - else if(resource instanceof IFolder) { - resourceTypeString = FOLDER_VALUE; - } - - else if(resource instanceof IProject) { - resourceTypeString = PROJECT_VALUE; - } - - else { - resourceTypeString = OTHER_VALUE; - } - resourceElement.setAttribute(RESOURCE_TYPE_ATTRIBUTE_NAME, resourceTypeString); - - // populate the node with any exclusions - List exclusions = fResourceToExclusionsMap.get(resource); - if (exclusions != null) { - for (RefreshExclusion exclusion : exclusions) { - exclusion.persistData(resourceElement); - } - } - - } - - } - } - - } - public synchronized void loadSettings() throws CoreException { - if(!fIsLoaded && !fIsLoading) { + if (!fIsLoaded && !fIsLoading) { fIsLoading = true; // iterate through all projects in the workspace. If they are C projects, attempt to load settings // from them. @@ -419,7 +428,7 @@ public class RefreshScopeManager { for (IProject project : workspaceRoot.getProjects()) { loadSettings(workspaceRoot, project); } - + fIsLoaded = true; fIsLoading = false; } @@ -434,16 +443,21 @@ public class RefreshScopeManager { throws CoreException { if (project.isOpen()) { if (project.hasNature(CProjectNature.C_NATURE_ID)) { - CProjectDescriptionManager descriptionManager = CProjectDescriptionManager.getInstance(); - ICProjectDescription projectDescription = descriptionManager.getProjectDescription(project, false); - + CProjectDescriptionManager descriptionManager = CProjectDescriptionManager + .getInstance(); + ICProjectDescription projectDescription = descriptionManager.getProjectDescription( + project, false); + if (projectDescription == null) { - // then there's nothing to load... could be an old project that pre-dates the project description's - // existence, or the project could have been just created but the project description hasn't been - // created yet. Either way, just do nothing, because there's nothing to load. + /* + * then there's nothing to load... could be an old project that pre-dates the project + * description's existence, or the project could have been just created but the project + * description hasn't been created yet. Either way, just do nothing, because there's + * nothing to load. + */ return; } - + ICStorageElement storageElement = projectDescription.getStorage( REFRESH_SCOPE_STORAGE_NAME, true); @@ -468,18 +482,18 @@ public class RefreshScopeManager { } else { - String resourceTypeString = child.getAttribute(RESOURCE_TYPE_ATTRIBUTE_NAME); - - if(resourceTypeString == null) { - // we'll do our best, but we won't be able to create handles to non-existent resources + String resourceTypeString = child + .getAttribute(RESOURCE_TYPE_ATTRIBUTE_NAME); + + if (resourceTypeString == null) { + // we'll do our best, but we won't be able to create handles to non-existent + // resources resourceTypeString = OTHER_VALUE; } - + // find the resource IResource resource = null; - - if (resourceTypeString.equals(PROJECT_VALUE)) { resource = workspaceRoot.getProject(resourcePath); } @@ -528,128 +542,124 @@ public class RefreshScopeManager { } } - public synchronized void clearExclusions(IResource resource) { + public synchronized void persistSettings(ICProjectDescription projectDescription) + throws CoreException { + getProjectToResourcesMap(); + getResourcesToExclusionsMap(); + IProject project = projectDescription.getProject(); + + if (!project.exists()) { + return; + } + + // 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()); + + String resourceTypeString = null; + + if (resource instanceof IFile) { + resourceTypeString = FILE_VALUE; + } + + else if (resource instanceof IFolder) { + resourceTypeString = FOLDER_VALUE; + } + + else if (resource instanceof IProject) { + resourceTypeString = PROJECT_VALUE; + } + + else { + resourceTypeString = OTHER_VALUE; + } + + resourceElement.setAttribute(RESOURCE_TYPE_ATTRIBUTE_NAME, resourceTypeString); + + // populate the node with any exclusions + List exclusions = fResourceToExclusionsMap.get(resource); + if (exclusions != null) { + for (RefreshExclusion exclusion : exclusions) { + exclusion.persistData(resourceElement); + } + } + + } + + } + } + + } + + public synchronized void removeExclusion(IResource resource, RefreshExclusion exclusion) { getResourcesToExclusionsMap(); List exclusions = fResourceToExclusionsMap.get(resource); - if(exclusions != null) { - exclusions.clear(); + if (exclusions == null) { + exclusions = new LinkedList(); + fResourceToExclusionsMap.put(resource, exclusions); } + + exclusions.remove(exclusion); } - + public synchronized void setExclusions(IResource resource, List newExclusions) { getResourcesToExclusionsMap(); List exclusions = new LinkedList(newExclusions); - + fResourceToExclusionsMap.put(resource, exclusions); } - - public synchronized void clearAllExclusions() { - if(fResourceToExclusionsMap != null) - fResourceToExclusionsMap.clear(); - } - - public synchronized void clearExclusionsForProject(IProject project) { - getResourcesToExclusionsMap(); - List resourcesToRemove = new LinkedList(); - - for(IResource resource : fResourceToExclusionsMap.keySet()) { - IProject project2 = resource.getProject(); - if(project2.equals(project)) { - resourcesToRemove.add(resource); - } - } - - for(IResource resource : resourcesToRemove) { - fResourceToExclusionsMap.remove(resource); - } - } - - private synchronized void clearDataForProject(IProject project) { - clearResourcesToRefresh(project); - clearExclusionsForProject(project); + + public synchronized void setResourcesToRefresh(IProject project, List resources) { + getProjectToResourcesMap(); + LinkedHashSet resourceSet = new LinkedHashSet(resources); + + fProjectToResourcesMap.put(project, resourceSet); } - public synchronized ExclusionInstance getInstanceForClassName(String className) { - RefreshExclusionFactory factory = getFactoryForClassName(className); - - if(factory == null) { - return null; - } - - return factory.createNewExclusionInstance(); - } - - public synchronized ISchedulingRule getRefreshSchedulingRule(IProject project) { - return new MultiRule(getResourcesToRefresh(project).toArray(new ISchedulingRule[0])); - } - - public IWorkspaceRunnable getRefreshRunnable(final IProject project) { - - IWorkspaceRunnable runnable = new IWorkspaceRunnable() { - - public void run(IProgressMonitor monitor) throws CoreException { - - List resourcesToRefresh = getResourcesToRefresh(project); - for(IResource resource : resourcesToRefresh) { - List exclusions = getExclusions(resource); - refreshResources(resource, exclusions, monitor); - } - - } - - /** - * @param q - * @param resource - * @throws CoreException - */ - private void refreshResources(IResource resource, List exclusions, IProgressMonitor monitor) throws CoreException { - if (resource instanceof IContainer) { - IContainer container = (IContainer) resource; - - if (shouldResourceBeRefreshed(resource)) { - resource.refreshLocal(IResource.DEPTH_ONE, monitor); - - } - - for (IResource child : container.members()) { - refreshResources(child, exclusions, monitor); - } - } - } - }; - - return runnable; - } - public synchronized boolean shouldResourceBeRefreshed(IResource resource) { IProject project = resource.getProject(); List resourcesToRefresh = getResourcesToRefresh(project); boolean isInSomeTree = false; IResource topLevelResource = null; - - for(IResource resourceToRefresh : resourcesToRefresh) { - if(resourceToRefresh.equals(resource)) { + + for (IResource resourceToRefresh : resourcesToRefresh) { + if (resourceToRefresh.equals(resource)) { isInSomeTree = true; topLevelResource = resource; break; } - + // see if the resource is a child of our top level resources - if(resourceToRefresh instanceof IContainer) { + if (resourceToRefresh instanceof IContainer) { IContainer container = (IContainer) resourceToRefresh; - if(container.getFullPath().isPrefixOf(resource.getFullPath())) { + if (container.getFullPath().isPrefixOf(resource.getFullPath())) { isInSomeTree = true; topLevelResource = resourceToRefresh; break; } } - + } - - if(!isInSomeTree) { + + if (!isInSomeTree) { return false; } - + // get any exclusions boolean isExcluded = false; @@ -659,7 +669,7 @@ public class RefreshScopeManager { break; } } - + return !isExcluded; } diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/resources/ResourceExclusion.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/resources/ResourceExclusion.java index 2f4ba6d192b..6b3ec75955a 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/resources/ResourceExclusion.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/resources/ResourceExclusion.java @@ -22,18 +22,19 @@ import org.eclipse.core.resources.IResource; /** * - * EXPERIMENTAL. This class or interface has been added as - * part of a work in progress. There is no guarantee that this API will work or - * that it will remain the same. Please do not use this API without consulting - * with the CDT team. + * EXPERIMENTAL. This class or interface has been added as part of a work in progress. There + * is no guarantee that this API will work or that it will remain the same. Please do not use this API without + * consulting with the CDT team. * * @author vkong * @since 5.3 - * + * */ public class ResourceExclusion extends RefreshExclusion { - - /* (non-Javadoc) + + /* + * (non-Javadoc) + * * @see org.eclipse.cdt.core.resources.RefreshExclusion#getName() */ @Override @@ -41,26 +42,34 @@ public class ResourceExclusion extends RefreshExclusion { return Messages.ResourceExclusion_name; } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.resources.RefreshExclusion#testExclusion(org.eclipse.core.resources.IResource) + @Override + public boolean supportsExclusionInstances() { + return true; + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.cdt.core.resources.RefreshExclusion#testExclusion(org.eclipse.core.resources.IResource) */ @Override public synchronized boolean testExclusion(IResource resource) { - - //Populate the resources to be excluded by this exclusion + + // Populate the resources to be excluded by this exclusion List excludedResources = new LinkedList(); List exclusionInstances = getExclusionInstances(); - - for(ExclusionInstance instance : exclusionInstances) { + + for (ExclusionInstance instance : exclusionInstances) { excludedResources.add(instance.getResource()); } - + if (excludedResources.contains(resource)) { return true; - } else { //check to see if the given resource is part of this exclusion - - for(IResource excludedResource : excludedResources) { - //TODO: need to update this for Phase 2 implementation + } else { // check to see if the given resource is part of this exclusion + + for (IResource excludedResource : excludedResources) { + // TODO: need to update this for Phase 2 implementation if (excludedResource instanceof IContainer) { IContainer container = (IContainer) excludedResource; if (container.getFullPath().isPrefixOf(resource.getFullPath())) { @@ -72,9 +81,4 @@ public class ResourceExclusion extends RefreshExclusion { return false; } - @Override - public boolean supportsExclusionInstances() { - return true; - } - } diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/resources/ResourceExclusionFactory.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/resources/ResourceExclusionFactory.java index 551bf2c321d..5e4265327cc 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/resources/ResourceExclusionFactory.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/resources/ResourceExclusionFactory.java @@ -16,7 +16,7 @@ import org.eclipse.cdt.core.resources.RefreshExclusionFactory; /** * @author crecoskie - * + * */ public class ResourceExclusionFactory extends RefreshExclusionFactory { @@ -27,7 +27,9 @@ public class ResourceExclusionFactory extends RefreshExclusionFactory { // TODO Auto-generated constructor stub } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.cdt.core.resources.RefreshExclusionFactory#createNewExclusion() */ @Override @@ -35,7 +37,9 @@ public class ResourceExclusionFactory extends RefreshExclusionFactory { return new ResourceExclusion(); } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.cdt.core.resources.RefreshExclusionFactory#createNewExclusionInstance() */ @Override @@ -44,7 +48,9 @@ public class ResourceExclusionFactory extends RefreshExclusionFactory { return null; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.cdt.core.resources.RefreshExclusionFactory#getExclusionClassname() */ @Override @@ -52,7 +58,9 @@ public class ResourceExclusionFactory extends RefreshExclusionFactory { return ResourceExclusion.class.getName(); } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.cdt.core.resources.RefreshExclusionFactory#getInstanceClassname() */ @Override diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/resources/ResourceExclusionContributor.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/resources/ResourceExclusionContributor.java index ba368dc8870..3f7931971f6 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/resources/ResourceExclusionContributor.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/resources/ResourceExclusionContributor.java @@ -47,44 +47,42 @@ import org.eclipse.cdt.ui.resources.RefreshExclusionContributor; import org.eclipse.cdt.internal.core.resources.ResourceExclusion; /** - * EXPERIMENTAL. This class or interface has been added as - * part of a work in progress. There is no guarantee that this API will work or - * that it will remain the same. Please do not use this API without consulting - * with the CDT team. + * EXPERIMENTAL. This class or interface has been added as part of a work in progress. There + * is no guarantee that this API will work or that it will remain the same. Please do not use this API without + * consulting with the CDT team. * * @author vkong * @since 5.3 - * + * */ public class ResourceExclusionContributor extends RefreshExclusionContributor { - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.cdt.ui.resources.RefreshExclusionContributor#createExclusion() */ @Override public RefreshExclusion createExclusion() { ResourceExclusion newExclusion = new ResourceExclusion(); newExclusion.setContributorId(getID()); - - //TODO change this for Phase 2 + + // TODO change this for Phase 2 newExclusion.setExclusionType(ExclusionType.FOLDER); return newExclusion; } - - private IResource getResourceRoot(RefreshExclusion exclusion) { - if (exclusion.getParentExclusion() != null) { - return getResourceRoot(exclusion.getParentExclusion()); - } - return exclusion.getParentResource(); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.ui.resources.RefreshExclusionContributor#createProperiesUI(org.eclipse.swt.widgets.Composite, org.eclipse.cdt.core.resources.RefreshExclusion) + /* + * (non-Javadoc) + * + * @see + * org.eclipse.cdt.ui.resources.RefreshExclusionContributor#createProperiesUI(org.eclipse.swt.widgets. + * Composite, org.eclipse.cdt.core.resources.RefreshExclusion) */ @Override public void createProperiesUI(Composite parent, final RefreshExclusion exclusion) { final Shell shell = parent.getShell(); - + Group g = new Group(parent, SWT.NONE); g.setText(Messages.RefreshPolicyExceptionDialog_exceptionTypeResources); g.setLayout(new GridLayout(1, false)); @@ -93,7 +91,7 @@ public class ResourceExclusionContributor extends RefreshExclusionContributor { gridData.horizontalSpan = 2; gridData.verticalSpan = 2; g.setLayoutData(gridData); - + final List exceptionsList = new List(g, SWT.NONE); gridData = new GridData(); gridData.verticalAlignment = GridData.FILL; @@ -103,13 +101,13 @@ public class ResourceExclusionContributor extends RefreshExclusionContributor { gridData.minimumHeight = 250; gridData.minimumWidth = 275; exceptionsList.setLayoutData(gridData); - + final HashMap exclusionInstanceStrings = new LinkedHashMap(); final HashMap exclusionInstanceResources = new LinkedHashMap(); - + java.util.List exclusionInstances = exclusion.getExclusionInstances(); - //populate exclusion instance list + // populate exclusion instance list if (exclusionInstances != null) { Iterator iterator = exclusionInstances.iterator(); while (iterator.hasNext()) { @@ -120,97 +118,106 @@ public class ResourceExclusionContributor extends RefreshExclusionContributor { exclusionInstanceResources.put(name, exclusionInstance.getResource()); } } - + Composite buttonComp = new Composite(parent, SWT.NONE); buttonComp.setLayout(new GridLayout(1, false)); gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL); gridData.minimumWidth = 100; buttonComp.setLayoutData(gridData); - + Button addButton = new Button(buttonComp, SWT.NONE); gridData = new GridData(); gridData.horizontalAlignment = GridData.FILL; gridData.grabExcessHorizontalSpace = true; addButton.setLayoutData(gridData); addButton.setText(Messages.RefreshPolicyExceptionDialog_addButtonLabel); - + addButton.addSelectionListener(new SelectionAdapter() { - /* (non-Javadoc) - * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent) + /* + * (non-Javadoc) + * + * @see + * org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent) */ @Override public void widgetSelected(SelectionEvent e) { - CheckedTreeSelectionDialog dialog = new CheckedTreeSelectionDialog(shell, WorkbenchLabelProvider.getDecoratingWorkbenchLabelProvider(), + CheckedTreeSelectionDialog dialog = new CheckedTreeSelectionDialog(shell, + WorkbenchLabelProvider.getDecoratingWorkbenchLabelProvider(), new ITreeContentProvider() { - - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - } - + public void dispose() { } - - public boolean hasChildren(Object element) { - return getChildren(element).length > 0; + + public Object[] getChildren(Object parentElement) { + if (parentElement instanceof IContainer) { + IContainer container = (IContainer) parentElement; + if (container.isAccessible()) { + try { + java.util.List children = new ArrayList(); + IResource[] members = container.members(); + for (int i = 0; i < members.length; i++) { + if (members[i].getType() == IResource.FOLDER) { + children.add(members[i]); + } + } + return children.toArray(); + } catch (CoreException e) { + // this should never happen because we call #isAccessible before + // invoking #members + } + } + } + return new Object[0]; } - + + public Object[] getElements(Object inputElement) { + return getChildren(inputElement); + } + public Object getParent(Object element) { if (element instanceof IResource) { return ((IResource) element).getParent(); } - return null; + return null; } - - public Object[] getElements(Object inputElement) { - return getChildren(inputElement); + + public boolean hasChildren(Object element) { + return getChildren(element).length > 0; } - - public Object[] getChildren(Object parentElement) { - if (parentElement instanceof IContainer) { - IContainer container = (IContainer) parentElement; - if (container.isAccessible()) { - try { - java.util.List children = new ArrayList(); - IResource[] members = container.members(); - for (int i = 0; i < members.length; i++) { - if (members[i].getType() == IResource.FOLDER) { - children.add(members[i]); - } - } - return children.toArray(); - } catch (CoreException e) { - // this should never happen because we call #isAccessible before invoking #members - } - } - } - return new Object[0]; + + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { } - } ); - + }); + dialog.setInput(getResourceRoot(exclusion)); - + if (exclusionInstanceResources.values().size() > 0) { - dialog.setInitialElementSelections(Arrays.asList(exclusionInstanceResources.values().toArray())); + dialog.setInitialElementSelections(Arrays.asList(exclusionInstanceResources.values() + .toArray())); } dialog.setMessage(Messages.RefreshPolicyExceptionDialog_SelectResourceDialogMessage); dialog.setTitle(Messages.RefreshPolicyExceptionDialog_SelectResourceDialogTitle); - + if (dialog.open() == Window.OK) { Object[] selection = dialog.getResult(); exceptionsList.removeAll(); exclusionInstanceResources.clear(); - final HashMap oldExclusionInstanceStrings = new LinkedHashMap(exclusionInstanceStrings); + final HashMap oldExclusionInstanceStrings = new LinkedHashMap( + exclusionInstanceStrings); exclusionInstanceStrings.clear(); - + for (int i = 0; i < selection.length; i++) { Object selected = selection[i]; if (selected instanceof IFolder) { - IPath path = ((IFolder)selected).getFullPath(); - IPath relativePath = path.makeRelativeTo(getResourceRoot(exclusion).getFullPath()); - + IPath path = ((IFolder) selected).getFullPath(); + IPath relativePath = path + .makeRelativeTo(getResourceRoot(exclusion).getFullPath()); + exceptionsList.add(relativePath.toString()); - ExclusionInstance instance = oldExclusionInstanceStrings.get(relativePath.toString()); - if (instance == null) { + ExclusionInstance instance = oldExclusionInstanceStrings.get(relativePath + .toString()); + if (instance == null) { instance = new ExclusionInstance(); instance.setExclusionType(ExclusionType.FOLDER); instance.setParentExclusion(exclusion); @@ -220,12 +227,12 @@ public class ResourceExclusionContributor extends RefreshExclusionContributor { } else { oldExclusionInstanceStrings.remove(relativePath.toString()); } - + exclusionInstanceStrings.put(instance.getDisplayString(), instance); - exclusionInstanceResources.put(instance.getDisplayString(), selected); + exclusionInstanceResources.put(instance.getDisplayString(), selected); } } - //remove deprecated exclusion instances + // remove deprecated exclusion instances oldExclusionInstanceStrings.keySet(); Iterator iterator = oldExclusionInstanceStrings.keySet().iterator(); while (iterator.hasNext()) { @@ -236,48 +243,58 @@ public class ResourceExclusionContributor extends RefreshExclusionContributor { } } } - + }); - + Button deleteButton = new Button(buttonComp, SWT.NONE); gridData = new GridData(); gridData.horizontalAlignment = GridData.FILL; gridData.grabExcessHorizontalSpace = true; deleteButton.setLayoutData(gridData); deleteButton.setText(Messages.RefreshPolicyExceptionDialog_deleteButtonLabel); - + deleteButton.addSelectionListener(new SelectionAdapter() { - /* (non-Javadoc) - * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent) + /* + * (non-Javadoc) + * + * @see + * org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent) */ @Override public void widgetSelected(SelectionEvent e) { - String[] selected = exceptionsList.getSelection(); + String[] selected = exceptionsList.getSelection(); if (selected.length < 1) return; - + for (int i = 0; i < selected.length; i++) { String folderToRemove = selected[i]; ExclusionInstance instanceToRemove = exclusionInstanceStrings.get(folderToRemove); - -// Iterator iterator = selectedFolders.iterator(); - -// while (iterator.hasNext()) { -// IPath path = ((IFolder)iterator.next()).getFullPath(); -// IPath relativePath = path.makeRelativeTo(getResourceRoot(exclusionRoot).getFullPath()); -// if (relativePath.toString().compareTo(folderToRemove) == 0) { -// iterator.remove(); -// break; -// } -// } + + // Iterator iterator = selectedFolders.iterator(); + + // while (iterator.hasNext()) { + // IPath path = ((IFolder)iterator.next()).getFullPath(); + // IPath relativePath = path.makeRelativeTo(getResourceRoot(exclusionRoot).getFullPath()); + // if (relativePath.toString().compareTo(folderToRemove) == 0) { + // iterator.remove(); + // break; + // } + // } exclusion.removeExclusionInstance(instanceToRemove); exclusionInstanceStrings.remove(folderToRemove); exclusionInstanceResources.remove(folderToRemove); - } + } exceptionsList.remove(exceptionsList.getSelectionIndices()); } - + }); } + + private IResource getResourceRoot(RefreshExclusion exclusion) { + if (exclusion.getParentExclusion() != null) { + return getResourceRoot(exclusion.getParentExclusion()); + } + return exclusion.getParentResource(); + } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/resources/RefreshExclusionContributionManager.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/resources/RefreshExclusionContributionManager.java index d07fa1b2c39..e0ad161908a 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/resources/RefreshExclusionContributionManager.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/resources/RefreshExclusionContributionManager.java @@ -23,33 +23,59 @@ import org.eclipse.core.runtime.Platform; import org.eclipse.cdt.ui.CUIPlugin; /** - * EXPERIMENTAL. This class or interface has been added as - * part of a work in progress. There is no guarantee that this API will work or - * that it will remain the same. Please do not use this API without consulting - * with the CDT team. + * EXPERIMENTAL. This class or interface has been added as part of a work in progress. There + * is no guarantee that this API will work or that it will remain the same. Please do not use this API without + * consulting with the CDT team. * * @author crecoskie * @since 5.3 - * + * */ public class RefreshExclusionContributionManager { - + public static final String EXCLUSION_CONTRIBUTOR = "exclusionContributor"; //$NON-NLS-1$ public static final String EXTENSION_ID = "RefreshExclusionContributor"; //$NON-NLS-1$ - private LinkedHashMap fIDtoContributorsMap; private static RefreshExclusionContributionManager fInstance; - + + public static synchronized RefreshExclusionContributionManager getInstance() { + if (fInstance == null) { + fInstance = new RefreshExclusionContributionManager(); + } + + return fInstance; + } + + private LinkedHashMap fIDtoContributorsMap; + private RefreshExclusionContributionManager() { fIDtoContributorsMap = new LinkedHashMap(); loadExtensions(); } - - public static synchronized RefreshExclusionContributionManager getInstance() { - if(fInstance == null) { - fInstance = new RefreshExclusionContributionManager(); + + public RefreshExclusionContributor getContributor(String id) { + return fIDtoContributorsMap.get(id); + } + + public List getContributors() { + return getContributors(false); + } + + public List getContributors(boolean returnTestContributors) { + List retVal = new LinkedList(); + + if (!returnTestContributors) { + for (RefreshExclusionContributor contributor : fIDtoContributorsMap.values()) { + if (!contributor.isTest()) { + retVal.add(contributor); + } + } + + return retVal; + } + + else { + return new LinkedList(fIDtoContributorsMap.values()); } - - return fInstance; } public synchronized void loadExtensions() { @@ -68,7 +94,7 @@ public class RefreshExclusionContributionManager { String contributorClassName = configElement.getAttribute("class"); //$NON-NLS-1$ boolean isTest = false; String isTestString = configElement.getAttribute("isTest"); //$NON-NLS-1$ - if(isTestString != null) { + if (isTestString != null) { isTest = Boolean.getBoolean(isTestString); } @@ -81,7 +107,7 @@ public class RefreshExclusionContributionManager { exclusionContributor.setName(name); exclusionContributor.setIsTest(isTest); fIDtoContributorsMap.put(id, exclusionContributor); - + } } catch (CoreException e) { CUIPlugin.log(e); @@ -92,30 +118,4 @@ public class RefreshExclusionContributionManager { } } } - - public RefreshExclusionContributor getContributor(String id) { - return fIDtoContributorsMap.get(id); - } - - public List getContributors() { - return getContributors(false); - } - - public List getContributors(boolean returnTestContributors) { - List retVal = new LinkedList(); - - if(!returnTestContributors) { - for(RefreshExclusionContributor contributor : fIDtoContributorsMap.values()) { - if(!contributor.isTest()) { - retVal.add(contributor); - } - } - - return retVal; - } - - else { - return new LinkedList(fIDtoContributorsMap.values()); - } - } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/resources/RefreshExclusionContributor.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/resources/RefreshExclusionContributor.java index 2c559d50aee..5ae521c528f 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/resources/RefreshExclusionContributor.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/resources/RefreshExclusionContributor.java @@ -15,37 +15,36 @@ import org.eclipse.swt.widgets.Composite; import org.eclipse.cdt.core.resources.RefreshExclusion; /** - * EXPERIMENTAL. This class or interface has been added as - * part of a work in progress. There is no guarantee that this API will work or - * that it will remain the same. Please do not use this API without consulting - * with the CDT team. + * EXPERIMENTAL. This class or interface has been added as part of a work in progress. There + * is no guarantee that this API will work or that it will remain the same. Please do not use this API without + * consulting with the CDT team. * * @author crecoskie * @since 5.3 - * + * */ public abstract class RefreshExclusionContributor { - + protected String fID; - protected String fName; protected boolean fIsTest; - + protected String fName; + + abstract public RefreshExclusion createExclusion(); + + /** + * Creates the UI that allows user to modify the given RefreshExclusion + * + * @param parent + * - the parent composite to contain the UI + * @param exclusion + * - the RefreshExclusion to be modified + */ + abstract public void createProperiesUI(Composite parent, RefreshExclusion exclusion); + public String getID() { return fID; } - - public void setID(String id) { - fID = id; - } - - public boolean isTest() { - return fIsTest; - } - - public void setIsTest(boolean isTest) { - fIsTest = isTest; - } - + /** * Returns the human-readable name of this exclusion type. * @@ -54,18 +53,21 @@ public abstract class RefreshExclusionContributor { public String getName() { return fName; } - + + public boolean isTest() { + return fIsTest; + } + + public void setID(String id) { + fID = id; + } + + public void setIsTest(boolean isTest) { + fIsTest = isTest; + } + public void setName(String name) { fName = name; } - - abstract public RefreshExclusion createExclusion(); - - /** - * Creates the UI that allows user to modify the given RefreshExclusion - * @param parent - the parent composite to contain the UI - * @param exclusion - the RefreshExclusion to be modified - */ - abstract public void createProperiesUI(Composite parent, RefreshExclusion exclusion); }