diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3b81f92b..5b2c99dd 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -36,24 +36,6 @@ jobs: with: version: ${{matrix.java}} - - uses: AdoptOpenJDK/install-jdk@v1 - name: set up JDK 10 - with: - version: 10 - targets: 'JAVA_HOME_10' - - - uses: AdoptOpenJDK/install-jdk@v1 - name: set up JDK 9 - with: - version: 9 - targets: 'JAVA_HOME_9' - - - uses: AdoptOpenJDK/install-jdk@v1 - name: set up JDK 8 - with: - version: 8 - targets: 'JAVA_HOME_8' - - name: Cache local Maven repository uses: actions/cache@v2 with: @@ -65,7 +47,7 @@ jobs: - name: build with maven run: | mvn -q -N io.takari:maven:0.7.7:wrapper -Dmaven=3.8.3 - ./mvnw -B formatter:validate verify --file pom.xml -Djava8.home=$JAVA_HOME_8 -Djava9.home=$JAVA_HOME_9 -Djava10.home=$JAVA_HOME_10 + ./mvnw -B formatter:validate verify --file pom.xml build-windows: runs-on: windows-latest @@ -80,24 +62,6 @@ jobs: with: version: 11 - - uses: AdoptOpenJDK/install-jdk@v1 - name: set up JDK 10 - with: - version: 10 - targets: 'JAVA_HOME_10' - - - uses: AdoptOpenJDK/install-jdk@v1 - name: set up JDK 9 - with: - version: 9 - targets: 'JAVA_HOME_9' - - - uses: AdoptOpenJDK/install-jdk@v1 - name: set up JDK 8 - with: - version: 8 - targets: 'JAVA_HOME_8' - - name: Cache local Maven repository uses: actions/cache@v2 with: @@ -110,7 +74,7 @@ jobs: shell: bash run: | mvn -q -N io.takari:maven:0.7.7:wrapper -Dmaven=3.8.3 - ./mvnw -B formatter:validate verify --file pom.xml -Djava8.home=$JAVA_HOME_8 -Djava9.home=$JAVA_HOME_9 -Djava10.home=$JAVA_HOME_10 + ./mvnw -B formatter:validate verify --file pom.xml build-macos: runs-on: macos-latest @@ -125,24 +89,6 @@ jobs: with: version: 11 - - uses: AdoptOpenJDK/install-jdk@v1 - name: set up JDK 10 - with: - version: 10 - targets: 'JAVA_HOME_10' - - - uses: AdoptOpenJDK/install-jdk@v1 - name: set up JDK 9 - with: - version: 9 - targets: 'JAVA_HOME_9' - - - uses: AdoptOpenJDK/install-jdk@v1 - name: set up JDK 8 - with: - version: 8 - targets: 'JAVA_HOME_8' - - name: Cache local Maven repository uses: actions/cache@v2 with: @@ -154,7 +100,7 @@ jobs: - name: build with maven run: | mvn -q -N io.takari:maven:0.7.7:wrapper -Dmaven=3.8.3 - ./mvnw -B formatter:validate verify --file pom.xml -Djava8.home=$JAVA_HOME_8 -Djava9.home=$JAVA_HOME_9 -Djava10.home=$JAVA_HOME_10 + ./mvnw -B formatter:validate verify --file pom.xml quality: needs: [build-linux,build-macos,build-windows] diff --git a/classloader/build-include-jdk-misc b/annotation/build-test-java11 similarity index 100% rename from classloader/build-include-jdk-misc rename to annotation/build-test-java11 diff --git a/classloader/build-release-8 b/classloader/build-test-java11 similarity index 100% rename from classloader/build-release-8 rename to classloader/build-test-java11 diff --git a/classloader/src/main/java/io/smallrye/common/classloader/ClassDefiner.java b/classloader/src/main/java/io/smallrye/common/classloader/ClassDefiner.java index 5fecaccc..0e5fe270 100644 --- a/classloader/src/main/java/io/smallrye/common/classloader/ClassDefiner.java +++ b/classloader/src/main/java/io/smallrye/common/classloader/ClassDefiner.java @@ -1,69 +1,26 @@ package io.smallrye.common.classloader; import java.lang.invoke.MethodHandles; -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; import java.security.AccessController; import java.security.PrivilegedAction; -import java.security.ProtectionDomain; - -import sun.misc.Unsafe; public class ClassDefiner { - private static final Unsafe unsafe; - private static final Method defineClass; + public static Class defineClass(MethodHandles.Lookup lookup, Class parent, String className, byte[] classBytes) { + SecurityManager sm = System.getSecurityManager(); + if (sm != null) { + sm.checkPermission(DefineClassPermission.getInstance()); + } - static { - unsafe = AccessController.doPrivileged(new PrivilegedAction() { - public Unsafe run() { + return AccessController.doPrivileged(new PrivilegedAction>() { + @Override + public Class run() { try { - final Field field = Unsafe.class.getDeclaredField("theUnsafe"); - field.setAccessible(true); - return (Unsafe) field.get(null); + MethodHandles.Lookup privateLookupIn = MethodHandles.privateLookupIn(parent, lookup); + return privateLookupIn.defineClass(classBytes); } catch (IllegalAccessException e) { throw new IllegalAccessError(e.getMessage()); - } catch (NoSuchFieldException e) { - throw new NoSuchFieldError(e.getMessage()); - } - } - }); - - defineClass = AccessController.doPrivileged(new PrivilegedAction() { - @Override - public Method run() { - try { - return Unsafe.class.getMethod("defineClass", String.class, byte[].class, int.class, int.class, - ClassLoader.class, ProtectionDomain.class); - } catch (NoSuchMethodException e) { - throw new NoSuchMethodError(e.getMessage()); } } }); } - - public static Class defineClass(MethodHandles.Lookup lookup, Class parent, String className, byte[] classBytes) { - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - sm.checkPermission(DefineClassPermission.getInstance()); - } - - // The className for Unsafe.defineClass must match the one in classBytes, so we can try to verify the package - // with the parent - String parentPkg = parent.getPackage().getName(); - String classPkg = className.substring(0, className.lastIndexOf('.')); - - if (!parentPkg.equals(classPkg)) { - throw new IllegalArgumentException("Class not in same package as lookup class"); - } - - try { - return (Class) defineClass.invoke(unsafe, className, classBytes, 0, classBytes.length, parent.getClassLoader(), - null); - } catch (IllegalAccessException e) { - throw new IllegalAccessError(e.getMessage()); - } catch (InvocationTargetException e) { - throw new IllegalStateException(e.getMessage()); - } - } } diff --git a/classloader/src/main/java9/io/smallrye/common/classloader/ClassDefiner.java b/classloader/src/main/java9/io/smallrye/common/classloader/ClassDefiner.java deleted file mode 100644 index 0e5fe270..00000000 --- a/classloader/src/main/java9/io/smallrye/common/classloader/ClassDefiner.java +++ /dev/null @@ -1,26 +0,0 @@ -package io.smallrye.common.classloader; - -import java.lang.invoke.MethodHandles; -import java.security.AccessController; -import java.security.PrivilegedAction; - -public class ClassDefiner { - public static Class defineClass(MethodHandles.Lookup lookup, Class parent, String className, byte[] classBytes) { - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - sm.checkPermission(DefineClassPermission.getInstance()); - } - - return AccessController.doPrivileged(new PrivilegedAction>() { - @Override - public Class run() { - try { - MethodHandles.Lookup privateLookupIn = MethodHandles.privateLookupIn(parent, lookup); - return privateLookupIn.defineClass(classBytes); - } catch (IllegalAccessException e) { - throw new IllegalAccessError(e.getMessage()); - } - } - }); - } -} diff --git a/classloader/build-test-java8 b/constraint/build-test-java11 similarity index 100% rename from classloader/build-test-java8 rename to constraint/build-test-java11 diff --git a/classloader/build-test-java9 b/cpu/build-test-java11 similarity index 100% rename from classloader/build-test-java9 rename to cpu/build-test-java11 diff --git a/cpu/src/main/java/io/smallrye/common/cpu/ProcessorInfo.java b/cpu/src/main/java/io/smallrye/common/cpu/ProcessorInfo.java index 32121529..d5b0656d 100644 --- a/cpu/src/main/java/io/smallrye/common/cpu/ProcessorInfo.java +++ b/cpu/src/main/java/io/smallrye/common/cpu/ProcessorInfo.java @@ -1,88 +1,13 @@ package io.smallrye.common.cpu; -import java.io.BufferedReader; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStreamReader; -import java.nio.charset.StandardCharsets; -import java.security.AccessController; -import java.security.PrivilegedAction; -import java.util.Locale; - /** - * Provides general information about the processors on this host. + * Provides general information about the processors on this host (Java 9 version). */ public class ProcessorInfo { private ProcessorInfo() { } - private static final String CPUS_ALLOWED = "Cpus_allowed:"; - - /** - * Returns the number of processors available to this process. On most operating systems this method - * simply delegates to {@link Runtime#availableProcessors()}. However, on Linux, this strategy - * is insufficient, since the JVM does not take into consideration the process' CPU set affinity - * which is employed by cgroups and numactl. Therefore this method will analyze the Linux proc filesystem - * to make the determination. Since the CPU affinity of a process can be change at any time, this method does - * not cache the result. Calls should be limited accordingly. - *
- * Note tha on Linux, both SMT units (Hyper-Threading) and CPU cores are counted as a processor. - * - * @return the available processors on this system. - */ public static int availableProcessors() { - if (System.getSecurityManager() != null) { - return AccessController.doPrivileged((PrivilegedAction) () -> Integer.valueOf(determineProcessors())) - .intValue(); - } - - return determineProcessors(); - } - - private static int determineProcessors() { - int javaProcs = Runtime.getRuntime().availableProcessors(); - if (!isLinux()) { - return javaProcs; - } - - int maskProcs = 0; - - try { - maskProcs = readCPUMask(); - } catch (Exception e) { - // yum - } - - return maskProcs > 0 ? Math.min(javaProcs, maskProcs) : javaProcs; - } - - private static int readCPUMask() throws IOException { - try (FileInputStream stream = new FileInputStream("/proc/self/status")) { - try (InputStreamReader inputReader = new InputStreamReader(stream, StandardCharsets.US_ASCII)) { - try (BufferedReader reader = new BufferedReader(inputReader)) { - String line; - while ((line = reader.readLine()) != null) { - if (line.startsWith(CPUS_ALLOWED)) { - int count = 0; - int start = CPUS_ALLOWED.length(); - for (int i = start; i < line.length(); i++) { - final int v = Character.digit(line.charAt(i), 16); - if (v != -1) { - count += Integer.bitCount(v); - } - } - return count; - } - } - } - } - } - - return -1; - } - - private static boolean isLinux() { - String osArch = System.getProperty("os.name", "unknown").toLowerCase(Locale.US); - return (osArch.contains("linux")); + return Runtime.getRuntime().availableProcessors(); } } diff --git a/cpu/src/main/java9/io/smallrye/common/cpu/ProcessorInfo.java b/cpu/src/main/java9/io/smallrye/common/cpu/ProcessorInfo.java deleted file mode 100644 index d5b0656d..00000000 --- a/cpu/src/main/java9/io/smallrye/common/cpu/ProcessorInfo.java +++ /dev/null @@ -1,13 +0,0 @@ -package io.smallrye.common.cpu; - -/** - * Provides general information about the processors on this host (Java 9 version). - */ -public class ProcessorInfo { - private ProcessorInfo() { - } - - public static int availableProcessors() { - return Runtime.getRuntime().availableProcessors(); - } -} diff --git a/cpu/build-release-8 b/expression/build-test-java11 similarity index 100% rename from cpu/build-release-8 rename to expression/build-test-java11 diff --git a/cpu/build-test-java9 b/function/build-test-java11 similarity index 100% rename from cpu/build-test-java9 rename to function/build-test-java11 diff --git a/io/src/main/java/io/smallrye/common/io/jar/JarEntries.java b/io/src/main/java/io/smallrye/common/io/jar/JarEntries.java index 470f4b23..d054c7ac 100644 --- a/io/src/main/java/io/smallrye/common/io/jar/JarEntries.java +++ b/io/src/main/java/io/smallrye/common/io/jar/JarEntries.java @@ -8,6 +8,6 @@ public class JarEntries { * On Java 10+, a getRealName() method was added */ public static String getRealName(JarEntry jarEntry) { - return jarEntry.getName(); + return jarEntry.getRealName(); } } diff --git a/io/src/main/java/io/smallrye/common/io/jar/JarFiles.java b/io/src/main/java/io/smallrye/common/io/jar/JarFiles.java index 69b12b7a..6d6fb733 100644 --- a/io/src/main/java/io/smallrye/common/io/jar/JarFiles.java +++ b/io/src/main/java/io/smallrye/common/io/jar/JarFiles.java @@ -2,12 +2,11 @@ import java.io.File; import java.io.IOException; -import java.io.UncheckedIOException; import java.util.jar.JarFile; -import java.util.jar.Manifest; +import java.util.zip.ZipFile; /** - * Java 8 variant of a JDK-specific class for working with {@code JarFile}s. + * Java 9+ variant of a JDK-specific class for working with {@code JarFile}s. */ public class JarFiles { /** @@ -15,7 +14,7 @@ public class JarFiles { * On Java 9+, an equivalent that is multi-release-enabled is returned. */ public static JarFile create(String name) throws IOException { - return new JarFile(name); + return new JarFile(new File(name), true, ZipFile.OPEN_READ, JarFile.runtimeVersion()); } /** @@ -23,7 +22,7 @@ public static JarFile create(String name) throws IOException { * On Java 9+, an equivalent that is multi-release-enabled is returned. */ public static JarFile create(String name, boolean verify) throws IOException { - return new JarFile(name, verify); + return new JarFile(new File(name), verify, ZipFile.OPEN_READ, JarFile.runtimeVersion()); } /** @@ -31,7 +30,7 @@ public static JarFile create(String name, boolean verify) throws IOException { * On Java 9+, an equivalent that is multi-release-enabled is returned. */ public static JarFile create(File file) throws IOException { - return new JarFile(file); + return new JarFile(file, true, ZipFile.OPEN_READ, JarFile.runtimeVersion()); } /** @@ -39,7 +38,7 @@ public static JarFile create(File file) throws IOException { * On Java 9+, an equivalent that is multi-release-enabled is returned. */ public static JarFile create(File file, boolean verify) throws IOException { - return new JarFile(file, verify); + return new JarFile(file, verify, ZipFile.OPEN_READ, JarFile.runtimeVersion()); } /** @@ -47,15 +46,7 @@ public static JarFile create(File file, boolean verify) throws IOException { * On Java 9+, there is a isMultiRelease method */ public static boolean isMultiRelease(JarFile jarFile) { - String value = null; - try { - Manifest manifest = jarFile.getManifest(); - if (manifest != null) { - value = manifest.getMainAttributes().getValue("Multi-Release"); - } - } catch (IOException e) { - throw new UncheckedIOException("Cannot read manifest attributes", e); - } - return Boolean.parseBoolean(value); + return jarFile.isMultiRelease(); } + } diff --git a/io/src/main/java10/io/smallrye/common/io/jar/JarEntries.java b/io/src/main/java10/io/smallrye/common/io/jar/JarEntries.java deleted file mode 100644 index d054c7ac..00000000 --- a/io/src/main/java10/io/smallrye/common/io/jar/JarEntries.java +++ /dev/null @@ -1,13 +0,0 @@ -package io.smallrye.common.io.jar; - -import java.util.jar.JarEntry; - -public class JarEntries { - /** - * Returns the real name of this {@link JarEntry}. On Java 8, it returns the {@link JarEntry#getName()} - * On Java 10+, a getRealName() method was added - */ - public static String getRealName(JarEntry jarEntry) { - return jarEntry.getRealName(); - } -} diff --git a/io/src/main/java9/io/smallrye/common/io/jar/JarEntries.java b/io/src/main/java9/io/smallrye/common/io/jar/JarEntries.java deleted file mode 100644 index 3697d6ba..00000000 --- a/io/src/main/java9/io/smallrye/common/io/jar/JarEntries.java +++ /dev/null @@ -1,36 +0,0 @@ -package io.smallrye.common.io.jar; - -import java.lang.reflect.Method; -import java.util.jar.JarEntry; - -public class JarEntries { - - private static final Method REAL_NAME_METHOD; - - static { - Method method; - try { - method = Class.forName("java.util.jar.JarFile$JarFileEntry").getDeclaredMethod("realName"); - method.setAccessible(true); - } catch (NoSuchMethodException | ClassNotFoundException e) { - method = null; - } - REAL_NAME_METHOD = method; - } - - /** - * Returns the real name of this {@link JarEntry}. On Java 8, it returns the {@link JarEntry#getName()} - * On Java 10+, a getRealName() method was added - */ - public static String getRealName(JarEntry jarEntry) { - if (REAL_NAME_METHOD != null) { - try { - return REAL_NAME_METHOD.invoke(jarEntry).toString(); - } catch (Exception e) { - // This should never happen - } - } - // As a safe net, fallback to the original value - return jarEntry.getName(); - } -} diff --git a/io/src/main/java9/io/smallrye/common/io/jar/JarFiles.java b/io/src/main/java9/io/smallrye/common/io/jar/JarFiles.java deleted file mode 100644 index 6d6fb733..00000000 --- a/io/src/main/java9/io/smallrye/common/io/jar/JarFiles.java +++ /dev/null @@ -1,52 +0,0 @@ -package io.smallrye.common.io.jar; - -import java.io.File; -import java.io.IOException; -import java.util.jar.JarFile; -import java.util.zip.ZipFile; - -/** - * Java 9+ variant of a JDK-specific class for working with {@code JarFile}s. - */ -public class JarFiles { - /** - * Returns an equivalent of {@code new JarFile(name)}. On Java 8, that's exactly what is returned. - * On Java 9+, an equivalent that is multi-release-enabled is returned. - */ - public static JarFile create(String name) throws IOException { - return new JarFile(new File(name), true, ZipFile.OPEN_READ, JarFile.runtimeVersion()); - } - - /** - * Returns an equivalent of {@code new JarFile(name, verify)}. On Java 8, that's exactly what is returned. - * On Java 9+, an equivalent that is multi-release-enabled is returned. - */ - public static JarFile create(String name, boolean verify) throws IOException { - return new JarFile(new File(name), verify, ZipFile.OPEN_READ, JarFile.runtimeVersion()); - } - - /** - * Returns an equivalent of {@code new JarFile(file)}. On Java 8, that's exactly what is returned. - * On Java 9+, an equivalent that is multi-release-enabled is returned. - */ - public static JarFile create(File file) throws IOException { - return new JarFile(file, true, ZipFile.OPEN_READ, JarFile.runtimeVersion()); - } - - /** - * Returns an equivalent of {@code new JarFile(file, verify)}. On Java 8, that's exactly what is returned. - * On Java 9+, an equivalent that is multi-release-enabled is returned. - */ - public static JarFile create(File file, boolean verify) throws IOException { - return new JarFile(file, verify, ZipFile.OPEN_READ, JarFile.runtimeVersion()); - } - - /** - * Returns true if this {@link JarFile} is a multi-release jar. On Java 8 this is done by browsing the manifest. - * On Java 9+, there is a isMultiRelease method - */ - public static boolean isMultiRelease(JarFile jarFile) { - return jarFile.isMultiRelease(); - } - -} diff --git a/io/build-release-8 b/net/build-test-java11 similarity index 100% rename from io/build-release-8 rename to net/build-test-java11 diff --git a/io/build-test-java10 b/os/build-test-java11 similarity index 100% rename from io/build-test-java10 rename to os/build-test-java11 diff --git a/os/build-test-java8 b/os/build-test-java8 deleted file mode 100644 index e69de29b..00000000 diff --git a/os/build-test-java9 b/os/build-test-java9 deleted file mode 100644 index e69de29b..00000000 diff --git a/os/src/main/java/io/smallrye/common/os/GetAllProcessesInfoAction.java b/os/src/main/java/io/smallrye/common/os/GetAllProcessesInfoAction.java index a93eb886..d16de967 100644 --- a/os/src/main/java/io/smallrye/common/os/GetAllProcessesInfoAction.java +++ b/os/src/main/java/io/smallrye/common/os/GetAllProcessesInfoAction.java @@ -1,122 +1,15 @@ package io.smallrye.common.os; -import java.io.BufferedReader; -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.nio.file.DirectoryStream; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; import java.security.PrivilegedAction; -import java.util.ArrayList; import java.util.List; -import java.util.Scanner; -import java.util.function.Predicate; -import java.util.regex.Pattern; +import java.util.stream.Collectors; final class GetAllProcessesInfoAction implements PrivilegedAction> { - private final static Predicate IS_NUMBER = Pattern.compile("\\d+").asPredicate(); - @Override public List run() { - // The ProcessHandle API does not exist, so we have to rely on external processes to get this information - switch (OS.current()) { - case LINUX: - return readLinuxProcesses(); - case MAC: - return readMacProcesses(); - case WINDOWS: - return readWindowsProcesses(); - default: - throw new UnsupportedOperationException( - "Listing all processes is not supported in JDK 8 in " + OS.current().name()); - } - } - - private List readLinuxProcesses() { - List processes = new ArrayList<>(); - try (DirectoryStream stream = Files.newDirectoryStream(Paths.get("/proc"))) { - for (Path procPath : stream) { - String name = procPath.getFileName().toString(); - if (IS_NUMBER.test(name)) { - long pid = Long.parseLong(name); - try (BufferedReader reader = Files - .newBufferedReader(procPath.resolve("cmdline"), StandardCharsets.UTF_8)) { - String line = reader.readLine(); - if (line != null) { - int idx = line.indexOf(0); - String cmdLine = idx == -1 ? line : line.substring(0, idx); - processes.add(new ProcessInfo(pid, cmdLine)); - } - } catch (IOException ignored) { - // ignore case where process exits right before we read cmdline - } - } - } - } catch (IOException ignored) { - // ignore - } - return processes; - } - - private List readMacProcesses() { - List processes = new ArrayList<>(); - java.lang.Process process = null; - try { - ProcessBuilder processBuilder = new ProcessBuilder("ps", "-ax", "-o", "pid=,comm="); - String thisCmd = String.join(" ", processBuilder.command()); - process = processBuilder.start(); - try (Scanner scanner = new Scanner(process.getInputStream())) { - while (scanner.hasNextLine()) { - String line = scanner.nextLine().trim(); - int separator = line.indexOf(" "); - String cmd = line.substring(separator + 1); - if (!thisCmd.equals(cmd)) { - long pid = Long.parseLong(line.substring(0, separator)); - processes.add(new ProcessInfo(pid, cmd)); - } - } - } - } catch (IOException e) { - // ignored - } finally { - if (process != null) { - process.destroy(); - } - } - return processes; - } - - private List readWindowsProcesses() { - List processes = new ArrayList<>(); - java.lang.Process process = null; - try { - ProcessBuilder processBuilder = new ProcessBuilder("tasklist.exe", "/fo", "csv", "/nh"); - String thisCmd = String.join(" ", processBuilder.command()); - process = processBuilder.start(); - try (Scanner sc = new Scanner(process.getInputStream())) { - // Skip first line - if (sc.hasNextLine()) { - sc.nextLine(); - } - while (sc.hasNextLine()) { - String line = sc.nextLine().trim(); - String[] parts = line.split(","); - String cmdLine = parts[0].substring(1).replaceFirst(".$", ""); - if (!thisCmd.equals(cmdLine)) { - long pid = Long.parseLong(parts[1].substring(1).replaceFirst(".$", "")); - processes.add(new ProcessInfo(pid, cmdLine)); - } - } - } - } catch (IOException e) { - // ignored - } finally { - if (process != null) { - process.destroy(); - } - } - return processes; + return ProcessHandle.allProcesses() + .map(processHandle -> new ProcessInfo(processHandle.pid(), processHandle.info().command().orElse(null))) + .collect(Collectors.toList()); } } diff --git a/os/src/main/java/io/smallrye/common/os/GetProcessInfoAction.java b/os/src/main/java/io/smallrye/common/os/GetProcessInfoAction.java index 927785df..454f524f 100644 --- a/os/src/main/java/io/smallrye/common/os/GetProcessInfoAction.java +++ b/os/src/main/java/io/smallrye/common/os/GetProcessInfoAction.java @@ -21,8 +21,6 @@ import static java.lang.Math.max; import java.io.File; -import java.lang.management.ManagementFactory; -import java.lang.management.RuntimeMXBean; import java.security.PrivilegedAction; /** @@ -31,30 +29,10 @@ final class GetProcessInfoAction implements PrivilegedAction { GetProcessInfoAction() { } - @Override public ProcessInfo run() { - long pid = -1L; - String processName = ""; - final RuntimeMXBean runtime; - try { - runtime = ManagementFactory.getPlatformMXBean(RuntimeMXBean.class); - } catch (Exception ignored) { - return new ProcessInfo(pid, processName); - } - // TODO: on Java 9, use ProcessHandle.current().pid() - // Process ID - final String name = runtime.getName(); - if (name != null) { - final int idx = name.indexOf('@'); - if (idx != -1) - try { - pid = Long.parseLong(name.substring(0, idx)); - } catch (NumberFormatException ignored) { - } - } - // TODO: on Java 9, maybe ProcessHandle.current().info().commandLine() or .command() instead - // Process name - processName = System.getProperty("jboss.process.name"); + final ProcessHandle processHandle = ProcessHandle.current(); + final long pid = processHandle.pid(); + String processName = System.getProperty("jboss.process.name"); if (processName == null) { final String classPath = System.getProperty("java.class.path"); final String commandLine = System.getProperty("sun.java.command"); @@ -99,6 +77,9 @@ public ProcessInfo run() { } } } + if (processName == null) { + processName = processHandle.info().command().orElse(null); + } if (processName == null) { processName = ""; } diff --git a/os/src/main/java/io/smallrye/common/os/ProcessRedirect.java b/os/src/main/java/io/smallrye/common/os/ProcessRedirect.java index 610f2722..1bdabf03 100644 --- a/os/src/main/java/io/smallrye/common/os/ProcessRedirect.java +++ b/os/src/main/java/io/smallrye/common/os/ProcessRedirect.java @@ -18,21 +18,11 @@ package io.smallrye.common.os; -import java.io.File; - -/** - * Process redirections that work on all JDK versions. - */ public final class ProcessRedirect { private ProcessRedirect() { } - /** - * Get the "discard" process redirection target. - * - * @return the discarding redirection target - */ public static ProcessBuilder.Redirect discard() { - return ProcessBuilder.Redirect.to(new File(OS.WINDOWS.isCurrent() ? "NUL" : "/dev/null")); + return ProcessBuilder.Redirect.DISCARD; } } diff --git a/os/src/main/java9/io/smallrye/common/os/GetAllProcessesInfoAction.java b/os/src/main/java9/io/smallrye/common/os/GetAllProcessesInfoAction.java deleted file mode 100644 index d16de967..00000000 --- a/os/src/main/java9/io/smallrye/common/os/GetAllProcessesInfoAction.java +++ /dev/null @@ -1,15 +0,0 @@ -package io.smallrye.common.os; - -import java.security.PrivilegedAction; -import java.util.List; -import java.util.stream.Collectors; - -final class GetAllProcessesInfoAction implements PrivilegedAction> { - - @Override - public List run() { - return ProcessHandle.allProcesses() - .map(processHandle -> new ProcessInfo(processHandle.pid(), processHandle.info().command().orElse(null))) - .collect(Collectors.toList()); - } -} diff --git a/os/src/main/java9/io/smallrye/common/os/GetProcessInfoAction.java b/os/src/main/java9/io/smallrye/common/os/GetProcessInfoAction.java deleted file mode 100644 index b96658b6..00000000 --- a/os/src/main/java9/io/smallrye/common/os/GetProcessInfoAction.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * JBoss, Home of Professional Open Source. - * Copyright 2018 Red Hat, Inc., and individual contributors - * as indicated by the @author tags. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.smallrye.common.os; - -import static java.lang.Math.max; - -import java.io.File; -import java.security.PrivilegedAction; - -/** - */ -final class GetProcessInfoAction implements PrivilegedAction { - GetProcessInfoAction() { - } - - public ProcessInfo run() { - final ProcessHandle processHandle = ProcessHandle.current(); - final long pid = processHandle.pid(); - String processName = System.getProperty("jboss.process.name"); - if (processName == null) { - final String classPath = System.getProperty("java.class.path"); - final String commandLine = System.getProperty("sun.java.command"); - if (commandLine != null) { - if (classPath != null && commandLine.startsWith(classPath)) { - // OK probably a JAR launch - final int sepIdx = classPath.lastIndexOf(File.separatorChar); - if (sepIdx > 0) { - processName = classPath.substring(sepIdx + 1); - } else { - processName = classPath; - } - } else { - // probably a class name - // it might be a class name followed by args, like org.foo.Bar -baz -zap - int firstSpace = commandLine.indexOf(' '); - final String className; - if (firstSpace > 0) { - className = commandLine.substring(0, firstSpace); - } else { - className = commandLine; - } - // no args now - int lastDot = className.lastIndexOf('.', firstSpace); - if (lastDot > 0) { - processName = className.substring(lastDot + 1); - if (processName.equalsIgnoreCase("jar") || processName.equalsIgnoreCase("ȷar")) { - // oops, I guess it was a JAR name... let's just take a guess then - int secondLastDot = className.lastIndexOf('.', lastDot - 1); - int sepIdx = className.lastIndexOf(File.separatorChar); - int lastSep = secondLastDot == - 1 ? sepIdx : sepIdx == - 1 ? secondLastDot : max(sepIdx, secondLastDot); - if (lastSep > 0) { - processName = className.substring(lastSep + 1); - } else { - processName = className; - } - } - } else { - processName = className; - } - } - } - } - if (processName == null) { - processName = processHandle.info().command().orElse(null); - } - if (processName == null) { - processName = ""; - } - return new ProcessInfo(pid, processName); - } -} diff --git a/os/src/main/java9/io/smallrye/common/os/ProcessRedirect.java b/os/src/main/java9/io/smallrye/common/os/ProcessRedirect.java deleted file mode 100644 index a58198d7..00000000 --- a/os/src/main/java9/io/smallrye/common/os/ProcessRedirect.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * JBoss, Home of Professional Open Source. - * Copyright 2018 Red Hat, Inc., and individual contributors - * as indicated by the @author tags. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.smallrye.common.os; - -public final class ProcessRedirect { - private ProcessRedirect() {} - - public static ProcessBuilder.Redirect discard() { - return ProcessBuilder.Redirect.DISCARD; - } -} diff --git a/pom.xml b/pom.xml index c1081145..a8592a09 100644 --- a/pom.xml +++ b/pom.xml @@ -231,6 +231,21 @@ + + maven-compiler-plugin + + + default-compile + + compile + + + + 11 + + + + diff --git a/io/build-test-java8 b/ref/build-test-java11 similarity index 100% rename from io/build-test-java8 rename to ref/build-test-java11 diff --git a/version/build-release-8 b/version/build-release-8 deleted file mode 100644 index e69de29b..00000000 diff --git a/io/build-test-java9 b/version/build-test-java11 similarity index 100% rename from io/build-test-java9 rename to version/build-test-java11 diff --git a/version/build-test-java8 b/version/build-test-java8 deleted file mode 100644 index e69de29b..00000000 diff --git a/version/build-test-java9 b/version/build-test-java9 deleted file mode 100644 index e69de29b..00000000 diff --git a/version/src/main/java/io/smallrye/common/version/JDKSpecific.java b/version/src/main/java/io/smallrye/common/version/JDKSpecific.java index 2c69de54..2f09fd80 100644 --- a/version/src/main/java/io/smallrye/common/version/JDKSpecific.java +++ b/version/src/main/java/io/smallrye/common/version/JDKSpecific.java @@ -1,14 +1,16 @@ package io.smallrye.common.version; +import java.lang.module.ModuleDescriptor; + final class JDKSpecific { private JDKSpecific() { } static boolean hasJpms() { - return false; + return true; } static int compareJpms(String v1, String v2) { - throw new UnsupportedOperationException("Java 9 only"); + return Integer.signum(ModuleDescriptor.Version.parse(v1).compareTo(ModuleDescriptor.Version.parse(v2))); } } diff --git a/version/src/main/java9/io/smallrye/common/version/JDKSpecific.java b/version/src/main/java9/io/smallrye/common/version/JDKSpecific.java deleted file mode 100644 index 78180a11..00000000 --- a/version/src/main/java9/io/smallrye/common/version/JDKSpecific.java +++ /dev/null @@ -1,15 +0,0 @@ -package io.smallrye.common.version; - -import java.lang.module.ModuleDescriptor; - -final class JDKSpecific { - private JDKSpecific() {} - - static boolean hasJpms() { - return true; - } - - static int compareJpms(String v1, String v2) { - return Integer.signum(ModuleDescriptor.Version.parse(v1).compareTo(ModuleDescriptor.Version.parse(v2))); - } -} diff --git a/os/build-release-8 b/vertx-context/build-test-java11 similarity index 100% rename from os/build-release-8 rename to vertx-context/build-test-java11