Croway commented on code in PR #27818:
URL: https://github.com/apache/camel/pull/27818#discussion_r4269326450


##########
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:
   Moved to `camel-4x-upgrade-guide-4_24.adoc` (b5049f0dbfce), and the entry 
now says that `--output=out/` with a single input 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:
##########
@@ -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:
   The warning goes to stderr now, without the `ERROR:` prefix, so stdout 
carries only the YAML; `theConsoleOutputWarnsToo` checks the stdout part is 
valid YAML and the WARN is on stderr.



##########
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:
   The command now refuses, with a clear error and exit code 1, when any file 
it would write (per-file name, `normalized*.yaml`, or the single `--output` 
file) is one of the input files; no in-place option; 
`theInputFilesAreNotOverwritten` covers `--output=<dir of the inputs>` and 
`--output=<an input file>`.



-- 
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]

Reply via email to