Skip to content

Commit 1d19e92

Browse files
committed
feat(core): Migrate Platform to environment component
1 parent 74204fe commit 1d19e92

File tree

1 file changed

+0
-351
lines changed

1 file changed

+0
-351
lines changed

internal-api/src/main/java/datadog/trace/api/Platform.java

Lines changed: 0 additions & 351 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@ private static class Captured {
1616
public static final boolean isNativeImage = checkForNativeImageBuilder();
1717
}
1818

19-
// private static final Version JAVA_VERSION =
20-
// parseJavaVersion(System.getProperty("java.version"));
21-
// private static final JvmRuntime RUNTIME = new JvmRuntime();
22-
2319
private static final boolean HAS_JFR = checkForJfr();
2420
private static final boolean IS_NATIVE_IMAGE_BUILDER = checkForNativeImageBuilder();
2521
private static final boolean IS_NATIVE_IMAGE = Captured.isNativeImage;
@@ -60,351 +56,4 @@ private static boolean checkForNativeImageBuilder() {
6056
return false;
6157
}
6258
}
63-
64-
// /* The method splits java version string by digits. Delimiters are: dot, underscore and plus
65-
// */
66-
// private static List<Integer> splitDigits(String str) {
67-
// List<Integer> results = new ArrayList<>();
68-
//
69-
// int len = str.length();
70-
//
71-
// int value = 0;
72-
// for (int i = 0; i < len; i++) {
73-
// char ch = str.charAt(i);
74-
// if (ch >= '0' && ch <= '9') {
75-
// value = value * 10 + (ch - '0');
76-
// } else if (ch == '.' || ch == '_' || ch == '+') {
77-
// results.add(value);
78-
// value = 0;
79-
// } else {
80-
// throw new NumberFormatException();
81-
// }
82-
// }
83-
// results.add(value);
84-
// return results;
85-
// }
86-
//
87-
// private static Version parseJavaVersion(String javaVersion) {
88-
// // Remove pre-release part, usually -ea
89-
// final int indexOfDash = javaVersion.indexOf('-');
90-
// if (indexOfDash >= 0) {
91-
// javaVersion = javaVersion.substring(0, indexOfDash);
92-
// }
93-
//
94-
// int major = 0;
95-
// int minor = 0;
96-
// int update = 0;
97-
//
98-
// try {
99-
// List<Integer> nums = splitDigits(javaVersion);
100-
// major = nums.get(0);
101-
//
102-
// // for java 1.6/1.7/1.8
103-
// if (major == 1) {
104-
// major = nums.get(1);
105-
// minor = nums.get(2);
106-
// update = nums.get(3);
107-
// } else {
108-
// minor = nums.get(1);
109-
// update = nums.get(2);
110-
// }
111-
// } catch (NumberFormatException | IndexOutOfBoundsException e) {
112-
// // unable to parse version string - do nothing
113-
// }
114-
// return new Version(major, minor, update);
115-
// }
116-
//
117-
// static final class Version {
118-
// public final int major, minor, update;
119-
//
120-
// public Version(int major, int minor, int update) {
121-
// this.major = major;
122-
// this.minor = minor;
123-
// this.update = update;
124-
// }
125-
//
126-
// public boolean is(int major) {
127-
// return this.major == major;
128-
// }
129-
//
130-
// public boolean is(int major, int minor) {
131-
// return this.major == major && this.minor == minor;
132-
// }
133-
//
134-
// public boolean is(int major, int minor, int update) {
135-
// return this.major == major && this.minor == minor && this.update == update;
136-
// }
137-
//
138-
// public boolean isAtLeast(int major, int minor, int update) {
139-
// return isAtLeast(this.major, this.minor, this.update, major, minor, update);
140-
// }
141-
//
142-
// public boolean isBetween(
143-
// int fromMajor, int fromMinor, int fromUpdate, int toMajor, int toMinor, int toUpdate) {
144-
// return isAtLeast(toMajor, toMinor, toUpdate, fromMajor, fromMinor, fromUpdate)
145-
// && isAtLeast(fromMajor, fromMinor, fromUpdate)
146-
// && !isAtLeast(toMajor, toMinor, toUpdate);
147-
// }
148-
//
149-
// private static boolean isAtLeast(
150-
// int major, int minor, int update, int atLeastMajor, int atLeastMinor, int atLeastUpdate)
151-
// {
152-
// return (major > atLeastMajor)
153-
// || (major == atLeastMajor && minor > atLeastMinor)
154-
// || (major == atLeastMajor && minor == atLeastMinor && update >= atLeastUpdate);
155-
// }
156-
// }
157-
//
158-
// static final class JvmRuntime {
159-
// /*
160-
// * Example:
161-
// * jvm -> "AdoptOpenJDK 1.8.0_265-b01"
162-
// *
163-
// * name -> "OpenJDK"
164-
// * vendor -> "AdoptOpenJDK"
165-
// * version -> "1.8.0_265"
166-
// * patches -> "b01"
167-
// */
168-
// public final String name;
169-
//
170-
// public final String vendor;
171-
// public final String version;
172-
// public final String vendorVersion;
173-
// public final String patches;
174-
//
175-
// public JvmRuntime() {
176-
// this(
177-
// System.getProperty("java.version"),
178-
// System.getProperty("java.runtime.version"),
179-
// System.getProperty("java.runtime.name"),
180-
// System.getProperty("java.vm.vendor"),
181-
// System.getProperty("java.vendor.version"));
182-
// }
183-
//
184-
// // Only visible for testing
185-
// JvmRuntime(String javaVer, String rtVer, String name, String vendor, String vendorVersion) {
186-
// this.name = name == null ? "" : name;
187-
// this.vendor = vendor == null ? "" : vendor;
188-
// javaVer = javaVer == null ? "" : javaVer;
189-
// this.version = javaVer;
190-
// this.vendorVersion = vendorVersion == null ? "" : vendorVersion;
191-
// rtVer = javaVer.isEmpty() || rtVer == null ? javaVer : rtVer;
192-
// int patchStart = javaVer.length() + 1;
193-
// this.patches = (patchStart >= rtVer.length()) ? "" : rtVer.substring(javaVer.length() +
194-
// 1);
195-
// }
196-
// }
197-
198-
// public static boolean isJavaVersion(int major) {
199-
// return JAVA_VERSION.is(major);
200-
// }
201-
//
202-
// public static boolean isJavaVersion(int major, int minor) {
203-
// return JAVA_VERSION.is(major, minor);
204-
// }
205-
//
206-
// public static boolean isJavaVersion(int major, int minor, int update) {
207-
// return JAVA_VERSION.is(major, minor, update);
208-
// }
209-
210-
// public static boolean isJavaVersionAtLeast(int major) {
211-
// return isJavaVersionAtLeast(major, 0, 0);
212-
// }
213-
//
214-
// public static boolean isJavaVersionAtLeast(int major, int minor) {
215-
// return isJavaVersionAtLeast(major, minor, 0);
216-
// }
217-
//
218-
// public static boolean isJavaVersionAtLeast(int major, int minor, int update) {
219-
// return JAVA_VERSION.isAtLeast(major, minor, update);
220-
// }
221-
222-
// /**
223-
// * Check if the Java version is between {@code fromMajor} (inclusive) and {@code toMajor}
224-
// * (exclusive).
225-
// *
226-
// * @param fromMajor major from version (inclusive)
227-
// * @param toMajor major to version (exclusive)
228-
// * @return if the current java version is between the from version (inclusive) and the to
229-
// version
230-
// * exclusive
231-
// */
232-
// public static boolean isJavaVersionBetween(int fromMajor, int toMajor) {
233-
// return isJavaVersionBetween(fromMajor, 0, toMajor, 0);
234-
// }
235-
//
236-
// /**
237-
// * Check if the Java version is between {@code fromMajor.fromMinor} (inclusive) and {@code
238-
// * toMajor.toMinor} (exclusive).
239-
// *
240-
// * @param fromMajor major from version (inclusive)
241-
// * @param fromMinor minor from version (inclusive)
242-
// * @param toMajor major to version (exclusive)
243-
// * @param toMinor minor to version (exclusive)
244-
// * @return if the current java version is between the from version (inclusive) and the to
245-
// version
246-
// * exclusive
247-
// */
248-
// public static boolean isJavaVersionBetween(
249-
// int fromMajor, int fromMinor, int toMajor, int toMinor) {
250-
// return isJavaVersionBetween(fromMajor, fromMinor, 0, toMajor, toMinor, 0);
251-
// }
252-
//
253-
// /**
254-
// * Check if the Java version is between {@code fromMajor.fromMinor.fromUpdate} (inclusive) and
255-
// * {@code toMajor.toMinor.toUpdate} (exclusive).
256-
// *
257-
// * @param fromMajor major from version (inclusive)
258-
// * @param fromMinor minor from version (inclusive)
259-
// * @param fromUpdate update from version (inclusive)
260-
// * @param toMajor major to version (exclusive)
261-
// * @param toMinor minor to version (exclusive)
262-
// * @param toUpdate update to version (exclusive)
263-
// * @return if the current java version is between the from version (inclusive) and the to
264-
// version
265-
// * exclusive
266-
// */
267-
// public static boolean isJavaVersionBetween(
268-
// int fromMajor, int fromMinor, int fromUpdate, int toMajor, int toMinor, int toUpdate) {
269-
// return JAVA_VERSION.isBetween(fromMajor, fromMinor, fromUpdate, toMajor, toMinor, toUpdate);
270-
// }
271-
272-
// public static boolean isLinux() {
273-
// return System.getProperty("os.name").toLowerCase(Locale.ROOT).contains("linux");
274-
// }
275-
//
276-
// public static boolean isWindows() {
277-
// // https://mkyong.com/java/how-to-detect-os-in-java-systemgetpropertyosname/
278-
// final String os = System.getProperty("os.name").toLowerCase(Locale.ROOT);
279-
// return os.contains("win");
280-
// }
281-
//
282-
// public static boolean isMac() {
283-
// final String os = System.getProperty("os.name").toLowerCase(Locale.ROOT);
284-
// return os.contains("mac");
285-
// }
286-
//
287-
// public static boolean isAarch64() {
288-
// return System.getProperty("os.arch").toLowerCase().contains("aarch64");
289-
// }
290-
//
291-
// public static boolean isMusl() {
292-
// if (!isLinux()) {
293-
// return false;
294-
// }
295-
// // check the Java exe then fall back to proc/self maps
296-
// try {
297-
// return isMuslJavaExecutable();
298-
// } catch (IOException e) {
299-
// try {
300-
// return isMuslProcSelfMaps();
301-
// } catch (IOException ignore) {
302-
// return false;
303-
// }
304-
// }
305-
// }
306-
//
307-
// static boolean isMuslProcSelfMaps() throws IOException {
308-
// try (BufferedReader reader = new BufferedReader(new FileReader("/proc/self/maps"))) {
309-
// String line;
310-
// while ((line = reader.readLine()) != null) {
311-
// if (line.contains("-musl-")) {
312-
// return true;
313-
// }
314-
// if (line.contains("/libc.")) {
315-
// return false;
316-
// }
317-
// }
318-
// }
319-
// return false;
320-
// }
321-
//
322-
// /**
323-
// * There is information about the linking in the ELF file. Since properly parsing ELF is not
324-
// * trivial this code will attempt a brute-force approach and will scan the first 4096 bytes of
325-
// the
326-
// * 'java' program image for anything prefixed with `/ld-` - in practice this will contain
327-
// * `/ld-musl` for musl systems and probably something else for non-musl systems (eg.
328-
// * `/ld-linux-...`). However, if such string is missing should indicate that the system is not
329-
// a
330-
// * musl one.
331-
// */
332-
// static boolean isMuslJavaExecutable() throws IOException {
333-
//
334-
// byte[] magic = new byte[] {(byte) 0x7f, (byte) 'E', (byte) 'L', (byte) 'F'};
335-
// byte[] prefix = new byte[] {(byte) '/', (byte) 'l', (byte) 'd', (byte) '-'}; // '/ld-*'
336-
// byte[] musl = new byte[] {(byte) 'm', (byte) 'u', (byte) 's', (byte) 'l'}; // 'musl'
337-
//
338-
// Path binary = Paths.get(System.getProperty("java.home"), "bin", "java");
339-
// byte[] buffer = new byte[4096];
340-
//
341-
// try (InputStream is = Files.newInputStream(binary)) {
342-
// int read = is.read(buffer, 0, 4);
343-
// if (read != 4 || !containsArray(buffer, 0, magic)) {
344-
// throw new IOException(Arrays.toString(buffer));
345-
// }
346-
// read = is.read(buffer);
347-
// if (read <= 0) {
348-
// throw new IOException();
349-
// }
350-
// int prefixPos = 0;
351-
// for (int i = 0; i < read; i++) {
352-
// if (buffer[i] == prefix[prefixPos]) {
353-
// if (++prefixPos == prefix.length) {
354-
// return containsArray(buffer, i + 1, musl);
355-
// }
356-
// } else {
357-
// prefixPos = 0;
358-
// }
359-
// }
360-
// }
361-
// return false;
362-
// }
363-
//
364-
// private static boolean containsArray(byte[] container, int offset, byte[] contained) {
365-
// for (int i = 0; i < contained.length; i++) {
366-
// int leftPos = offset + i;
367-
// if (leftPos >= container.length) {
368-
// return false;
369-
// }
370-
// if (container[leftPos] != contained[i]) {
371-
// return false;
372-
// }
373-
// }
374-
// return true;
375-
// }
376-
377-
// public static boolean isOracleJDK8() {
378-
// return isJavaVersion(8)
379-
// && RUNTIME.vendor.contains("Oracle")
380-
// && !RUNTIME.name.contains("OpenJDK");
381-
// }
382-
//
383-
// public static boolean isJ9() {
384-
// return System.getProperty("java.vm.name").contains("J9");
385-
// }
386-
//
387-
// public static boolean isIbm8() {
388-
// return isJavaVersion(8) && RUNTIME.vendor.contains("IBM");
389-
// }
390-
//
391-
// public static boolean isGraalVM() {
392-
// return RUNTIME.vendorVersion.toLowerCase().contains("graalvm");
393-
// }
394-
395-
// public static String getLangVersion() {
396-
// return String.valueOf(JAVA_VERSION.major);
397-
// }
398-
//
399-
// public static String getRuntimeVendor() {
400-
// return RUNTIME.vendor;
401-
// }
402-
//
403-
// public static String getRuntimeVersion() {
404-
// return RUNTIME.version;
405-
// }
406-
//
407-
// public static String getRuntimePatches() {
408-
// return RUNTIME.patches;
409-
// }
41059
}

0 commit comments

Comments
 (0)