Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 350833

Summary: Scope of PRE_BUILD and POST_BUILD events
Product: [Tools] CDT Reporter: stasik0
Component: cdt-buildAssignee: cdt-build-inbox <cdt-build-inbox>
Status: NEW --- QA Contact: Jonah Graham <jonah>
Severity: major    
Priority: P3 CC: cdtdoug, jamesblackburn+eclipse, jeblen, remy.suen, stasik0, Szymon.Brandys
Version: 1.0   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Whiteboard:

Description stasik0 CLA 2011-06-30 09:58:39 EDT
Build Identifier: 20110615-0604

After moving on Helios I am getting wrong PRE_BUILD and POST_BUILD event behaviour in my plugins.

Instead of getting IProject or IWorkspace objects in event.getSource() depending on the scope of the build I am always getting IWorkspace objects.

Reproducible: Always

Steps to Reproduce:
1. startup class
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IResourceChangeListener listener = new RessourceChangeListener();
workspace.addResourceChangeListener(listener,
IResourceChangeEvent.PRE_BUILD |  IResourceChangeEvent.POST_BUILD);
2.
Listener:
Now in the listener itself following code gets called:
public void resourceChanged(IResourceChangeEvent event) {
		System.out.println("source: "+event.getSource().getClass().toString());
}
3. I do always get IWorkspace independent from what I build.
Comment 1 stasik0 CLA 2011-06-30 12:22:30 EDT
I am sorry for the typo, the bug is for INDIGO.
Comment 2 James Blackburn CLA 2011-07-01 11:56:34 EDT
This is dependent on how the build is run. 

If your build action calls IProject#build, the source will be a project. If you build using IWorkspace#build, the source will be at the workspace level. In Indigo the default build action uses IWorkspace API to build a project and its references.

For each build invocation, only one PRE_BUILD and POST_BUILD are fired.  As a workspace build invocation may build more than one project, the build scope / event source will be at the IWorkspace level.  It's not correct to rely on the build event source being an IProject, as IProject#build is one of 3 methods which will cause a project to be built (the others are: auto-build and Workspace build).  So to work out whether a project is being built you really need to look at the delta, not the source.

See also bug 341838 comment 2
Comment 3 stasik0 CLA 2011-07-02 06:43:21 EDT
Well, I noticed, that my code is not working any longer since the scope is now at IWorkspace. Is it maybe a problem with the new CDT s.t. even the build project trigger triggers IWorkspace build?
Comment 4 James Blackburn CLA 2011-07-02 06:49:09 EDT
It might have to build references as well. Hence it's a workspace scoped build.
Comment 5 stasik0 CLA 2011-07-04 03:52:23 EDT
i am trying to traverse Delta

event.getDelta().accept(new IResourceDeltaVisitor(){
	public boolean visit(IResourceDelta delta) throws CoreException {
		System.out.println(delta.getResource().getProject().getName());
		return true;
	}
});

the inner function is never called, delta seems to be empty, am i doing something wrong?
Comment 6 John Eblen CLA 2012-06-19 11:47:00 EDT
This behavior still occurs in Juno. It seems the delta is sometimes empty after invoking a build with the hammer icon. Also, it seems to depend on the current focus. If I select the project in Project Explorer and build, the delta contains the project. If I select a view, such as the console view, and build, the delta is empty.
Comment 7 John Eblen CLA 2012-06-19 11:58:41 EDT
I forgot to mention that I'm using CDT to build. So I don't know if this is a CDT problem or a platform problem.
Comment 8 Szymon Brandys CLA 2012-06-25 05:12:45 EDT
CDT please comment.
Comment 9 James Blackburn CLA 2012-06-25 09:44:41 EDT
The delta issue sounds different. There may be no resource changes when the build was requested.