langtools/test/tools/javadoc/6227454/Test.java
author sogoel
Thu, 26 Jun 2014 16:39:14 -0700
changeset 25297 28ed439b96e9
parent 25280 687ed8b6d77b
child 26779 5437f17cbf69
permissions -rw-r--r--
8048293: update tools/javadoc/6227454 to have missing <head> tag Reviewed-by: jjg, bpatel
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 {
25280
687ed8b6d77b 8047300: update tools/javadoc/6227454 test for missing <DOCTYPE> tags
sogoel
parents: 8632
diff changeset
    41
        String docType = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" "
687ed8b6d77b 8047300: update tools/javadoc/6227454 test for missing <DOCTYPE> tags
sogoel
parents: 8632
diff changeset
    42
                         + "\"http://www.w3.org/TR/html4/loose.dtd\">";
25297
28ed439b96e9 8048293: update tools/javadoc/6227454 to have missing <head> tag
sogoel
parents: 25280
diff changeset
    43
        String headTag = "<head><title>Title </title></head>";
25280
687ed8b6d77b 8047300: update tools/javadoc/6227454 test for missing <DOCTYPE> tags
sogoel
parents: 8632
diff changeset
    44
        test(docType+"<html><body>ABC      XYZ</body></html>");
687ed8b6d77b 8047300: update tools/javadoc/6227454 test for missing <DOCTYPE> tags
sogoel
parents: 8632
diff changeset
    45
        test(docType+"<html><body>ABC      XYZ</BODY></html>");
687ed8b6d77b 8047300: update tools/javadoc/6227454 test for missing <DOCTYPE> tags
sogoel
parents: 8632
diff changeset
    46
        test(docType+"<html><BODY>ABC      XYZ</body></html>");
687ed8b6d77b 8047300: update tools/javadoc/6227454 test for missing <DOCTYPE> tags
sogoel
parents: 8632
diff changeset
    47
        test(docType+"<html><BODY>ABC      XYZ</BODY></html>");
687ed8b6d77b 8047300: update tools/javadoc/6227454 test for missing <DOCTYPE> tags
sogoel
parents: 8632
diff changeset
    48
        test(docType+"<html><BoDy>ABC      XYZ</bOdY></html>");
25297
28ed439b96e9 8048293: update tools/javadoc/6227454 to have missing <head> tag
sogoel
parents: 25280
diff changeset
    49
        test(docType+"<html>"+headTag+"      ABC      XYZ</bOdY></html>", "Body tag missing from HTML");
25280
687ed8b6d77b 8047300: update tools/javadoc/6227454 test for missing <DOCTYPE> tags
sogoel
parents: 8632
diff changeset
    50
        test(docType+"<html><body>ABC      XYZ       </html>", "Close body tag missing from HTML");
25297
28ed439b96e9 8048293: update tools/javadoc/6227454 to have missing <head> tag
sogoel
parents: 25280
diff changeset
    51
        test(docType+"<html>"+headTag+"      ABC      XYZ       </html>", "Body tag missing from HTML");
25280
687ed8b6d77b 8047300: update tools/javadoc/6227454 test for missing <DOCTYPE> tags
sogoel
parents: 8632
diff changeset
    52
        test(docType+"<html><body>ABC" + bigText(8192, 40) + "XYZ</body></html>");
8632
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
        if (errors > 0)
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    55
            throw new Exception(errors + " errors occurred");
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    56
    }
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
    void test(String text) throws IOException {
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    59
        test(text, null);
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    60
    }
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    61
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    62
    void test(String text, String expectError) throws IOException {
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    63
        testNum++;
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    64
        System.err.println("test " + testNum);
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    65
        File file = writeFile("overview" + testNum + ".html", text);
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    66
        String thisClassName = Test.class.getName();
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    67
        File testSrc = new File(System.getProperty("test.src"));
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    68
        String[] args = {
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    69
            "-bootclasspath",
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    70
                System.getProperty("java.class.path")
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    71
                + File.pathSeparator
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    72
                + System.getProperty("sun.boot.class.path"),
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    73
            "-classpath", ".",
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    74
            "-package",
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    75
            "-overview", file.getPath(),
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    76
            new File(testSrc, thisClassName + ".java").getPath()
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    77
        };
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
        StringWriter sw = new StringWriter();
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    80
        PrintWriter pw = new PrintWriter(sw);
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    81
        int rc = com.sun.tools.javadoc.Main.execute(
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    82
                "javadoc",
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    83
                pw, pw, pw,
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    84
                thisClassName,
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    85
                args);
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    86
        pw.close();
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    87
        String out = sw.toString();
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    88
        if (!out.isEmpty())
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    89
            System.err.println(out);
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    90
        System.err.println("javadoc exit: rc=" + rc);
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    91
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    92
        if (expectError == null) {
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    93
            if (rc != 0)
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    94
                error("unexpected exit from javadoc; rc:" + rc);
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    95
        } else {
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    96
            if (!out.contains(expectError))
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    97
                error("expected error text not found: " + expectError);
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
    98
        }
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
    String bigText(int lines, int lineLength) {
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
   102
        StringBuilder sb = new StringBuilder();
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
   103
        for (int i = 0; i < lineLength; i++)
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
   104
            sb.append(String.valueOf(i % 10));
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
   105
        sb.append("\n");
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
   106
        String line = sb.toString();
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
   107
        sb.setLength(0);
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
   108
        for (int i = 0; i < lines; i++)
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
   109
            sb.append(line);
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
   110
        return sb.toString();
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
   111
    }
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
    File writeFile(String path, String body) throws IOException {
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
   114
        File f = new File(path);
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
   115
        FileWriter out = new FileWriter(f);
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
   116
        try {
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
   117
            out.write(body);
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
   118
        } finally {
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
   119
            out.close();
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
   120
        }
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
   121
        return f;
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
   122
    }
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
    void error(String msg) {
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
   125
        System.err.println("Error: " + msg);
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
   126
        errors++;
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
   127
    }
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
    int testNum;
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
   130
    int errors;
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
   131
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
   132
    public static boolean start(RootDoc root) {
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
   133
        String text = root.commentText();
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
   134
        if (text.length() < 64)
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
   135
            System.err.println("text: '" + text + "'");
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
   136
        else
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
   137
            System.err.println("text: '"
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
   138
                    + text.substring(0, 20)
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
   139
                    + "..."
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
   140
                    + text.substring(text.length() - 20)
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
   141
                    + "'");
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
   142
        return text.startsWith("ABC") && text.endsWith("XYZ");
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
   143
    }
af2a1f02c8ac 6227454: package.html and overview.html may not be read fully
jjg
parents:
diff changeset
   144
}