Skip to content

Commit 516ca91

Browse files
llxiapshipton
authored andcommitted
Add machine info detection
[ci skip] Signed-off-by: lanxia <[email protected]>
1 parent 6a35610 commit 516ca91

File tree

4 files changed

+359
-41
lines changed

4 files changed

+359
-41
lines changed

test/TestConfig/src/build_envInfo.xml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,26 +46,27 @@
4646
<jar jarfile="./EnvDetector.jar" filesonly="true">
4747
<fileset dir="${build}"/>
4848
<manifest>
49-
<attribute name="Main-Class" value="org.openj9.java.EnvDetector"/>
49+
<attribute name="Main-Class" value="org.openj9.envInfo.EnvDetector"/>
5050
</manifest>
5151
</jar>
5252
</target>
5353

5454
<target name="run" depends="dist">
5555
<property name="javaexecutable.java" value="${JAVA_BIN}/java" />
56-
<java jar="./EnvDetector.jar" fork="true" failonerror="true" jvm="${javaexecutable.java}"/>
56+
<java jar="./EnvDetector.jar" fork="true" failonerror="true" jvm="${javaexecutable.java}">
57+
<arg value="JavaInfo"/>
58+
</java>
5759
</target>
5860

5961
<target name="clean" description="clean up">
62+
<delete file="../autoGenEnv.mk" />
6063
<delete dir="${build}" />
61-
<delete file="EnvDetector.jar" />
64+
<delete file="EnvDetector.jar" />
6265
</target>
6366

6467
<target name="build">
65-
<delete file="../autoGenEnv.mk" />
6668
<antcall target="clean" inheritall="true" />
6769
<antcall target="run" inheritall="true" />
68-
<antcall target="clean" inheritall="true" />
6970
</target>
7071

7172
</project>

test/TestConfig/src/org/openj9/envInfo/EnvDetector.java

Lines changed: 69 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -20,43 +20,77 @@
2020
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
2121
*******************************************************************************/
2222

23-
package org.openj9.java;
23+
package org.openj9.envInfo;
2424

25-
import java.io.*;
25+
import java.io.FileOutputStream;
26+
import java.io.OutputStreamWriter;
2627
import java.io.IOException;
27-
import java.nio.charset.StandardCharsets;
28-
import java.util.ArrayList;
29-
28+
import java.io.BufferedWriter;
3029

3130
public class EnvDetector {
32-
/**
33-
* This method create autoGenEnv.mk file for auto detecting environment.
34-
*/
35-
public static void main(String[] args) {
36-
37-
JavaInfo envDetection = new JavaInfo();
38-
String SPECInfo = envDetection.getSPEC();
39-
int javaVersionInfo = envDetection.getJDKVersion();
40-
String javaImplInfo = envDetection.getJDKImpl();
41-
if (SPECInfo == null || javaVersionInfo == -1 || javaImplInfo == null) {
42-
System.exit(1);
43-
}
44-
String SPECvalue = "DETECTED_SPEC=" + SPECInfo + "\n";
45-
String JDKVERSIONvalue = "DETECTED_JDK_VERSION="+ javaVersionInfo + "\n";
46-
String JDKIMPLvalue = "DETECTED_JDK_IMPL=" + javaImplInfo + "\n";
47-
48-
BufferedWriter output = null;
49-
try {
50-
output = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("../autoGenEnv.mk")));
51-
output.write("########################################################\n");
52-
output.write("# This is an auto generated file. Please do NOT modify!\n");
53-
output.write("########################################################\n");
54-
output.write(SPECvalue);
55-
output.write(JDKVERSIONvalue);
56-
output.write(JDKIMPLvalue);
57-
output.close();
58-
} catch ( IOException e ) {
59-
e.printStackTrace();
60-
}
61-
}
31+
static boolean isMachineInfo = false;
32+
static boolean isJavaInfo = false;
33+
34+
public static void main(String[] args) {
35+
parseArgs(args);
36+
}
37+
38+
private static void parseArgs(String[] args) {
39+
for (int i = 0; i < args.length; i++) {
40+
String option = args[i].toLowerCase();
41+
if (option.equals("machineinfo")) {
42+
getMachineInfo();
43+
} else if (option.equals("javainfo")) {
44+
getJavaInfo();
45+
}
46+
}
47+
}
48+
49+
/*
50+
* getJavaInfo() is used for AUTO_DETECT
51+
*/
52+
private static void getJavaInfo() {
53+
JavaInfo envDetection = new JavaInfo();
54+
String SPECInfo = envDetection.getSPEC();
55+
int javaVersionInfo = envDetection.getJDKVersion();
56+
String javaImplInfo = envDetection.getJDKImpl();
57+
if (SPECInfo == null || javaVersionInfo == -1 || javaImplInfo == null) {
58+
System.exit(1);
59+
}
60+
String SPECvalue = "DETECTED_SPEC=" + SPECInfo + "\n";
61+
String JDKVERSIONvalue = "DETECTED_JDK_VERSION=" + javaVersionInfo + "\n";
62+
String JDKIMPLvalue = "DETECTED_JDK_IMPL=" + javaImplInfo + "\n";
63+
64+
/**
65+
* autoGenEnv.mk file will be created to store auto detected java info.
66+
*/
67+
BufferedWriter output = null;
68+
try {
69+
output = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("../autoGenEnv.mk")));
70+
output.write("########################################################\n");
71+
output.write("# This is an auto generated file. Please do NOT modify!\n");
72+
output.write("########################################################\n");
73+
output.write(SPECvalue);
74+
output.write(JDKVERSIONvalue);
75+
output.write(JDKIMPLvalue);
76+
output.close();
77+
} catch (IOException e) {
78+
e.printStackTrace();
79+
}
80+
81+
}
82+
83+
private static void getMachineInfo() {
84+
MachineInfo machineInfo = new MachineInfo();
85+
86+
machineInfo.getMachineInfo(MachineInfo.UNAME_CMD);
87+
machineInfo.getMachineInfo(MachineInfo.SYS_ARCH_CMD);
88+
machineInfo.getMachineInfo(MachineInfo.PROC_ARCH_CMD);
89+
machineInfo.getMachineInfo(MachineInfo.SYS_OS_CMD);
90+
machineInfo.getMachineInfo(MachineInfo.CPU_CORES_CMD);
91+
92+
machineInfo.getRuntimeInfo();
93+
machineInfo.getSpaceInfo("");
94+
System.out.println(machineInfo);
95+
}
6296
}

test/TestConfig/src/org/openj9/envInfo/JavaInfo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
2121
*******************************************************************************/
2222

23-
package org.openj9.java;
23+
package org.openj9.envInfo;
2424

2525
import java.io.*;
2626
import java.io.IOException;

0 commit comments

Comments
 (0)