-
Notifications
You must be signed in to change notification settings - Fork 311
Migrate internal apis to environment component #9291
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,19 @@ | ||
package datadog.trace.util; | ||
|
||
import datadog.environment.EnvironmentVariables; | ||
import datadog.environment.JavaVirtualMachine; | ||
import datadog.environment.OperatingSystem; | ||
import datadog.environment.SystemProperties; | ||
import de.thetaphi.forbiddenapis.SuppressForbidden; | ||
import java.io.IOException; | ||
import java.lang.management.ManagementFactory; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.Collections; | ||
import java.util.Objects; | ||
import java.util.Set; | ||
import java.util.function.Predicate; | ||
import java.util.function.Supplier; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
@@ -75,14 +79,16 @@ private static String getTempDir() { | |
if (OperatingSystem.isLinux()) { | ||
return "/tmp"; | ||
} else if (OperatingSystem.isWindows()) { | ||
return Stream.of(System.getenv("TMP"), System.getenv("TEMP"), System.getenv("USERPROFILE")) | ||
.filter(String::isEmpty) | ||
return Stream.of("TMP", "TEMP", "USERPROFILE") | ||
.map(EnvironmentVariables::get) | ||
.filter(Objects::nonNull) | ||
.filter(((Predicate<String>) String::isEmpty).negate()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📝 notes: This behavior change (empty --> !empty) is expected. It’s a fix to the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe add some comment about that? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For clarification, what kind of comment do you expect here? One of the next step for the environment component will be to handle the "temp dir" computation. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comment that will explain this non obvious |
||
.findFirst() | ||
.orElse("C:\\Windows"); | ||
} else if (OperatingSystem.isMacOs()) { | ||
return System.getenv("TMPDIR"); | ||
return EnvironmentVariables.get("TMPDIR"); | ||
} else { | ||
return System.getProperty("java.io.tmpdir"); | ||
return SystemProperties.get("java.io.tmpdir"); | ||
} | ||
} else { | ||
try { | ||
|
@@ -93,7 +99,7 @@ private static String getTempDir() { | |
.invoke(null); | ||
} catch (Throwable t) { | ||
// Fall back to constants based on J9 source code, may not have perfect coverage | ||
String tmpDir = System.getProperty("java.io.tmpdir"); | ||
String tmpDir = SystemProperties.get("java.io.tmpdir"); | ||
if (tmpDir != null && !tmpDir.isEmpty()) { | ||
return tmpDir; | ||
} else if (OperatingSystem.isWindows()) { | ||
|
@@ -114,7 +120,7 @@ private static Path getJavaProcessesDir() { | |
} else { | ||
// Emulating the hotspot way to enumerate the JVM processes using the perfdata file | ||
// https://github.com/openjdk/jdk/blob/d7cb933b89839b692f5562aeeb92076cd25a99f6/src/hotspot/share/runtime/perfMemory.cpp#L244 | ||
return Paths.get(getTempDir(), "hsperfdata_" + System.getProperty("user.name")); | ||
return Paths.get(getTempDir(), "hsperfdata_" + SystemProperties.get("user.name")); | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just thinking out loud here...
Is that OK that we stop iterating on first SecurityException?
Would it make sense to test each property and ignore only those that failed?
But potentially that could be slow...