mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Bug 133881 - Make refreshing after building optional
Work in progress.
This commit is contained in:
parent
07b6a0943d
commit
1cbc7db6e6
4 changed files with 171 additions and 28 deletions
|
@ -20,6 +20,7 @@ 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.testplugin.CTestPlugin;
|
||||
import org.eclipse.core.resources.IFolder;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
|
@ -39,6 +40,10 @@ public class RefreshScopeTests extends TestCase {
|
|||
private IProject fProject;
|
||||
private IResource fFolder1;
|
||||
private IResource fFolder2;
|
||||
private IFolder fFolder3;
|
||||
private IFolder fFolder4;
|
||||
private IFolder fFolder5;
|
||||
private IFolder fFolder6;
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see junit.framework.TestCase#setUp()
|
||||
|
@ -70,17 +75,40 @@ public class RefreshScopeTests extends TestCase {
|
|||
IWorkspaceRoot root = CTestPlugin.getWorkspace().getRoot();
|
||||
IProject project = root.getProject("testRefreshScope");
|
||||
|
||||
// create a couple folders
|
||||
// create some folders
|
||||
// structure is:
|
||||
/*
|
||||
* testRefreshScope
|
||||
* folder1
|
||||
* folder2
|
||||
* folder 3
|
||||
* folder 4
|
||||
* folder 5
|
||||
* folder 6
|
||||
*
|
||||
*/
|
||||
final IFolder folder1 = project.getFolder("folder1");
|
||||
fFolder1 = folder1;
|
||||
final IFolder folder2 = project.getFolder("folder2");
|
||||
fFolder2 = folder2;
|
||||
fFolder2 = folder2;
|
||||
final IFolder folder3 = folder2.getFolder("folder3");
|
||||
fFolder3 = folder3;
|
||||
final IFolder folder4 = folder3.getFolder("folder4");
|
||||
fFolder4 = folder4;
|
||||
final IFolder folder5 = folder3.getFolder("folder5");
|
||||
fFolder5 = folder5;
|
||||
final IFolder folder6 = folder2.getFolder("folder6");
|
||||
fFolder6 = folder6;
|
||||
|
||||
CTestPlugin.getWorkspace().run(new IWorkspaceRunnable() {
|
||||
public void run(IProgressMonitor monitor) throws CoreException {
|
||||
|
||||
folder1.create(true, true, monitor);
|
||||
folder2.create(true, true, monitor);
|
||||
folder3.create(true, true, monitor);
|
||||
folder4.create(true, true, monitor);
|
||||
folder5.create(true, true, monitor);
|
||||
folder6.create(true, true, monitor);
|
||||
}
|
||||
}, null);
|
||||
|
||||
|
@ -264,5 +292,57 @@ public class RefreshScopeTests extends TestCase {
|
|||
manager.clearAllData();
|
||||
}
|
||||
|
||||
public void testResourceExclusion() {
|
||||
RefreshScopeManager manager = RefreshScopeManager.getInstance();
|
||||
manager.addResourceToRefresh(fProject, fProject);
|
||||
|
||||
// create a series of nested exclusions that include/exclude certain folders
|
||||
// will be included/excluded as follows
|
||||
/*
|
||||
* testRefreshScope - include
|
||||
* folder1 - exclude
|
||||
* folder2 - exclude, except,
|
||||
* folder 3 - include
|
||||
* folder 4 - exclude
|
||||
* folder 5 - include
|
||||
* folder 6 - exclude
|
||||
*
|
||||
*/
|
||||
|
||||
ResourceExclusion exclusion1 = new ResourceExclusion();
|
||||
ExclusionInstance instance1 = new ExclusionInstance();
|
||||
instance1.setResource(fFolder1);
|
||||
exclusion1.addExclusionInstance(instance1);
|
||||
ExclusionInstance instance2 = new ExclusionInstance();
|
||||
instance2.setResource(fFolder2);
|
||||
exclusion1.addExclusionInstance(instance2);
|
||||
manager.addExclusion(fProject, exclusion1);
|
||||
|
||||
ResourceExclusion exclusion2 = new ResourceExclusion();
|
||||
ExclusionInstance instance3 = new ExclusionInstance();
|
||||
instance3.setResource(fFolder3);
|
||||
exclusion2.addExclusionInstance(instance3);
|
||||
exclusion1.addNestedExclusion(exclusion2);
|
||||
|
||||
ResourceExclusion exclusion3 = new ResourceExclusion();
|
||||
ExclusionInstance instance4 = new ExclusionInstance();
|
||||
instance4.setResource(fFolder4);
|
||||
exclusion3.addExclusionInstance(instance4);
|
||||
exclusion2.addNestedExclusion(exclusion3);
|
||||
|
||||
|
||||
// now check and see if the right folders are included/excluded
|
||||
assertEquals(true, manager.shouldResourceBeRefreshed(fProject));
|
||||
assertEquals(false, manager.shouldResourceBeRefreshed(fFolder1));
|
||||
assertEquals(false, manager.shouldResourceBeRefreshed(fFolder2));
|
||||
assertEquals(true, manager.shouldResourceBeRefreshed(fFolder3));
|
||||
assertEquals(false, manager.shouldResourceBeRefreshed(fFolder4));
|
||||
assertEquals(true, manager.shouldResourceBeRefreshed(fFolder5));
|
||||
assertEquals(false, manager.shouldResourceBeRefreshed(fFolder6));
|
||||
|
||||
manager.clearAllData();
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -119,14 +119,46 @@ public abstract class RefreshExclusion {
|
|||
public abstract String getName();
|
||||
|
||||
/**
|
||||
* Tests a given resource to see if this exclusion should exclude it from being refreshed.
|
||||
* This should consult any nested exclusions to see if they in turn ought to exclude the resource.
|
||||
* Tests a given resource to see if this exclusion applies to it.
|
||||
*
|
||||
* @param resource the resource to be tested.
|
||||
* @return true if the resource should be excluded, false otherwise.
|
||||
* @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 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<RefreshExclusion> 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
|
||||
*/
|
||||
|
|
|
@ -498,7 +498,7 @@ public class RefreshScopeManager {
|
|||
boolean isExcluded = false;
|
||||
|
||||
for (RefreshExclusion exclusion : exclusions) {
|
||||
if (exclusion.testExclusion(resource)) {
|
||||
if (exclusion.testExclusionChain(resource)) {
|
||||
isExcluded = true;
|
||||
break;
|
||||
}
|
||||
|
@ -517,5 +517,48 @@ public class RefreshScopeManager {
|
|||
|
||||
return runnable;
|
||||
}
|
||||
|
||||
public boolean shouldResourceBeRefreshed(IResource resource) {
|
||||
IProject project = resource.getProject();
|
||||
List<IResource> resourcesToRefresh = getResourcesToRefresh(project);
|
||||
boolean isInSomeTree = false;
|
||||
IResource topLevelResource = null;
|
||||
|
||||
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) {
|
||||
IContainer container = (IContainer) resourceToRefresh;
|
||||
if(container.getFullPath().isPrefixOf(resource.getFullPath())) {
|
||||
isInSomeTree = true;
|
||||
topLevelResource = resourceToRefresh;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(!isInSomeTree) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// get any exclusions
|
||||
boolean isExcluded = false;
|
||||
|
||||
for (RefreshExclusion exclusion : getExclusions(topLevelResource)) {
|
||||
if (exclusion.testExclusionChain(resource)) {
|
||||
isExcluded = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return !isExcluded;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -11,11 +11,10 @@
|
|||
|
||||
package org.eclipse.cdt.core.resources;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.core.resources.IFolder;
|
||||
import org.eclipse.core.resources.IContainer;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
|
||||
/**
|
||||
|
@ -45,36 +44,25 @@ public class ResourceExclusion extends RefreshExclusion {
|
|||
@Override
|
||||
public boolean testExclusion(IResource resource) {
|
||||
|
||||
//First, check to see if the given resource is an exception to this exclusion
|
||||
List<RefreshExclusion> nestedExclusions = getNestedExclusions();
|
||||
if (nestedExclusions != null) {
|
||||
Iterator<RefreshExclusion> exclusions = nestedExclusions.iterator();
|
||||
while (exclusions.hasNext()) {
|
||||
RefreshExclusion exclusion = exclusions.next();
|
||||
if (exclusion.testExclusion(resource)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Populate the resources to be excluded by this exclusion
|
||||
List<IResource> excludedResources = new LinkedList<IResource>();
|
||||
List<ExclusionInstance> exclusionInstances = getExclusionInstances();
|
||||
Iterator<ExclusionInstance> iterator = exclusionInstances.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
ExclusionInstance instance = iterator.next();
|
||||
|
||||
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
|
||||
Iterator<IResource> resources = excludedResources.iterator();
|
||||
while (resources.hasNext()) {
|
||||
|
||||
for(IResource excludedResource : excludedResources) {
|
||||
//TODO: need to update this for Phase 2 implementation
|
||||
IFolder excludedResource = (IFolder) resources.next();
|
||||
if (excludedResource.exists(resource.getFullPath())) {
|
||||
return true;
|
||||
if (excludedResource instanceof IContainer) {
|
||||
IContainer container = (IContainer) excludedResource;
|
||||
if (container.getFullPath().isPrefixOf(resource.getFullPath())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue