test/testlibrary/com/oracle/java/testlibrary/ProcessTools.java

Print this page

        

*** 29,38 **** --- 29,39 ---- import java.lang.management.RuntimeMXBean; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Collections; + import java.util.List; import sun.management.VMManagement; public final class ProcessTools {
*** 105,123 **** return pid; } /** * Get platform specific VM arguments (e.g. -d64 on 64bit Solaris) * * @return String[] with platform specific arguments, empty if there are none */ public static String[] getPlatformSpecificVMArgs() { - String osName = System.getProperty("os.name"); - String dataModel = System.getProperty("sun.arch.data.model"); ! if (osName.equals("SunOS") && dataModel.equals("64")) { return new String[] { "-d64" }; } return new String[] {}; } --- 106,138 ---- return pid; } /** + * Get the string containing input arguments passed to the VM + * + * @return arguments + */ + public static String getVmInputArguments() { + RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean(); + + List<String> args = runtime.getInputArguments(); + StringBuilder result = new StringBuilder(); + for (String arg : args) + result.append(arg).append(' '); + + return result.toString(); + } + + /** * Get platform specific VM arguments (e.g. -d64 on 64bit Solaris) * * @return String[] with platform specific arguments, empty if there are none */ public static String[] getPlatformSpecificVMArgs() { ! if (Platform.is64bit() && Platform.isSolaris()) { return new String[] { "-d64" }; } return new String[] {}; }
*** 132,141 **** ArrayList<String> args = new ArrayList<>(); args.add(javapath); Collections.addAll(args, getPlatformSpecificVMArgs()); Collections.addAll(args, command); ! return new ProcessBuilder(args.toArray(new String[args.size()])); } } --- 147,161 ---- ArrayList<String> args = new ArrayList<>(); args.add(javapath); Collections.addAll(args, getPlatformSpecificVMArgs()); Collections.addAll(args, command); ! // Reporting ! StringBuilder cmdLine = new StringBuilder(); ! for (String cmd : args) ! cmdLine.append(cmd).append(' '); ! System.out.println("Command line: [" + cmdLine.toString() + "]"); + return new ProcessBuilder(args.toArray(new String[args.size()])); } }