You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2023/10/25 13:22:01 UTC

[camel] branch jbang-win created (now 0033e2b8d1b)

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

davsclaus pushed a change to branch jbang-win
in repository https://gitbox.apache.org/repos/asf/camel.git


      at 0033e2b8d1b CAMEL-20033: camel-jbang - Write to settings properties file using JDK Properties code that escapes key and value so it works on Windows.

This branch includes the following new commits:

     new 0033e2b8d1b CAMEL-20033: camel-jbang - Write to settings properties file using JDK Properties code that escapes key and value so it works on Windows.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[camel] 01/01: CAMEL-20033: camel-jbang - Write to settings properties file using JDK Properties code that escapes key and value so it works on Windows.

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch jbang-win
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 0033e2b8d1b7ecc76f360e18e6aa817d5c721bd5
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Wed Oct 25 15:21:47 2023 +0200

    CAMEL-20033: camel-jbang - Write to settings properties file using JDK Properties code that escapes key and value so it works on Windows.
---
 .../org/apache/camel/dsl/jbang/core/commands/Run.java | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Run.java b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Run.java
index 3c718fe5eca..d432e2daec1 100644
--- a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Run.java
+++ b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Run.java
@@ -26,6 +26,7 @@ import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.StringWriter;
 import java.nio.charset.StandardCharsets;
 import java.nio.file.FileSystems;
 import java.nio.file.Files;
@@ -1282,10 +1283,22 @@ public class Run extends CamelCommand {
     private void writeSettings(String key, String value) {
         FileOutputStream fos = null;
         try {
+            // use java.util.Properties to ensure the value is escaped correctly
+            Properties prop = new Properties();
+            prop.setProperty(key, value);
+            StringWriter sw = new StringWriter();
+            prop.store(sw, null);
+
             fos = new FileOutputStream(WORK_DIR + "/" + RUN_SETTINGS_FILE, true);
-            String line = key + "=" + value;
-            fos.write(line.getBytes(StandardCharsets.UTF_8));
-            fos.write(System.lineSeparator().getBytes(StandardCharsets.UTF_8));
+
+            String[] lines = sw.toString().split(System.lineSeparator());
+            for (String line : lines) {
+                // properties store timestamp as comment which we want to skip
+                if (!line.startsWith("#")) {
+                    fos.write(line.getBytes(StandardCharsets.UTF_8));
+                    fos.write(System.lineSeparator().getBytes(StandardCharsets.UTF_8));
+                }
+            }
         } catch (Exception e) {
             // ignore
         } finally {