test/langtools/jdk/javadoc/tool/6942366/T6942366.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 36526 langtools/test/jdk/javadoc/tool/6942366/T6942366.java@3b41f1c69604
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7332
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
     1
/*
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35426
diff changeset
     2
 * Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved.
7332
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
     4
 *
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
     8
 *
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    13
 * accompanied this code).
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    14
 *
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    18
 *
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    21
 * questions.
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    22
 */
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    23
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    24
/*
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    25
 * @test
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    26
 * @bug 6942366
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    27
 * @summary javadoc no longer inherits doc from sourcepath
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35426
diff changeset
    28
 * @modules jdk.javadoc/jdk.javadoc.internal.tool
7332
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    29
 * @build p.Base Test
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    30
 * @run main T6942366
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    31
 */
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    32
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    33
import java.io.*;
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    34
import java.util.*;
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    35
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    36
public class T6942366 {
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    37
    public static void main(String... args) throws Exception {
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    38
        new T6942366().run();
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    39
    }
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    40
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    41
    File testSrc;
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    42
    File testClasses;
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    43
    int count;
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    44
    int errors;
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    45
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    46
    void run() throws Exception {
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    47
        testSrc = new File(System.getProperty("test.src"));
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    48
        testClasses = new File(System.getProperty("test.classes"));
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    49
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    50
        test(true,  false);
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    51
        test(false, true);
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    52
        test(true,  true);
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    53
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    54
        if (errors > 0)
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    55
            throw new Exception(errors + " errors found");
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    56
    }
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    57
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    58
    void test(boolean useSourcePath, boolean useClassPath) throws Exception {
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    59
        System.out.println("test " + (++count) + " sp:" + useSourcePath + " cp:" + useClassPath);
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    60
        File testDir = new File("test" + count);
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    61
        testDir.mkdirs();
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    62
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    63
        List<String> args = new ArrayList<String>();
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    64
        //args.add("-verbose");
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    65
        args.add("-d");
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    66
        args.add(testDir.getPath());
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    67
        if (useSourcePath) {
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    68
            args.add("-sourcepath");
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    69
            args.add(testSrc.getPath());
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    70
        }
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    71
        if (useClassPath) {
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    72
            args.add("-classpath");
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    73
            args.add(testClasses.getPath());
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    74
        } else {
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    75
            // override classpath to avoid stuff jtreg might have put on papth
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    76
            args.add("-classpath");
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    77
            args.add(".");
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    78
        }
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    79
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    80
        args.add(new File(testSrc, "Test.java").getPath());
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    81
        System.out.println("javadoc: " + args);
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    82
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 30730
diff changeset
    83
        int rc = jdk.javadoc.internal.tool.Main.execute(args.toArray(new String[args.size()]));
7332
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    84
        if (rc != 0)
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    85
            throw new Exception("unexpected exit from javadoc, rc=" + rc);
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    86
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    87
        if (useSourcePath && useClassPath) {
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    88
            long srcLastMod = new File(testSrc, "Test.java").lastModified();
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    89
            long classLastMod = new File(testClasses, "Test.class").lastModified();
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    90
            System.out.println("Test.java last modified:  " + new Date(srcLastMod));
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    91
            System.out.println("Test.class last modified: " + new Date(classLastMod));
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    92
            System.out.println((srcLastMod > classLastMod ? "source" : "class") + " is newer");
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    93
        }
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    94
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    95
        String s = "javadoc-for-Base.m";
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    96
        boolean expect = useSourcePath;
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    97
        boolean found = contains(new File(testDir, "Test.html"), s);
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    98
        if (found) {
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
    99
            if (expect)
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
   100
                System.out.println("javadoc content \"" + s + "\" found, as expected");
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
   101
            else
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
   102
                error("javadoc content \"" + s + "\" found unexpectedly");
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
   103
        } else {
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
   104
            if (expect)
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
   105
                error("javadoc content \"" + s + "\" not found");
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
   106
            else
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
   107
                System.out.println("javadoc content \"" + s + "\" not found, as expected");
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
   108
        }
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
   109
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
   110
        System.out.println();
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
   111
    }
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
   112
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
   113
    boolean contains(File f, String s) throws Exception {
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
   114
        byte[] buf = new byte[(int) f.length()];
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
   115
        try (DataInputStream in = new DataInputStream(new FileInputStream(f))) {
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
   116
            in.readFully(buf);
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
   117
        }
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
   118
        return new String(buf).contains(s);
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
   119
    }
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
   120
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
   121
    void error(String msg) {
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
   122
        System.out.println("Error: " + msg);
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
   123
        errors++;
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
   124
    }
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
   125
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
   126
}
3e90e60e4ce8 6942366: javadoc no longer inherits doc from sourcepath
jjg
parents:
diff changeset
   127