1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 22:52:11 +02:00

Bug 133881 - Make refreshing after building optional

Work in progress.
This commit is contained in:
Chris Recoskie 2011-04-29 18:02:57 +00:00
parent fe52e11b25
commit 1ab1affd17
7 changed files with 233 additions and 84 deletions

View file

@ -31,6 +31,7 @@ import org.eclipse.cdt.core.ICommandLauncher;
import org.eclipse.cdt.core.model.ICModelMarker;
import org.eclipse.cdt.core.resources.ACBuilder;
import org.eclipse.cdt.core.resources.IConsole;
import org.eclipse.cdt.core.resources.RefreshScopeManager;
import org.eclipse.cdt.internal.core.ConsoleOutputSniffer;
import org.eclipse.cdt.make.internal.core.MakeMessages;
import org.eclipse.cdt.make.internal.core.StreamMonitor;
@ -295,7 +296,11 @@ public class MakeBuilder extends ACBuilder {
// Do not allow the cancel of the refresh, since the builder is external
// to Eclipse, files may have been created/modified and we will be out-of-sync.
// The caveat is for huge projects, it may take sometimes at every build.
project.refreshLocal(IResource.DEPTH_INFINITE, null);
// project.refreshLocal(IResource.DEPTH_INFINITE, null);
// use the refresh scope manager to refresh
IWorkspaceRunnable runnable = RefreshScopeManager.getInstance().getRefreshRunnable(project);
ResourcesPlugin.getWorkspace().run(runnable, null);
} catch (CoreException e) {
MakeCorePlugin.log(e);
}

View file

