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/11/09 11:23:23 UTC
(camel) 02/02: CAMEL-20033: camel-jbang - Write to settings properties file using JDK Properties code that escapes key and value so it works on Windows.
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch jb-agent
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 8fa9ce25667f2cbe9b26fbb345f4cba7f5ba8bf9
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Nov 9 12:19:54 2023 +0100
CAMEL-20033: camel-jbang - Write to settings properties file using JDK Properties code that escapes key and value so it works on Windows.
---
.../camel/dsl/jbang/core/common/RuntimeUtil.java | 22 ++++++++++++++--------
1 file changed, 14 insertions(+), 8 deletions(-)
diff --git a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/RuntimeUtil.java b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/RuntimeUtil.java
index 97d985590b6..834acfb682e 100644
--- a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/RuntimeUtil.java
+++ b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/RuntimeUtil.java
@@ -19,6 +19,8 @@ package org.apache.camel.dsl.jbang.core.common;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
+import java.io.StringReader;
+import java.nio.file.Files;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
@@ -99,17 +101,21 @@ public final class RuntimeUtil {
}
public static List<String> loadPropertiesLines(File file) throws IOException {
- List<String> lines = new ArrayList<>();
if (!file.exists()) {
- return lines;
+ return new ArrayList<>();
}
- Properties prop = new OrderedProperties();
- loadProperties(prop, file);
- for (String k : prop.stringPropertyNames()) {
- String v = prop.getProperty(k);
- if (v != null) {
- lines.add(k + "=" + v);
+ List<String> lines = new ArrayList<>();
+ for (String line : Files.readAllLines(file.toPath())) {
+ // need to use java.util.Properties to read raw value and un-escape
+ Properties prop = new OrderedProperties();
+ prop.load(new StringReader(line));
+
+ for (String key : prop.stringPropertyNames()) {
+ String value = prop.getProperty(key);
+ if (value != null) {
+ lines.add(key + "=" + value);
+ }
}
}
return lines;