Bug 58649 - [buildpath] Builders don't trigger on resources refreshed during build
Summary: [buildpath] Builders don't trigger on resources refreshed during build
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.0   Edit
Hardware: PC Linux
: P3 normal with 3 votes (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
: 74798 86770 114887 184333 221151 (view as bug list)
Depends on:
Blocks:
 
Reported: 2004-04-15 09:59 EDT by Matthew Conway CLA
Modified: 2023-05-23 00:36 EDT (History)
13 users (show)

See Also:


Attachments
JavaProject with ExternalTooBuilder and JavaBuilder (1.90 KB, application/zip)
2004-07-08 06:05 EDT, Frank Neblung CLA
no flags Details
Draft patch (3.30 KB, patch)
2012-01-12 00:04 EST, Jay Arthanareeswaran CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Matthew Conway CLA 2004-04-15 09:59:29 EDT
I have a java project setup with multiple external tool builders.  This lets me
call our makefile whenever I change resource that need an external build.  My
builders look something like:

make config
Build jar
make deploy

This, make config only gets run if I change a config file, Build jar happens
whenever java files get compiled by eclipse, and make deploy should happen if
any of the two steps above get triggered.

This is mostly working except for when make deploy gets triggered - I have it
set to trigger on a workingset including the jar produced by build jar.  However
it never gets triggered, I'm guessing because even though Build jar does a
refresh of the jar it creates, this is happening during the buid and thus make
deploy doesn't get to see it as having changed.

Can this be fixed?  As a workaround, I can make it trigger on the same files
that trigger build jar, but this is a bit of a hack and doesn't scale well if I
have multiple other builders whose output I want make deploy to trigger on.
Comment 1 Matthew Conway CLA 2004-04-15 10:00:21 EDT
Oops, forgot to mention this is on eclipse I20040413 on linux fedora core 1
Comment 2 Darin Wright CLA 2004-05-10 13:06:35 EDT
This is not currently possible. The way things work under the covers is as 
follows:

* When a build is invoked (auto or manual), the external tool builder first 
checks if it should "build" by determining if the resources that have changed 
since the last build include any resources in the relevant working set. If so, 
the external tool builder runs.

However, I do not believe resource changes from builders are used to trigger 
more builds. John, can you clarify this point? 
Comment 3 John Arthorne CLA 2004-05-10 13:25:37 EDT
I'm not sure if I understand the question... If you have three different
builders on a project, then each builder will receive a delta that includes
changes made by previous builders. However, with the external tool builder, I
believe there is only one builder instance, so this won't work; the second copy
of the builder will not receive a delta, since nothing has changed since it last
finished running.
Comment 4 Darin Wright CLA 2004-05-10 13:56:28 EDT
Clarification: Builder A creates a "jar" file based on a resource delta 
(changed class files). Builder B deploys the jar file (when the jar changes). 
However, when the build runs, builder B will not do anything because nothing 
has change that it cares about (i.e. as John states, the delta will not show 
that the jar has changed since the last build).

I presume there are rules to avoid one builder triggering another - i.e. one 
build causes a resource change that triggers another?
 
Comment 5 John Arthorne CLA 2004-05-10 18:16:34 EDT
Yes, changes inside an autobuild do not trigger another autobuild to occur.
Again, I think the problem here is that Builder A and Builder B are in fact the
same external tool builder. A builder can never see deltas for changes that it
made itself.
Comment 6 Darin Wright CLA 2004-05-10 18:23:15 EDT
Deferred
Comment 7 Frank Neblung CLA 2004-07-01 10:05:03 EDT
We have similar build problems.
An Ant-Build is called to generate Java-Sources from CORBA-IDL files.
After that build Eclipse's Java Builder shall be run to compile the
generated sources.
Since there aren't any Java-Sources until the first builder
completes the Java Builder isn't run at all.

The problem is still present in the 3.0 final release.
Comment 8 Frank Neblung CLA 2004-07-07 04:57:29 EDT
Couldn't you give us back the good old "Rebuild project"/"Rebuild All" which
calls all builders in the given order, regardless of the project's state and any
builder's delta?
Or does anyone know a suitable plugin?
Comment 9 John Arthorne CLA 2004-07-07 10:28:41 EDT
Re comment #7 - it sounds like in your case you just need to put the ant builder
before the Java builder, and ensure the Ant builder does not run in the
background. That way the Java builder will run after the Ant builder has
generated the Java source, and it will be compiled.
Comment 10 Frank Neblung CLA 2004-07-07 11:48:45 EDT
The Ant builder is before the Java builder and the ant builder doesn't run in
the background. But the Java builder isn't run anyway. May be the problem is
that the source folders don't exist when "build project" is performed.

When I check out my project from CVS there isn't a folder "generated" yet. That
makes sense, since generated sources aren't version controlled. But the folder
"generated" is (one of) the JavaProject->Properties...Java Build Path/Source
folder. Seems that the condition for the Java builder to be run is evaluated too
early. If I do the trick an create the "generated" folder by hand, then - voila
-  both the ant builder and the Java builder are run.
Comment 11 Frank Neblung CLA 2004-07-08 06:05:20 EDT
Created attachment 13047 [details]
JavaProject with ExternalTooBuilder and JavaBuilder

unzip the project to the file system
start a fresh workspace
turn off Preferences:build automatically
import the unzipped project as an existing project to the workspace
try to build the project
Comment 12 Frank Neblung CLA 2004-07-08 06:11:31 EDT
I found that JavaBuilder.isWorthBuilding() erroneously returns false. The called
method isClasspathBroken() finds Markers of the type
org.eclipse.jdt.core.buildpath_problem. You can debug that with the attached
project in comment#11.
So the JavaBuilder isn't run due to an outdated ProjectInfo. I don't know where
the bug is. Should the JavaBuilder cause the ProjectInfo to be updated prior to
its isWorthBuilding()? Or should the ExternalToolBuilder do so when its job is done?
I also don't know if that kind of problem is actually related to the initial
comment. If not, I'm sorry...
Comment 13 John Arthorne CLA 2004-07-08 11:24:03 EDT
I will investigate
Comment 14 John Arthorne CLA 2004-07-08 11:40:38 EDT
Thank you for the test case. It nicely illustrates what is happening.

The Java builder has the "generated" folder as a source folder. This folder does
not exist yet (it is created by the ant builder). Thus, the Java project
initially starts with a build path error. When the build is run, the generated
folder is created, but the Java builder's build path error does not go away. I
think the Java builder should be detecting that the build path error has been fixed.
Comment 15 Kent Johnson CLA 2004-09-23 13:51:29 EDT
I see 2 problems here:

1. No refresh is performed by the first builder so that workspace knows that 
the missing source folder has been created. Is there some reason why a refresh 
is not done?

2. The classpath computation generates an error for a missing source folder 
instead of just creating it... which is what the JavaBuilder would do if given 
the chance.

Now I can change the JavaBuilder to ignore the classpath error & create 
the 'missing' folder but that's just a hack.
Comment 16 John Arthorne CLA 2004-09-23 14:35:42 EDT
Frank/Mark, can you confirm whether your external tool builder is refreshing the
project when it completes (as specified on the "Refresh" tab of your external
tool builder configuration).
Comment 17 Kent Johnson CLA 2004-09-23 14:39:16 EDT
If your external/ant builder does not refresh, then the JavaBuilder will not 
see any .java files that you create... assuming the source folder did exist.
Comment 18 Philipe Mulet CLA 2004-09-23 16:39:37 EDT
The Java builder is supposed to trigger classpath marker updates before doing 
some work, so presumably the refresh should improve things, since the source 
folder should be discovered and classpath considered to be fixed (that's the 
theory).

Comment 19 Kent Johnson CLA 2004-09-23 16:41:43 EDT
Yes I was mistaken when I said the JavaBuilder would create missing source 
folders... we only create missing output folders.

We expect source folders to exist (as a resource in the workspace, not just on 
disk) before a build starts.
Comment 20 Frank Neblung CLA 2004-09-24 03:14:09 EDT
Re comment#15 comment#16 As you can see in the attached project the external
builder IS refreshing the whole project on completion.
Comment 21 Kent Johnson CLA 2004-09-24 11:34:31 EDT
Frank is right - I was reminded again to never rename test projects... I 
missed a place in the Generator.launch file.

So it appears that our classpath computation is either never receiving 
notification that the 'generated' source folder was created or is not 
listening for it.

But the folder does show up [if you take the testcase as is ;)] & every full 
build continues to fail. Touching the .classpath file or looking at the 
project's properties->build path fixes the problem.
Comment 22 Kent Johnson CLA 2004-09-24 11:38:18 EDT
*** Bug 74798 has been marked as a duplicate of this bug. ***
Comment 23 Darin Swanson CLA 2004-09-24 11:48:40 EDT
A note from my duplicate bug report is that the user who contacted me claims 
this is a regression for 3.0 and 3.1 (worked in 2.1)
Comment 24 Frank Neblung CLA 2004-09-27 05:02:01 EDT
Yep, the regression prevents us from upgrading.
The 2.1 builders run in order. A pre java builder may create sources or even
source folders that the java builder than takes into account. Therefore the
"rebuild project" or "rebuild all" really build. With 3.0 it is not (yet) as
convenient to build ones projects.
Comment 25 Frank Neblung CLA 2004-12-02 10:45:56 EST
The bug isn't targeted yet. Is there hope to see the feature in 3.0.2 or 3.1?
Sorry for impatience.
Comment 26 Philipe Mulet CLA 2005-02-08 10:27:47 EST
We should try to investigate some solution for M6.
Comment 27 Darin Swanson CLA 2005-02-27 16:02:42 EST
*** Bug 86770 has been marked as a duplicate of this bug. ***
Comment 28 Kent Johnson CLA 2005-11-03 12:10:17 EST
*** Bug 114887 has been marked as a duplicate of this bug. ***
Comment 29 Kent Johnson CLA 2006-01-30 16:33:01 EST
I think the root of this problem is JavaProject.flushClasspathProblemMarkers():