@ -31,6 +31,7 @@ import org.eclipse.cdt.core.envvar.IEnvironmentVariable;
import org.eclipse.cdt.core.envvar.IEnvironmentVariableManager;
import org.eclipse.cdt.core.model.ICModelMarker;
import org.eclipse.cdt.core.resources.IConsole;
import org.eclipse.cdt.core.resources.RefreshScopeManager;
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
import org.eclipse.cdt.internal.core.ConsoleOutputSniffer;
import org.eclipse.cdt.make.core.scannerconfig.IScannerConfigBuilderInfo2;
@ -51,7 +52,9 @@ import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceRunnable;
import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
@ -196,7 +199,11 @@ public class ExternalBuildRunner extends AbstractBuildRunner {
// The caveat is for huge projects, it may take sometimes at every build.
// TODO should only refresh output folders
project.refreshLocal(IResource.DEPTH_INFINITE, null);
//project.refreshLocal(IResource.DEPTH_INFINITE, null);
// use the refresh scope manager to refresh
IWorkspaceRunnable runnable = RefreshScopeManager.getInstance().getRefreshRunnable(project);
ResourcesPlugin.getWorkspace().run(runnable, null);
} catch (CoreException e) {
}
} else {

View file

@ -30,6 +30,7 @@ import org.eclipse.cdt.core.IMarkerGenerator;
import org.eclipse.cdt.core.model.ICModelMarker;
import org.eclipse.cdt.core.resources.ACBuilder;
import org.eclipse.cdt.core.resources.IConsole;
import org.eclipse.cdt.core.resources.RefreshScopeManager;
import org.eclipse.cdt.managedbuilder.buildmodel.BuildDescriptionManager;
import org.eclipse.cdt.managedbuilder.buildmodel.IBuildDescription;
import org.eclipse.cdt.managedbuilder.buildmodel.IBuildIOType;
@ -58,7 +59,9 @@ import org.eclipse.core.resources.IResourceDelta;
import org.eclipse.core.resources.IResourceDeltaVisitor;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.IWorkspaceRunnable;
import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
@ -1104,8 +1107,11 @@ public class GeneratedMakefileBuilder extends ACBuilder {
monitor.subTask(ManagedMakeMessages
.getResourceString(REFRESH));
try {
currentProject.refreshLocal(
IResource.DEPTH_INFINITE, null);
//currentProject.refreshLocal(IResource.DEPTH_INFINITE, null);
// use the refresh scope manager to refresh
IWorkspaceRunnable runnable = RefreshScopeManager.getInstance().getRefreshRunnable(currentProject);
ResourcesPlugin.getWorkspace().run(runnable, null);
} catch (CoreException e) {
monitor.subTask(ManagedMakeMessages
.getResourceString(REFRESH_ERROR));

View file

@ -28,6 +28,7 @@ import org.eclipse.cdt.ui.newui.AbstractCPropertyTab;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.ISelection;
@ -600,5 +601,12 @@ public class RefreshPolicyTab extends AbstractCPropertyTab {
List<RefreshExclusion> exclusions = fResourceToExclusionsMap.get(resource);
fManager.setExclusions(resource, exclusions);
}
try {
fManager.persistSettings();
} catch (CoreException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

View file

@ -10,10 +10,14 @@
*******************************************************************************/
package org.eclipse.cdt.core.resources.tests;
import java.io.File;
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.eclipse.cdt.core.CProjectNature;
import org.eclipse.cdt.core.resources.ExclusionInstance;
@ -28,7 +32,9 @@ import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.IWorkspaceRunnable;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
/**
@ -38,8 +44,8 @@ import org.eclipse.core.runtime.IProgressMonitor;
public class RefreshScopeTests extends TestCase {
private IProject fProject;
private IResource fFolder1;
private IResource fFolder2;
private IFolder fFolder1;
private IFolder fFolder2;
private IFolder fFolder3;
private IFolder fFolder4;
private IFolder fFolder5;
@ -133,9 +139,11 @@ public class RefreshScopeTests extends TestCase {
}
public void testAddDeleteResource() throws CoreException {
RefreshScopeManager manager = RefreshScopeManager.getInstance();
manager.clearAllData();
manager.addResourceToRefresh(fProject, fFolder1);
IResource[] resources = manager.getResourcesToRefresh(fProject).toArray(new IResource[0]);
@ -170,6 +178,8 @@ public class RefreshScopeTests extends TestCase {
public void testSetResourcesToRefresh() {
RefreshScopeManager manager = RefreshScopeManager.getInstance();
manager.clearAllData();
List<IResource> resources = new LinkedList<IResource>();
resources.add(fFolder1);
resources.add(fFolder2);
@ -186,6 +196,8 @@ public class RefreshScopeTests extends TestCase {
public void testAddRemoveExclusion() {
RefreshScopeManager manager = RefreshScopeManager.getInstance();
manager.clearAllData();
manager.addResourceToRefresh(fProject, fProject);
RefreshExclusion exclusion1 = new TestExclusion();
manager.addExclusion(fProject, exclusion1);
@ -215,6 +227,8 @@ public class RefreshScopeTests extends TestCase {
public void testPersistAndLoad() {
RefreshScopeManager manager = RefreshScopeManager.getInstance();
manager.clearAllData();
manager.addResourceToRefresh(fProject, fProject);
RefreshExclusion exclusion1 = new TestExclusion();
@ -294,6 +308,8 @@ public class RefreshScopeTests extends TestCase {
public void testResourceExclusion() {
RefreshScopeManager manager = RefreshScopeManager.getInstance();
manager.clearAllData();
manager.addResourceToRefresh(fProject, fProject);
// create a series of nested exclusions that include/exclude certain folders
@ -340,12 +356,73 @@ public class RefreshScopeTests extends TestCase {
assertEquals(true, manager.shouldResourceBeRefreshed(fFolder5));
assertEquals(false, manager.shouldResourceBeRefreshed(fFolder6));
// now let's create a bunch of files in these directories using java.io.File (so that we don't get
// resource deltas happening), and refresh the project according to the policy. We should only see the files
// in the same folders above when consulting the resource system
IPath path = fProject.getLocation();
createTestFile(path);
path = fFolder1.getLocation();
createTestFile(path);
path = fFolder2.getLocation();
createTestFile(path);
path = fFolder3.getLocation();
createTestFile(path);
path = fFolder4.getLocation();
createTestFile(path);
path = fFolder5.getLocation();
createTestFile(path);
path = fFolder6.getLocation();
createTestFile(path);
// now refresh
IWorkspaceRunnable runnable = manager.getRefreshRunnable(fProject);
try {
ResourcesPlugin.getWorkspace().run(runnable, null);
} catch (CoreException e) {
fail();
}
// check if the proper resources exist in the workspace
IResource resource = fProject.getFile("foo.cpp");
assertEquals(true, resource.exists());
resource = fFolder1.getFile("foo.cpp");
assertEquals(false, resource.exists());
resource = fFolder2.getFile("foo.cpp");
assertEquals(false, resource.exists());
resource = fFolder3.getFile("foo.cpp");
assertEquals(true, resource.exists());
resource = fFolder4.getFile("foo.cpp");
assertEquals(false, resource.exists());
resource = fFolder5.getFile("foo.cpp");
assertEquals(true, resource.exists());
resource = fFolder6.getFile("foo.cpp");
assertEquals(false, resource.exists());
manager.clearAllData();
}
private void createTestFile(IPath path) {
path = path.append("foo.cpp");
File file = new File(path.toOSString());
try {
file.createNewFile();
} catch (IOException e) {
fail();
}
}
public void testDefaults() {
RefreshScopeManager manager = RefreshScopeManager.getInstance();
manager.clearAllData();
// by default, a project should refresh its root
List<IResource> resourcesToRefresh = manager.getResourcesToRefresh(fProject);
@ -383,6 +460,10 @@ public class RefreshScopeTests extends TestCase {
assertEquals(0, exclusions.size());
}
public static Test suite() {
return new TestSuite(RefreshScopeTests.class);
}
}

View file

@ -29,6 +29,7 @@ import org.eclipse.cdt.core.model.tests.ElementDeltaTests;
import org.eclipse.cdt.core.model.tests.WorkingCopyTests;
import org.eclipse.cdt.core.parser.tests.ParserTestSuite;
import org.eclipse.cdt.core.parser.tests.rewrite.RewriteTests;
import org.eclipse.cdt.core.resources.tests.RefreshScopeTests;
import org.eclipse.cdt.core.tests.templateengine.AllTemplateEngineTests;
import org.eclipse.cdt.internal.index.tests.IndexTests;
import org.eclipse.cdt.internal.pdom.tests.PDOMTests;
@ -83,6 +84,8 @@ public class AutomatedIntegrationSuite extends TestSuite {
suite.addTest(IndexTests.suite());
suite.addTest(AllTemplateEngineTests.suite());
suite.addTest(RefreshScopeTests.suite());
return suite;
}

View file

@ -33,6 +33,10 @@ import org.eclipse.cdt.core.CProjectNature;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceChangeEvent;
import org.eclipse.core.resources.IResourceChangeListener;
import org.eclipse.core.resources.IResourceDelta;
import org.eclipse.core.resources.IResourceDeltaVisitor;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.IWorkspaceRunnable;
import org.eclipse.core.resources.ResourcesPlugin;
@ -89,6 +93,40 @@ public class RefreshScopeManager {
private RefreshScopeManager(){
fClassnameToExclusionFactoryMap = new HashMap<String, RefreshExclusionFactory>();
loadExtensions();
try {
loadSettings();
} catch (CoreException e) {
CCorePlugin.log(e);
}
// add a resource change listener that will try to load settings for projects when they open
ResourcesPlugin.getWorkspace().addResourceChangeListener(new IResourceChangeListener() {
public void resourceChanged(IResourceChangeEvent event) {
IResourceDelta delta = event.getDelta();
try {
delta.accept(new IResourceDeltaVisitor() {
public boolean visit(IResourceDelta delta) throws CoreException {
if(delta.getResource() instanceof IProject && delta.getKind() == IResourceDelta.ADDED) {
IProject project = (IProject) delta.getResource();
loadSettings(ResourcesPlugin.getWorkspace().getRoot(), project);
return false;
}
return true;
}
}
);
} catch (CoreException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}, IResourceChangeEvent.POST_CHANGE);
}
public synchronized void loadExtensions() {
@ -350,95 +388,104 @@ public class RefreshScopeManager {
IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
for (IProject project : workspaceRoot.getProjects()) {
if (project.isOpen()) {
if (project.hasNature(CProjectNature.C_NATURE_ID)) {
String xmlString = project.getPersistentProperty(REFRESH_SCOPE_PROPERTY_NAME);
loadSettings(workspaceRoot, project);
}
}
// if there are no settings, then configure the default behaviour of refreshing the entire
// project,
// with no exclusions
if (xmlString == null) {
addResourceToRefresh(project, project);
/**
* @param workspaceRoot
* @param project
* @throws CoreException
*/
private 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);
// if there are no settings, then configure the default behaviour of refreshing the entire
// project,
// with no exclusions
if (xmlString == null) {
addResourceToRefresh(project, project);
}
else {
// convert the XML string to a DOM model
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory
.newInstance();
DocumentBuilder docBuilder = null;
try {
docBuilder = docBuilderFactory.newDocumentBuilder();
} catch (ParserConfigurationException e) {
throw new CoreException(CCorePlugin.createStatus(
Messages.RefreshScopeManager_0, e));
}
else {
// convert the XML string to a DOM model
Document doc = null;
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory
.newInstance();
DocumentBuilder docBuilder = null;
try {
docBuilder = docBuilderFactory.newDocumentBuilder();
} catch (ParserConfigurationException e) {
throw new CoreException(CCorePlugin.createStatus(
Messages.RefreshScopeManager_0, e));
}
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));
}
Document doc = null;
// walk the DOM and load the settings
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));
}
// for now ignore the version attribute, as we only have version 1 at this time
// walk the DOM and load the settings
// iterate through the child nodes
NodeList nodeList = doc.getDocumentElement().getChildNodes(); // child of the doc is the root
// for now ignore the version attribute, as we only have version 1 at this time
for (int k = 0; k < nodeList.getLength(); k++) {
Node node = nodeList.item(k);
// iterate through the child nodes
NodeList nodeList = doc.getDocumentElement().getChildNodes(); // child of the doc is the root
// node will be an element
if (node instanceof Element) {
Element resourceElement = (Element) node;
for (int k = 0; k < nodeList.getLength(); k++) {
Node node = nodeList.item(k);
if (resourceElement.getNodeName().equals(RESOURCE_ELEMENT_NAME)) {
// node will be an element
if (node instanceof Element) {
Element resourceElement = (Element) node;
// get the resource path
String resourcePath = resourceElement
.getAttribute(WORKSPACE_PATH_ATTRIBUTE_NAME);
if (resourceElement.getNodeName().equals(RESOURCE_ELEMENT_NAME)) {
if (resourcePath == null) {
// error
// get the resource path
String resourcePath = resourceElement
.getAttribute(WORKSPACE_PATH_ATTRIBUTE_NAME);
}
if (resourcePath == null) {
else {
// find the resource
IResource resource = workspaceRoot.findMember(resourcePath);
if (resource == null) {
// error
}
else {
// find the resource
IResource resource = workspaceRoot.findMember(resourcePath);
addResourceToRefresh(project, resource);
if (resource == null) {
// error
}
// load any exclusions
List<RefreshExclusion> exclusions = RefreshExclusion.loadData(resourceElement, null, resource);
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);
}
}
}
}
}
}
}
}
}
}
@ -459,7 +506,8 @@ public class RefreshScopeManager {
}
public void clearAllExclusions() {
fResourceToExclusionsMap.clear();
if(fResourceToExclusionsMap != null)
fResourceToExclusionsMap.clear();
}
public ExclusionInstance getInstanceForClassName(String className) {
@ -496,22 +544,13 @@ public class RefreshScopeManager {
if (resource instanceof IContainer) {
IContainer container = (IContainer) resource;
// get any exclusions
boolean isExcluded = false;
for (RefreshExclusion exclusion : exclusions) {
if (exclusion.testExclusionChain(resource)) {
isExcluded = true;
break;
}
}
if (!isExcluded) {
if (shouldResourceBeRefreshed(resource)) {
resource.refreshLocal(IResource.DEPTH_ONE, monitor);
for (IResource child : container.members()) {
refreshResources(child, exclusions, monitor);
}
}
for (IResource child : container.members()) {
refreshResources(child, exclusions, monitor);
}
}
}