Skip to content

Commit

Permalink
Workaround for "m2e plugin sometimes 'loses' resources"
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,
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)

See #1511
See #1275
  • Loading branch information
kohlschuetter committed Dec 22, 2023
1 parent 2332602 commit 2ae34a5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion org.eclipse.m2e.core/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %Bundle-Name
Bundle-SymbolicName: org.eclipse.m2e.core;singleton:=true
Bundle-Version: 2.4.1.qualifier
Bundle-Version: 2.4.2.qualifier
Bundle-Activator: org.eclipse.m2e.core.internal.MavenPluginActivator
Bundle-Vendor: %Bundle-Vendor
Bundle-Localization: plugin
Expand Down
2 changes: 1 addition & 1 deletion org.eclipse.m2e.core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
</parent>

<artifactId>org.eclipse.m2e.core</artifactId>
<version>2.4.1-SNAPSHOT</version>
<version>2.4.2-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>

<name>Maven Integration for Eclipse Core Plug-in</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Predicate;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -209,6 +210,11 @@ private boolean hasRelevantDelta(IMavenProjectFacade projectFacade, IResourceDel
if(project == null || buildOutputLocation == null) {
return true;
}

Predicate<IPath> isOutput = toPrefixPredicate(projectFacade.getOutputLocation());
Predicate<IPath> isTestOutput = toPrefixPredicate(projectFacade.getTestOutputLocation());
Predicate<IPath> isOutputOrTestOutput = isOutput.or(isTestOutput);

IPath projectPath = project.getFullPath();
List<IPath> moduleLocations = projectFacade.getMavenProjectModules().stream()
.map(module -> projectPath.append(module)).toList();
Expand All @@ -219,7 +225,11 @@ 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(isOutputOrTestOutput.test(fullPath) && !resource.exists()) {
hasRelevantDelta.set(true);
return false;
}
return true;
}
for(IPath modulePath : moduleLocations) {
Expand All @@ -237,6 +247,13 @@ private boolean hasRelevantDelta(IMavenProjectFacade projectFacade, IResourceDel
return hasRelevantDelta.get();
}

private static Predicate<IPath> toPrefixPredicate(IPath location) {
if(location == null) {
return (p) -> false;
}
return (p) -> location.isPrefixOf(p);
}

private List<IIncrementalBuildFramework.BuildContext> setupProjectBuildContext(IProject project, int kind,
IResourceDelta delta, IIncrementalBuildFramework.BuildResultCollector results, ProjectBuildState buildState)
throws CoreException {
Expand Down

0 comments on commit 2ae34a5

Please sign in to comment.