Skip to content

Commit 9a51d6d

Browse files
committed
Make if-check shorter/easier to read (eclipse-m2e#1511)
... addressing reviewer concerns
1 parent 70a58f7 commit 9a51d6d

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

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

+12-4
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;
@@ -210,8 +211,9 @@ private boolean hasRelevantDelta(IMavenProjectFacade projectFacade, IResourceDel
210211
return true;
211212
}
212213

213-
IPath outputLocation = projectFacade.getOutputLocation();
214-
IPath testOutputLocation = projectFacade.getTestOutputLocation();
214+
Predicate<IPath> isOutput = toPrefixPredicate(projectFacade.getOutputLocation());
215+
Predicate<IPath> isTestOutput = toPrefixPredicate(projectFacade.getTestOutputLocation());
216+
Predicate<IPath> isOutputOrTestOutput = isOutput.or(isTestOutput);
215217

216218
IPath projectPath = project.getFullPath();
217219
List<IPath> moduleLocations = projectFacade.getMavenProjectModules().stream()
@@ -224,8 +226,7 @@ private boolean hasRelevantDelta(IMavenProjectFacade projectFacade, IResourceDel
224226
if(buildOutputLocation.isPrefixOf(fullPath)) {
225227
//anything in the build output is not interesting for a change as it is produced by the build
226228
// ... unless a classpath resource that existed before has been deleted, possibly by another builder
227-
if(!resource.exists() && ((outputLocation != null && outputLocation.isPrefixOf(fullPath))
228-
|| (testOutputLocation != null && testOutputLocation.isPrefixOf(fullPath)))) {
229+
if(!resource.exists() && isOutputOrTestOutput.test(fullPath)) {
229230
hasRelevantDelta.set(true);
230231
return false;
231232
}
@@ -246,6 +247,13 @@ private boolean hasRelevantDelta(IMavenProjectFacade projectFacade, IResourceDel
246247
return hasRelevantDelta.get();
247248
}
248249

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+
249257
private List<IIncrementalBuildFramework.BuildContext> setupProjectBuildContext(IProject project, int kind,
250258
IResourceDelta delta, IIncrementalBuildFramework.BuildResultCollector results, ProjectBuildState buildState)
251259
throws CoreException {

0 commit comments

Comments
 (0)