Skip to content
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

fix(core): system-independent relative path sorting for FILES output #19726

Merged
merged 1 commit into from
Oct 3, 2024
Merged
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 @@ -31,7 +31,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 @@ -1981,7 +1981,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 @@ -1994,10 +1995,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));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

sort the relative path strings, after they've been made platform-independent in

relativePath = relativePath.replace(File.separator, "/");

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
Loading