Skip to content

Commit afee101

Browse files
committed
1
1 parent 7800116 commit afee101

File tree

5 files changed

+10
-142
lines changed

5 files changed

+10
-142
lines changed

seatunnel-common/pom.xml

+6
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@
7474
<groupId>commons-codec</groupId>
7575
<artifactId>commons-codec</artifactId>
7676
</dependency>
77+
<dependency>
78+
<groupId>org.junit-pioneer</groupId>
79+
<artifactId>junit-pioneer</artifactId>
80+
<version>1.9.1</version>
81+
<scope>test</scope>
82+
</dependency>
7783
</dependencies>
7884

7985
</project>

seatunnel-common/src/main/java/org/apache/seatunnel/common/config/EnvConfigParserUtil.java

+1-58
Original file line numberDiff line numberDiff line change
@@ -17,69 +17,12 @@
1717

1818
package org.apache.seatunnel.common.config;
1919

20-
import org.apache.seatunnel.common.utils.FileUtils;
21-
22-
import java.nio.file.Path;
2320
import java.util.HashMap;
2421
import java.util.Map;
2522

2623
public class EnvConfigParserUtil {
2724

2825
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());
8427
}
8528
}

seatunnel-common/src/test/java/org/apache/seatunnel/common/config/EnvConfigParserUtilTest.java

+3-41
Original file line numberDiff line numberDiff line change
@@ -17,56 +17,18 @@
1717

1818
package org.apache.seatunnel.common.config;
1919

20-
import org.junit.jupiter.api.AfterEach;
2120
import org.junit.jupiter.api.Assertions;
22-
import org.junit.jupiter.api.BeforeEach;
2321
import org.junit.jupiter.api.Test;
22+
import org.junitpioneer.jupiter.SetEnvironmentVariable;
2423

25-
import java.net.URISyntaxException;
26-
import java.nio.file.Paths;
2724
import java.util.Map;
2825

2926
public class EnvConfigParserUtilTest {
3027

31-
private String originSeatunnelHome = null;
32-
private DeployMode originMode = null;
33-
private static final String seatunnelHome;
34-
35-
static {
36-
try {
37-
seatunnelHome =
38-
Paths.get(EnvConfigParserUtilTest.class.getResource("/home").toURI())
39-
.toString();
40-
} catch (URISyntaxException e) {
41-
throw new RuntimeException("Failed to get seatunnelHome path", e);
42-
}
43-
}
44-
45-
@BeforeEach
46-
public void before() {
47-
originMode = Common.getDeployMode();
48-
Common.setDeployMode(DeployMode.CLIENT);
49-
originSeatunnelHome = Common.getSeaTunnelHome();
50-
Common.setSeaTunnelHome(seatunnelHome);
51-
}
52-
5328
@Test
29+
@SetEnvironmentVariable(key = "A", value = "B")
5430
public void testParseEnvConfig() {
5531
Map<String, String> envMap = EnvConfigParserUtil.parseEnvConfig();
56-
Assertions.assertEquals(2, envMap.size());
57-
String os = System.getProperty("os.name").toLowerCase();
58-
if (os.startsWith("win")) {
59-
Assertions.assertEquals("C:\\Program Files\\spark", envMap.get("SPARK_HOME"));
60-
Assertions.assertEquals("C:\\Program Files\\flink", envMap.get("FLINK_HOME"));
61-
return;
62-
}
63-
Assertions.assertEquals("/opt/spark", envMap.get("SPARK_HOME"));
64-
Assertions.assertEquals("/opt/flink", envMap.get("FLINK_HOME"));
65-
}
66-
67-
@AfterEach
68-
public void after() {
69-
Common.setSeaTunnelHome(originSeatunnelHome);
70-
Common.setDeployMode(originMode);
32+
Assertions.assertEquals("B", envMap.get("A"));
7133
}
7234
}

seatunnel-common/src/test/resources/home/config/seatunnel-env.cmd

-21
This file was deleted.

seatunnel-common/src/test/resources/home/config/seatunnel-env.sh

-22
This file was deleted.

0 commit comments

Comments
 (0)