Skip to content

Commit

Permalink
Fix file sorting when previously matched (#261)
Browse files Browse the repository at this point in the history
* use StringUtils match instead of split length

* putAndMoveToLast and comment
  • Loading branch information
WaitingIdly authored Nov 8, 2024
1 parent 668102b commit c3d8582
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.cleanroommc.groovyscript.api.GroovyLog;
import it.unimi.dsi.fastutil.objects.Object2IntLinkedOpenHashMap;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.Logger;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -147,16 +148,19 @@ static Collection<File> getSortedFilesOf(File root, Collection<String> paths) {
if (!rootFile.exists()) {
continue;
}
int pathSize = path.split(separator).length;
// if we are looking at a specific file, we don't want that to be overridden.
// otherwise, we want to use the specificity based on the number of file separators.
int pathSize = StringUtils.countMatches(path, separator);
try (Stream<Path> stream = Files.walk(rootFile.toPath())) {
stream.filter(path1 -> isGroovyFile(path1.toString()))
.map(Path::toFile)
//.filter(Preprocessor::validatePreprocessors)
.sorted(Comparator.comparing(File::getPath))
.forEach(file -> {
if (files.containsKey(file)) {
// if the file already exists, push the priority down if we are more specific than the already existing entry
if (pathSize > files.getInt(file)) {
files.put(file, pathSize);
files.putAndMoveToLast(file, pathSize);
}
} else {
files.put(file, pathSize);
Expand Down

0 comments on commit c3d8582

Please sign in to comment.