test/langtools/jdk/javadoc/doclet/lib/JavadocTester.java
author jjg
Wed, 13 Dec 2017 17:27:43 -0800
changeset 48325 e5cdedd37b78
parent 47395 2ea4edfdef8e
child 50118 919c36db208c
permissions -rw-r--r--
8178070: duplicate entries in package table Reviewed-by: bpatel, ksrini
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
44684
6ce4d52084e8 8178067: support for @uses/@provides tags is broken
ksrini
parents: 42842
diff changeset
     2
 * Copyright (c) 2002, 2017, Oracle and/or its affiliates. All rights reserved.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
06bc494ca11e Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
06bc494ca11e Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3890
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3890
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3890
diff changeset
    21
 * questions.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    22
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    23
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    24
import java.io.BufferedWriter;
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    25
import java.io.ByteArrayOutputStream;
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    26
import java.io.File;
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    27
import java.io.FileNotFoundException;
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    28
import java.io.FileWriter;
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    29
import java.io.FilenameFilter;
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    30
import java.io.IOException;
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    31
import java.io.PrintStream;
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    32
import java.io.PrintWriter;
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    33
import java.io.StringWriter;
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    34
import java.lang.annotation.Annotation;
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    35
import java.lang.annotation.Retention;
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    36
import java.lang.annotation.RetentionPolicy;
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    37
import java.lang.ref.SoftReference;
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    38
import java.lang.reflect.InvocationTargetException;
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    39
import java.lang.reflect.Method;
47328
d18df41954ba 8187521: In some corner cases the javadoc tool can reuse id attribute
jjg
parents: 47216
diff changeset
    40
import java.nio.charset.Charset;
d18df41954ba 8187521: In some corner cases the javadoc tool can reuse id attribute
jjg
parents: 47216
diff changeset
    41
import java.nio.charset.UnsupportedCharsetException;
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    42
import java.nio.file.Files;
26091
c40ba05822ad 8054044: [javadoc] javadoc tester must print out the javadoc run arguments.
ksrini
parents: 25004
diff changeset
    43
import java.util.Arrays;
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    44
import java.util.ArrayList;
40500
f293dbb81a53 8162353: javadoc should provide a way to disable use of frames
jjg
parents: 35426
diff changeset
    45
import java.util.Collection;
41252
058d83c9b1c7 8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents: 40500
diff changeset
    46
import java.util.Collections;
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    47
import java.util.EnumMap;
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    48
import java.util.HashMap;
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    49
import java.util.List;
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    50
import java.util.Map;
47328
d18df41954ba 8187521: In some corner cases the javadoc tool can reuse id attribute
jjg
parents: 47216
diff changeset
    51
import java.util.Objects;
44684
6ce4d52084e8 8178067: support for @uses/@provides tags is broken
ksrini
parents: 42842
diff changeset
    52
import java.util.function.Function;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
/**
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    56
 * Test framework for running javadoc and performing tests on the resulting output.
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    57
 *
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    58
 * <p>
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    59
 * Tests are typically written as subtypes of JavadocTester, with a main
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    60
 * method that creates an instance of the test class and calls the runTests()
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    61
 * method. The runTests() methods calls all the test methods declared in the class,
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    62
 * and then calls a method to print a summary, and throw an exception if
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    63
 * any of the test methods reported a failure.
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    64
 *
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    65
 * <p>
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    66
 * Test methods are identified with a @Test annotation. They have no parameters.
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    67
 * The name of the method is not important, but if you have more than one, it is
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    68
 * recommended that the names be meaningful and suggestive of the test case
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    69
 * contained therein.
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    70
 *
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    71
 * <p>
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    72
 * Typically, a test method will invoke javadoc, and then perform various
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    73
 * checks on the results. The standard checks are:
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    74
 *
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    75
 * <dl>
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    76
 * <dt>checkExitCode
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    77
 * <dd>Check the exit code returned from javadoc.
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    78
 * <dt>checkOutput
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    79
 * <dd>Perform a series of checks on the contents on a file or output stream
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    80
 *     generated by javadoc.
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    81
 *     The checks can be either that a series of strings are found or are not found.
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    82
 * <dt>checkFiles
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    83
 * <dd>Perform a series of checks on the files generated by javadoc.
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    84
 *     The checks can be that a series of files are found or are not found.
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    85
 * </dl>
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    86
 *
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    87
 * <pre><code>
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    88
 *  public class MyTester extends JavadocTester {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    89
 *      public static void main(String... args) throws Exception {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    90
 *          MyTester tester = new MyTester();
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    91
 *          tester.runTests();
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    92
 *      }
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    93
 *
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    94
 *      // test methods...
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    95
 *      @Test
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    96
 *      void test() {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    97
 *          javadoc(<i>args</i>);
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    98
 *          checkExit(Exit.OK);
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    99
 *          checkOutput(<i>file</i>, true,
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   100
 *              <i>strings-to-find</i>);
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   101
 *          checkOutput(<i>file</i>, false,
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   102
 *              <i>strings-to-not-find</i>);
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   103
 *      }
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   104
 *  }
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   105
 * </code></pre>
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   106
 *
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   107
 * <p>
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   108
 * If javadoc is run more than once in a test method, you can compare the
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   109
 * results that are generated with the diff method. Since files written by
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   110
 * javadoc typically contain a timestamp, you may want to use the -notimestamp
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   111
 * option if you are going to compare the results from two runs of javadoc.
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   112
 *
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   113
 * <p>
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   114
 * If you have many calls of checkOutput that are very similar, you can write
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   115
 * your own check... method to reduce the amount of duplication. For example,
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   116
 * if you want to check that many files contain the same string, you could
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   117
 * write a method that takes a varargs list of files and calls checkOutput
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   118
 * on each file in turn with the string to be checked.
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   119
 *
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   120
 * <p>
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   121
 * You can also write you own custom check methods, which can use
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   122
 * readFile to get the contents of a file generated by javadoc,
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   123
 * and then use pass(...) or fail(...) to report whether the check
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   124
 * succeeded or not.
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   125
 *
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   126
 * <p>
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   127
 * You can have many separate test methods, each identified with a @Test
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   128
 * annotation. However, you should <b>not</b> assume they will be called
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   129
 * in the order declared in your source file.  If the order of a series
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   130
 * of javadoc invocations is important, do that within a single method.
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   131
 * If the invocations are independent, for better clarity, use separate
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   132
 * test methods, each with their own set of checks on the results.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
 * @author Doug Kramer
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
 * @author Jamie Ho
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   136
 * @author Jonathan Gibbons (rewrite)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
public abstract class JavadocTester {
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   140
    public static final String FS = System.getProperty("file.separator");
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   141
    public static final String PS = System.getProperty("path.separator");
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   142
    public static final String NL = System.getProperty("line.separator");
23971
f5ff1f5a8dee 8031649: Clean up javadoc tests
jjg
parents: 20238
diff changeset
   143
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   144
    public enum Output {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   145
        /** The name of the output stream from javadoc. */
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   146
        OUT,
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   147
        /** The name for any output written to System.out. */
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   148
        STDOUT,
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   149
        /** The name for any output written to System.err. */
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   150
        STDERR
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   151
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   153
    /** The output directory used in the most recent call of javadoc. */
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   154
    protected File outputDir;
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   155
47328
d18df41954ba 8187521: In some corner cases the javadoc tool can reuse id attribute
jjg
parents: 47216
diff changeset
   156
    /** The output charset used in the most recent call of javadoc. */
d18df41954ba 8187521: In some corner cases the javadoc tool can reuse id attribute
jjg
parents: 47216
diff changeset
   157
    protected Charset charset = Charset.defaultCharset();
d18df41954ba 8187521: In some corner cases the javadoc tool can reuse id attribute
jjg
parents: 47216
diff changeset
   158
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   159
    /** The exit code of the most recent call of javadoc. */
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   160
    private int exitCode;
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   161
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   162
    /** The output generated by javadoc to the various writers and streams. */
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   163
    private final Map<Output, String> outputMap = new EnumMap<>(Output.class);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   165
    /** A cache of file content, to avoid reading files unnecessarily. */
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   166
    private final Map<File,SoftReference<String>> fileContentCache = new HashMap<>();
47328
d18df41954ba 8187521: In some corner cases the javadoc tool can reuse id attribute
jjg
parents: 47216
diff changeset
   167
    /** The charset used for files in the fileContentCache. */
