This is an automated email from the ASF dual-hosted git repository.
apupier pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new f94c88c34bf4 CAMEL-26480: camel-jbang - follow-up improvements for
deterministic file ordering
f94c88c34bf4 is described below
commit f94c88c34bf46b52da483653dcb25e6e82545b66
Author: Aurélien Pupier <[email protected]>
AuthorDate: Mon Nov 2 11:36:33 2026 +0100
CAMEL-26480: camel-jbang - follow-up improvements for deterministic file
ordering
- Explicitly compare file names as strings (Comparator.comparing(p ->
p.getFileName().toString())) in ExportHelper and RunPipeline so sorting is
case-sensitive and uniform across all platforms (Windows/Linux/macOS)
- Add filesOfADirectoryAreSorted unit test in RunDirectoryTest to lock in
directory sorting expectations
- Optimize walkResourceDir in ExportHelper by performing the sort after the
resource limit validation check
- Remove redundant sorting in Exporter.copyApplicationPropertiesFiles
Co-authored-by: IBM Bob 2.2.1
Signed-off-by: Aurélien Pupier <[email protected]>
---
.../camel/dsl/jbang/core/commands/RunDirectoryTest.java | 11 +++++++++++
.../main/java/org/apache/camel/dsl/jbang/run/RunPipeline.java | 7 ++++---
.../org/apache/camel/dsl/jbang/run/common/ExportHelper.java | 6 +++---
.../java/org/apache/camel/dsl/jbang/run/export/Exporter.java | 1 -
4 files changed, 18 insertions(+), 7 deletions(-)
diff --git
a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/RunDirectoryTest.java
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/RunDirectoryTest.java
index 9be9bc9d3974..c20eae43df40 100644
---
a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/RunDirectoryTest.java
+++
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/RunDirectoryTest.java
@@ -75,4 +75,15 @@ class RunDirectoryTest {
assertThat(files).containsExactly(dir + "/orders.camel.yaml");
}
+
+ @Test
+ void filesOfADirectoryAreSorted(@TempDir Path dir) throws Exception {
+ Files.writeString(dir.resolve("route.camel.yaml"), "- route:\n");
+ Files.writeString(dir.resolve("Greeter.java"), "class Greeter {}\n");
+ Files.writeString(dir.resolve("application.properties"), "");
+ List<String> files = new ArrayList<>();
+ RunHelper.dirToFiles(dir + "/", files);
+
+ assertThat(files).containsExactly(dir + "/Greeter.java", dir +
"/application.properties", dir + "/route.camel.yaml");
+ }
}
diff --git
a/dsl/camel-jbang/camel-jbang-run/src/main/java/org/apache/camel/dsl/jbang/run/RunPipeline.java
b/dsl/camel-jbang/camel-jbang-run/src/main/java/org/apache/camel/dsl/jbang/run/RunPipeline.java
index 5a6b16e166f5..aa756d8970cf 100644
---
a/dsl/camel-jbang/camel-jbang-run/src/main/java/org/apache/camel/dsl/jbang/run/RunPipeline.java
+++
b/dsl/camel-jbang/camel-jbang-run/src/main/java/org/apache/camel/dsl/jbang/run/RunPipeline.java
@@ -318,7 +318,8 @@ public class RunPipeline {
// silent-run then auto-detect all initial files for source-dir
Path sourceDirPath = Paths.get(sourceDir);
try (Stream<Path> paths = Files.list(sourceDirPath)) {
- paths.sorted().forEach(p ->
files.add(sourceDirPath.resolve(p.getFileName()).toString()));
+ paths.sorted(Comparator.comparing(p ->
p.getFileName().toString()))
+ .forEach(p ->
files.add(sourceDirPath.resolve(p.getFileName()).toString()));
} catch (IOException e) {
// Ignore
}
@@ -331,8 +332,8 @@ public class RunPipeline {
} else {
// silent-run then auto-detect all files
try (Stream<Path> paths = Files.list(Paths.get("."))) {
- paths.sorted()
- .map(p -> p.getFileName().toString())
+ paths.map(p -> p.getFileName().toString())
+ .sorted()
.forEach(files::add);
} catch (IOException e) {
// Ignore
diff --git
a/dsl/camel-jbang/camel-jbang-run/src/main/java/org/apache/camel/dsl/jbang/run/common/ExportHelper.java
b/dsl/camel-jbang/camel-jbang-run/src/main/java/org/apache/camel/dsl/jbang/run/common/ExportHelper.java
index 57e41ac05953..f42c63621d0a 100644
---
a/dsl/camel-jbang/camel-jbang-run/src/main/java/org/apache/camel/dsl/jbang/run/common/ExportHelper.java
+++
b/dsl/camel-jbang/camel-jbang-run/src/main/java/org/apache/camel/dsl/jbang/run/common/ExportHelper.java
@@ -75,14 +75,14 @@ public final class ExportHelper {
public static List<Path> walkResourceDir(Path dirPath) throws IOException {
try (Stream<Path> walk = Files.walk(dirPath)) {
- List<Path> files =
walk.filter(Files::isRegularFile).sorted().toList();
+ List<Path> files = walk.filter(Files::isRegularFile).toList();
if (files.size() > MAX_RESOURCE_DIR_FILES) {
throw new IllegalArgumentException(
"--resource-dirs directory contains " + files.size()
+ " files which exceeds the
limit of " + MAX_RESOURCE_DIR_FILES + ": "
+ dirPath);
}
- return files;
+ return
files.stream().sorted(Comparator.comparing(Path::toString)).toList();
}
}
@@ -101,7 +101,7 @@ public final class ExportHelper {
return false;
}
})
- .sorted()
+ .sorted(Comparator.comparing(p ->
p.getFileName().toString()))
.forEach(f -> files.add(base + f.getFileName()));
} catch (IOException e) {
// Ignore
diff --git
a/dsl/camel-jbang/camel-jbang-run/src/main/java/org/apache/camel/dsl/jbang/run/export/Exporter.java
b/dsl/camel-jbang/camel-jbang-run/src/main/java/org/apache/camel/dsl/jbang/run/export/Exporter.java
index 42b2f73b0928..6960df98d326 100644
---
a/dsl/camel-jbang/camel-jbang-run/src/main/java/org/apache/camel/dsl/jbang/run/export/Exporter.java
+++
b/dsl/camel-jbang/camel-jbang-run/src/main/java/org/apache/camel/dsl/jbang/run/export/Exporter.java
@@ -1286,7 +1286,6 @@ abstract class Exporter {
protected void copyApplicationPropertiesFiles(Path srcResourcesDir) throws
Exception {
try (Stream<Path> files = Files.list(request.baseDir)) {
files.filter(p -> Files.isRegularFile(p))
- .sorted()
.filter(p -> {
String fileName = p.getFileName().toString();
String ext = FileUtil.onlyExt(fileName);