Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 398121 - Order of classpath entries is modified when updating maven project
Summary: Order of classpath entries is modified when updating maven project
Status: RESOLVED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: m2e (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-01-14 14:40 EST by Roberto Sanchez Herrera CLA
Modified: 2021-04-19 13:24 EDT (History)
5 users (show)

See Also:


Attachments
Pure Java project with custom classpath order (5.44 KB, application/x-zip-compressed)
2013-01-15 03:25 EST, Fred Bricon CLA
no flags Details
Proposed patch (2.90 KB, patch)
2013-01-21 15:24 EST, Roberto Sanchez Herrera CLA
no flags Details | Diff
Proposed patch (v2) (3.50 KB, patch)
2013-01-30 16:12 EST, Roberto Sanchez Herrera CLA
no flags Details | Diff
JUnits (7.18 KB, patch)
2013-01-30 16:12 EST, Roberto Sanchez Herrera CLA
no flags Details | Diff
Proposed patch (v3) (3.27 KB, patch)
2013-01-31 17:25 EST, Roberto Sanchez Herrera CLA
no flags Details | Diff
Proposed patch (v3-corrected) (3.22 KB, patch)
2013-01-31 17:32 EST, Roberto Sanchez Herrera CLA
igor: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Roberto Sanchez Herrera CLA 2013-01-14 14:40:08 EST
I'm using m2e 1.3 and m2e-wtp 0.17.0 on Juno Java EE package. Steps to recreate the problem I'm seeing:

1. Create a dynamic web project and target it to Tomcat
2. Convert the web project to Maven using the war packaging
3. Go to the Java build path property page of the Maven project
4. In the order and export tab, you will see the Tomcat classpath container, the JRE container and the Maven dependencies container. Make sure the Tomcat classpath container is at the bottom (use the Up and down button to move it)
5. Select Maven -> Update project in the Java maven project. 

The result is that the order of the entries is modified, always putting the Maven classpath container at the bottom and the JRE container above it. 

This causes problems if the server classpath container has old versions of jars we want to "override" using the Maven dependencies classpath container. If the Maven container is moved to be above the server runtime so we can compile against the jars in the Maven container, and then we refresh the project, then order is changes and we see compilation problems. 

I did some investigation and found that the method rg.eclipse.m2e.jdt.internal.AbstractJavaProjectConfigurator.configure(ProjectConfigurationRequest request, IProgressMonitor monitor) is the one changing the classpath order. 

Is this behavior working as designed? Is there a reason to always put the Maven and JRE classpath containers at the bottom?
Comment 1 Igor Fedorenko CLA 2013-01-14 22:03:37 EST
I'll assume this is m2e/wtp fault unless proven otherwise.
Comment 2 Fred Bricon CLA 2013-01-15 03:25:50 EST
Created attachment 225608 [details]
Pure Java project with custom classpath order

Nice try Igor, but this one goes to m2e-jdt :-)
Attached is a test java project, already mavenized (same thing happens during conversion). The classpath order is : Maven, JRE, src/main/resources/, src/test/java, Junit4.

Once imported, or when you do Maven > Update Project, the classpath order changes to : src/main/resources/, src/test/java, Junit4, JRE, Maven.
Comment 3 Roberto Sanchez Herrera CLA 2013-01-21 15:24:05 EST
Created attachment 225911 [details]
Proposed patch

The proposed patch removes the lines that remove the Maven and JRE classpath containers before adding them again. This is because the implementation of IClasspathDescriptor used in AbstractJavaProjectConfigurator, which is ClasspathDescriptor, implements the method addEntry(IClasspathEntry cpe) in a way that if the path of the cpe used as input already exist, it is replaced to avoid duplicates.
Comment 4 Fred Bricon CLA 2013-01-22 04:54:09 EST
Roberto, your patch doesn't properly handle the conversion scenario you described in your first comment.
You end up with 2 JRE entries : http://screencast.com/t/cGopPz3VHcDq