d18df41954ba 8187521: In some corner cases the javadoc tool can reuse id attribute
jjg
parents: 47216
diff changeset
   168
    private Charset fileContentCacheCharset = null;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   170
    /** Stream used for logging messages. */
40500
f293dbb81a53 8162353: javadoc should provide a way to disable use of frames
jjg
parents: 35426
diff changeset
   171
    protected final PrintStream out = System.out;
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   172
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   173
    /** The directory containing the source code for the test. */
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   174
    public static final String testSrc = System.getProperty("test.src");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
    /**
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   177
     * Get the path for a source file in the test source directory.
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   178
     * @param path the path of a file or directory in the source directory
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   179
     * @return the full path of the specified file
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
     */
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   181
    public static String testSrc(String path) {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   182
        return new File(testSrc, path).getPath();
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   183
    }
24072
e7549dcbc4af 8040903: Clean up use of BUG_ID in javadoc tests
jjg
parents: 24065
diff changeset
   184
e7549dcbc4af 8040903: Clean up use of BUG_ID in javadoc tests
jjg
parents: 24065
diff changeset
   185
    /**
24217
25b12d4d4192 8040904: Ensure javadoc tests do not overwrite results within tests
jjg
parents: 24072
diff changeset
   186
     * Alternatives for checking the contents of a directory.
25b12d4d4192 8040904: Ensure javadoc tests do not overwrite results within tests
jjg
parents: 24072
diff changeset
   187
     */
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   188
    public enum DirectoryCheck {
24217
25b12d4d4192 8040904: Ensure javadoc tests do not overwrite results within tests
jjg
parents: 24072
diff changeset
   189
        /**
25b12d4d4192 8040904: Ensure javadoc tests do not overwrite results within tests
jjg
parents: 24072
diff changeset
   190
         * Check that the directory is empty.
25b12d4d4192 8040904: Ensure javadoc tests do not overwrite results within tests
jjg
parents: 24072
diff changeset
   191
         */
25b12d4d4192 8040904: Ensure javadoc tests do not overwrite results within tests
jjg
parents: 24072
diff changeset
   192
        EMPTY((file, name) -> true),
25b12d4d4192 8040904: Ensure javadoc tests do not overwrite results within tests
jjg
parents: 24072
diff changeset
   193
        /**
25b12d4d4192 8040904: Ensure javadoc tests do not overwrite results within tests
jjg
parents: 24072
diff changeset
   194
         * Check that the directory does not contain any HTML files,
25b12d4d4192 8040904: Ensure javadoc tests do not overwrite results within tests
jjg
parents: 24072
diff changeset
   195
         * such as may have been generated by a prior run of javadoc
25b12d4d4192 8040904: Ensure javadoc tests do not overwrite results within tests
jjg
parents: 24072
diff changeset
   196
         * using this directory.
25b12d4d4192 8040904: Ensure javadoc tests do not overwrite results within tests
jjg
parents: 24072
diff changeset
   197
         * For now, the check is only performed on the top level directory.
25b12d4d4192 8040904: Ensure javadoc tests do not overwrite results within tests
jjg
parents: 24072
diff changeset
   198
         */
25b12d4d4192 8040904: Ensure javadoc tests do not overwrite results within tests
jjg
parents: 24072
diff changeset
   199
        NO_HTML_FILES((file, name) -> name.endsWith(".html")),
25b12d4d4192 8040904: Ensure javadoc tests do not overwrite results within tests
jjg
parents: 24072
diff changeset
   200
        /**
25b12d4d4192 8040904: Ensure javadoc tests do not overwrite results within tests
jjg
parents: 24072
diff changeset
   201
         * No check is performed on the directory contents.
25b12d4d4192 8040904: Ensure javadoc tests do not overwrite results within tests
jjg
parents: 24072
diff changeset
   202
         */
25b12d4d4192 8040904: Ensure javadoc tests do not overwrite results within tests
jjg
parents: 24072
diff changeset
   203
        NONE(null) { @Override void check(File dir) { } };
25b12d4d4192 8040904: Ensure javadoc tests do not overwrite results within tests
jjg
parents: 24072
diff changeset
   204
25b12d4d4192 8040904: Ensure javadoc tests do not overwrite results within tests
jjg
parents: 24072
diff changeset
   205
        /** The filter used to detect that files should <i>not</i> be present. */
25b12d4d4192 8040904: Ensure javadoc tests do not overwrite results within tests
jjg
parents: 24072
diff changeset
   206
        FilenameFilter filter;
25b12d4d4192 8040904: Ensure javadoc tests do not overwrite results within tests
jjg
parents: 24072
diff changeset
   207
25b12d4d4192 8040904: Ensure javadoc tests do not overwrite results within tests
jjg
parents: 24072
diff changeset
   208
        DirectoryCheck(FilenameFilter f) {
25b12d4d4192 8040904: Ensure javadoc tests do not overwrite results within tests
jjg
parents: 24072
diff changeset
   209
            filter = f;
25b12d4d4192 8040904: Ensure javadoc tests do not overwrite results within tests
jjg
parents: 24072
diff changeset
   210
        }
25b12d4d4192 8040904: Ensure javadoc tests do not overwrite results within tests
jjg
parents: 24072
diff changeset
   211
25b12d4d4192 8040904: Ensure javadoc tests do not overwrite results within tests
jjg
parents: 24072
diff changeset
   212
        void check(File dir) {
25b12d4d4192 8040904: Ensure javadoc tests do not overwrite results within tests
jjg
parents: 24072
diff changeset
   213
            if (dir.isDirectory()) {
25b12d4d4192 8040904: Ensure javadoc tests do not overwrite results within tests
jjg
parents: 24072
diff changeset
   214
                String[] contents = dir.list(filter);
25b12d4d4192 8040904: Ensure javadoc tests do not overwrite results within tests
jjg
parents: 24072
diff changeset
   215
                if (contents == null)
25b12d4d4192 8040904: Ensure javadoc tests do not overwrite results within tests
jjg
parents: 24072
diff changeset
   216
                    throw new Error("cannot list directory: " + dir);
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   217
                if (contents.length > 0) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   218
                    System.err.println("Found extraneous files in dir:" + dir.getAbsolutePath());
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   219
                    for (String x : contents) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   220
                        System.err.println(x);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   221
                    }
24217
25b12d4d4192 8040904: Ensure javadoc tests do not overwrite results within tests
jjg
parents: 24072
diff changeset
   222
                    throw new Error("directory has unexpected content: " + dir);
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   223
                }
24217
25b12d4d4192 8040904: Ensure javadoc tests do not overwrite results within tests
jjg
parents: 24072
diff changeset
   224
            }
25b12d4d4192 8040904: Ensure javadoc tests do not overwrite results within tests
jjg
parents: 24072
diff changeset
   225
        }
25b12d4d4192 8040904: Ensure javadoc tests do not overwrite results within tests
jjg
parents: 24072
diff changeset
   226
    }
25b12d4d4192 8040904: Ensure javadoc tests do not overwrite results within tests
jjg
parents: 24072
diff changeset
   227
25b12d4d4192 8040904: Ensure javadoc tests do not overwrite results within tests
jjg
parents: 24072
diff changeset
   228
    private DirectoryCheck outputDirectoryCheck = DirectoryCheck.EMPTY;
25b12d4d4192 8040904: Ensure javadoc tests do not overwrite results within tests
jjg
parents: 24072
diff changeset
   229
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   230
    /** The current subtest number. Incremented when checking(...) is called. */
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   231
    private int numTestsRun = 0;
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   232
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   233
    /** The number of subtests passed. Incremented when passed(...) is called. */
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   234
    private int numTestsPassed = 0;
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   235
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   236
    /** The current run of javadoc. Incremented when javadoc is called. */
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   237
    private int javadocRunNum = 0;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   238
48325
e5cdedd37b78 8178070: duplicate entries in package table
jjg
parents: 47395
diff changeset
   239
    /** The current subtest number for this run of javadoc. Incremented when checking(...) is called. */
e5cdedd37b78 8178070: duplicate entries in package table
jjg
parents: 47395
diff changeset
   240
    private int javadocTestNum = 0;
e5cdedd37b78 8178070: duplicate entries in package table
jjg
parents: 47395
diff changeset
   241
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   242
    /** Marker annotation for test methods to be invoked by runTests. */
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   243
    @Retention(RetentionPolicy.RUNTIME)
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   244
    @interface Test { }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   245
