This is an automated email from the ASF dual-hosted git repository.

davsclaus 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 43a888d8d6f7 CAMEL-27390: camel-package-maven-plugin - do not split 
the ModelWriter source with the platform line separator (#30605)
43a888d8d6f7 is described below

commit 43a888d8d6f73a5cce30f0d036661d6bb3f28064
Author: Saravanakumar Selvaraj <[email protected]>
AuthorDate: Sun Nov 22 18:07:51 2026 +0000

    CAMEL-27390: camel-package-maven-plugin - do not split the ModelWriter 
source with the platform line separator (#30605)
    
    ModelWriterGeneratorMojo.postGenerateWriter moves the onFallback line of 
the circuit breaker below the outputs. It
    split the generated source with System.lineSeparator(). The source has the 
line ends of the template, which are LF.
    So on Windows the method found one line and moved nothing. A build there 
wrote onFallback before the outputs, and a
    final newline, into ModelWriter.java of camel-xml-io.
    
    The method now splits at LF or CRLF and joins with LF. The generated source 
is then the same on every platform.
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
 .../maven/packaging/ModelWriterGeneratorMojo.java  |  6 ++-
 .../packaging/ModelWriterGeneratorMojoTest.java    | 52 ++++++++++++++++++++++
 2 files changed, 56 insertions(+), 2 deletions(-)

diff --git 
a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/ModelWriterGeneratorMojo.java
 
b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/ModelWriterGeneratorMojo.java
index d73750f0a326..eebf43141502 100644
--- 
a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/ModelWriterGeneratorMojo.java
+++ 
b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/ModelWriterGeneratorMojo.java
@@ -183,7 +183,9 @@ public abstract class ModelWriterGeneratorMojo extends 
AbstractGeneratorMojo {
         // the velocity templates are ugly to maintain so lets hack here to 
control the order in circuit-breaker
         // we want onFallback to be after outputs, but because the writer is 
hard-coded to not be able to generate code
         // that respect this order, then we swap the lines after the source 
code is generated
-        String[] lines = writer.split(System.lineSeparator());
+        // the source has the line ends of the velocity template (LF, or CRLF 
in a working tree with CRLF line ends),
+        // which can differ from the line separator of the platform, so split 
at LF or CRLF and join with LF
+        String[] lines = writer.split("\r?\n");
         int pos = -1;
         for (int i = 0; i < lines.length; i++) {
             String s = lines[i].trim();
@@ -199,7 +201,7 @@ public abstract class ModelWriterGeneratorMojo extends 
AbstractGeneratorMojo {
             lines[pos] = next;
             lines[pos + 1] = prev;
         }
-        return String.join(System.lineSeparator(), lines);
+        return String.join("\n", lines);
     }
 
     protected Class<?> loadClass(ClassLoader loader, String name) {
diff --git 
a/tooling/maven/camel-package-maven-plugin/src/test/java/org/apache/camel/maven/packaging/ModelWriterGeneratorMojoTest.java
 
b/tooling/maven/camel-package-maven-plugin/src/test/java/org/apache/camel/maven/packaging/ModelWriterGeneratorMojoTest.java
new file mode 100644
index 000000000000..4173975d3fd6
--- /dev/null
+++ 
b/tooling/maven/camel-package-maven-plugin/src/test/java/org/apache/camel/maven/packaging/ModelWriterGeneratorMojoTest.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.maven.packaging;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+/**
+ * Tests that {@link ModelWriterGeneratorMojo#postGenerateWriter(String)} 
moves the onFallback line below the outputs
+ * line, with LF or CRLF line ends (CAMEL-27390).
+ */
+class ModelWriterGeneratorMojoTest {
+
+    private static final String BEFORE = "        startElement(name);";
+    private static final String ON_FALLBACK
+            = "        doWriteElement(\"onFallback\", def.getOnFallback(), 
this::doWriteOnFallbackDefinition);";
+    private static final String OUTPUTS
+            = "        doWriteList(null, null, def.getOutputs(), 
this::doWriteProcessorDefinitionRef);";
+    private static final String AFTER = "        endElement(name);";
+    private static final String EXPECTED = String.join("\n", BEFORE, OUTPUTS, 
ON_FALLBACK, AFTER);
+
+    private final XmlModelWriterGeneratorMojo mojo = new 
XmlModelWriterGeneratorMojo(null, null);
+
+    @Test
+    void postGenerateWriter_movesOnFallbackBelowOutputsWithLfLineEnds() {
+        assertEquals(EXPECTED, mojo.postGenerateWriter(source("\n")));
+    }
+
+    @Test
+    void postGenerateWriter_givesTheSameResultWithCrLfLineEnds() {
+        assertEquals(EXPECTED, mojo.postGenerateWriter(source("\r\n")));
+    }
+
+    private static String source(String lineEnd) {
+        return BEFORE + lineEnd + ON_FALLBACK + lineEnd + OUTPUTS + lineEnd + 
AFTER + lineEnd;
+    }
+}

Reply via email to