Skip to content

Commit a9b8b8c

Browse files
committed
feat(env): Migrate CI Visibility to environment component
1 parent 12fe9dc commit a9b8b8c

File tree

3 files changed

+23
-21
lines changed

3 files changed

+23
-21
lines changed

dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ProcessHierarchy.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package datadog.trace.civisibility;
22

3+
import static datadog.trace.api.config.CiVisibilityConfig.CIVISIBILITY_SIGNAL_SERVER_HOST;
4+
import static datadog.trace.api.config.CiVisibilityConfig.CIVISIBILITY_SIGNAL_SERVER_PORT;
35
import static datadog.trace.bootstrap.instrumentation.api.AgentPropagation.extractContextAndGetSpanContext;
6+
import static datadog.trace.util.Strings.propertyNameToSystemPropertyName;
47

5-
import datadog.trace.api.config.CiVisibilityConfig;
8+
import datadog.environment.SystemProperties;
69
import datadog.trace.bootstrap.instrumentation.api.AgentPropagation;
710
import datadog.trace.bootstrap.instrumentation.api.AgentSpanContext;
8-
import datadog.trace.util.Strings;
911
import java.net.InetSocketAddress;
1012
import java.util.Properties;
1113
import javax.annotation.Nullable;
@@ -69,8 +71,8 @@ private boolean isWrapper() {
6971
}
7072

7173
private boolean isMavenParent() {
72-
return System.getProperty("maven.home") != null
73-
&& System.getProperty("classworlds.conf") != null
74+
return SystemProperties.get("maven.home") != null
75+
&& SystemProperties.get("classworlds.conf") != null
7476
// when using Maven Wrapper
7577
|| ClassLoader.getSystemClassLoader()
7678
.getResource("org/apache/maven/wrapper/WrapperExecutor.class")
@@ -82,7 +84,7 @@ private boolean isGradleDaemon() {
8284
.getResource("org/gradle/launcher/daemon/bootstrap/GradleDaemon.class")
8385
!= null
8486
// double-check this is not a Gradle Worker
85-
&& System.getProperties().getProperty("org.gradle.internal.worker.tmpdir") == null;
87+
&& SystemProperties.get("org.gradle.internal.worker.tmpdir") == null;
8688
}
8789

8890
private boolean isGradleLauncher() {
@@ -93,16 +95,12 @@ private boolean isGradleLauncher() {
9395

9496
@Nullable
9597
public InetSocketAddress getSignalServerAddress() {
96-
// System.getProperty is used rather than Config,
98+
// System properties are used rather than Config,
9799
// because system variables can be set after config was initialized
98100
String host =
99-
System.getProperty(
100-
Strings.propertyNameToSystemPropertyName(
101-
CiVisibilityConfig.CIVISIBILITY_SIGNAL_SERVER_HOST));
101+
SystemProperties.get(propertyNameToSystemPropertyName(CIVISIBILITY_SIGNAL_SERVER_HOST));
102102
String port =
103-
System.getProperty(
104-
Strings.propertyNameToSystemPropertyName(
105-
CiVisibilityConfig.CIVISIBILITY_SIGNAL_SERVER_PORT));
103+
SystemProperties.get(propertyNameToSystemPropertyName(CIVISIBILITY_SIGNAL_SERVER_PORT));
106104
if (host != null && port != null) {
107105
return new InetSocketAddress(host, Integer.parseInt(port));
108106
} else {

dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/domain/buildsystem/BuildSystemModuleImpl.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -138,15 +138,18 @@ private Map<String, String> getPropertiesPropagatedToChildProcess(
138138
ExecutionSettings executionSettings,
139139
BuildSessionSettings sessionSettings) {
140140
Map<String, String> propagatedSystemProperties = new HashMap<>();
141-
Properties systemProperties = System.getProperties();
142-
for (Map.Entry<Object, Object> e : systemProperties.entrySet()) {
143-
String propertyName = (String) e.getKey();
144-
Object propertyValue = e.getValue();
145-
if ((propertyName.startsWith(Config.PREFIX)
146-
|| propertyName.startsWith("datadog.slf4j.simpleLogger.defaultLogLevel"))
147-
&& propertyValue != null) {
148-
propagatedSystemProperties.put(propertyName, propertyValue.toString());
141+
try {
142+
Properties systemProperties = System.getProperties();
143+
for (Map.Entry<Object, Object> e : systemProperties.entrySet()) {
144+
String propertyName = (String) e.getKey();
145+
Object propertyValue = e.getValue();
146+
if ((propertyName.startsWith(Config.PREFIX)
147+
|| propertyName.startsWith("datadog.slf4j.simpleLogger.defaultLogLevel"))
148+
&& propertyValue != null) {
149+
propagatedSystemProperties.put(propertyName, propertyValue.toString());
150+
}
149151
}
152+
} catch (SecurityException ignored) {
150153
}
151154

152155
propagatedSystemProperties.put(

dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/utils/FileUtils.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package datadog.trace.civisibility.utils;
22

3+
import datadog.environment.SystemProperties;
34
import de.thetaphi.forbiddenapis.SuppressForbidden;
45
import java.io.IOException;
56
import java.nio.file.FileVisitResult;
@@ -77,7 +78,7 @@ public static String expandTilde(final String path) {
7778
return path;
7879
}
7980

80-
return path.replaceFirst("^~", System.getProperty("user.home"));
81+
return path.replaceFirst("^~", SystemProperties.getOrDefault("user.home", ""));
8182
}
8283

8384
public static String toRealPath(String path) {

0 commit comments

Comments
 (0)