06bc494ca11e Initial load
duke
parents:
diff changeset
   246
    /**
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   247
     * Run all methods annotated with @Test, followed by printSummary.
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   248
     * Typically called on a tester object in main()
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   249
     * @throws Exception if any errors occurred
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   250
     */
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   251
    public void runTests() throws Exception {
44684
6ce4d52084e8 8178067: support for @uses/@provides tags is broken
ksrini
parents: 42842
diff changeset
   252
        runTests(m -> new Object[0]);
6ce4d52084e8 8178067: support for @uses/@provides tags is broken
ksrini
parents: 42842
diff changeset
   253
    }
6ce4d52084e8 8178067: support for @uses/@provides tags is broken
ksrini
parents: 42842
diff changeset
   254
6ce4d52084e8 8178067: support for @uses/@provides tags is broken
ksrini
parents: 42842
diff changeset
   255
    /**
6ce4d52084e8 8178067: support for @uses/@provides tags is broken
ksrini
parents: 42842
diff changeset
   256
     * Run all methods annotated with @Test, followed by printSummary.
6ce4d52084e8 8178067: support for @uses/@provides tags is broken
ksrini
parents: 42842
diff changeset
   257
     * Typically called on a tester object in main()
6ce4d52084e8 8178067: support for @uses/@provides tags is broken
ksrini
parents: 42842
diff changeset
   258
     * @param f a function which will be used to provide arguments to each
6ce4d52084e8 8178067: support for @uses/@provides tags is broken
ksrini
parents: 42842
diff changeset
   259
     *          invoked method
6ce4d52084e8 8178067: support for @uses/@provides tags is broken
ksrini
parents: 42842
diff changeset
   260
     * @throws Exception if any errors occurred
6ce4d52084e8 8178067: support for @uses/@provides tags is broken
ksrini
parents: 42842
diff changeset
   261
     */
