aoqi@0: /* aoqi@0: * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: */ aoqi@0: aoqi@0: /* aoqi@0: * @test aoqi@0: * @bug 8006263 aoqi@0: * @summary Supplementary test cases needed for doclint aoqi@0: */ aoqi@0: aoqi@0: import com.sun.tools.doclint.DocLint; aoqi@0: import com.sun.tools.doclint.DocLint.BadArgs; aoqi@0: import java.io.File; aoqi@0: import java.io.FileWriter; aoqi@0: import java.io.IOException; aoqi@0: import java.io.PrintWriter; aoqi@0: import java.io.StringWriter; aoqi@0: import java.util.regex.Pattern; aoqi@0: aoqi@0: public class PathsTest { aoqi@0: public static void main(String... args) throws Exception { aoqi@0: new PathsTest().run(); aoqi@0: } aoqi@0: aoqi@0: void run() throws Exception { aoqi@0: String PS = File.pathSeparator; aoqi@0: writeFile("src1/p/A.java", aoqi@0: "package p; public class A { }"); aoqi@0: compile("-d", "classes1", "src1/p/A.java"); aoqi@0: aoqi@0: writeFile("src2/q/B.java", aoqi@0: "package q; public class B extends p.A { }"); aoqi@0: compile("-d", "classes2", "-classpath", "classes1", "src2/q/B.java"); aoqi@0: aoqi@0: writeFile("src/Test.java", aoqi@0: "/** &0; */ class Test extends q.B { }"); aoqi@0: aoqi@0: test("src/Test.java", "-sourcepath", "src1" + PS + "src2"); aoqi@0: test("src/Test.java", "-classpath", "classes1" + PS + "classes2"); aoqi@0: String sysBootClassPath = System.getProperty("sun.boot.class.path"); aoqi@0: test("src/Test.java", "-bootclasspath", aoqi@0: sysBootClassPath + PS + "classes1" + PS + "classes2"); aoqi@0: aoqi@0: if (errors > 0) aoqi@0: throw new Exception(errors + " errors found"); aoqi@0: } aoqi@0: aoqi@0: Pattern pkgNotFound = Pattern.compile("package [a-z]+ does not exist"); aoqi@0: Pattern badHtmlEntity = Pattern.compile("bad HTML entity"); aoqi@0: aoqi@0: void test(String file, String pathOpt, String path) throws BadArgs, IOException { aoqi@0: System.err.println("test " + pathOpt); aoqi@0: String out1 = doclint("-Xmsgs", file); aoqi@0: if (!pkgNotFound.matcher(out1).find()) aoqi@0: error("message not found: " + pkgNotFound); aoqi@0: aoqi@0: String out2 = doclint("-Xmsgs", pathOpt, path, file); aoqi@0: if (pkgNotFound.matcher(out2).find()) aoqi@0: error("unexpected message found: " + pkgNotFound); aoqi@0: if (!badHtmlEntity.matcher(out1).find()) aoqi@0: error("message not found: " + badHtmlEntity); aoqi@0: aoqi@0: try { aoqi@0: doclint("-Xmsgs", pathOpt); aoqi@0: error("expected exception not thrown"); aoqi@0: } catch (BadArgs e) { aoqi@0: System.err.println(e); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: void compile(String... args) { aoqi@0: for (int i = 0; i < args.length; i++) { aoqi@0: if (args[i].equals("-d")) { aoqi@0: new File(args[++i]).mkdirs(); aoqi@0: break; aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: StringWriter sw = new StringWriter(); aoqi@0: PrintWriter pw = new PrintWriter(sw); aoqi@0: int rc = com.sun.tools.javac.Main.compile(args, pw); aoqi@0: pw.close(); aoqi@0: String out = sw.toString(); aoqi@0: if (!out.isEmpty()) aoqi@0: System.err.println(out); aoqi@0: if (rc != 0) aoqi@0: error("compilation failed: rc=" + rc); aoqi@0: } aoqi@0: aoqi@0: String doclint(String... args) throws BadArgs, IOException { aoqi@0: StringWriter sw = new StringWriter(); aoqi@0: PrintWriter pw = new PrintWriter(sw); aoqi@0: DocLint dl = new DocLint(); aoqi@0: dl.run(pw, args); aoqi@0: pw.close(); aoqi@0: String out = sw.toString(); aoqi@0: if (!out.isEmpty()) aoqi@0: System.err.println(out); aoqi@0: return out; aoqi@0: } aoqi@0: aoqi@0: File writeFile(String path, String body) throws IOException { aoqi@0: File f = new File(path); aoqi@0: f.getParentFile().mkdirs(); aoqi@0: try (FileWriter fw = new FileWriter(path)) { aoqi@0: fw.write(body); aoqi@0: } aoqi@0: return f; aoqi@0: } aoqi@0: aoqi@0: void error(String msg) { aoqi@0: System.err.println("Error: " + msg); aoqi@0: errors++; aoqi@0: } aoqi@0: aoqi@0: int errors; aoqi@0: }