Skip to content

Commit

Permalink
Fix machineInfo curl validation
Browse files Browse the repository at this point in the history
- update curl version command
- switch machineInfo detection to warning mode
- processBuilder to use env copied from the parent shell environment

Signed-off-by: renfeiw <rfwang009@gmail.com>
  • Loading branch information
renfeiw committed Jul 12, 2023
1 parent 822aae9 commit 303ce0a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
8 changes: 8 additions & 0 deletions src/org/openj9/envInfo/CmdExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -36,9 +37,16 @@ public String execute(String[] commands) {
String rt = null;
try {
ProcessBuilder builder = new ProcessBuilder(Arrays.asList(commands));
Map<String, String> env = builder.environment();
// clear env and copy from the parent shell environment
env.clear();
Map<String, String> shellEnv = System.getenv();
env.putAll(shellEnv);
System.out.println(String.join(" ",builder.command().toArray(new String[0])));
builder.redirectErrorStream(true);
Process proc = builder.start();
BufferedReader stdOutput = new BufferedReader(new InputStreamReader(proc.getInputStream()));

StringBuilder sb = new StringBuilder();
String line = null;
String newline = "";
Expand Down
20 changes: 10 additions & 10 deletions src/org/openj9/envInfo/MachineInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public class MachineInfo {
public static final String[] ANT_VERSION_CMD = new String[] {"bash", "-c", "ant -version"};
public static final String[] MAKE_VERSION_CMD = new String[] {"bash", "-c", "make --version"};
public static final String[] PERL_VERSION_CMD = new String[] {"bash", "-c", "perl --version"};
public static final String[] CURL_VERSION_CMD = new String[] {"bash", "-c", "curl --version"};
public static final String[] CURL_VERSION_CMD = new String[] {"bash", "-c", "curl --version | head -n 1 | awk '{ print $2 }'"};


// Console
Expand Down Expand Up @@ -142,11 +142,12 @@ private void makeSameLength(ArrayList<Integer> list, int requiredLength){
}
}

private boolean validateVersion(String versionName, String actualVersionStr, String requriedVersionStr) {
private boolean validateVersion(Info info, String requriedVersionStr) {
boolean isValid = true;
String actualVersionStr = parseInfo(info.output);
ArrayList<Integer> accVer = versionStr2ArrList(actualVersionStr);
ArrayList<Integer> reqVer = versionStr2ArrList(requriedVersionStr);
try {
ArrayList<Integer> accVer = versionStr2ArrList(actualVersionStr);
ArrayList<Integer> reqVer = versionStr2ArrList(requriedVersionStr);
int accVerLen = accVer.size();
int reqVerLen = reqVer.size();
if (accVerLen > reqVerLen) {
Expand All @@ -162,11 +163,11 @@ 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);
System.out.println("Warning: "+ info.name + " information cannot be extracted.");
System.out.println(info.name + " output: " + actualVersionStr);
}
return isValid;
}
Expand All @@ -175,12 +176,11 @@ 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);
// System.exit(1);
}
}

Expand Down

0 comments on commit 303ce0a

Please sign in to comment.