langtools/test/tools/javadoc/6227454/Test.java
author enevill
Tue, 05 May 2015 09:08:20 +0000
changeset 30325 1472b22475f2
parent 26779 5437f17cbf69
child 30730 d3ce7619db2c
permissions -rw-r--r--
8078245: AARCH64: JDK fails to build due to undefined symbol in libpng Summary: Add -DPNG_ARM_NEON_OPT=0 to LIBSPLASHSCREEN_CFLAGS flags Reviewed-by: dholmes, ihse, erikj
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8632
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
     1
/*
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
     2
 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
     4
 *
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
     8
 *
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    13
 * accompanied this code).
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    14
 *
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    18
 *
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    21
 * questions.
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    22
 */
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    23
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    24
/*
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    25
 * @test
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    26
 * @bug 6227454
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    27
 * @summary package.html and overview.html may not be read fully
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    28
 */
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    29
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    30
import java.io.*;
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    31
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    32
import com.sun.javadoc.Doclet;
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    33
import com.sun.javadoc.RootDoc;
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    34
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    35
public class Test extends Doclet {
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    36
    public static void main(String... args) throws Exception {
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    37
        new Test().run();
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    38
    }
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    39
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    40
    void run() throws Exception {
26779
5437f17cbf69 8058755: Update tools/javadoc/6227454 to add head tag
sogoel
parents: 25297
diff changeset
    41
        test("<body>ABC      XYZ</body>");
5437f17cbf69 8058755: Update tools/javadoc/6227454 to add head tag
sogoel
parents: 25297
diff changeset
    42
        test("<body>ABC      XYZ</BODY>");
5437f17cbf69 8058755: Update tools/javadoc/6227454 to add head tag
sogoel
parents: 25297
diff changeset
    43
        test("<BODY>ABC      XYZ</body>");
5437f17cbf69 8058755: Update tools/javadoc/6227454 to add head tag
sogoel
parents: 25297
diff changeset
    44
        test("<BODY>ABC      XYZ</BODY>");
5437f17cbf69 8058755: Update tools/javadoc/6227454 to add head tag
sogoel
parents: 25297
diff changeset
    45
        test("<BoDy>ABC      XYZ</bOdY>");
5437f17cbf69 8058755: Update tools/javadoc/6227454 to add head tag
sogoel
parents: 25297
diff changeset
    46
        test("      ABC      XYZ</bOdY>", "Body tag missing from HTML");
5437f17cbf69 8058755: Update tools/javadoc/6227454 to add head tag
sogoel
parents: 25297
diff changeset
    47
        test("<body>ABC      XYZ       ", "Close body tag missing from HTML");
5437f17cbf69 8058755: Update tools/javadoc/6227454 to add head tag
sogoel
parents: 25297
diff changeset
    48
        test("      ABC      XYZ       ", "Body tag missing from HTML");
5437f17cbf69 8058755: Update tools/javadoc/6227454 to add head tag
sogoel
parents: 25297
diff changeset
    49
        test("<body>ABC" + bigText(8192, 40) + "XYZ</body>");
8632
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    50
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    51
        if (errors > 0)
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    52
            throw new Exception(errors + " errors occurred");
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    53
    }
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    54
26779
5437f17cbf69 8058755: Update tools/javadoc/6227454 to add head tag
sogoel
parents: 25297
diff changeset
    55
    void test(String body) throws IOException {
5437f17cbf69 8058755: Update tools/javadoc/6227454 to add head tag
sogoel
parents: 25297
diff changeset
    56
        test(body, null);
8632
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    57
    }
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    58
26779
5437f17cbf69 8058755: Update tools/javadoc/6227454 to add head tag
sogoel
parents: 25297
diff changeset
    59
    void test(String body, String expectError) throws IOException {
5437f17cbf69 8058755: Update tools/javadoc/6227454 to add head tag
sogoel
parents: 25297
diff changeset
    60
        String docType = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" "
5437f17cbf69 8058755: Update tools/javadoc/6227454 to add head tag
sogoel
parents: 25297
diff changeset
    61
                         + "\"http://www.w3.org/TR/html4/loose.dtd\">";
5437f17cbf69 8058755: Update tools/javadoc/6227454 to add head tag
sogoel
parents: 25297
diff changeset
    62
        String headTag = "<head><title>Title </title></head>";
5437f17cbf69 8058755: Update tools/javadoc/6227454 to add head tag
sogoel
parents: 25297
diff changeset
    63
        String text = docType + "<html>" + headTag + body + "</html>";
8632
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    64
        testNum++;
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    65
        System.err.println("test " + testNum);
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    66
        File file = writeFile("overview" + testNum + ".html", text);
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    67
        String thisClassName = Test.class.getName();
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    68
        File testSrc = new File(System.getProperty("test.src"));
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    69
        String[] args = {
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    70
            "-bootclasspath",
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    71
                System.getProperty("java.class.path")
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    72
                + File.pathSeparator
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    73
                + System.getProperty("sun.boot.class.path"),
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    74
            "-classpath", ".",
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    75
            "-package",
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    76
            "-overview", file.getPath(),
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    77
            new File(testSrc, thisClassName + ".java").getPath()
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    78
        };
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    79
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    80
        StringWriter sw = new StringWriter();
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    81
        PrintWriter pw = new PrintWriter(sw);
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    82
        int rc = com.sun.tools.javadoc.Main.execute(
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    83
                "javadoc",
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    84
                pw, pw, pw,
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    85
                thisClassName,
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    86
                args);
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    87
        pw.close();
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    88
        String out = sw.toString();
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    89
        if (!out.isEmpty())
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    90
            System.err.println(out);
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    91
        System.err.println("javadoc exit: rc=" + rc);
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    92
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    93
        if (expectError == null) {
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    94
            if (rc != 0)
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    95
                error("unexpected exit from javadoc; rc:" + rc);
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    96
        } else {
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    97
            if (!out.contains(expectError))
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    98
                error("expected error text not found: " + expectError);
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    99
        }
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
   100
    }
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
   101
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
   102
    String bigText(int lines, int lineLength) {
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
   103
        StringBuilder sb = new StringBuilder();
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
   104
        for (int i = 0; i < lineLength; i++)
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
   105
            sb.append(String.valueOf(i % 10));
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
   106
        sb.append("\n");
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
   107
        String line = sb.toString();
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
   108
        sb.setLength(0);
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
   109
        for (int i = 0; i < lines; i++)
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
   110
            sb.append(line);
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
   111
        return sb.toString();
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
   112
    }
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
   113
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
   114
    File writeFile(String path, String body) throws IOException {
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
   115
        File f = new File(path);
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
   116
        FileWriter out = new FileWriter(f);
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
   117
        try {
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
   118
            out.write(body);
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
   119
        } finally {
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
   120
            out.close();
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
   121
        }
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
   122
        return f;
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
   123
    }
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
   124
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
   125
    void error(String msg) {
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
   126
        System.err.println("Error: " + msg);
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
   127
        errors++;
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
   128
    }
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
   129
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
   130
    int testNum;
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
   131
    int errors;
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
   132
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
   133
    public static boolean start(RootDoc root) {
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
   134
        String text = root.commentText();
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
   135
        if (text.length() < 64)
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
   136
            System.err.println("text: '" + text + "'");
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
   137
        else
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
   138
            System.err.println("text: '"
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
   139
                    + text.substring(0, 20)
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
   140
                    + "..."
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
   141
                    + text.substring(text.length() - 20)
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
   142
                    + "'");
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
   143
        return text.startsWith("ABC") && text.endsWith("XYZ");
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
   144
    }
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
   145
}