6937318: jdk7 b86: javah and javah -help is no output for these commands
Reviewed-by: darcy
This commit is contained in:
parent
624b674ca3
commit
8ef8d879e4
@ -318,12 +318,6 @@ public class JavahTask implements NativeHeaderTool.NativeHeaderTask {
|
||||
int run(String[] args) {
|
||||
try {
|
||||
handleOptions(args);
|
||||
if (classes == null || classes.size() == 0) {
|
||||
if (help || version || fullVersion)
|
||||
return 0;
|
||||
else
|
||||
return 1;
|
||||
}
|
||||
boolean ok = run();
|
||||
return ok ? 0 : 1;
|
||||
} catch (BadArgs e) {
|
||||
@ -355,7 +349,7 @@ public class JavahTask implements NativeHeaderTool.NativeHeaderTask {
|
||||
fileManager = getDefaultFileManager(diagnosticListener, log);
|
||||
|
||||
Iterator<String> iter = args.iterator();
|
||||
boolean noArgs = !iter.hasNext();
|
||||
noArgs = !iter.hasNext();
|
||||
|
||||
while (iter.hasNext()) {
|
||||
String arg = iter.next();
|
||||
@ -416,9 +410,9 @@ public class JavahTask implements NativeHeaderTool.NativeHeaderTask {
|
||||
|
||||
Util util = new Util(log, diagnosticListener);
|
||||
|
||||
if (help) {
|
||||
if (noArgs || help) {
|
||||
showHelp();
|
||||
return true;
|
||||
return help; // treat noArgs as an error for purposes of exit code
|
||||
}
|
||||
|
||||
if (version || fullVersion) {
|
||||
@ -636,6 +630,7 @@ public class JavahTask implements NativeHeaderTool.NativeHeaderTask {
|
||||
String usercp;
|
||||
List<String> classes;
|
||||
boolean verbose;
|
||||
boolean noArgs;
|
||||
boolean help;
|
||||
boolean trace;
|
||||
boolean version;
|
||||
|
@ -23,7 +23,7 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 6893943
|
||||
* @bug 6893943 6937318
|
||||
* @summary exit code from javah with no args is 0
|
||||
*/
|
||||
|
||||
@ -31,22 +31,32 @@ import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
public class T6893943 {
|
||||
static final String[] NO_ARGS = { };
|
||||
static final String[] HELP = { "-help" };
|
||||
static final String NEWLINE = System.getProperty("line.separator");
|
||||
|
||||
public static void main(String... args) throws Exception {
|
||||
new T6893943().run();
|
||||
}
|
||||
|
||||
void run() throws Exception {
|
||||
testSimpleAPI();
|
||||
testCommand();
|
||||
testSimpleAPI(NO_ARGS, 1);
|
||||
testSimpleAPI(HELP, 0);
|
||||
testCommand(NO_ARGS, 1);
|
||||
testCommand(HELP, 0);
|
||||
}
|
||||
|
||||
void testSimpleAPI() throws Exception {
|
||||
PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.err));
|
||||
int rc = com.sun.tools.javah.Main.run(new String[] { }, pw);
|
||||
expect("testSimpleAPI", rc, 1);
|
||||
void testSimpleAPI(String[] args, int expect_rc) throws Exception {
|
||||
System.err.println("Test simple api: " + Arrays.asList(args));
|
||||
StringWriter sw = new StringWriter();
|
||||
PrintWriter pw = new PrintWriter(sw);
|
||||
int rc = com.sun.tools.javah.Main.run(args, pw);
|
||||
pw.close();
|
||||
expect("testSimpleAPI", sw.toString(), rc, expect_rc);
|
||||
}
|
||||
|
||||
void testCommand() throws Exception {
|
||||
void testCommand(String[] args, int expect_rc) throws Exception {
|
||||
System.err.println("Test command: " + Arrays.asList(args));
|
||||
File javaHome = new File(System.getProperty("java.home"));
|
||||
if (javaHome.getName().equals("jre"))
|
||||
javaHome = javaHome.getParentFile();
|
||||
@ -54,22 +64,32 @@ public class T6893943 {
|
||||
List<String> command = new ArrayList<String>();
|
||||
command.add(new File(new File(javaHome, "bin"), "javah").getPath());
|
||||
command.add("-J-Xbootclasspath:" + System.getProperty("sun.boot.class.path"));
|
||||
command.addAll(Arrays.asList(args));
|
||||
//System.err.println("command: " + command);
|
||||
|
||||
ProcessBuilder pb = new ProcessBuilder(command);
|
||||
pb.redirectErrorStream(true);
|
||||
Process p = pb.start();
|
||||
p.getOutputStream().close();
|
||||
StringWriter sw = new StringWriter();
|
||||
String line;
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
|
||||
while ((line = in.readLine()) != null)
|
||||
System.err.println("javah: " + line);
|
||||
sw.write(line + NEWLINE);
|
||||
int rc = p.waitFor();
|
||||
expect("testCommand", rc, 1);
|
||||
expect("testCommand", sw.toString(), rc, expect_rc);
|
||||
}
|
||||
|
||||
void expect(String name, int actual, int expect) throws Exception {
|
||||
if (actual != expect)
|
||||
throw new Exception(name + ": unexpected exit: " + actual + ", expected: " + expect);
|
||||
void expect(String name, String out, int actual_rc, int expect_rc) throws Exception {
|
||||
if (out.isEmpty())
|
||||
throw new Exception("No output from javah");
|
||||
|
||||
if (!out.startsWith("Usage:")) {
|
||||
System.err.println(out);
|
||||
throw new Exception("Unexpected output from javah");
|
||||
}
|
||||
|
||||
if (actual_rc != expect_rc)
|
||||
throw new Exception(name + ": unexpected exit: " + actual_rc + ", expected: " + expect_rc);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user