Skip to content

Commit

Permalink
Fix "m2e plugin sometimes 'loses' resources" (eclipse-m2e#1511)
Browse files Browse the repository at this point in the history
The Java Builder may delete files from the project output directory that
need to be re-created by the m2e Maven Builder.

With commit 8e5cd49 (a fix for eclipse-m2e#1275),
any changes to the project output directory were ignored, leading to
unexpected errors when running an application after modifying the
project POM: resources were missing from the target classpath, leading
all sorts of unexpected program behavior.

This change allows marking these changes as relevant, as long as the
following conditions are met:

- The expected resource no longer exists (i.e., it was deleted by
  another builder, plugin or outside process)
- The modification applies to a resource in the classes or test-classes
  folder (i.e., outputLocation/testOutputLocation)

eclipse-m2e#1511
eclipse-m2e#1275
  • Loading branch information
kohlschuetter committed Dec 20, 2023
1 parent 2332602 commit 70a58f7
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@ private boolean hasRelevantDelta(IMavenProjectFacade projectFacade, IResourceDel
if(project == null || buildOutputLocation == null) {
return true;
}

IPath outputLocation = projectFacade.getOutputLocation();
IPath testOutputLocation = projectFacade.getTestOutputLocation();

IPath projectPath = project.getFullPath();
List<IPath> moduleLocations = projectFacade.getMavenProjectModules().stream()
.map(module -> projectPath.append(module)).toList();
Expand All @@ -219,7 +223,12 @@ private boolean hasRelevantDelta(IMavenProjectFacade projectFacade, IResourceDel
IPath fullPath = delta.getFullPath();
if(buildOutputLocation.isPrefixOf(fullPath)) {
//anything in the build output is not interesting for a change as it is produced by the build
//lets see if there are more interesting parts...
// ... unless a classpath resource that existed before has been deleted, possibly by another builder
if(!resource.exists() && ((outputLocation != null && outputLocation.isPrefixOf(fullPath))
|| (testOutputLocation != null && testOutputLocation.isPrefixOf(fullPath)))) {
hasRelevantDelta.set(true);
return false;
}
return true;
}
for(IPath modulePath : moduleLocations) {
Expand Down

0 comments on commit 70a58f7

Please sign in to comment.