For that kind of sensitive change, you should also provide some ITs, make sure the  existing test suite doesn't exhibit regressions. 
There will most likely be failing tests if the behaviour is changed, but you need to make sure the failures are expected (and change the expectation) or not (that'd be bad)
Comment 5 Roberto Sanchez Herrera CLA 2013-01-22 09:49:15 EST
(In reply to comment #4)
> Roberto, your patch doesn't properly handle the conversion scenario you
> described in your first comment.
> You end up with 2 JRE entries : http://screencast.com/t/cGopPz3VHcDq
> 
> For that kind of sensitive change, you should also provide some ITs, make
> sure the  existing test suite doesn't exhibit regressions. 
> There will most likely be failing tests if the behaviour is changed, but you
> need to make sure the failures are expected (and change the expectation) or
> not (that'd be bad)

Yes, you are correct, I found the same problem last night while doing some testing. 
In fact, in the scenario I have, only the Maven dependencies classpath container is the one causing problems. I mean, I can live with the JRE container being moved to the bottom, so probably I could modify the patch to change the behavior of the Maven dependencies container only, what do you think? 

BTW, what do you mean by IT? Integration testing?
Comment 6 Fred Bricon CLA 2013-01-22 11:14:08 EST
(In reply to comment #5)
> In fact, in the scenario I have, only the Maven dependencies classpath
> container is the one causing problems. I mean, I can live with the JRE
> container being moved to the bottom, so probably I could modify the patch to
> change the behavior of the Maven dependencies container only, what do you
> think?
Having different classpath entries behaving seemingly randomly doesn't seem a very good idea IMHO, but I'm not too familiar with the JDT integration. Igor's opinion would probably be more insightful here.
 
> 
> BTW, what do you mean by IT? Integration testing?
yes
Comment 7 Roberto Sanchez Herrera CLA 2013-01-30 16:12:31 EST
Created attachment 226348 [details]
Proposed patch (v2)
Comment 8 Roberto Sanchez Herrera CLA 2013-01-30 16:12:54 EST
Created attachment 226349 [details]
JUnits
Comment 9 Fred Bricon CLA 2013-01-30 17:30:01 EST
I dont' believe checking if the Maven Classpath Library path makes sense. That path is controlled by m2e AND used to identify the library
Comment 10 Fred Bricon CLA 2013-01-30 17:31:07 EST
I dont' believe checking if the Maven Classpath Library path *changed* makes sense. That path is controlled by m2e AND used to identify the library

-- gotta love BZ editing abilities
Comment 11 Roberto Sanchez Herrera CLA 2013-01-30 17:36:00 EST
At this moment, I agree. I was thinking in the future, in case something else is added to the path of this container. 

But if you believe there are few chances for this to happen, then I believe I can remove the code that removes the Maven classpath container, and always add it, like in the first patch.
Comment 12 Fred Bricon CLA 2013-01-30 17:42:17 EST
I'm not aware of any plans for changing that path in any forseeable future.
Igor?
Comment 13 Igor Fedorenko CLA 2013-01-30 21:45:13 EST
I will not have time to review this for m5 but plan to provide feedback before m6.
Comment 14 Roberto Sanchez Herrera CLA 2013-01-31 17:25:27 EST
Created attachment 226425 [details]
Proposed patch (v3)

Patch that does not check for modified Maven classpath container.
Comment 15 Roberto Sanchez Herrera CLA 2013-01-31 17:26:35 EST
(In reply to comment #10)
> I dont' believe checking if the Maven Classpath Library path *changed* makes
> sense. That path is controlled by m2e AND used to identify the library
> 
> -- gotta love BZ editing abilities

Based on your comment, I just updated a new patch, which does not check for changed Maven classpath container
Comment 16 Roberto Sanchez Herrera CLA 2013-01-31 17:32:04 EST
Created attachment 226426 [details]
Proposed patch (v3-corrected)

Same patch as v3, but removing a local variable that was not used.
Comment 17 Roberto Sanchez Herrera CLA 2013-02-13 10:07:48 EST
Pinging.... I believe M5 is over and M6 started this week (at least for other projects, I'm not sure if is the same for m2e).
Comment 18 Igor Fedorenko CLA 2013-02-13 10:37:58 EST
Like I said, I plan to provide feedback *before* m6, i.e. by http://wiki.eclipse.org/Kepler/Simultaneous_Release_Plan http://wiki.eclipse.org/Kepler/Simultaneous_Release_Plan . Also note use of "plan" in the previous sentence and plans do change.
Comment 20 Denis Roy CLA 2021-04-19 13:24:06 EDT
Moved to https://github.com/eclipse-m2e/m2e-core/issues/