|
2 | 2 |
|
3 | 3 | import com.cleanroommc.groovyscript.api.GroovyLog; |
4 | 4 | import it.unimi.dsi.fastutil.objects.Object2IntLinkedOpenHashMap; |
| 5 | +import org.apache.commons.lang3.StringUtils; |
5 | 6 | import org.apache.logging.log4j.Logger; |
6 | 7 | import org.jetbrains.annotations.ApiStatus; |
7 | 8 | import org.jetbrains.annotations.NotNull; |
@@ -147,16 +148,19 @@ static Collection<File> getSortedFilesOf(File root, Collection<String> paths) { |
147 | 148 | if (!rootFile.exists()) { |
148 | 149 | continue; |
149 | 150 | } |
150 | | - int pathSize = path.split(separator).length; |
| 151 | + // if we are looking at a specific file, we don't want that to be overridden. |
| 152 | + // otherwise, we want to use the specificity based on the number of file separators. |
| 153 | + int pathSize = StringUtils.countMatches(path, separator); |
151 | 154 | try (Stream<Path> stream = Files.walk(rootFile.toPath())) { |
152 | 155 | stream.filter(path1 -> isGroovyFile(path1.toString())) |
153 | 156 | .map(Path::toFile) |
154 | 157 | //.filter(Preprocessor::validatePreprocessors) |
155 | 158 | .sorted(Comparator.comparing(File::getPath)) |
156 | 159 | .forEach(file -> { |
157 | 160 | if (files.containsKey(file)) { |
| 161 | + // if the file already exists, push the priority down if we are more specific than the already existing entry |
158 | 162 | if (pathSize > files.getInt(file)) { |
159 | | - files.put(file, pathSize); |
| 163 | + files.putAndMoveToLast(file, pathSize); |
160 | 164 | } |
161 | 165 | } else { |
162 | 166 | files.put(file, pathSize); |
|
0 commit comments