|
17 | 17 |
|
18 | 18 | package org.apache.seatunnel.common.config;
|
19 | 19 |
|
20 |
| -import org.apache.seatunnel.common.utils.FileUtils; |
21 |
| - |
22 |
| -import java.nio.file.Path; |
23 | 20 | import java.util.HashMap;
|
24 | 21 | import java.util.Map;
|
25 | 22 |
|
26 | 23 | public class EnvConfigParserUtil {
|
27 | 24 |
|
28 | 25 | public static Map<String, String> parseEnvConfig() {
|
29 |
| - Path path = Common.configDir(); |
30 |
| - String os = System.getProperty("os.name").toLowerCase(); |
31 |
| - |
32 |
| - if (os.startsWith("win")) { |
33 |
| - String envScript = "seatunnel-env.cmd"; |
34 |
| - Path envScriptPath = path.resolve(envScript); |
35 |
| - if (envScriptPath.toFile().exists()) { |
36 |
| - String content = FileUtils.readFileToStr(envScriptPath); |
37 |
| - Map<String, String> config = new HashMap<>(); |
38 |
| - String[] lines = content.split("\\r?\\n"); |
39 |
| - for (String line : lines) { |
40 |
| - line = line.trim(); |
41 |
| - if (line.startsWith("if") && line.contains("set")) { |
42 |
| - int setIndex = line.indexOf("set"); |
43 |
| - if (setIndex != -1) { |
44 |
| - String assignment = line.substring(setIndex + 4).trim(); |
45 |
| - String[] keyValue = assignment.split("="); |
46 |
| - if (keyValue.length == 2) { |
47 |
| - String key = keyValue[0].replace("\"", "").trim(); |
48 |
| - String value = keyValue[1].replace("\"", "").trim(); |
49 |
| - config.put(key, value); |
50 |
| - } |
51 |
| - } |
52 |
| - } |
53 |
| - } |
54 |
| - return config; |
55 |
| - } |
56 |
| - |
57 |
| - } else { |
58 |
| - String envScript = "seatunnel-env.sh"; |
59 |
| - Path envScriptPath = path.resolve(envScript); |
60 |
| - if (envScriptPath.toFile().exists()) { |
61 |
| - String content = FileUtils.readFileToStr(envScriptPath); |
62 |
| - Map<String, String> config = new HashMap<>(); |
63 |
| - String[] lines = content.split("\\r?\\n"); |
64 |
| - for (String line : lines) { |
65 |
| - line = line.trim(); |
66 |
| - if (line.contains("=") && !line.startsWith("#")) { |
67 |
| - String[] keyValue = line.split("=", 2); |
68 |
| - if (keyValue.length == 2) { |
69 |
| - String key = keyValue[0].trim(); |
70 |
| - String value = keyValue[1].trim(); |
71 |
| - if (value.startsWith("${") && value.contains(":-")) { |
72 |
| - value = |
73 |
| - value.substring( |
74 |
| - value.indexOf(":-") + 2, value.length() - 1); |
75 |
| - } |
76 |
| - config.put(key, value); |
77 |
| - } |
78 |
| - } |
79 |
| - } |
80 |
| - return config; |
81 |
| - } |
82 |
| - } |
83 |
| - return null; |
| 26 | + return new HashMap<>(System.getenv()); |
84 | 27 | }
|
85 | 28 | }
|
0 commit comments