IMarker[] markers = this.project.findMarkers(BUILDPATH_PROBLEM_MARKER...
for (int i = 0, length = markers.length; i < length; i++) {
 IMarker marker = markers[i];
 if (flushCycleMarkers && flushClasspathFormatMarkers) {
  marker.delete();
 } else {
  String cycleAttr = marker.getAttribute(CYCLE_DETECTED);
  String classpathFileFormatAttr = marker.getAttribute(CLASSPATH_FILE_FORMAT);
  if ((flushCycleMarkers == "true".equals(cycleAttr)) &&
   (flushClasspathFormatMarkers == "true".equals(classpathFileFormatAttr))))
     marker.delete();
 }
}

So if only 1 of flushCycleMarkers or flushClasspathFormatMarkers is true, then only problems with the corresponding attribute are deleted.

But what about problems with neither of these attributes - such as the problem created for a missing source folder - when are these problems deleted?

You need to call flushClasspathProblemMarkers(false, false) or flushClasspathProblemMarkers(true, true) to delete these problems.

There is only 1 sender of flushClasspathProblemMarkers(true, true) which will delete all markers and it comes from DeltaProcessor.updateClasspathMarkers() AND only when a JavaProject deletes its JavaNature.

There is only 1 sender of flushClasspathProblemMarkers(false, false) which will delete the missing source folder marker and it comes from JavaProject.updateClasspathMarkers(), which looks like:

