Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 370685 - [regression] inconsistent source folders management on the build path
Summary: [regression] inconsistent source folders management on the build path
Status: RESOLVED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: m2e (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows 7
: P3 critical (vote)
Target Milestone: ---   Edit
Assignee: Fred Bricon CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-02-06 04:02 EST by Fred Bricon CLA
Modified: 2021-04-19 13:24 EDT (History)
1 user (show)

See Also:


Attachments
Patch adding resource folders to classpath (2.96 KB, patch)
2012-02-28 10:10 EST, Fred Bricon CLA
no flags Details | Diff
Test case verifying the resources are added after project update (12.47 KB, patch)
2012-02-28 10:12 EST, Fred Bricon CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Fred Bricon CLA 2012-02-06 04:02:17 EST
While upgrading m2e-wtp to build against m2e 1.1M5, several integration tests started to fail due to a change in the java source folder management.

The following can be reproduced without m2e-wtp : when creating a project using the maven-archetype-webapp archetype, the project contains only one empty src/main/resources folder (beside the webapp stuff)

In m2e 1.0.x : only src/main/resources is added to the classpath
In m2e 1.1.x : also adds src/main/java and src/test/java to the classpath, but since the folders don't actually exist, the build path entries are marked as missing in the source tab of the project's Build Path properties page.
As a side effect, when m2e-wtp is in the mix, these missing folders are actually created when installing WTP's Java facet.

That change may be intended (or not) and I could live with that (just update the m2e-wtp test cases accordingly). However the real fun begins when you run Maven > Update Project :
src/main/resources is removed from the build path.

run Maven > Update Project a second time :
src/main/resources is added to the build path.

repeat ...

The resources folder is also removed even if it's not empty
Comment 1 Fred Bricon CLA 2012-02-06 04:06:01 EST
Looks very similar to bug 368333 actually. But in this case, src/main/resources is not generated.
Comment 2 Fred Bricon CLA 2012-02-06 04:08:22 EST
I should also add that I reproduced the problem using latest m2e-core sources from master, on Juno JavaEE M4 (and no m2e-wtp)
Comment 3 Igor Fedorenko CLA 2012-02-06 11:39:26 EST
The change to java source folders classpath entries is intentional, see bug 361549 for reasons behind this.

Disappearing src/main/resources classpath entry is not expected and indeed the erroneous behaviour appears to be similar to bug 368333. Maybe we should just remove resources sources classpath entries...
Comment 4 Fred Bricon CLA 2012-02-06 12:05:20 EST
In AbstractJavaProjectConfigurator.addResourceDirs() (https://github.com/eclipse/m2e-core/blob/554e77b2d9fa56c3eaffa165f76d9020bdf4b25b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/AbstractJavaProjectConfigurator.java#L413) cped = getEnclosingEntryDescriptor(classpath, r.getFullPath()); returns a non-null value so it's not added to the classpath
Comment 5 Fred Bricon CLA 2012-02-28 10:10:30 EST
Created attachment 211731 [details]
Patch adding resource folders to classpath
Comment 6 Fred Bricon CLA 2012-02-28 10:12:32 EST
Created attachment 211732 [details]
Test case verifying the resources are added after project update

I added the test to CustomClasspathTest.java then decided it could be renamed to JavaClasspathTest.java
Comment 7 Igor Fedorenko CLA 2012-03-14 22:44:37 EDT
Yes, both the fix and the test look reasonable. I pushed the test to github and also made you a committer on m2e-core-test (sorry it took so long).

To make isResourceDescriptor 100% reliable, we can annotate resource IClasspathEntry with special attribute (for example, m2e.resource=true). It probably makes sense to check for entry kind too. But we can improve this later, if current implementation proves to be problematic.
Comment 8 Fred Bricon CLA 2012-03-15 04:41:21 EDT
I also thought about tagging resource folders with some metadata. Not sure that'd make it 100% reliable though, as I believe new resources could be added by 3rd party plugins.
Comment 9 Igor Fedorenko CLA 2012-03-15 06:23:54 EDT
(In reply to comment #8)
> I also thought about tagging resource folders with some metadata. Not sure
> that'd make it 100% reliable though, as I believe new resources could be added
> by 3rd party plugins.

Custom resources (any custom classpath entries, actually) are already handled differently and should be preserved. In fact, current implementation has a small bug, where custom source entries are replaced with m2e-managed during configuration update.
Comment 10 Fred Bricon CLA 2012-03-15 06:25:38 EDT
Something added by this patch?
Comment 11 Igor Fedorenko CLA 2012-03-15 06:31:31 EDT
(In reply to comment #10)
> Something added by this patch?

Yes. Steps to reproduce 

* manually create source folder "foo" with excludes=** (i.e. the same as auto-created resource classpath entry)
* add "foo" resource in pom.xml , update project configuration
* remove "foo" resource from pom.xml, update project configuration

"foo" resource classpath entry was explicitly created by the user, so m2e is not expected to remove it, but I believe after this patch this is not longer the case. Very minor and very "edgy" scenario, so I would not worry about it until somebody complains.
Comment 12 Fred Bricon CLA 2012-03-15 06:37:18 EDT
Indeed, the foo folder is removed, as m2e has no clue it was a custom resource folder originally. And that's a very very edgy case :-)
Comment 13 Igor Fedorenko CLA 2012-03-15 06:45:06 EDT
(In reply to comment #12)
> Indeed, the foo folder is removed, as m2e has no clue it was a custom resource
> folder originally. And that's a very very edgy case :-)

m2e DID know it was a custom resource originally but this information was wiped during project configuration update.
Comment 14 Fred Bricon CLA 2012-03-15 06:46:30 EDT
Ok, if that's the case, then I'll look into it.
Comment 15 Igor Fedorenko CLA 2012-03-15 06:48:01 EDT
(In reply to comment #14)
> Ok, if that's the case, then I'll look into it.

nah. nobody is going to notice ;-)
Comment 16 Denis Roy CLA 2021-04-19 13:24:49 EDT
Moved to https://github.com/eclipse-m2e/m2e-core/issues/