From 1ef86a8b759a93f6d00d0b44fdbbe802d9d9ad2f Mon Sep 17 00:00:00 2001 From: renfeiw Date: Fri, 14 Jul 2023 14:13:06 -0400 Subject: [PATCH] Fix machineInfo curl validation - based on #457 - change back curl version command as it doesn't work for certain machines - provide fix for NumberFormatException This reverts commit d59bb56ed06d98fb063572db5ab14b03cfb950e0. --- src/org/openj9/envInfo/CmdExecutor.java | 7 +++++++ src/org/openj9/envInfo/MachineInfo.java | 25 +++++++++++++++---------- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/org/openj9/envInfo/CmdExecutor.java b/src/org/openj9/envInfo/CmdExecutor.java index 52609f47..012933c5 100644 --- a/src/org/openj9/envInfo/CmdExecutor.java +++ b/src/org/openj9/envInfo/CmdExecutor.java @@ -18,6 +18,7 @@ import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; +import java.util.Map; public class CmdExecutor { private static CmdExecutor instance; @@ -36,9 +37,15 @@ public String execute(String[] commands) { String rt = null; try { ProcessBuilder builder = new ProcessBuilder(Arrays.asList(commands)); + Map env = builder.environment(); + // clear env and copy from the parent shell environment + env.clear(); + Map shellEnv = System.getenv(); + env.putAll(shellEnv); builder.redirectErrorStream(true); Process proc = builder.start(); BufferedReader stdOutput = new BufferedReader(new InputStreamReader(proc.getInputStream())); + StringBuilder sb = new StringBuilder(); String line = null; String newline = ""; diff --git a/src/org/openj9/envInfo/MachineInfo.java b/src/org/openj9/envInfo/MachineInfo.java index 0685fb2f..94151154 100644 --- a/src/org/openj9/envInfo/MachineInfo.java +++ b/src/org/openj9/envInfo/MachineInfo.java @@ -142,9 +142,10 @@ private void makeSameLength(ArrayList list, int requiredLength){ } } - private boolean validateVersion(String versionName, String actualVersionStr, String requriedVersionStr) { + private boolean validateVersion(Info info, String requriedVersionStr) { boolean isValid = true; - try { + String actualVersionStr = parseInfo(info.output); + try { ArrayList accVer = versionStr2ArrList(actualVersionStr); ArrayList reqVer = versionStr2ArrList(requriedVersionStr); int accVerLen = accVer.size(); @@ -162,11 +163,13 @@ private boolean validateVersion(String versionName, String actualVersionStr, Str } } if (!isValid) { - System.out.println("Error: required " + versionName + ": " + requriedVersionStr + ". Installed version: " + actualVersionStr); + System.out.println("Warning: required " + info.name + ": " + requriedVersionStr + ". Output:\n" + info.output); } } catch (NumberFormatException e){ - System.out.println("Warning: "+ versionName + " information cannot be extracted."); - System.out.println(versionName + " output: " + actualVersionStr); + // We need to add an option to toggle the failure or warning mode. + // isValid = false; + System.out.println("Warning: "+ info.name + " information cannot be extracted."); + System.out.println(info.name + " output: " + actualVersionStr); } return isValid; } @@ -175,13 +178,15 @@ private void validateInfo() { boolean valid = true; for (Info info : infoMap.values()) { if (info.req != null) { - String version = parseInfo(info.output); - valid &= validateVersion(info.name, version, info.req); + valid &= validateVersion(info, info.req); } } - if (!valid) { - System.exit(1); - } + + // Do not fail if the check not pass for the build environment. + // We need to add an option to toggle the failure or warning mode. + // if (!valid) { + // System.exit(1); + //} } private void getSysInfo() {