public void updateClasspathMarkers(Map preferredClasspaths, Map preferredOutputs) {
  this.flushClasspathProblemMarkers(false/*cycle*/, true/*format*/);
  this.flushClasspathProblemMarkers(false/*cycle*/, false/*format*/);

WHY make consecutive calls?

Since this is the case, should JavaProject.getRawClasspath(boolean createMarkers, boolean logProblems) be ?

if (createMarkers) {
 this.flushClasspathProblemMarkers(false/*cycle*/, true/*format*/);
 this.flushClasspathProblemMarkers(false/*cycle*/, false/*format*/);
 classpath = this.readClasspathFile(createMarkers, logProblems);
}
Comment 30 Kent Johnson CLA 2006-01-31 12:29:24 EST
I have question:

When the JavaBuilder runs and computes its NameEnvironment, it retrieves the classpath with the call:

IClasspathEntry[] classpathEntries = javaProject.getExpandedClasspath(true/*ignore unresolved variable*/, false/*don't create markers*/, ...);

So why don't we create markers here?

Especially when we know that the project has BUILDPATH_PROBLEM_MARKERs
Comment 31 Kent Johnson CLA 2006-02-01 12:05:07 EST
Jerome - can you have a look at this please.
Comment 32 Philipe Mulet CLA 2006-02-01 12:16:05 EST
Counter scenario would be that at very beginning, the classpath looks good (no marker), but some builder (ahead of Java builder) is breaking the classpath by deleting a source folder. Our builder should also notice this (i.e. we cannot only check if classpath markers are still legite).
Comment 33 Kent Johnson CLA 2006-02-02 10:35:32 EST
We could always check to see if multiple builders are attached before spending time recreating the markers.

And maybe its enough to only do it on full builds.
Comment 34 Frank Neblung CLA 2006-07-25 02:10:49 EDT
Unchecking the new 3.2-Preference
  Java+Compiler+Building/BuildPathProblems:AbortBuildWhenBuildPathErrorsOccur
solves all our problems

thanks
Comment 35 Steven Schlotfeldt CLA 2007-04-27 17:38:54 EDT
*** Bug 184333 has been marked as a duplicate of this bug. ***
Comment 36 Steven Schlotfeldt CLA 2007-04-27 17:53:07 EDT
Is anything being done on this bug?  This is causing us much trouble as it requires generated source folders to be checked into our configuration management tool.
Comment 37 Jerome Lanneluc CLA 2007-05-02 12:38:30 EDT
(In reply to comment #36)
> Is anything being done on this bug?  This is causing us much trouble as it
> requires generated source folders to be checked into our configuration
> management tool.
Sorry there is no good solution to this problem for now.
Possible workarounds are:
1. Deactivate the checking: Preferences > Java > Compiler > Building > Incomplete Build path > Warning
2. Make the source folder optional (sorry no UI for that) by creating the source entry with an optional attribute (see JavaCore.newSourceEntry(..., IClasspathAttribute[]) and IClasspathAttriibute#OPTIONAL
3. Make the source folder optional by editing the .classpath file, e.g.
	<classpathentry kind="src" path="src1">
		<attributes>
			<attribute name="optional" value="true"/>
		</attributes>
	</classpathentry>

Comment 38 Jerome Lanneluc CLA 2007-06-21 04:44:25 EDT
Will try to come up with a solution for 3.4
Comment 39 Jerome Lanneluc CLA 2008-03-07 04:41:38 EST
*** Bug 221151 has been marked as a duplicate of this bug. ***
Comment 40 Jim Mayer CLA 2008-03-12 23:54:43 EDT
This problem has been a big pain for my project as well and I very much look forward to seeing a fix.  The problems all involve resources created by one project that are used by another.  For us, these include both automatically generated java source and third party packages that create jar files.

Changing the 'Incomplete Build Path' preference works for us, but leaves a persistent warning in the problems list.  One way to force this to go away is to make a trivial modification to each ".classpath" from outside eclipse (e.g., for cp in */.classpath; do echo >> $cp; done), refresh all the projects, and then restore the projects from source control.  I'm sure there's a better way, but at least this one is completely rote and doesn't involve a lot of button pushing.
Comment 41 Jerome Lanneluc CLA 2008-03-13 05:57:38 EDT
(In reply to comment #40)
Sorry Jim, but we don't currently have the manpower to fix this. A good quality patch is welcome though.

Comment 42 Jerome Lanneluc CLA 2008-05-12 05:14:16 EDT
Deferring post 3.4
Comment 43 Benjamin Shelton CLA 2012-01-11 15:32:48 EST
Unfortunately this issue is still present in v3.7.1.  We had the same issue in our project with a jar (kind="lib") that is being auto-generated and were able to circumvent the problem with Jerome's suggestion of making the library optional.  Not exactly the best solution since the library really is required, but at least the build works now  Any plans on addressing this at some point?
Comment 44 Srikanth Sankaran CLA 2012-01-11 23:13:18 EST
At the moment, we find ourselves having bitten off more than we
can comfortably chew for 3.8. And Java SE8 work will start bubbling
up in priority just after that.

As requested in comment#41, patches are welcome - though we can't
commit to 3.8 timeframe for review, testing and incorporation.
Comment 45 Jay Arthanareeswaran CLA 2012-01-12 00:04:05 EST
Created attachment 209350 [details]
Draft patch

As Srikanth said, I don't expect to be able to spend much time with this any time soon. However, I am attaching a patch, which I think, has the approach we should be looking at. I must also mention that I haven't investigated in depth and the patch is not thoroughly tested. This seem to work for the scenario where the source folder created is not recognized. 

If someone can come up with a proper fix with tests, we can look at using it.
Comment 46 Eclipse Genie CLA 2021-06-01 05:44:27 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.
Comment 47 Eclipse Genie CLA 2023-05-23 00:36:21 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.