davsclaus commented on code in PR #27818:
URL: https://github.com/apache/camel/pull/27818#discussion_r4269066879
##########
dsl/camel-jbang/camel-jbang-plugin-validate/src/main/java/org/apache/camel/dsl/jbang/core/commands/validate/YamlNormalizeCommand.java:
##########
@@ -171,6 +237,104 @@ protected void doAddInitialProperty(KameletMain main) {
return 0;
}
+ /**
+ * Warns when the top-level onException, errorHandler, onCompletion or
intercept of an input file ends up applying
+ * to the routes of the other input files, as the routes of all the files
are written together.
+ */
+ private void warnIfScopeWidens(Map<String, String> perFile) {
+ Set<String> withRoutes = new LinkedHashSet<>();
+ for (Map.Entry<String, String> e : perFile.entrySet()) {
+ if (!topLevel(e.getValue(), Set.of("route")).isEmpty()) {
+ withRoutes.add(e.getKey());
+ }
+ }
+ for (Map.Entry<String, String> e : perFile.entrySet()) {
+ Set<String> kinds = topLevel(e.getValue(), SCOPED);
+ Set<String> others = new LinkedHashSet<>(withRoutes);
+ others.remove(e.getKey());
+ if (!kinds.isEmpty() && !others.isEmpty()) {
+ printer().println("WARN: the top-level " + String.join(", ",
kinds) + " of " + e.getKey()
Review Comment:
Without `--output` this lands on stdout in front of the normalized YAML, so
`... > merged.yaml` produces a file that does not start with YAML. Please send
it to stderr (`printErr` prefixes `ERROR:`, so `System.err` or a `#` comment
may read better).
##########
docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_23.adoc:
##########
@@ -3016,6 +3016,18 @@ a parse error. The command now catches the exception per
file, prints
non-zero when at least one file failed. Files that convert successfully are
still written to the
output directory.
+==== camel validate normalize writes one file per input file to an output
directory
Review Comment:
4.23.0 is released, so this belongs in `camel-4x-upgrade-guide-4_24.adoc`.
Please also mention the single-input case: `--output=out/` with one file now
writes `out/<name>.yaml` instead of `out/normalized.yaml`.
##########
dsl/camel-jbang/camel-jbang-plugin-validate/src/main/java/org/apache/camel/dsl/jbang/core/commands/validate/YamlNormalizeCommand.java:
##########
@@ -141,27 +177,57 @@ protected void doAddInitialProperty(KameletMain main) {
}
String routes = KameletNormalizer.withoutTemplates(normalized,
kameletIds);
+ // what was dumped for each input file that is not a Kamelet
+ Map<String, String> perFile = new LinkedHashMap<>();
+ for (String n : matched) {
+ if (!kamelets.containsKey(n)) {
+ String text =
readFile(perFileDir.resolve(names.get(sourcePath(n))).toString());
+ if (text != null) {
+ perFile.put(n, KameletNormalizer.withoutTemplates(text,
kameletIds));
+ }
+ }
+ }
+
+ Path outPath = output != null ? Path.of(output) : null;
+ if (outPath != null && (output.endsWith("/") ||
output.endsWith(File.separator))) {
+ Files.createDirectories(outPath);
+ }
+ if (outPath != null && Files.isDirectory(outPath)) {
+ for (Map.Entry<String, String> e : perFile.entrySet()) {
+ if (!e.getValue().isBlank()) {
+
Files.writeString(outPath.resolve(names.get(sourcePath(e.getKey()))),
e.getValue());
Review Comment:
When `--output` is the directory the inputs live in, this overwrites the
source files with the normalized dump. The dump drops a top-level
`errorHandler`/`intercept` (as the PR description notes), plus comments, so
content can be lost. Please refuse when `outPath.resolve(name)` equals one of
the input paths, or make in-place rewriting an explicit option, and add a test.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]