|
1 /* |
|
2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 * |
|
5 * This code is free software; you can redistribute it and/or modify it |
|
6 * under the terms of the GNU General Public License version 2 only, as |
|
7 * published by the Free Software Foundation. |
|
8 * |
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
|
13 * accompanied this code). |
|
14 * |
|
15 * You should have received a copy of the GNU General Public License version |
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 * |
|
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. |
|
22 */ |
|
23 |
|
24 /* |
|
25 * @test |
|
26 * @bug 8025693 |
|
27 * @summary javadoc should ignore <clinit> methods found in classes on classpath |
|
28 */ |
|
29 |
|
30 import java.io.*; |
|
31 |
|
32 public class Test { |
|
33 public static void main(String[] args) throws Exception { |
|
34 new Test().run(); |
|
35 } |
|
36 |
|
37 final File baseFile = new File("src/Base.java"); |
|
38 final String baseText = |
|
39 "package p;\n" + |
|
40 "public class Base { static { } }\n"; |
|
41 |
|
42 final File srcFile = new File("src/C.java"); |
|
43 final String srcText = |
|
44 "package p;\n" + |
|
45 "/** comment */\n" + |
|
46 "public abstract class C extends Base { }\n"; |
|
47 |
|
48 void run() throws Exception { |
|
49 File classesDir = new File("classes"); |
|
50 classesDir.mkdirs(); |
|
51 writeFile(baseFile, baseText); |
|
52 String[] javacArgs = { |
|
53 "-d", classesDir.getPath(), |
|
54 baseFile.getPath() |
|
55 }; |
|
56 com.sun.tools.javac.Main.compile(javacArgs); |
|
57 |
|
58 writeFile(srcFile, srcText); |
|
59 String[] args = { |
|
60 "-d", "api", |
|
61 "-classpath", classesDir.getPath(), |
|
62 "-package", "p", |
|
63 srcFile.getPath() |
|
64 }; |
|
65 |
|
66 ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
|
67 PrintStream ps = new PrintStream(baos); |
|
68 PrintStream prev = System.err; |
|
69 System.setErr(ps); |
|
70 try { |
|
71 int rc = com.sun.tools.javadoc.Main.execute(args); |
|
72 } finally { |
|
73 System.err.flush(); |
|
74 System.setErr(prev); |
|
75 } |
|
76 String out = baos.toString(); |
|
77 System.out.println(out); |
|
78 |
|
79 String errorMessage = "java.lang.IllegalArgumentException: <clinit>"; |
|
80 if (out.contains(errorMessage)) |
|
81 throw new Exception("error message found: " + errorMessage); |
|
82 } |
|
83 |
|
84 void writeFile(File file, String body) throws IOException { |
|
85 file.getParentFile().mkdirs(); |
|
86 try (FileWriter out = new FileWriter(file)) { |
|
87 out.write(body); |
|
88 } |
|
89 } |
|
90 } |
|
91 |