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 a8b99c70c4fe CAMEL-25919: camel-core - setOutput with a directory 
clears the file name of a previous setOutput (#29050)
a8b99c70c4fe is described below

commit a8b99c70c4fe171e974fd36a7acce7df5cdf7c62
Author: Urmila Unni <[email protected]>
AuthorDate: Tue Nov 3 16:43:38 2026 +0530

    CAMEL-25919: camel-core - setOutput with a directory clears the file name 
of a previous setOutput (#29050)
    
    Co-authored-by: Claude <[email protected]>
---
 .../camel/impl/DefaultDumpRoutesStrategy.java      |  2 +
 .../impl/DefaultDumpRoutesStrategyOutputTest.java  | 60 ++++++++++++++++++++++
 2 files changed, 62 insertions(+)

diff --git 
a/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultDumpRoutesStrategy.java
 
b/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultDumpRoutesStrategy.java
index 2f023a1205a6..460928cd7603 100644
--- 
a/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultDumpRoutesStrategy.java
+++ 
b/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultDumpRoutesStrategy.java
@@ -149,6 +149,8 @@ public class DefaultDumpRoutesStrategy extends 
ServiceSupport implements DumpRou
                 this.output = ".";
             }
         } else {
+            // a directory starts a fresh directory output, so forget a file 
name from a previous setOutput
+            outputFileName = null;
             this.output = output;
         }
     }
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/impl/DefaultDumpRoutesStrategyOutputTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/impl/DefaultDumpRoutesStrategyOutputTest.java
new file mode 100644
index 000000000000..e3ddcc149c36
--- /dev/null
+++ 
b/core/camel-core/src/test/java/org/apache/camel/impl/DefaultDumpRoutesStrategyOutputTest.java
@@ -0,0 +1,60 @@
+/*
+ * 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.impl;
+
+import java.io.File;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.spi.DumpRoutesStrategy;
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class DefaultDumpRoutesStrategyOutputTest extends ContextTestSupport {
+
+    @Test
+    public void testDirectoryOutputAfterFileOutput() throws Exception {
+        DumpRoutesStrategy drs = 
context.getCamelContextExtension().getContextPlugin(DumpRoutesStrategy.class);
+        drs.setInclude("*");
+        drs.setLog(false);
+
+        File fileDir = testDirectory().resolve("first").toFile();
+        File folder = testDirectory().resolve("second").toFile();
+
+        // first dump to a file
+        drs.setOutput(new File(fileDir, "MyTest-test.xml").getPath());
+        drs.dumpRoutes("xml");
+
+        // then dump to a directory, which must not reuse the file name from 
the first dump
+        drs.setOutput(folder.getPath());
+        drs.dumpRoutes("xml");
+
+        assertThat(folder.list()).containsExactly("dump1.xml");
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+            @Override
+            public void configure() {
+                from("direct:start").routeId("foo")
+                        .to("mock:result");
+            }
+        };
+    }
+}

Reply via email to