author | katleman |
Thu, 21 Aug 2014 14:16:14 -0700 | |
changeset 25878 | 6d561031123e |
parent 7681 | 1f0819a3341f |
child 30730 | d3ce7619db2c |
permissions | -rw-r--r-- |
858
3081a24a8223
6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff
changeset
|
1 |
/* |
7681 | 2 |
* Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. |
858
3081a24a8223
6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3081a24a8223
6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff
changeset
|
4 |
* |
3081a24a8223
6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
3081a24a8223
6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
3081a24a8223
6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
3081a24a8223
6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff
changeset
|
8 |
* |
3081a24a8223
6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
3081a24a8223
6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
3081a24a8223
6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
3081a24a8223
6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
3081a24a8223
6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff
changeset
|
13 |
* accompanied this code). |
3081a24a8223
6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff
changeset
|
14 |
* |
3081a24a8223
6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
3081a24a8223
6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
3081a24a8223
6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
3081a24a8223
6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff
changeset
|
18 |
* |
5520 | 19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
858
3081a24a8223
6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff
changeset
|
22 |
*/ |
3081a24a8223
6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff
changeset
|
23 |
|
3081a24a8223
6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff
changeset
|
24 |
import java.io.*; |
3081a24a8223
6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff
changeset
|
25 |
import java.util.*; |
3081a24a8223
6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff
changeset
|
26 |
|
3081a24a8223
6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff
changeset
|
27 |
/* |
3081a24a8223
6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff
changeset
|
28 |
* @test |
3081a24a8223
6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff
changeset
|
29 |
* @bug 6715251 |
3081a24a8223
6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff
changeset
|
30 |
* @summary javap should be consistent with javac and return 2 if given no arguments |
3081a24a8223
6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff
changeset
|
31 |
*/ |
3081a24a8223
6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff
changeset
|
32 |
|
3081a24a8223
6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff
changeset
|
33 |
public class T6715251 { |
3081a24a8223
6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff
changeset
|
34 |
public static void main(String... args) throws Exception { |
3081a24a8223
6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff
changeset
|
35 |
new T6715251().run(); |
3081a24a8223
6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff
changeset
|
36 |
} |
3081a24a8223
6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff
changeset
|
37 |
|
3081a24a8223
6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff
changeset
|
38 |
void run() throws Exception { |
3081a24a8223
6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff
changeset
|
39 |
String testClasses = System.getProperty("test.classes", "."); |
3081a24a8223
6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff
changeset
|
40 |
|
3081a24a8223
6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff
changeset
|
41 |
test(2); |
3081a24a8223
6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff
changeset
|
42 |
test(0, "-help"); |
3081a24a8223
6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff
changeset
|
43 |
test(0, "-version"); |
3081a24a8223
6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff
changeset
|
44 |
test(0, "-fullversion"); |
3081a24a8223
6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff
changeset
|
45 |
test(0, "-classpath", testClasses, "T6715251"); |
3081a24a8223
6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff
changeset
|
46 |
|
3081a24a8223
6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff
changeset
|
47 |
if (errors > 0) |
3081a24a8223
6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff
changeset
|
48 |
throw new Exception(errors + " errors received"); |
3081a24a8223
6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff
changeset
|
49 |
} |
3081a24a8223
6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff
changeset
|
50 |
|
3081a24a8223
6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff
changeset
|
51 |
void test(int expect, String ... args) { |
3081a24a8223
6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff
changeset
|
52 |
int rc = javap(args); |
3081a24a8223
6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff
changeset
|
53 |
if (rc != expect) |
3081a24a8223
6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff
changeset
|
54 |
error("bad result: expected: " + expect + ", found " + rc + "\n" |
3081a24a8223
6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff
changeset
|
55 |
+ log); |
3081a24a8223
6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff
changeset
|
56 |
|
3081a24a8223
6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff
changeset
|
57 |
} |
3081a24a8223
6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff
changeset
|
58 |
|
3081a24a8223
6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff
changeset
|
59 |
int javap(String... args) { |
3081a24a8223
6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff
changeset
|
60 |
StringWriter sw = new StringWriter(); |
3081a24a8223
6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff
changeset
|
61 |
PrintWriter pw = new PrintWriter(sw); |
3081a24a8223
6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff
changeset
|
62 |
int rc = com.sun.tools.javap.Main.run(args, pw); |
3081a24a8223
6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff
changeset
|
63 |
log = sw.toString(); |
3081a24a8223
6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff
changeset
|
64 |
return rc; |
3081a24a8223
6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff
changeset
|
65 |
} |
3081a24a8223
6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff
changeset
|
66 |
|
3081a24a8223
6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff
changeset
|
67 |
void error(String msg) { |
3081a24a8223
6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff
changeset
|
68 |
System.err.println(msg); |
3081a24a8223
6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff
changeset
|
69 |
errors++; |
3081a24a8223
6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff
changeset
|
70 |
} |
3081a24a8223
6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff
changeset
|
71 |
|
3081a24a8223
6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff
changeset
|
72 |
String log; |
3081a24a8223
6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff
changeset
|
73 |
int errors; |
5213 | 74 |
} |