T7091528.java revision 3294:9adfb22ff08f
1/* 2 * Copyright (c) 2009, 2016, 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 7091528 8029145 8037484 27 * @summary ensures javadoc parses unique source files and ignores all class files 28 * @modules jdk.javadoc/jdk.javadoc.internal.tool 29 * @compile p/C1.java p/q/C2.java 30 * @run main T7091528 31 */ 32 33import java.io.File; 34import java.io.PrintWriter; 35import java.io.StringWriter; 36 37public class T7091528 { 38 public static void main(String... args) { 39 new T7091528().run(); 40 } 41 void run() { 42 File testSrc = new File(System.getProperty("test.src")); 43 File testClasses = new File(System.getProperty("test.classes")); 44 // 7091528, tests if class files are being ignored 45 runTest("-d", "out-1", 46 "-sourcepath", testClasses + File.pathSeparator + testSrc, 47 "-subpackages", 48 "p"); 49 // 8029145, tests if unique source files are parsed 50 runTest("-d", "out-2", 51 "-sourcepath", testSrc.getAbsolutePath(), 52 "-subpackages", 53 "p:p.q"); 54 File testPkgDir = new File(testSrc, "p"); 55 File testFile = new File(testPkgDir, "C3.java"); 56 runTest("-d", "out-3", 57 "-sourcepath", testSrc.getAbsolutePath(), 58 testFile.getAbsolutePath()); 59 runTest("-d", "out-4", 60 "-classpath", testSrc.getAbsolutePath(), 61 testFile.getAbsolutePath()); 62 63 } 64 65 String getOutputDir(String... args) { 66 for (int i = 0; i < args.length; i++) { 67 if (args[i].equals("-d")) { 68 i++; 69 return args[i]; 70 } 71 } 72 return "."; 73 } 74 75 void runTest(String... args) { 76 String outdirname = getOutputDir(args); 77 StringWriter sw = new StringWriter(); 78 PrintWriter pw = new PrintWriter(sw); 79 int rc = jdk.javadoc.internal.tool.Main.execute(args, pw); 80 pw.close(); 81 82 String out = sw.toString(); 83 if (!out.isEmpty()) { 84 System.err.println(out); 85 } 86 87 if (rc != 0) 88 throw new Error("javadoc failed: exit code = " + rc); 89 90 if (out.matches("(?s).*p/[^ ]+\\.class.*")) 91 throw new Error("reading .class files"); 92 93 if (!new File(outdirname, "index.html").exists()) 94 throw new Error("index.html not found"); 95 } 96} 97