Skip to content

Commit 2ae34a5

Browse files
Workaround for "m2e plugin sometimes 'loses' resources"
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
1 parent 2332602 commit 2ae34a5

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

org.eclipse.m2e.core/META-INF/MANIFEST.MF

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
22
Bundle-ManifestVersion: 2
33
Bundle-Name: %Bundle-Name
44
Bundle-SymbolicName: org.eclipse.m2e.core;singleton:=true
5-
Bundle-Version: 2.4.1.qualifier
5+
Bundle-Version: 2.4.2.qualifier
66
Bundle-Activator: org.eclipse.m2e.core.internal.MavenPluginActivator
77
Bundle-Vendor: %Bundle-Vendor
88
Bundle-Localization: plugin

org.eclipse.m2e.core/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
</parent>
2020

2121
<artifactId>org.eclipse.m2e.core</artifactId>
22-
<version>2.4.1-SNAPSHOT</version>
22+
<version>2.4.2-SNAPSHOT</version>
2323
<packaging>eclipse-plugin</packaging>
2424

2525
<name>Maven Integration for Eclipse Core Plug-in</name>

org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/builder/MavenBuilderImpl.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import java.util.Set;
3030
import java.util.concurrent.ConcurrentHashMap;
3131
import java.util.concurrent.atomic.AtomicBoolean;
32+
import java.util.function.Predicate;
3233

3334
import org.slf4j.Logger;
3435
import org.slf4j.LoggerFactory;
@@ -209,6 +210,11 @@ private boolean hasRelevantDelta(IMavenProjectFacade projectFacade, IResourceDel
209210
if(project == null || buildOutputLocation == null) {
210211
return true;
211212
}
213+
214+
Predicate<IPath> isOutput = toPrefixPredicate(projectFacade.getOutputLocation());
215+
Predicate<IPath> isTestOutput = toPrefixPredicate(projectFacade.getTestOutputLocation());
216+
Predicate<IPath> isOutputOrTestOutput = isOutput.or(isTestOutput);
217+
212218
IPath projectPath = project.getFullPath();
213219
List<IPath> moduleLocations = projectFacade.getMavenProjectModules().stream()
214220
.map(module -> projectPath.append(module)).toList();
@@ -219,7 +225,11 @@ private boolean hasRelevantDelta(IMavenProjectFacade projectFacade, IResourceDel
219225
IPath fullPath = delta.getFullPath();
220226
if(buildOutputLocation.isPrefixOf(fullPath)) {
221227
//anything in the build output is not interesting for a change as it is produced by the build
222-
//lets see if there are more interesting parts...
228+
// ... unless a classpath resource that existed before has been deleted, possibly by another builder
229+
if(isOutputOrTestOutput.test(fullPath) && !resource.exists()) {
230+
hasRelevantDelta.set(true);
231+
return false;
232+
}
223233
return true;
224234
}
225235
for(IPath modulePath : moduleLocations) {
@@ -237,6 +247,13 @@ private boolean hasRelevantDelta(IMavenProjectFacade projectFacade, IResourceDel
237247
return hasRelevantDelta.get();
238248
}
239249

250+
private static Predicate<IPath> toPrefixPredicate(IPath location) {
251+
if(location == null) {
252+
return (p) -> false;
253+
}
254+
return (p) -> location.isPrefixOf(p);
255+
}
256+
240257
private List<IIncrementalBuildFramework.BuildContext> setupProjectBuildContext(IProject project, int kind,
241258
IResourceDelta delta, IIncrementalBuildFramework.BuildResultCollector results, ProjectBuildState buildState)
242259
throws CoreException {

0 commit comments

Comments
 (0)