Skip to content

Commit

Permalink
Migrate from Runtime exec using String to exec using String array bec…
Browse files Browse the repository at this point in the history
…ause of deprecation.
  • Loading branch information
jedla97 authored and fedinskiy committed Oct 12, 2023
1 parent c23ab76 commit 5d0e8ae
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public class OsJvmEnvInfoLogger {
+ " </ul>\n"
+ "</li>\n";

private static final String VERSION_COMMAND = "--version";

public static void main(String[] args) throws IOException, InterruptedException {
final String os = getOs();
final String architecture = System.getProperty("os.arch");
Expand All @@ -57,15 +59,17 @@ private static String getOs() throws IOException {
}

private static String getJavaVersionCmdOutput() throws InterruptedException, IOException {
final String cmd = System.getProperty("java.home") + File.separator + "bin" + File.separator + "java --version";
final String javaExecutablePath = System.getProperty("java.home") + File.separator + "bin" + File.separator + "java";
final String[] cmd = new String[] { javaExecutablePath, VERSION_COMMAND };
Process pr = Runtime.getRuntime().exec(cmd);
pr.waitFor(1, TimeUnit.MINUTES);
return new BufferedReader(new InputStreamReader(pr.getInputStream())).lines().reduce((first, second) -> second)
.orElse(null);
}

private static List<String> getMvnVersionCmdOutput() {
final String cmd = System.getProperty("maven.home") + File.separator + "bin" + File.separator + "mvn --version";
String mavenExecutablePath = System.getProperty("maven.home") + File.separator + "bin" + File.separator + "mvn";
final String[] cmd = new String[] { mavenExecutablePath, VERSION_COMMAND };
try {
Process pr = Runtime.getRuntime().exec(cmd);
pr.waitFor(1, TimeUnit.MINUTES);
Expand Down

0 comments on commit 5d0e8ae

Please sign in to comment.