Test.java revision 3233:b5d08bc0d224
1/* 2 * Copyright (c) 2013, 2015, 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 * @modules jdk.javadoc 29 */ 30 31import java.io.*; 32 33public class Test { 34 public static void main(String[] args) throws Exception { 35 new Test().run(); 36 } 37 38 final File baseFile = new File("src/Base.java"); 39 final String baseText = 40 "package p;\n" + 41 "public class Base { static { } }\n"; 42 43 final File srcFile = new File("src/C.java"); 44 final String srcText = 45 "package p;\n" + 46 "/** comment */\n" + 47 "public abstract class C extends Base { }\n"; 48 49 void run() throws Exception { 50 File classesDir = new File("classes"); 51 classesDir.mkdirs(); 52 writeFile(baseFile, baseText); 53 String[] javacArgs = { 54 "-d", classesDir.getPath(), 55 baseFile.getPath() 56 }; 57 com.sun.tools.javac.Main.compile(javacArgs); 58 59 writeFile(srcFile, srcText); 60 String[] args = { 61 "-d", "api", 62 "-classpath", classesDir.getPath(), 63 "-package", "p", 64 srcFile.getPath() 65 }; 66 67 ByteArrayOutputStream baos = new ByteArrayOutputStream(); 68 PrintStream ps = new PrintStream(baos); 69 PrintStream prev = System.err; 70 System.setErr(ps); 71 try { 72 int rc = com.sun.tools.javadoc.Main.execute(args); 73 } finally { 74 System.err.flush(); 75 System.setErr(prev); 76 } 77 String out = baos.toString(); 78 System.out.println(out); 79 80 String errorMessage = "java.lang.IllegalArgumentException: <clinit>"; 81 if (out.contains(errorMessage)) 82 throw new Exception("error message found: " + errorMessage); 83 } 84 85 void writeFile(File file, String body) throws IOException { 86 file.getParentFile().mkdirs(); 87 try (FileWriter out = new FileWriter(file)) { 88 out.write(body); 89 } 90 } 91} 92 93