Bug 514914 - "Source not found." when debugging Maven dependencies in workspace
Summary: "Source not found." when debugging Maven dependencies in workspace
Status: REOPENED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Debug (show other bugs)
Version: 4.7   Edit
Hardware: All All
: P3 normal with 4 votes (vote)
Target Milestone: ---   Edit
Assignee: JDT-Debug-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2017-04-07 04:57 EDT by Claus Schrammel CLA
Modified: 2023-10-11 18:40 EDT (History)
3 users (show)

See Also:


Attachments
eclipse.jdt.debug.patch - The patch (9.52 KB, patch)
2017-04-07 04:57 EDT, Claus Schrammel CLA
no flags Details | Diff
The projects to reproduce the problem (115.36 KB, application/x-zip-compressed)
2017-04-07 04:58 EDT, Claus Schrammel CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Claus Schrammel CLA 2017-04-07 04:57:55 EDT
Created attachment 267692 [details]
eclipse.jdt.debug.patch - The patch

The Problem
-----------

The problem occurs when debugging a Maven web application with Eclipse Jetty Integration plugin. Then the sources of Maven dependencies that are open projects in the Eclipse workspace cannot be found. The problem also occurs for my own custom launch configuration; basically any launch configuration other than Java, JUnit or TestNG.


Reproducibility
---------------

The attached projects.zip contains 4 projects: twice a web application project and a dependency; one time as standard Eclipse projects and another time as Maven projects. One can import the projects into an Eclipse workspace, define a break point in the "Dep" classes in the eclipse-dep and maven-dep projects, launch the given Eclipse Jetty Integration launch configurations with "Debug As" and load http://localhost:8080 with a browser of choice.

The standard Eclipse project properly halts in Dep.java, showing the source code. The Maven project does not find the source code of Dep.java.


Maven Source Lookup
-------------------

The Maven Source Lookup does work for Java launch configurations, JUnit and TestNG tests. This works because m2e hooks into launch configuration creation and adds CLASSPATH_PROVIDER and SOURCE_PATH_PROVIDER to these types of launch configurations. It would be nice if this worked for any launch configuration, or at least when added manually. I reported that as a bug already (https://bugs.eclipse.org/bugs/show_bug.cgi?id=501099) but there is no progress there.

Anyway, since I think, neither m2e should know about Jetty, nor Eclipse Jetty Integration whether it is a Maven project, the problem should be solved here.


The Bug
-------

The bug is located in StandardSourcePathProvider. The Maven container (MavenClasspathContainer) is resolved with JavaRuntime.resolveRuntimeClasspathEntry(...), which produces a runtime classpath (output locations) instead of a source lookup path (project references).


The Patch
---------

Attached you can find a patch for the problem: eclipse.jdt.debug.patch

The patch adds methods resolveSourceLookupClasspathEntry(...) to JavaRuntime and changes the calls in StandardSourcePathProvider.

I had different ideas for the patch. I finally decided for that one, because it does a lot of copy&paste, which makes it sort of obvious what is going on: do twice the same with some small differences. The other solutions were not elegant either. Finally, this was the only way not breaking the contract of JavaRuntime.resolveRuntimeClasspathEntry(...):

	 * ... If the entry is of kind <code>PROJECT</code>,
	 * and the associated Java project specifies non-default output locations,
	 * the corresponding output locations are returned. Otherwise, the given
	 * entry is returned.

I found it quite confusing, that some projects get expanded to the output locations here and others have to be expanded later (in AbstractJavaLaunchConfigurationDelegate). Maybe it would be a good idea to refactor JavaRuntime, but that is a different story. We can talk about this, if somebody is interested.
Comment 1 Claus Schrammel CLA 2017-04-07 04:58:40 EDT
Created attachment 267693 [details]
The projects to reproduce the problem
Comment 2 Andrey Loskutov CLA 2017-04-07 05:05:25 EDT
Claus, thanks for the report and patch. Can you please create a gerrit change with your patch? See https://projects.eclipse.org/projects/eclipse.jdt.debug/developer.
Comment 3 Sarika Sinha CLA 2017-04-07 06:09:45 EDT
Also, can you specify the plugins which should be installed to test this on Eclipse SDK ?
Comment 4 Claus Schrammel CLA 2017-04-07 15:44:32 EDT
Sarika,

you'll need m2e and Eclipse Jetty Integration plugins for testing this bug. m2e should already be included in Eclipse SDK.

*Expert Mode:*

You do not even need the Eclipse Jetty Integration plugin. The *-war projects contain a "launch" directory with prepared launch configurations. Since the example servlets also contain a main method, there are standard Java launch configurations.

maven-war-java.launch contains the CLASSPATH_PROVIDER and SOURCE_PATH_PROVIDER (added by m2e) as stated in the bug description. The source lookup will work.

maven-war-java-without-classpath-provider.launch does not contain these providers. I removed them. Therefore the same StandardSourcePathProvider will be used as with the Eclipse Jetty Integration launch configuration. The source lookup will fail.

Unfortunately, when importing the projects into Eclipse, the CLASSPATH_PROVIDER and SOURCE_PATH_PROVIDER are added to the maven-war-java-without-classpath-provider.launch. You will have to remove them again after the import.

Sorry for that. I wish it would be different. Hence, expert mode.

But if you do this way, you can spare the Eclipse Jetty Integration plugin and the browser for testing. This is much quicker.
Comment 5 Eclipse Genie CLA 2017-04-07 16:40:17 EDT
New Gerrit change created: https://git.eclipse.org/r/94702
Comment 6 Eclipse Genie CLA 2020-03-01 17:44:39 EST
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. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. 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 7 Sarika Sinha CLA 2020-03-02 03:38:37 EST
Gerrit is pending review, if someone can help!
Comment 8 Wjatscheslaw Talanow CLA 2021-10-19 04:23:52 EDT
I'd like to vote for this topic as well. We are using eclipse with git/maven for software development in our company and are facing major issues when debugging applications.

Imagine working on the next version of an application while having to maintain a couple of previous releases. In this scenario, we are switching between tags/branches back and forth using the same eclipse workspace (that's where git-integration really shines).

When debugging an application up to its dependencies (we have the sources for these), developers are forced to specify the matching source archives in their launch configurations manually. Now, switching to another tag/branch requires the launch configurations to be adjusted. When having a great number of dependencies, this becomes really cumbersome and error prone. Failing to adjust the launch configuration results in the binaries not matching the specified source code (although the source code fetched from the maven repository is correct), thus confusing developers even further.

The feature introduced with this topic would greatly increase productivity and improve debugging. Is there any chance to include it in the next eclipse release?
Comment 9 Eclipse Genie CLA 2023-10-11 18:40:04 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.