2014-11-18 15:20:16 +00:00
|
|
|
/*
|
2015-11-23 19:49:04 +00:00
|
|
|
* Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
|
2014-11-18 15:20:16 +00:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
|
|
*
|
|
|
|
* This code is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License version 2 only, as
|
|
|
|
* published by the Free Software Foundation. Oracle designates this
|
|
|
|
* particular file as subject to the "Classpath" exception as provided
|
|
|
|
* by Oracle in the LICENSE file that accompanied this code.
|
|
|
|
*
|
|
|
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* version 2 for more details (a copy is included in the LICENSE file that
|
|
|
|
* accompanied this code).
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License version
|
|
|
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
|
|
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
|
|
* or visit www.oracle.com if you need additional information or have any
|
|
|
|
* questions.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
|
|
|
import jdk.testlibrary.JDKToolLauncher;
|
|
|
|
import jdk.testlibrary.OutputAnalyzer;
|
|
|
|
import jdk.testlibrary.ProcessTools;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The helper class for running jinfo utility.
|
|
|
|
*/
|
|
|
|
public final class JInfoHelper {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Print configuration information for the current process
|
|
|
|
*
|
|
|
|
* @param toolArgs List of jinfo options
|
|
|
|
*/
|
|
|
|
public static OutputAnalyzer jinfo(String... toolArgs) throws Exception {
|
|
|
|
return jinfo(true, toolArgs);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Print usage information
|
|
|
|
*
|
|
|
|
* @param toolArgs List of jinfo options
|
|
|
|
*/
|
|
|
|
public static OutputAnalyzer jinfoNoPid(String... toolArgs) throws Exception {
|
|
|
|
return jinfo(false, toolArgs);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static OutputAnalyzer jinfo(boolean toPid, String... toolArgs) throws Exception {
|
|
|
|
JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jinfo");
|
|
|
|
if (toolArgs != null) {
|
|
|
|
for (String toolArg : toolArgs) {
|
|
|
|
launcher.addToolArg(toolArg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (toPid) {
|
2015-11-23 19:49:04 +00:00
|
|
|
launcher.addToolArg(Long.toString(ProcessTools.getProcessId()));
|
2014-11-18 15:20:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ProcessBuilder processBuilder = new ProcessBuilder(launcher.getCommand());
|
|
|
|
System.out.println(Arrays.toString(processBuilder.command().toArray()).replace(",", ""));
|
|
|
|
OutputAnalyzer output = ProcessTools.executeProcess(processBuilder);
|
|
|
|
System.out.println(output.getOutput());
|
|
|
|
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|