6942366: javadoc no longer inherits doc from sourcepath

Tue, 23 Nov 2010 13:32:29 -0800

author
jjg
date
Tue, 23 Nov 2010 13:32:29 -0800
changeset 754
285896f2227a
parent 753
2536dedd897e
child 755
79d0c48d361e

6942366: javadoc no longer inherits doc from sourcepath
Reviewed-by: mcimadamore

src/share/classes/com/sun/tools/javadoc/JavadocClassReader.java file | annotate | diff | comparison | revisions
test/tools/javadoc/6942366/T6942366.java file | annotate | diff | comparison | revisions
test/tools/javadoc/6942366/Test.java file | annotate | diff | comparison | revisions
test/tools/javadoc/6942366/p/Base.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/classes/com/sun/tools/javadoc/JavadocClassReader.java	Tue Nov 23 11:08:43 2010 +0000
     1.2 +++ b/src/share/classes/com/sun/tools/javadoc/JavadocClassReader.java	Tue Nov 23 13:32:29 2010 -0800
     1.3 @@ -62,6 +62,7 @@
     1.4      private JavadocClassReader(Context context) {
     1.5          super(context, true);
     1.6          docenv = DocEnv.instance(context);
     1.7 +        preferSource = true;
     1.8      }
     1.9  
    1.10      /**
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/test/tools/javadoc/6942366/T6942366.java	Tue Nov 23 13:32:29 2010 -0800
     2.3 @@ -0,0 +1,134 @@
     2.4 +/*
     2.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
     2.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     2.7 + *
     2.8 + * This code is free software; you can redistribute it and/or modify it
     2.9 + * under the terms of the GNU General Public License version 2 only, as
    2.10 + * published by the Free Software Foundation.
    2.11 + *
    2.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    2.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    2.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    2.15 + * version 2 for more details (a copy is included in the LICENSE file that
    2.16 + * accompanied this code).
    2.17 + *
    2.18 + * You should have received a copy of the GNU General Public License version
    2.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    2.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    2.21 + *
    2.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    2.23 + * or visit www.oracle.com if you need additional information or have any
    2.24 + * questions.
    2.25 + */
    2.26 +
    2.27 +/*
    2.28 + * @test
    2.29 + * @bug 6942366
    2.30 + * @summary javadoc no longer inherits doc from sourcepath
    2.31 + * @build p.Base Test
    2.32 + * @run main T6942366
    2.33 + */
    2.34 +
    2.35 +import java.io.*;
    2.36 +import java.util.*;
    2.37 +
    2.38 +public class T6942366 {
    2.39 +    public static void main(String... args) throws Exception {
    2.40 +        new T6942366().run();
    2.41 +    }
    2.42 +
    2.43 +    File testSrc;
    2.44 +    File testClasses;
    2.45 +    int count;
    2.46 +    int errors;
    2.47 +
    2.48 +    void run() throws Exception {
    2.49 +        testSrc = new File(System.getProperty("test.src"));
    2.50 +        testClasses = new File(System.getProperty("test.classes"));
    2.51 +
    2.52 +        test(true,  false);
    2.53 +        test(false, true);
    2.54 +        test(true,  true);
    2.55 +
    2.56 +        if (errors > 0)
    2.57 +            throw new Exception(errors + " errors found");
    2.58 +    }
    2.59 +
    2.60 +    void test(boolean useSourcePath, boolean useClassPath) throws Exception {
    2.61 +        System.out.println("test " + (++count) + " sp:" + useSourcePath + " cp:" + useClassPath);
    2.62 +        File testDir = new File("test" + count);
    2.63 +        testDir.mkdirs();
    2.64 +
    2.65 +        List<String> args = new ArrayList<String>();
    2.66 +        //args.add("-verbose");
    2.67 +        args.add("-d");
    2.68 +        args.add(testDir.getPath());
    2.69 +        if (useSourcePath) {
    2.70 +            args.add("-sourcepath");
    2.71 +            args.add(testSrc.getPath());
    2.72 +        }
    2.73 +        if (useClassPath) {
    2.74 +            args.add("-classpath");
    2.75 +            args.add(testClasses.getPath());
    2.76 +        } else {
    2.77 +            // override classpath to avoid stuff jtreg might have put on papth
    2.78 +            args.add("-classpath");
    2.79 +            args.add(".");
    2.80 +        }
    2.81 +
    2.82 +        // use a very simple bootclasspath to avoid stuff jtreg might have put on path
    2.83 +        File javaHome = new File(System.getProperty("java.home"));
    2.84 +        File rt_jar = new File(javaHome, "lib/rt.jar");
    2.85 +        if (!rt_jar.exists())
    2.86 +            throw new Exception("rt.jar not found");
    2.87 +        args.add("-bootclasspath");
    2.88 +        args.add(rt_jar.getPath());
    2.89 +
    2.90 +        args.add(new File(testSrc, "Test.java").getPath());
    2.91 +        System.out.println("javadoc: " + args);
    2.92 +
    2.93 +        int rc = com.sun.tools.javadoc.Main.execute(args.toArray(new String[args.size()]));
    2.94 +        if (rc != 0)
    2.95 +            throw new Exception("unexpected exit from javadoc, rc=" + rc);
    2.96 +
    2.97 +        if (useSourcePath && useClassPath) {
    2.98 +            long srcLastMod = new File(testSrc, "Test.java").lastModified();
    2.99 +            long classLastMod = new File(testClasses, "Test.class").lastModified();
   2.100 +            System.out.println("Test.java last modified:  " + new Date(srcLastMod));
   2.101 +            System.out.println("Test.class last modified: " + new Date(classLastMod));
   2.102 +            System.out.println((srcLastMod > classLastMod ? "source" : "class") + " is newer");
   2.103 +        }
   2.104 +
   2.105 +        String s = "javadoc-for-Base.m";
   2.106 +        boolean expect = useSourcePath;
   2.107 +        boolean found = contains(new File(testDir, "Test.html"), s);
   2.108 +        if (found) {
   2.109 +            if (expect)
   2.110 +                System.out.println("javadoc content \"" + s + "\" found, as expected");
   2.111 +            else
   2.112 +                error("javadoc content \"" + s + "\" found unexpectedly");
   2.113 +        } else {
   2.114 +            if (expect)
   2.115 +                error("javadoc content \"" + s + "\" not found");
   2.116 +            else
   2.117 +                System.out.println("javadoc content \"" + s + "\" not found, as expected");
   2.118 +        }
   2.119 +
   2.120 +        System.out.println();
   2.121 +    }
   2.122 +
   2.123 +    boolean contains(File f, String s) throws Exception {
   2.124 +        byte[] buf = new byte[(int) f.length()];
   2.125 +        try (DataInputStream in = new DataInputStream(new FileInputStream(f))) {
   2.126 +            in.readFully(buf);
   2.127 +        }
   2.128 +        return new String(buf).contains(s);
   2.129 +    }
   2.130 +
   2.131 +    void error(String msg) {
   2.132 +        System.out.println("Error: " + msg);
   2.133 +        errors++;
   2.134 +    }
   2.135 +
   2.136 +}
   2.137 +
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/test/tools/javadoc/6942366/Test.java	Tue Nov 23 13:32:29 2010 -0800
     3.3 @@ -0,0 +1,28 @@
     3.4 +/*
     3.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
     3.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3.7 + *
     3.8 + * This code is free software; you can redistribute it and/or modify it
     3.9 + * under the terms of the GNU General Public License version 2 only, as
    3.10 + * published by the Free Software Foundation.
    3.11 + *
    3.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    3.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    3.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    3.15 + * version 2 for more details (a copy is included in the LICENSE file that
    3.16 + * accompanied this code).
    3.17 + *
    3.18 + * You should have received a copy of the GNU General Public License version
    3.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    3.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    3.21 + *
    3.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    3.23 + * or visit www.oracle.com if you need additional information or have any
    3.24 + * questions.
    3.25 + */
    3.26 +
    3.27 +public class Test extends p.Base {
    3.28 +    // overrides Base.m
    3.29 +    public void m() { }
    3.30 +}
    3.31 +
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/test/tools/javadoc/6942366/p/Base.java	Tue Nov 23 13:32:29 2010 -0800
     4.3 @@ -0,0 +1,30 @@
     4.4 +/*
     4.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
     4.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4.7 + *
     4.8 + * This code is free software; you can redistribute it and/or modify it
     4.9 + * under the terms of the GNU General Public License version 2 only, as
    4.10 + * published by the Free Software Foundation.
    4.11 + *
    4.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    4.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    4.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    4.15 + * version 2 for more details (a copy is included in the LICENSE file that
    4.16 + * accompanied this code).
    4.17 + *
    4.18 + * You should have received a copy of the GNU General Public License version
    4.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    4.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    4.21 + *
    4.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    4.23 + * or visit www.oracle.com if you need additional information or have any
    4.24 + * questions.
    4.25 + */
    4.26 +
    4.27 +package p;
    4.28 +
    4.29 +public class Base {
    4.30 +    /** javadoc-for-Base.m. */
    4.31 +    public void m() { }
    4.32 +}
    4.33 +

mercurial