Skip to content

Improve DeltaList behavior for large projects #335

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: maven-compiler-plugin-3.x
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1840,19 +1840,19 @@ private boolean hasInputFileTreeChanged(IncrementalBuildHelper ibh, Set<File> in
}
Path mojoConfigFile = mojoConfigBase.resolve(INPUT_FILES_LST_FILENAME);

List<String> oldInputFiles = Collections.emptyList();
Set<String> oldInputFiles = Collections.emptySet();
if (Files.isRegularFile(mojoConfigFile)) {
try {
oldInputFiles = Files.readAllLines(mojoConfigFile);
oldInputFiles = new HashSet<>(Files.readAllLines(mojoConfigFile));
} catch (IOException e) {
// we cannot read the mojo config file, so don't do anything beside logging
getLog().warn("Error while reading old mojo status: " + mojoConfigFile);
return false;
}
}

List<String> newInputFiles =
inputFiles.stream().sorted().map(File::getAbsolutePath).collect(Collectors.toList());
Set<String> newInputFiles =
inputFiles.stream().map(File::getAbsolutePath).collect(Collectors.toCollection(HashSet::new));

try {
Files.write(mojoConfigFile, newInputFiles);
Expand All @@ -1864,10 +1864,13 @@ private boolean hasInputFileTreeChanged(IncrementalBuildHelper ibh, Set<File> in

DeltaList<String> inputTreeChanges = new DeltaList<>(oldInputFiles, newInputFiles);
if (getLog().isDebugEnabled() || showCompilationChanges) {
for (String fileAdded : inputTreeChanges.getAdded()) {
// we only sort the output when pushed to the user
for (String fileAdded :
inputTreeChanges.getAdded().stream().sorted().collect(Collectors.toList())) {
getLog().info("\tInput tree files (+): " + fileAdded);
}
for (String fileRemoved : inputTreeChanges.getRemoved()) {
for (String fileRemoved :
inputTreeChanges.getRemoved().stream().sorted().collect(Collectors.toList())) {
getLog().info("\tInput tree files (-): " + fileRemoved);
}
}
Expand Down
8 changes: 3 additions & 5 deletions src/main/java/org/apache/maven/plugin/compiler/DeltaList.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
*/
package org.apache.maven.plugin.compiler;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
* Show the modifications between two lists.
Expand All @@ -33,10 +33,8 @@ final class DeltaList<E> {
private final boolean hasChanged;

DeltaList(Collection<E> oldList, Collection<E> newList) {
this.added = new ArrayList<>(newList);
this.removed = new ArrayList<>(oldList);
added.removeAll(oldList);
removed.removeAll(newList);
this.added = newList.stream().filter(i -> !oldList.contains(i)).collect(Collectors.toList());
this.removed = oldList.stream().filter(i -> !newList.contains(i)).collect(Collectors.toList());
Comment on lines +36 to +37
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea is to use HashSets and avoid copying then removing a lot of elements.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could it be better to use the old for loop instead of streams?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could sure.

this.hasChanged = !added.isEmpty() || !removed.isEmpty();
}

Expand Down