6ce4d52084e8 8178067: support for @uses/@provides tags is broken
ksrini
parents: 42842
diff changeset
   262
    public void runTests(Function<Method, Object[]> f) throws Exception {
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   263
        for (Method m: getClass().getDeclaredMethods()) {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   264
            Annotation a = m.getAnnotation(Test.class);
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   265
            if (a != null) {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   266
                try {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   267
                    out.println("Running test " + m.getName());
44684
6ce4d52084e8 8178067: support for @uses/@provides tags is broken
ksrini
parents: 42842
diff changeset
   268
                    m.invoke(this, f.apply(m));
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   269
                } catch (InvocationTargetException e) {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   270
                    Throwable cause = e.getCause();
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   271
                    throw (cause instanceof Exception) ? ((Exception) cause) : e;
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   272
                }
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   273
                out.println();
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   274
            }
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   275
        }
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   276
        printSummary();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   277
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   278
06bc494ca11e Initial load
duke
parents:
diff changeset
   279
    /**
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   280
     * Run javadoc.
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   281
     * The output directory used by this call and the final exit code
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   282
     * will be saved for later use.
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   283
     * To aid the reader, it is recommended that calls to this method
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   284
     * put each option and the arguments it takes on a separate line.
20238
a08610368936 8024096: some javadoc tests may contain false positive results
bpatel
parents: 10190
diff changeset
   285
     *
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   286
     * Example:
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   287
     * <pre><code>
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   288
     *  javadoc("-d", "out",
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   289
     *          "-sourcepath", testSrc,
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   290
     *          "-notimestamp",
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   291
     *          "pkg1", "pkg2", "pkg3/C.java");
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   292
     * </code></pre>
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   293
     *
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   294
     * @param args the arguments to pass to javadoc
20238
a08610368936 8024096: some javadoc tests may contain false positive results
bpatel
parents: 10190
diff changeset
   295
     */
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   296
    public void javadoc(String... args) {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   297
        outputMap.clear();
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   298
        fileContentCache.clear();
20238
a08610368936 8024096: some javadoc tests may contain false positive results
bpatel
parents: 10190
diff changeset
   299
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   300
        javadocRunNum++;
48325
e5cdedd37b78 8178070: duplicate entries in package table
jjg
parents: 47395
diff changeset
   301
        javadocTestNum = 0; // reset counter for this run of javadoc
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   302
        if (javadocRunNum == 1) {
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   303
            out.println("Running javadoc...");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   304
        } else {
48325
e5cdedd37b78 8178070: duplicate entries in package table
jjg
parents: 47395
diff changeset
   305
            out.println("Running javadoc (run "+ javadocRunNum + ")...");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   306
        }
47328
d18df41954ba 8187521: In some corner cases the javadoc tool can reuse id attribute
jjg
parents: 47216
diff changeset
   307
24072
e7549dcbc4af 8040903: Clean up use of BUG_ID in javadoc tests
jjg
parents: 24065
diff changeset
   308
        outputDir = new File(".");
47328
d18df41954ba 8187521: In some corner cases the javadoc tool can reuse id attribute
jjg
parents: 47216
diff changeset
   309
        String charsetArg = null;
d18df41954ba 8187521: In some corner cases the javadoc tool can reuse id attribute
jjg
parents: 47216
diff changeset
   310
        String docencodingArg = null;
d18df41954ba 8187521: In some corner cases the javadoc tool can reuse id attribute
jjg
parents: 47216
diff changeset
   311
        String encodingArg = null;
24072
e7549dcbc4af 8040903: Clean up use of BUG_ID in javadoc tests
jjg
parents: 24065
diff changeset
   312
        for (int i = 0; i < args.length - 2; i++) {
47328
d18df41954ba 8187521: In some corner cases the javadoc tool can reuse id attribute
jjg
parents: 47216
diff changeset
   313
            switch (args[i]) {
d18df41954ba 8187521: In some corner cases the javadoc tool can reuse id attribute
jjg
parents: 47216
diff changeset
   314
                case "-d":
d18df41954ba 8187521: In some corner cases the javadoc tool can reuse id attribute
jjg
parents: 47216
diff changeset
   315
                    outputDir = new File(args[++i]);
d18df41954ba 8187521: In some corner cases the javadoc tool can reuse id attribute
jjg
parents: 47216
diff changeset
   316
                    break;
d18df41954ba 8187521: In some corner cases the javadoc tool can reuse id attribute
jjg
parents: 47216
diff changeset
   317
                case "-charset":
d18df41954ba 8187521: In some corner cases the javadoc tool can reuse id attribute
jjg
parents: 47216
diff changeset
   318
                    charsetArg = args[++i];
d18df41954ba 8187521: In some corner cases the javadoc tool can reuse id attribute
jjg
parents: 47216
diff changeset
   319
                    break;
d18df41954ba 8187521: In some corner cases the javadoc tool can reuse id attribute
jjg
parents: 47216
diff changeset
   320
                case "-docencoding":
d18df41954ba 8187521: In some corner cases the javadoc tool can reuse id attribute
jjg
parents: 47216
diff changeset
   321
                    docencodingArg = args[++i];
d18df41954ba 8187521: In some corner cases the javadoc tool can reuse id attribute
jjg
parents: 47216
diff changeset
   322
                    break;
d18df41954ba 8187521: In some corner cases the javadoc tool can reuse id attribute
jjg
parents: 47216
diff changeset
   323
                case "-encoding":
d18df41954ba 8187521: In some corner cases the javadoc tool can reuse id attribute
jjg
parents: 47216
diff changeset
   324
                    encodingArg = args[++i];
d18df41954ba 8187521: In some corner cases the javadoc tool can reuse id attribute
jjg
parents: 47216
diff changeset
   325
                    break;
24072
e7549dcbc4af 8040903: Clean up use of BUG_ID in javadoc tests
jjg
parents: 24065
diff changeset
   326
            }
e7549dcbc4af 8040903: Clean up use of BUG_ID in javadoc tests
jjg
parents: 24065
diff changeset
   327
        }
47328
d18df41954ba 8187521: In some corner cases the javadoc tool can reuse id attribute
jjg
parents: 47216
diff changeset
   328
d18df41954ba 8187521: In some corner cases the javadoc tool can reuse id attribute
jjg
parents: 47216
diff changeset
   329
        // The following replicates HtmlConfiguration.finishOptionSettings0
d18df41954ba 8187521: In some corner cases the javadoc tool can reuse id attribute
jjg
parents: 47216
diff changeset
   330
        // and sets up the charset used to read files.
d18df41954ba 8187521: In some corner cases the javadoc tool can reuse id attribute
jjg
parents: 47216
diff changeset
   331
        String cs;
d18df41954ba 8187521: In some corner cases the javadoc tool can reuse id attribute
jjg
parents: 47216
diff changeset
   332
        if (docencodingArg == null) {
d18df41954ba 8187521: In some corner cases the javadoc tool can reuse id attribute
jjg
parents: 47216
diff changeset
   333
            if (charsetArg == null) {
d18df41954ba 8187521: In some corner cases the javadoc tool can reuse id attribute
jjg
parents: 47216
diff changeset
   334
                cs = (encodingArg == null) ? "UTF-8" : encodingArg;
d18df41954ba 8187521: In some corner cases the javadoc tool can reuse id attribute
jjg
parents: 47216
diff changeset
   335
            } else {
d18df41954ba 8187521: In some corner cases the javadoc tool can reuse id attribute
jjg
parents: 47216
diff changeset
   336
                cs = charsetArg;
d18df41954ba 8187521: In some corner cases the javadoc tool can reuse id attribute
jjg
parents: 47216
diff changeset
   337
            }
d18df41954ba 8187521: In some corner cases the javadoc tool can reuse id attribute
jjg
parents: 47216
diff changeset
   338
        } else {
d18df41954ba 8187521: In some corner cases the javadoc tool can reuse id attribute
jjg
parents: 47216
diff changeset
   339
           cs = docencodingArg;
d18df41954ba 8187521: In some corner cases the javadoc tool can reuse id attribute
jjg
parents: 47216
diff changeset
   340
        }
d18df41954ba 8187521: In some corner cases the javadoc tool can reuse id attribute
jjg
parents: 47216
diff changeset
   341
        try {
d18df41954ba 8187521: In some corner cases the javadoc tool can reuse id attribute
jjg
parents: 47216
diff changeset
   342
            charset = Charset.forName(cs);
d18df41954ba 8187521: In some corner cases the javadoc tool can reuse id attribute
jjg
parents: 47216
diff changeset
   343
        } catch (UnsupportedCharsetException e) {
d18df41954ba 8187521: In some corner cases the javadoc tool can reuse id attribute
jjg
parents: 47216
diff changeset
   344
            charset = Charset.defaultCharset();
d18df41954ba 8187521: In some corner cases the javadoc tool can reuse id attribute
jjg
parents: 47216
diff changeset
   345
        }
d18df41954ba 8187521: In some corner cases the javadoc tool can reuse id attribute
jjg
parents: 47216
diff changeset
   346
26091
c40ba05822ad 8054044: [javadoc] javadoc tester must print out the javadoc run arguments.
ksrini
parents: 25004
diff changeset
   347
        out.println("args: " + Arrays.toString(args));
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   348
//        log.setOutDir(outputDir);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   349
24217
25b12d4d4192 8040904: Ensure javadoc tests do not overwrite results within tests
jjg
parents: 24072
diff changeset
   350
        outputDirectoryCheck.check(outputDir);
25b12d4d4192 8040904: Ensure javadoc tests do not overwrite results within tests
jjg
parents: 24072
diff changeset
   351
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   352
        // This is the sole stream used by javadoc
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   353
        WriterOutput outOut = new WriterOutput();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   354
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   355
        // These are to catch output to System.out and System.err,
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   356
        // in case these are used instead of the primary streams
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   357
        StreamOutput sysOut = new StreamOutput(System.out, System::setOut);
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   358
        StreamOutput sysErr = new StreamOutput(System.err, System::setErr);
10190
11c701650189 6735320: StringIndexOutOfBoundsException for empty @serialField tag
ksrini
parents: 5520
diff changeset
   359
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   360
        try {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   361
            exitCode = jdk.javadoc.internal.tool.Main.execute(args, outOut.pw);
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   362
        } finally {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   363
            outputMap.put(Output.STDOUT, sysOut.close());
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   364
            outputMap.put(Output.STDERR, sysErr.close());
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   365
            outputMap.put(Output.OUT, outOut.close());
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   366
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   367
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   368
        outputMap.forEach((name, text) -> {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   369
            if (!text.isEmpty()) {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   370
                out.println("javadoc " + name + ":");
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   371
                out.println(text);
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   372
            }
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   373
        });
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   374
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   375
06bc494ca11e Initial load
duke
parents:
diff changeset
   376
    /**
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   377
     * Set the kind of check for the initial contents of the output directory
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   378
     * before javadoc is run.
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   379
     * The filter should return true for files that should <b>not</b> appear.
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   380
     * @param c the kind of check to perform
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   381
     */
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   382
    public void setOutputDirectoryCheck(DirectoryCheck c) {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   383
        outputDirectoryCheck = c;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   384
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   385
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 41252
diff changeset
   386
    /**
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 41252
diff changeset
   387
     * The exit codes returned by the javadoc tool.
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 41252
diff changeset
   388
     * @see jdk.javadoc.internal.tool.Main.Result
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 41252
diff changeset
   389
     */
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   390
    public enum Exit {
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 41252
diff changeset
   391
        OK(0),        // Javadoc completed with no errors.
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 41252
diff changeset
   392
        ERROR(1),     // Completed but reported errors.
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 41252
diff changeset
   393
        CMDERR(2),    // Bad command-line arguments
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 41252
diff changeset
   394
        SYSERR(3),    // System error or resource exhaustion.
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 41252
diff changeset
   395
        ABNORMAL(4);  // Javadoc terminated abnormally
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   396
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   397
        Exit(int code) {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   398
            this.code = code;
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   399
        }
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   400
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   401
        final int code;
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 41252
diff changeset
   402
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 41252
diff changeset
   403
        @Override
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 41252
diff changeset
   404
        public String toString() {
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 41252
diff changeset
   405
            return name() + '(' + code + ')';
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 41252
diff changeset
   406
        }
20238
a08610368936 8024096: some javadoc tests may contain false positive results
bpatel
parents: 10190
diff changeset
   407
    }
a08610368936 8024096: some javadoc tests may contain false positive results
bpatel
parents: 10190
diff changeset
   408
a08610368936 8024096: some javadoc tests may contain false positive results
bpatel
parents: 10190
diff changeset
   409
    /**
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   410
     * Check the exit code of the most recent call of javadoc.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   411
     *
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   412
     * @param expected the exit code that is required for the test
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   413
     * to pass.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   414
     */
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   415
    public void checkExit(Exit expected) {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   416
        checking("check exit code");
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   417
        if (exitCode == expected.code) {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   418
            passed("return code " + exitCode);
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   419
        } else {
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 41252
diff changeset
   420
            failed("return code " + exitCode +"; expected " + expected);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   421
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   422
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   423
06bc494ca11e Initial load
duke
parents:
diff changeset
   424
    /**
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   425
     * Check for content in (or not in) the generated output.
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   426
     * Within the search strings, the newline character \n
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   427
     * will be translated to the platform newline character sequence.
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   428
     * @param path a path within the most recent output directory
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   429
     *  or the name of one of the output buffers, identifying
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   430
     *  where to look for the search strings.
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   431
     * @param expectedFound true if all of the search strings are expected
42842
2f0b2a65b284 8171413: jdk/javadoc/doclet/testModules/TestModules.java failed due to some subtests failed
jjg
parents: 41451
diff changeset
   432
     *  to be found, or false if the file is not expected to be found
2f0b2a65b284 8171413: jdk/javadoc/doclet/testModules/TestModules.java failed due to some subtests failed
jjg
parents: 41451
diff changeset
   433
     * @param strings the strings to be searched for
2f0b2a65b284 8171413: jdk/javadoc/doclet/testModules/TestModules.java failed due to some subtests failed
jjg
parents: 41451
diff changeset
   434
     */
2f0b2a65b284 8171413: jdk/javadoc/doclet/testModules/TestModules.java failed due to some subtests failed
jjg
parents: 41451
diff changeset
   435
    public void checkFileAndOutput(String path, boolean expectedFound, String... strings) {
2f0b2a65b284 8171413: jdk/javadoc/doclet/testModules/TestModules.java failed due to some subtests failed
jjg
parents: 41451
diff changeset
   436
        if (expectedFound) {
2f0b2a65b284 8171413: jdk/javadoc/doclet/testModules/TestModules.java failed due to some subtests failed
jjg
parents: 41451
diff changeset
   437
            checkOutput(path, true, strings);
2f0b2a65b284 8171413: jdk/javadoc/doclet/testModules/TestModules.java failed due to some subtests failed
jjg
parents: 41451
diff changeset
   438
        } else {
2f0b2a65b284 8171413: jdk/javadoc/doclet/testModules/TestModules.java failed due to some subtests failed
jjg
parents: 41451
diff changeset
   439
            checkFiles(false, path);
2f0b2a65b284 8171413: jdk/javadoc/doclet/testModules/TestModules.java failed due to some subtests failed
jjg
parents: 41451
diff changeset
   440
        }
2f0b2a65b284 8171413: jdk/javadoc/doclet/testModules/TestModules.java failed due to some subtests failed
jjg
parents: 41451
diff changeset
   441
    }
2f0b2a65b284 8171413: jdk/javadoc/doclet/testModules/TestModules.java failed due to some subtests failed
jjg
parents: 41451
diff changeset
   442
2f0b2a65b284 8171413: jdk/javadoc/doclet/testModules/TestModules.java failed due to some subtests failed
jjg
parents: 41451
diff changeset
   443
    /**
2f0b2a65b284 8171413: jdk/javadoc/doclet/testModules/TestModules.java failed due to some subtests failed
jjg
parents: 41451
diff changeset
   444
     * Check for content in (or not in) the generated output.
2f0b2a65b284 8171413: jdk/javadoc/doclet/testModules/TestModules.java failed due to some subtests failed
jjg
parents: 41451
diff changeset
   445
     * Within the search strings, the newline character \n
2f0b2a65b284 8171413: jdk/javadoc/doclet/testModules/TestModules.java failed due to some subtests failed
jjg
parents: 41451
diff changeset
   446
     * will be translated to the platform newline character sequence.
48325
e5cdedd37b78 8178070: duplicate entries in package table
jjg
parents: 47395
diff changeset
   447
     * @param path a path within the most recent output directory, identifying
42842
2f0b2a65b284 8171413: jdk/javadoc/doclet/testModules/TestModules.java failed due to some subtests failed
jjg
parents: 41451
diff changeset
   448
     *  where to look for the search strings.
2f0b2a65b284 8171413: jdk/javadoc/doclet/testModules/TestModules.java failed due to some subtests failed
jjg
parents: 41451
diff changeset
   449
     * @param expectedFound true if all of the search strings are expected
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   450
     *  to be found, or false if all of the strings are expected to be
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   451
     *  not found
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   452
     * @param strings the strings to be searched for
20238
a08610368936 8024096: some javadoc tests may contain false positive results
bpatel
parents: 10190
diff changeset
   453
     */
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   454
    public void checkOutput(String path, boolean expectedFound, String... strings) {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   455
        // Read contents of file
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   456
        try {
48325
e5cdedd37b78 8178070: duplicate entries in package table
jjg
parents: 47395
diff changeset
   457
            String fileString = readFile(outputDir, path);
e5cdedd37b78 8178070: duplicate entries in package table
jjg
parents: 47395
diff changeset
   458
            checkOutput(new File(outputDir, path).getPath(), fileString, expectedFound, strings);
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   459
        } catch (Error e) {
42842
2f0b2a65b284 8171413: jdk/javadoc/doclet/testModules/TestModules.java failed due to some subtests failed
jjg
parents: 41451
diff changeset
   460
            checking("Read file");
2f0b2a65b284 8171413: jdk/javadoc/doclet/testModules/TestModules.java failed due to some subtests failed
jjg
parents: 41451
diff changeset
   461
            failed("Error reading file: " + e);
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   462
        }
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   463
    }
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   464
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   465
    /**
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   466
     * Check for content in (or not in) the one of the output streams written by
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   467
     * javadoc. Within the search strings, the newline character \n
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   468
     * will be translated to the platform newline character sequence.
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   469
     * @param output the output stream to check
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   470
     * @param expectedFound true if all of the search strings are expected
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   471
     *  to be found, or false if all of the strings are expected to be
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   472
     *  not found
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   473
     * @param strings the strings to be searched for
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   474
     */
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   475
    public void checkOutput(Output output, boolean expectedFound, String... strings) {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   476
        checkOutput(output.toString(), outputMap.get(output), expectedFound, strings);
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   477
    }
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   478
48325
e5cdedd37b78 8178070: duplicate entries in package table
jjg
parents: 47395
diff changeset
   479
    // NOTE: path may be the name of an Output stream as well as a file path
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   480
    private void checkOutput(String path, String fileString, boolean expectedFound, String... strings) {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   481
        for (String stringToFind : strings) {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   482
//            log.logCheckOutput(path, expectedFound, stringToFind);
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   483
            checking("checkOutput");
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   484
            // Find string in file's contents
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   485
            boolean isFound = findString(fileString, stringToFind);
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   486
            if (isFound == expectedFound) {
42842
2f0b2a65b284 8171413: jdk/javadoc/doclet/testModules/TestModules.java failed due to some subtests failed
jjg
parents: 41451
diff changeset
   487
                passed(path + ": following text " + (isFound ? "found:" : "not found:") + "\n"
48325
e5cdedd37b78 8178070: duplicate entries in package table
jjg
parents: 47395
diff changeset
   488
                        + stringToFind);
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   489
            } else {
42842
2f0b2a65b284 8171413: jdk/javadoc/doclet/testModules/TestModules.java failed due to some subtests failed
jjg
parents: 41451
diff changeset
   490
                failed(path + ": following text " + (isFound ? "found:" : "not found:") + "\n"
48325
e5cdedd37b78 8178070: duplicate entries in package table
jjg
parents: 47395
diff changeset
   491
                        + stringToFind);
20238
a08610368936 8024096: some javadoc tests may contain false positive results
bpatel
parents: 10190
diff changeset
   492
            }
a08610368936 8024096: some javadoc tests may contain false positive results
bpatel
parents: 10190
diff changeset
   493
        }
a08610368936 8024096: some javadoc tests may contain false positive results
bpatel
parents: 10190
diff changeset
   494
    }
a08610368936 8024096: some javadoc tests may contain false positive results
bpatel
parents: 10190
diff changeset
   495
a08610368936 8024096: some javadoc tests may contain false positive results
bpatel
parents: 10190
diff changeset
   496
    /**
48325
e5cdedd37b78 8178070: duplicate entries in package table
jjg
parents: 47395
diff changeset
   497
     * Get the content of the one of the output streams written by javadoc.
e5cdedd37b78 8178070: duplicate entries in package table
jjg
parents: 47395
diff changeset
   498
     * @param output the name of the output stream
e5cdedd37b78 8178070: duplicate entries in package table
jjg
parents: 47395
diff changeset
   499
     * @return the content of the output stream
41252
058d83c9b1c7 8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents: 40500
diff changeset
   500
     */
058d83c9b1c7 8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents: 40500
diff changeset
   501
    public String getOutput(Output output) {
058d83c9b1c7 8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents: 40500
diff changeset
   502
        return outputMap.get(output);
058d83c9b1c7 8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents: 40500
diff changeset
   503
    }
058d83c9b1c7 8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents: 40500
diff changeset
   504
058d83c9b1c7 8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents: 40500
diff changeset
   505
    /**
48325
e5cdedd37b78 8178070: duplicate entries in package table
jjg
parents: 47395
diff changeset
   506
     * Get the content of the one of the output streams written by javadoc.
e5cdedd37b78 8178070: duplicate entries in package table
jjg
parents: 47395
diff changeset
   507
     * @param output the name of the output stream
e5cdedd37b78 8178070: duplicate entries in package table
jjg
parents: 47395
diff changeset
   508
     * @return the content of the output stream, as a line of lines
41252
058d83c9b1c7 8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents: 40500
diff changeset
   509
     */
058d83c9b1c7 8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents: 40500
diff changeset
   510
    public List<String> getOutputLines(Output output) {
058d83c9b1c7 8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents: 40500
diff changeset
   511
        String text = outputMap.get(output);
058d83c9b1c7 8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents: 40500
diff changeset
   512
        return (text == null) ? Collections.emptyList() : Arrays.asList(text.split(NL));
058d83c9b1c7 8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents: 40500
diff changeset
   513
    }
058d83c9b1c7 8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents: 40500
diff changeset
   514
058d83c9b1c7 8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents: 40500
diff changeset
   515
    /**
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   516
     * Check for files in (or not in) the generated output.
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   517
     * @param expectedFound true if all of the files are expected
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   518
     *  to be found, or false if all of the files are expected to be
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   519
     *  not found
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   520
     * @param paths the files to check, within the most recent output directory.
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   521
     * */
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   522
    public void checkFiles(boolean expectedFound, String... paths) {
40500
f293dbb81a53 8162353: javadoc should provide a way to disable use of frames
jjg
parents: 35426
diff changeset
   523
        checkFiles(expectedFound, Arrays.asList(paths));
f293dbb81a53 8162353: javadoc should provide a way to disable use of frames
jjg
parents: 35426
diff changeset
   524
    }
f293dbb81a53 8162353: javadoc should provide a way to disable use of frames
jjg
parents: 35426
diff changeset
   525
f293dbb81a53 8162353: javadoc should provide a way to disable use of frames
jjg
parents: 35426
diff changeset
   526
    /**
f293dbb81a53 8162353: javadoc should provide a way to disable use of frames
jjg
parents: 35426
diff changeset
   527
     * Check for files in (or not in) the generated output.
f293dbb81a53 8162353: javadoc should provide a way to disable use of frames
jjg
parents: 35426
diff changeset
   528
     * @param expectedFound true if all of the files are expected
f293dbb81a53 8162353: javadoc should provide a way to disable use of frames
jjg
parents: 35426
diff changeset
   529
     *  to be found, or false if all of the files are expected to be
f293dbb81a53 8162353: javadoc should provide a way to disable use of frames
jjg
parents: 35426
diff changeset
   530
     *  not found
f293dbb81a53 8162353: javadoc should provide a way to disable use of frames
jjg
parents: 35426
diff changeset
   531
     * @param paths the files to check, within the most recent output directory.
f293dbb81a53 8162353: javadoc should provide a way to disable use of frames
jjg
parents: 35426
diff changeset
   532
     * */
f293dbb81a53 8162353: javadoc should provide a way to disable use of frames
jjg
parents: 35426
diff changeset
   533
    public void checkFiles(boolean expectedFound, Collection<String> paths) {
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   534
        for (String path: paths) {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   535
//            log.logCheckFile(path, expectedFound);
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   536
            checking("checkFile");
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   537
            File file = new File(outputDir, path);
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   538
            boolean isFound = file.exists();
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   539
            if (isFound == expectedFound) {
48325
e5cdedd37b78 8178070: duplicate entries in package table
jjg
parents: 47395
diff changeset
   540
                passed(file, "file " + (isFound ? "found:" : "not found:") + "\n");
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   541
            } else {
48325
e5cdedd37b78 8178070: duplicate entries in package table
jjg
parents: 47395
diff changeset
   542
                failed(file, "file " + (isFound ? "found:" : "not found:") + "\n");
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   543
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   544
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   545
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   546
06bc494ca11e Initial load
duke
parents:
diff changeset
   547
    /**
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   548
     * Check that a series of strings are found in order in a file in
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   549
     * the generated output.
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   550
     * @param path the file to check
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   551
     * @param strings  the strings whose order to check
24072
e7549dcbc4af 8040903: Clean up use of BUG_ID in javadoc tests
jjg
parents: 24065
diff changeset
   552
     */
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   553
    public void checkOrder(String path, String... strings) {
48325
e5cdedd37b78 8178070: duplicate entries in package table
jjg
parents: 47395
diff changeset
   554
        File file = new File(outputDir, path);
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   555
        String fileString = readOutputFile(path);
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   556
        int prevIndex = -1;
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   557
        for (String s : strings) {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   558
            s = s.replace("\n", NL); // normalize new lines
47395
2ea4edfdef8e 8157000: Do not generate javadoc for overridden method with no spec change
ksrini
parents: 47328
diff changeset
   559
            int currentIndex = fileString.indexOf(s, prevIndex + 1);
48325
e5cdedd37b78 8178070: duplicate entries in package table
jjg
parents: 47395
diff changeset
   560
            checking("file: " + file + ": " + s + " at index " + currentIndex);
25004
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24399
diff changeset
   561
            if (currentIndex == -1) {
48325
e5cdedd37b78 8178070: duplicate entries in package table
jjg
parents: 47395
diff changeset
   562
                failed(file, s + " not found.");
25004
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24399
diff changeset
   563
                continue;
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24399
diff changeset
   564
            }
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24399
diff changeset
   565
            if (currentIndex > prevIndex) {
48325
e5cdedd37b78 8178070: duplicate entries in package table
jjg
parents: 47395
diff changeset
   566
                passed(file, s + " is in the correct order");
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   567
            } else {
48325
e5cdedd37b78 8178070: duplicate entries in package table
jjg
parents: 47395
diff changeset
   568
                failed(file, s + " is in the wrong order.");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   569
            }
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   570
            prevIndex = currentIndex;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   571
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   572
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   573
06bc494ca11e Initial load
duke
parents:
diff changeset
   574
    /**
26270
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 26091
diff changeset
   575
     * Ensures that a series of strings appear only once, in the generated output,
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 26091
diff changeset
   576
     * noting that, this test does not exhaustively check for all other possible
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 26091
diff changeset
   577
     * duplicates once one is found.
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 26091
diff changeset
   578
     * @param path the file to check
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 26091
diff changeset
   579
     * @param strings ensure each are unique
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 26091
diff changeset
   580
     */
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 26091
diff changeset
   581
    public void checkUnique(String path, String... strings) {
48325
e5cdedd37b78 8178070: duplicate entries in package table
jjg
parents: 47395
diff changeset
   582
        File file = new File(outputDir, path);
26270
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 26091
diff changeset
   583
        String fileString = readOutputFile(path);
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 26091
diff changeset
   584
        for (String s : strings) {
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 26091
diff changeset
   585
            int currentIndex = fileString.indexOf(s);
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 26091
diff changeset
   586
            checking(s + " at index " + currentIndex);
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 26091
diff changeset
   587
            if (currentIndex == -1) {
48325
e5cdedd37b78 8178070: duplicate entries in package table
jjg
parents: 47395
diff changeset
   588
                failed(file, s + " not found.");
26270
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 26091
diff changeset
   589
                continue;
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 26091
diff changeset
   590
            }
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 26091
diff changeset
   591
            int nextindex = fileString.indexOf(s, currentIndex + s.length());
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 26091
diff changeset
   592
            if (nextindex == -1) {
48325
e5cdedd37b78 8178070: duplicate entries in package table
jjg
parents: 47395
diff changeset
   593
                passed(file, s + " is unique");
26270
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 26091
diff changeset
   594
            } else {
48325
e5cdedd37b78 8178070: duplicate entries in package table
jjg
parents: 47395
diff changeset
   595
                failed(file, s + " is not unique, found at " + nextindex);
26270
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 26091
diff changeset
   596
            }
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 26091
diff changeset
   597
        }
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 26091
diff changeset
   598
    }
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 26091
diff changeset
   599
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 26091
diff changeset
   600
    /**
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   601
     * Compare a set of files in each of two directories.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   602
     *
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   603
     * @param baseDir1 the directory containing the first set of files
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   604
     * @param baseDir2 the directory containing the second set of files
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   605
     * @param files the set of files to be compared
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   606
     */
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   607
    public void diff(String baseDir1, String baseDir2, String... files) {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   608
        File bd1 = new File(baseDir1);
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   609
        File bd2 = new File(baseDir2);
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   610
        for (String file : files) {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   611
            diff(bd1, bd2, file);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   612
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   613
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   614
06bc494ca11e Initial load
duke
parents:
diff changeset
   615
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   616
     * A utility to copy a directory from one place to another.
06bc494ca11e Initial load
duke
parents:
diff changeset
   617
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   618
     * @param targetDir the directory to copy.
06bc494ca11e Initial load
duke
parents:
diff changeset
   619
     * @param destDir the destination to copy the directory to.
06bc494ca11e Initial load
duke
parents:
diff changeset
   620
     */
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   621
    // TODO: convert to using java.nio.Files.walkFileTree
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   622
    public void copyDir(String targetDir, String destDir) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   623
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   624
            File targetDirObj = new File(targetDir);
06bc494ca11e Initial load
duke
parents:
diff changeset
   625
            File destDirParentObj = new File(destDir);
06bc494ca11e Initial load
duke
parents:
diff changeset
   626
            File destDirObj = new File(destDirParentObj, targetDirObj.getName());
06bc494ca11e Initial load
duke
parents:
diff changeset
   627
            if (! destDirParentObj.exists()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   628
                destDirParentObj.mkdir();
06bc494ca11e Initial load
duke
parents:
diff changeset
   629
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   630
            if (! destDirObj.exists()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   631
                destDirObj.mkdir();
06bc494ca11e Initial load
duke
parents:
diff changeset
   632
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   633
            String[] files = targetDirObj.list();
24072
e7549dcbc4af 8040903: Clean up use of BUG_ID in javadoc tests
jjg
parents: 24065
diff changeset
   634
            for (String file : files) {
e7549dcbc4af 8040903: Clean up use of BUG_ID in javadoc tests
jjg
parents: 24065
diff changeset
   635
                File srcFile = new File(targetDirObj, file);
e7549dcbc4af 8040903: Clean up use of BUG_ID in javadoc tests
jjg
parents: 24065
diff changeset
   636
                File destFile = new File(destDirObj, file);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   637
                if (srcFile.isFile()) {
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   638
                    out.println("Copying " + srcFile + " to " + destFile);
24072
e7549dcbc4af 8040903: Clean up use of BUG_ID in javadoc tests
jjg
parents: 24065
diff changeset
   639
                    copyFile(destFile, srcFile);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   640
                } else if(srcFile.isDirectory()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   641
                    copyDir(srcFile.getAbsolutePath(), destDirObj.getAbsolutePath());
06bc494ca11e Initial load
duke
parents:
diff changeset
   642
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   643
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   644
        } catch (IOException exc) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   645
            throw new Error("Could not copy " + targetDir + " to " + destDir);
06bc494ca11e Initial load
duke
parents:
diff changeset
   646
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   647
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   648
06bc494ca11e Initial load
duke
parents:
diff changeset
   649
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   650
     * Copy source file to destination file.
06bc494ca11e Initial load
duke
parents:
diff changeset
   651
     *
24072
e7549dcbc4af 8040903: Clean up use of BUG_ID in javadoc tests
jjg
parents: 24065
diff changeset
   652
     * @param destfile the destination file
e7549dcbc4af 8040903: Clean up use of BUG_ID in javadoc tests
jjg
parents: 24065
diff changeset
   653
     * @param srcfile the source file
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   654
     * @throws IOException
06bc494ca11e Initial load
duke
parents:
diff changeset
   655
     */
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   656
    public void copyFile(File destfile, File srcfile) throws IOException {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   657
        Files.copy(srcfile.toPath(), destfile.toPath());
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   658
    }
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   659
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   660
    /**
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   661
     * Read a file from the output directory.
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   662
     *
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   663
     * @param fileName  the name of the file to read
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   664
     * @return          the file in string format
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   665
     */
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   666
    public String readOutputFile(String fileName) throws Error {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   667
        return readFile(outputDir, fileName);
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   668
    }
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   669
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   670
    protected String readFile(String fileName) throws Error {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   671
        return readFile(outputDir, fileName);
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   672
    }
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   673
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   674
    protected String readFile(String baseDir, String fileName) throws Error {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   675
        return readFile(new File(baseDir), fileName);
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   676
    }
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   677
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   678
    /**
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   679
     * Read the file and return it as a string.
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   680
     *
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   681
     * @param baseDir   the directory in which to locate the file
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   682
     * @param fileName  the name of the file to read
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   683
     * @return          the file in string format
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   684
     */
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   685
    private String readFile(File baseDir, String fileName) throws Error {
47328
d18df41954ba 8187521: In some corner cases the javadoc tool can reuse id attribute
jjg
parents: 47216
diff changeset
   686
        if (!Objects.equals(fileContentCacheCharset, charset)) {
d18df41954ba 8187521: In some corner cases the javadoc tool can reuse id attribute
jjg
parents: 47216
diff changeset
   687
            fileContentCache.clear();
d18df41954ba 8187521: In some corner cases the javadoc tool can reuse id attribute
jjg
parents: 47216
diff changeset
   688
            fileContentCacheCharset = charset;
d18df41954ba 8187521: In some corner cases the javadoc tool can reuse id attribute
jjg
parents: 47216
diff changeset
   689
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   690
        try {
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   691
            File file = new File(baseDir, fileName);
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   692
            SoftReference<String> ref = fileContentCache.get(file);
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   693
            String content = (ref == null) ? null : ref.get();
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   694
            if (content != null)
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   695
                return content;
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   696
47328
d18df41954ba 8187521: In some corner cases the javadoc tool can reuse id attribute
jjg
parents: 47216
diff changeset
   697
            // charset defaults to a value inferred from latest javadoc run
d18df41954ba 8187521: In some corner cases the javadoc tool can reuse id attribute
jjg
parents: 47216
diff changeset
   698
            content = new String(Files.readAllBytes(file.toPath()), charset);
40500
f293dbb81a53 8162353: javadoc should provide a way to disable use of frames
jjg
parents: 35426
diff changeset
   699
            fileContentCache.put(file, new SoftReference<>(content));
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   700
            return content;
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   701
        } catch (FileNotFoundException e) {
42842
2f0b2a65b284 8171413: jdk/javadoc/doclet/testModules/TestModules.java failed due to some subtests failed
jjg
parents: 41451
diff changeset
   702
            throw new Error("File not found: " + fileName + ": " + e);
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   703
        } catch (IOException e) {
42842
2f0b2a65b284 8171413: jdk/javadoc/doclet/testModules/TestModules.java failed due to some subtests failed
jjg
parents: 41451
diff changeset
   704
            throw new Error("Error reading file: " + fileName + ": " + e);
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   705
        }
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   706
    }
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   707
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   708
    protected void checking(String message) {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   709
        numTestsRun++;
48325
e5cdedd37b78 8178070: duplicate entries in package table
jjg
parents: 47395
diff changeset
   710
        javadocTestNum++;
e5cdedd37b78 8178070: duplicate entries in package table
jjg
parents: 47395
diff changeset
   711
        print("Starting subtest " + javadocRunNum + "." + javadocTestNum, message);
e5cdedd37b78 8178070: duplicate entries in package table
jjg
parents: 47395
diff changeset
   712
    }
e5cdedd37b78 8178070: duplicate entries in package table
jjg
parents: 47395
diff changeset
   713
e5cdedd37b78 8178070: duplicate entries in package table
jjg
parents: 47395
diff changeset
   714
    protected void passed(File file, String message) {
e5cdedd37b78 8178070: duplicate entries in package table
jjg
parents: 47395
diff changeset
   715
        passed(file + ": " + message);
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   716
    }
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   717
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   718
    protected void passed(String message) {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   719
        numTestsPassed++;
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   720
        print("Passed", message);
48325
e5cdedd37b78 8178070: duplicate entries in package table
jjg
parents: 47395
diff changeset
   721
        out.println();
e5cdedd37b78 8178070: duplicate entries in package table
jjg
parents: 47395
diff changeset
   722
    }
e5cdedd37b78 8178070: duplicate entries in package table
jjg
parents: 47395
diff changeset
   723
e5cdedd37b78 8178070: duplicate entries in package table
jjg
parents: 47395
diff changeset
   724
    protected void failed(File file, String message) {
e5cdedd37b78 8178070: duplicate entries in package table
jjg
parents: 47395
diff changeset
   725
        failed(file + ": " + message);
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   726
    }
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   727
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   728
    protected void failed(String message) {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   729
        print("FAILED", message);
48325
e5cdedd37b78 8178070: duplicate entries in package table
jjg
parents: 47395
diff changeset
   730
        StackWalker.getInstance().walk(s -> {
e5cdedd37b78 8178070: duplicate entries in package table
jjg
parents: 47395
diff changeset
   731
            s.dropWhile(f -> f.getMethodName().equals("failed"))
e5cdedd37b78 8178070: duplicate entries in package table
jjg
parents: 47395
diff changeset
   732
                    .takeWhile(f -> !f.getMethodName().equals("runTests"))
e5cdedd37b78 8178070: duplicate entries in package table
jjg
parents: 47395
diff changeset
   733
                    .forEach(f -> out.println("        at "
e5cdedd37b78 8178070: duplicate entries in package table
jjg
parents: 47395
diff changeset
   734
                            + f.getClassName() + "." + f.getMethodName()
e5cdedd37b78 8178070: duplicate entries in package table
jjg
parents: 47395
diff changeset
   735
                            + "(" + f.getFileName() + ":" + f.getLineNumber() + ")"));
e5cdedd37b78 8178070: duplicate entries in package table
jjg
parents: 47395
diff changeset
   736
            return null;
e5cdedd37b78 8178070: duplicate entries in package table
jjg
parents: 47395
diff changeset
   737
        });
e5cdedd37b78 8178070: duplicate entries in package table
jjg
parents: 47395
diff changeset
   738
        out.println();
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   739
    }
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   740
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   741
    private void print(String prefix, String message) {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   742
        if (message.isEmpty())
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   743
            out.println(prefix);
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   744
        else {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   745
            out.print(prefix);
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   746
            out.print(": ");
48325
e5cdedd37b78 8178070: duplicate entries in package table
jjg
parents: 47395
diff changeset
   747
            out.print(message.replace("\n", NL));
e5cdedd37b78 8178070: duplicate entries in package table
jjg
parents: 47395
diff changeset
   748
            if (!(message.endsWith("\n") || message.endsWith(NL))) {
e5cdedd37b78 8178070: duplicate entries in package table
jjg
parents: 47395
diff changeset
   749
                out.println();
e5cdedd37b78 8178070: duplicate entries in package table
jjg
parents: 47395
diff changeset
   750
            }
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   751
        }
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   752
    }
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   753
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   754
    /**
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   755
     * Print a summary of the test results.
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   756
     */
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   757
    protected void printSummary() {
40500
f293dbb81a53 8162353: javadoc should provide a way to disable use of frames
jjg
parents: 35426
diff changeset
   758
        String javadocRuns = (javadocRunNum <= 1) ? ""
f293dbb81a53 8162353: javadoc should provide a way to disable use of frames
jjg
parents: 35426
diff changeset
   759
                : ", in " + javadocRunNum + " runs of javadoc";
f293dbb81a53 8162353: javadoc should provide a way to disable use of frames
jjg
parents: 35426
diff changeset
   760
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   761
        if (numTestsRun != 0 && numTestsPassed == numTestsRun) {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   762
            // Test passed
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   763
            out.println();
40500
f293dbb81a53 8162353: javadoc should provide a way to disable use of frames
jjg
parents: 35426
diff changeset
   764
            out.println("All " + numTestsPassed + " subtests passed" + javadocRuns);
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   765
        } else {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   766
            // Test failed
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   767
            throw new Error((numTestsRun - numTestsPassed)
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   768
                    + " of " + (numTestsRun)
40500
f293dbb81a53 8162353: javadoc should provide a way to disable use of frames
jjg
parents: 35426
diff changeset
   769
                    + " subtests failed"
f293dbb81a53 8162353: javadoc should provide a way to disable use of frames
jjg
parents: 35426
diff changeset
   770
                    + javadocRuns);
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   771
        }
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   772
    }
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   773
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   774
    /**
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   775
     * Search for the string in the given file and return true
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   776
     * if the string was found.
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   777
     *
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   778
     * @param fileString    the contents of the file to search through
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   779
     * @param stringToFind  the string to search for
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   780
     * @return              true if the string was found
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   781
     */
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   782
    private boolean findString(String fileString, String stringToFind) {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   783
        // javadoc (should) always use the platform newline sequence,
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   784
        // but in the strings to find it is more convenient to use the Java
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   785
        // newline character. So we translate \n to NL before we search.
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   786
        stringToFind = stringToFind.replace("\n", NL);
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   787
        return fileString.contains(stringToFind);
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   788
    }
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   789
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   790
    /**
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   791
     * Compare the two given files.
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   792
     *
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   793
     * @param baseDir1 the directory in which to locate the first file
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   794
     * @param baseDir2 the directory in which to locate the second file
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   795
     * @param file the file to compare in the two base directories
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   796
     * @param throwErrorIFNoMatch flag to indicate whether or not to throw
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   797
     * an error if the files do not match.
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   798
     * @return true if the files are the same and false otherwise.
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   799
     */
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   800
    private void diff(File baseDir1, File baseDir2, String file) {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   801
        String file1Contents = readFile(baseDir1, file);
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   802
        String file2Contents = readFile(baseDir2, file);
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   803
        checking("diff " + new File(baseDir1, file) + ", " + new File(baseDir2, file));
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   804
        if (file1Contents.trim().compareTo(file2Contents.trim()) == 0) {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   805
            passed("files are equal");
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   806
        } else {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   807
            failed("files differ");
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   808
        }
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   809
    }
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   810
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   811
    /**
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   812
     * Utility class to simplify the handling of temporarily setting a
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   813
     * new stream for System.out or System.err.
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   814
     */
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   815
    private static class StreamOutput {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   816
        // functional interface to set a stream.
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   817
        private interface Initializer {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   818
            void set(PrintStream s);
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   819
        }
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   820
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   821
        private final ByteArrayOutputStream baos = new ByteArrayOutputStream();
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   822
        private final PrintStream ps = new PrintStream(baos);
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   823
        private final PrintStream prev;
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   824
        private final Initializer init;
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   825
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   826
        StreamOutput(PrintStream s, Initializer init) {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   827
            prev = s;
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   828
            init.set(ps);
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   829
            this.init = init;
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   830
        }
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   831
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   832
        String close() {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   833
            init.set(prev);
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   834
            ps.close();
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   835
            return baos.toString();
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   836
        }
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   837
    }
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   838
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   839
    /**
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   840
     * Utility class to simplify the handling of creating an in-memory PrintWriter.
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   841
     */
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   842
    private static class WriterOutput {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   843
        private final StringWriter sw = new StringWriter();
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   844
        final PrintWriter pw = new PrintWriter(sw);
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   845
        String close() {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   846
            pw.close();
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   847
            return sw.toString();
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   848
        }
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   849
    }
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   850
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   851
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   852
//    private final Logger log = new Logger();
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   853
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   854
    //--------- Logging --------------------------------------------------------
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   855
    //
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   856
    // This class writes out the details of calls to checkOutput and checkFile
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   857
    // in a canonical way, so that the resulting file can be checked against
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   858
    // similar files from other versions of JavadocTester using the same logging
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   859
    // facilities.
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   860
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   861
    static class Logger {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   862
        private static final int PREFIX = 40;
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   863
        private static final int SUFFIX = 20;
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   864
        private static final int MAX = PREFIX + SUFFIX;
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   865
        List<String> tests = new ArrayList<>();
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   866
        String outDir;
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   867
        String rootDir = rootDir();
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   868
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   869
        static String rootDir() {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   870
            File f = new File(".").getAbsoluteFile();
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   871
            while (!new File(f, ".hg").exists())
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   872
                f = f.getParentFile();
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   873
            return f.getPath();
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   874
        }
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   875
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   876
        void setOutDir(File outDir) {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   877
            this.outDir = outDir.getPath();
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   878
        }
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   879
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   880
        void logCheckFile(String file, boolean positive) {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   881
            // Strip the outdir because that will typically not be the same
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   882
            if (file.startsWith(outDir + "/"))
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   883
                file = file.substring(outDir.length() + 1);
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   884
            tests.add(file + " " + positive);
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   885
        }
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   886
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   887
        void logCheckOutput(String file, boolean positive, String text) {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   888
            // Compress the string to be displayed in the log file
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   889
            String simpleText = text.replaceAll("\\s+", " ").replace(rootDir, "[ROOT]");
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   890
            if (simpleText.length() > MAX)
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   891
                simpleText = simpleText.substring(0, PREFIX)
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   892
                        + "..." + simpleText.substring(simpleText.length() - SUFFIX);
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   893
            // Strip the outdir because that will typically not be the same
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   894
            if (file.startsWith(outDir + "/"))
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   895
                file = file.substring(outDir.length() + 1);
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   896
            // The use of text.hashCode ensure that all of "text" is taken into account
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   897
            tests.add(file + " " + positive + " " + text.hashCode() + " " + simpleText);
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   898
        }
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   899
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   900
        void write() {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   901
            // sort the log entries because the subtests may not be executed in the same order
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   902
            tests.sort((a, b) -> a.compareTo(b));
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   903
            try (BufferedWriter bw = new BufferedWriter(new FileWriter("tester.log"))) {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   904
                for (String t: tests) {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   905
                    bw.write(t);
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   906
                    bw.newLine();
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   907
                }
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   908
            } catch (IOException e) {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   909
                throw new Error("problem writing log: " + e);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   910
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   911
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   912
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   913
}