Skip to content

Commit

Permalink
fix(core): relative path sorting (#19726)
Browse files Browse the repository at this point in the history
  • Loading branch information
joscha authored Oct 3, 2024
1 parent 2111713 commit 0371799
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import io.swagger.v3.oas.models.tags.Tag;
import lombok.Getter;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.comparator.PathFileComparator;
import org.apache.commons.io.IOCase;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.openapitools.codegen.api.TemplateDefinition;
Expand Down Expand Up @@ -1988,7 +1988,8 @@ private void generateFilesMetadata(List<File> files) {
// NOTE: Don't use File.separator here as we write linux-style paths to FILES, and File.separator will
// result in incorrect match on Windows machines.
String relativeMeta = METADATA_DIR + "/VERSION";
filesToSort.sort(PathFileComparator.PATH_COMPARATOR);

final List<String> relativePaths = new ArrayList<>(filesToSort.size());
filesToSort.forEach(f -> {
// some Java implementations don't honor .relativize documentation fully.
// When outDir is /a/b and the input is /a/b/c/d, the result should be c/d.
Expand All @@ -2001,10 +2002,15 @@ private void generateFilesMetadata(List<File> files) {
relativePath = relativePath.replace(File.separator, "/");
}
if (!relativePath.equals(relativeMeta)) {
sb.append(relativePath).append(System.lineSeparator());
relativePaths.add(relativePath);
}
});

Collections.sort(relativePaths, (a, b) -> IOCase.SENSITIVE.checkCompareTo(a,b));
relativePaths.forEach(relativePath -> {
sb.append(relativePath).append(System.lineSeparator());
});

String targetFile = config.outputFolder() + File.separator + METADATA_DIR + File.separator + config.getFilesMetadataFilename();

File filesFile = this.templateProcessor.writeToFile(targetFile, sb.toString().getBytes(StandardCharsets.UTF_8));
Expand Down

0 comments on commit 0371799

Please sign in to comment.