author | katleman |
Thu, 21 Aug 2014 14:16:14 -0700 | |
changeset 25878 | 6d561031123e |
parent 5520 | 86e4b9a9da40 |
child 30730 | d3ce7619db2c |
permissions | -rw-r--r-- |
5319
63dc7f367a37
6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff
changeset
|
1 |
/* |
5520 | 2 |
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. |
5319
63dc7f367a37
6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
63dc7f367a37
6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff
changeset
|
4 |
* |
63dc7f367a37
6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
63dc7f367a37
6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
63dc7f367a37
6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
63dc7f367a37
6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff
changeset
|
8 |
* |
63dc7f367a37
6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
63dc7f367a37
6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
63dc7f367a37
6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
63dc7f367a37
6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
63dc7f367a37
6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff
changeset
|
13 |
* accompanied this code). |
63dc7f367a37
6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff
changeset
|
14 |
* |
63dc7f367a37
6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
63dc7f367a37
6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
63dc7f367a37
6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
63dc7f367a37
6942649: add hidden option to identify location and version of javac classes
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. |
|
5319
63dc7f367a37
6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff
changeset
|
22 |
*/ |
63dc7f367a37
6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff
changeset
|
23 |
|
63dc7f367a37
6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff
changeset
|
24 |
|
63dc7f367a37
6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff
changeset
|
25 |
/* |
63dc7f367a37
6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff
changeset
|
26 |
* @test |
63dc7f367a37
6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff
changeset
|
27 |
* @bug 6942649 |
63dc7f367a37
6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff
changeset
|
28 |
* @summary add hidden option to identify location and version of javac classes |
63dc7f367a37
6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff
changeset
|
29 |
*/ |
63dc7f367a37
6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff
changeset
|
30 |
|
63dc7f367a37
6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff
changeset
|
31 |
import java.io.*; |
63dc7f367a37
6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff
changeset
|
32 |
|
63dc7f367a37
6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff
changeset
|
33 |
public class T6942649 { |
63dc7f367a37
6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff
changeset
|
34 |
public static void main(String... args) throws Exception { |
63dc7f367a37
6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff
changeset
|
35 |
new T6942649().run(); |
63dc7f367a37
6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff
changeset
|
36 |
} |
63dc7f367a37
6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff
changeset
|
37 |
|
63dc7f367a37
6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff
changeset
|
38 |
void run() throws Exception { |
63dc7f367a37
6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff
changeset
|
39 |
test("-XDshowClass", "com.sun.tools.javac.Main"); |
63dc7f367a37
6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff
changeset
|
40 |
test("-XDshowClass=com.sun.tools.javac.util.Log", "com.sun.tools.javac.util.Log"); |
63dc7f367a37
6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff
changeset
|
41 |
} |
63dc7f367a37
6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff
changeset
|
42 |
|
63dc7f367a37
6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff
changeset
|
43 |
void test(String opt, String clazz) throws Exception { |
63dc7f367a37
6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff
changeset
|
44 |
System.err.println("test " + opt); |
63dc7f367a37
6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff
changeset
|
45 |
StringWriter sw = new StringWriter(); |
63dc7f367a37
6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff
changeset
|
46 |
PrintWriter pw = new PrintWriter(sw); |
63dc7f367a37
6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff
changeset
|
47 |
int rc = com.sun.tools.javac.Main.compile(new String[] { opt }, pw); |
63dc7f367a37
6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff
changeset
|
48 |
pw.close(); |
63dc7f367a37
6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff
changeset
|
49 |
String out = sw.toString(); |
63dc7f367a37
6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff
changeset
|
50 |
System.err.println("javac rc=" + rc + "\n" + out); |
63dc7f367a37
6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff
changeset
|
51 |
if (!out.contains(clazz)) |
63dc7f367a37
6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff
changeset
|
52 |
throw new Exception("class name not found in output"); |
63dc7f367a37
6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff
changeset
|
53 |
int lastDot = clazz.lastIndexOf("."); |
63dc7f367a37
6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff
changeset
|
54 |
if (!out.contains(clazz.substring(lastDot + 1) + ".class")) |
63dc7f367a37
6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff
changeset
|
55 |
throw new Exception("location of class not found in output"); |
63dc7f367a37
6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff
changeset
|
56 |
if (!out.contains("MD5 checksum: ")) |
63dc7f367a37
6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff
changeset
|
57 |
throw new Exception("checksum not found in output"); |
63dc7f367a37
6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff
changeset
|
58 |
} |
63dc7f367a37
6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff
changeset
|
59 |
} |