langtools/test/jdk/javadoc/doclet/lib/JavadocTester.java
author jjg
Mon, 15 Aug 2016 18:00:36 -0700
changeset 40500 f293dbb81a53
parent 35426 374342e56a56
child 41252 058d83c9b1c7
permissions -rw-r--r--
8162353: javadoc should provide a way to disable use of frames Reviewed-by: bpatel, ksrini
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
40500
f293dbb81a53 8162353: javadoc should provide a way to disable use of frames
jjg
parents: 35426
diff changeset
     2
 * Copyright (c) 2002, 2016, 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;
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    40
import java.nio.file.Files;
26091
c40ba05822ad 8054044: [javadoc] javadoc tester must print out the javadoc run arguments.
ksrini
parents: 25004
diff changeset
    41
import java.util.Arrays;
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    42
import java.util.ArrayList;
40500
f293dbb81a53 8162353: javadoc should provide a way to disable use of frames
jjg
parents: 35426
diff changeset
    43
import java.util.Collection;
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    44
import java.util.EnumMap;
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    45
import java.util.HashMap;
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    46
import java.util.List;
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    47
import java.util.Map;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
/**
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    51
 * 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
    52
 *
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    53
 * <p>
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    54
 * 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
    55
 * 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
    56
 * 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
    57
 * 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
    58
 * 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
    59
 *
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    60
 * <p>
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    61
 * 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
    62
 * 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
    63
 * 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
    64
 * contained therein.
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    65
 *
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    66
 * <p>
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    67
 * 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
    68
 * 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
    69
 *
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    70
 * <dl>
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    71
 * <dt>checkExitCode
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    72
 * <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
    73
 * <dt>checkOutput
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    74
 * <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
    75
 *     generated by javadoc.
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    76
 *     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
    77
 * <dt>checkFiles
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    78
 * <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
    79
 *     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
    80
 * </dl>
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    81
 *
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    82
 * <pre><code>
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    83
 *  public class MyTester extends JavadocTester {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    84
 *      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
    85
 *          MyTester tester = new MyTester();
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    86
 *          tester.runTests();
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    87
 *      }
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    88
 *
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    89
 *      // test methods...
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    90
 *      @Test
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    91
 *      void test() {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    92
 *          javadoc(<i>args</i>);
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    93
 *          checkExit(Exit.OK);
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    94
 *          checkOutput(<i>file</i>, true,
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    95
 *              <i>strings-to-find</i>);
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    96
 *          checkOutput(<i>file</i>, false,
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    97
 *              <i>strings-to-not-find</i>);
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    98
 *      }
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
    99
 *  }
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   100
 * </code></pre>
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   101
 *
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   102
 * <p>
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   103
 * 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
   104
 * 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
   105
 * 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
   106
 * 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
   107
 *
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   108
 * <p>
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   109
 * 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
   110
 * 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
   111
 * 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
   112
 * 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
   113
 * 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
   114
 *
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   115
 * <p>
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   116
 * 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
   117
 * 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
   118
 * 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
   119
 * succeeded or not.
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   120
 *
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   121
 * <p>
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   122
 * 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
   123
 * 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
   124
 * 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
   125
 * 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
   126
 * 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
   127
 * test methods, each with their own set of checks on the results.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
 * @author Doug Kramer
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
 * @author Jamie Ho
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   131
 * @author Jonathan Gibbons (rewrite)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
public abstract class JavadocTester {
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   135
    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
   136
    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
   137
    public static final String NL = System.getProperty("line.separator");
23971
f5ff1f5a8dee 8031649: Clean up javadoc tests
jjg
parents: 20238
diff changeset
   138
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   139
    public enum Output {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   140
        /** The name of the output stream from javadoc. */
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   141
        OUT,
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   142
        /** 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
   143
        STDOUT,
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   144
        /** 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
   145
        STDERR
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   146
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   148
    /** 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
   149
    protected File outputDir;
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   150
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   151
    /** 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
   152
    private int exitCode;
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   153
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   154
    /** 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
   155
    private final Map<Output, String> outputMap = new EnumMap<>(Output.class);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   157
    /** 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
   158
    private final Map<File,SoftReference<String>> fileContentCache = new HashMap<>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   160
    /** Stream used for logging messages. */
40500
f293dbb81a53 8162353: javadoc should provide a way to disable use of frames
jjg
parents: 35426
diff changeset
   161
    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
   162
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   163
    /** 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
   164
    public static final String testSrc = System.getProperty("test.src");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
    /**
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   167
     * 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
   168
     * @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
   169
     * @return the full path of the specified file
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
     */
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   171
    public static String testSrc(String path) {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   172
        return new File(testSrc, path).getPath();
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   173
    }
24072
e7549dcbc4af 8040903: Clean up use of BUG_ID in javadoc tests
jjg
parents: 24065
diff changeset
   174
e7549dcbc4af 8040903: Clean up use of BUG_ID in javadoc tests
jjg
parents: 24065
diff changeset
   175
    /**
24217
25b12d4d4192 8040904: Ensure javadoc tests do not overwrite results within tests
jjg
parents: 24072
diff changeset
   176
     * Alternatives for checking the contents of a directory.
25b12d4d4192 8040904: Ensure javadoc tests do not overwrite results within tests
jjg
parents: 24072
diff changeset
   177
     */
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   178
    public enum DirectoryCheck {
24217
25b12d4d4192 8040904: Ensure javadoc tests do not overwrite results within tests
jjg
parents: 24072
diff changeset
   179
        /**
25b12d4d4192 8040904: Ensure javadoc tests do not overwrite results within tests
jjg
parents: 24072
diff changeset
   180
         * Check that the directory is empty.
25b12d4d4192 8040904: Ensure javadoc tests do not overwrite results within tests
jjg
parents: 24072
diff changeset
   181
         */
25b12d4d4192 8040904: Ensure javadoc tests do not overwrite results within tests
jjg
parents: 24072
diff changeset
   182
        EMPTY((file, name) -> true),
25b12d4d4192 8040904: Ensure javadoc tests do not overwrite results within tests
jjg
parents: 24072
diff changeset
   183
        /**
25b12d4d4192 8040904: Ensure javadoc tests do not overwrite results within tests
jjg
parents: 24072
diff changeset
   184
         * 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
   185
         * 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
   186
         * using this directory.
25b12d4d4192 8040904: Ensure javadoc tests do not overwrite results within tests
jjg
parents: 24072
diff changeset
   187
         * 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
   188
         */
25b12d4d4192 8040904: Ensure javadoc tests do not overwrite results within tests
jjg
parents: 24072
diff changeset
   189
        NO_HTML_FILES((file, name) -> name.endsWith(".html")),
25b12d4d4192 8040904: Ensure javadoc tests do not overwrite results within tests
jjg
parents: 24072
diff changeset
   190
        /**
25b12d4d4192 8040904: Ensure javadoc tests do not overwrite results within tests
jjg
parents: 24072
diff changeset
   191
         * No check is performed on the directory contents.
25b12d4d4192 8040904: Ensure javadoc tests do not overwrite results within tests
jjg
parents: 24072
diff changeset
   192
         */
25b12d4d4192 8040904: Ensure javadoc tests do not overwrite results within tests
jjg
parents: 24072
diff changeset
   193
        NONE(null) { @Override void check(File dir) { } };
25b12d4d4192 8040904: Ensure javadoc tests do not overwrite results within tests
jjg
parents: 24072
diff changeset
   194
25b12d4d4192 8040904: Ensure javadoc tests do not overwrite results within tests
jjg
parents: 24072
diff changeset
   195
        /** 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
   196
        FilenameFilter filter;
25b12d4d4192 8040904: Ensure javadoc tests do not overwrite results within tests
jjg
parents: 24072
diff changeset
   197
25b12d4d4192 8040904: Ensure javadoc tests do not overwrite results within tests
jjg
parents: 24072
diff changeset
   198
        DirectoryCheck(FilenameFilter f) {
25b12d4d4192 8040904: Ensure javadoc tests do not overwrite results within tests
jjg
parents: 24072
diff changeset
   199
            filter = f;
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
25b12d4d4192 8040904: Ensure javadoc tests do not overwrite results within tests
jjg
parents: 24072
diff changeset
   202
        void check(File dir) {
25b12d4d4192 8040904: Ensure javadoc tests do not overwrite results within tests
jjg
parents: 24072
diff changeset
   203
            if (dir.isDirectory()) {
25b12d4d4192 8040904: Ensure javadoc tests do not overwrite results within tests
jjg
parents: 24072
diff changeset
   204
                String[] contents = dir.list(filter);
25b12d4d4192 8040904: Ensure javadoc tests do not overwrite results within tests
jjg
parents: 24072
diff changeset
   205
                if (contents == null)
25b12d4d4192 8040904: Ensure javadoc tests do not overwrite results within tests
jjg
parents: 24072
diff changeset
   206
                    throw new Error("cannot list directory: " + dir);
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   207
                if (contents.length > 0) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   208
                    System.err.println("Found extraneous files in dir:" + dir.getAbsolutePath());
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   209
                    for (String x : contents) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   210
                        System.err.println(x);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   211
                    }
24217
25b12d4d4192 8040904: Ensure javadoc tests do not overwrite results within tests
jjg
parents: 24072
diff changeset
   212
                    throw new Error("directory has unexpected content: " + dir);
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   213
                }
24217
25b12d4d4192 8040904: Ensure javadoc tests do not overwrite results within tests
jjg
parents: 24072
diff changeset
   214
            }
25b12d4d4192 8040904: Ensure javadoc tests do not overwrite results within tests
jjg
parents: 24072
diff changeset
   215
        }
25b12d4d4192 8040904: Ensure javadoc tests do not overwrite results within tests
jjg
parents: 24072
diff changeset
   216
    }
25b12d4d4192 8040904: Ensure javadoc tests do not overwrite results within tests
jjg
parents: 24072
diff changeset
   217
25b12d4d4192 8040904: Ensure javadoc tests do not overwrite results within tests
jjg
parents: 24072
diff changeset
   218
    private DirectoryCheck outputDirectoryCheck = DirectoryCheck.EMPTY;
25b12d4d4192 8040904: Ensure javadoc tests do not overwrite results within tests
jjg
parents: 24072
diff changeset
   219
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   220
    /** 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
   221
    private int numTestsRun = 0;
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   222
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   223
    /** 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
   224
    private int numTestsPassed = 0;
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   225
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   226
    /** 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
   227
    private int javadocRunNum = 0;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   228
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   229
    /** 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
   230
    @Retention(RetentionPolicy.RUNTIME)
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   231
    @interface Test { }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   232
06bc494ca11e Initial load
duke
parents:
diff changeset
   233
    /**
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   234
     * 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
   235
     * 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
   236
     * @throws Exception if any errors occurred
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   237
     */
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   238
    public void runTests() throws Exception {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   239
        for (Method m: getClass().getDeclaredMethods()) {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   240
            Annotation a = m.getAnnotation(Test.class);
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   241
            if (a != null) {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   242
                try {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   243
                    out.println("Running test " + m.getName());
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   244
                    m.invoke(this, new Object[] { });
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   245
                } catch (InvocationTargetException e) {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   246
                    Throwable cause = e.getCause();
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   247
                    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
   248
                }
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   249
                out.println();
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   250
            }
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   251
        }
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   252
        printSummary();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   253
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   254
06bc494ca11e Initial load
duke
parents:
diff changeset
   255
    /**
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   256
     * Run javadoc.
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   257
     * 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
   258
     * will be saved for later use.
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   259
     * 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
   260
     * 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
   261
     *
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   262
     * Example:
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   263
     * <pre><code>
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   264
     *  javadoc("-d", "out",
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   265
     *          "-sourcepath", testSrc,
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   266
     *          "-notimestamp",
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   267
     *          "pkg1", "pkg2", "pkg3/C.java");
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   268
     * </code></pre>
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   269
     *
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   270
     * @param args the arguments to pass to javadoc
20238
a08610368936 8024096: some javadoc tests may contain false positive results
bpatel
parents: 10190
diff changeset
   271
     */
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   272
    public void javadoc(String... args) {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   273
        outputMap.clear();
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   274
        fileContentCache.clear();
20238
a08610368936 8024096: some javadoc tests may contain false positive results
bpatel
parents: 10190
diff changeset
   275
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   276
        javadocRunNum++;
06bc494ca11e Initial load
duke
parents:
diff changeset
   277
        if (javadocRunNum == 1) {
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   278
            out.println("Running javadoc...");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   279
        } else {
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   280
            out.println("Running javadoc (run "
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   281
                                    + javadocRunNum + ")...");
06bc494ca11e Initial load
duke
parents:
diff changeset
   282
        }
24072
e7549dcbc4af 8040903: Clean up use of BUG_ID in javadoc tests
jjg
parents: 24065
diff changeset
   283
        outputDir = new File(".");
e7549dcbc4af 8040903: Clean up use of BUG_ID in javadoc tests
jjg
parents: 24065
diff changeset
   284
        for (int i = 0; i < args.length - 2; i++) {
e7549dcbc4af 8040903: Clean up use of BUG_ID in javadoc tests
jjg
parents: 24065
diff changeset
   285
            if (args[i].equals("-d")) {
e7549dcbc4af 8040903: Clean up use of BUG_ID in javadoc tests
jjg
parents: 24065
diff changeset
   286
                outputDir = new File(args[++i]);
e7549dcbc4af 8040903: Clean up use of BUG_ID in javadoc tests
jjg
parents: 24065
diff changeset
   287
                break;
e7549dcbc4af 8040903: Clean up use of BUG_ID in javadoc tests
jjg
parents: 24065
diff changeset
   288
            }
e7549dcbc4af 8040903: Clean up use of BUG_ID in javadoc tests
jjg
parents: 24065
diff changeset
   289
        }
26091
c40ba05822ad 8054044: [javadoc] javadoc tester must print out the javadoc run arguments.
ksrini
parents: 25004
diff changeset
   290
        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
   291
//        log.setOutDir(outputDir);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   292
24217
25b12d4d4192 8040904: Ensure javadoc tests do not overwrite results within tests
jjg
parents: 24072
diff changeset
   293
        outputDirectoryCheck.check(outputDir);
25b12d4d4192 8040904: Ensure javadoc tests do not overwrite results within tests
jjg
parents: 24072
diff changeset
   294
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   295
        // This is the sole stream used by javadoc
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   296
        WriterOutput outOut = new WriterOutput();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   297
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   298
        // 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
   299
        // 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
   300
        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
   301
        StreamOutput sysErr = new StreamOutput(System.err, System::setErr);
10190
11c701650189 6735320: StringIndexOutOfBoundsException for empty @serialField tag
ksrini
parents: 5520
diff changeset
   302
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   303
        try {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   304
            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
   305
        } finally {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   306
            outputMap.put(Output.STDOUT, sysOut.close());
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   307
            outputMap.put(Output.STDERR, sysErr.close());
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   308
            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
   309
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   310
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   311
        outputMap.forEach((name, text) -> {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   312
            if (!text.isEmpty()) {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   313
                out.println("javadoc " + name + ":");
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   314
                out.println(text);
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   315
            }
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   316
        });
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   317
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   318
06bc494ca11e Initial load
duke
parents:
diff changeset
   319
    /**
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   320
     * 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
   321
     * before javadoc is run.
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   322
     * 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
   323
     * @param c the kind of check to perform
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   324
     */
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   325
    public void setOutputDirectoryCheck(DirectoryCheck c) {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   326
        outputDirectoryCheck = c;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   327
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   328
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   329
    public enum Exit {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   330
        OK(0),
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   331
        FAILED(1);
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   332
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   333
        Exit(int code) {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   334
            this.code = code;
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   335
        }
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   336
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   337
        final int code;
20238
a08610368936 8024096: some javadoc tests may contain false positive results
bpatel
parents: 10190
diff changeset
   338
    }
a08610368936 8024096: some javadoc tests may contain false positive results
bpatel
parents: 10190
diff changeset
   339
a08610368936 8024096: some javadoc tests may contain false positive results
bpatel
parents: 10190
diff changeset
   340
    /**
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   341
     * Check the exit code of the most recent call of javadoc.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   342
     *
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   343
     * @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
   344
     * to pass.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   345
     */
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   346
    public void checkExit(Exit expected) {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   347
        checking("check exit code");
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   348
        if (exitCode == expected.code) {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   349
            passed("return code " + exitCode);
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   350
        } else {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   351
            failed("return code " + exitCode +"; expected " + expected.code + " (" + expected + ")");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   352
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   353
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   354
06bc494ca11e Initial load
duke
parents:
diff changeset
   355
    /**
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   356
     * 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
   357
     * 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
   358
     * 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
   359
     * @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
   360
     *  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
   361
     *  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
   362
     * @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
   363
     *  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
   364
     *  not found
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   365
     * @param strings the strings to be searched for
20238
a08610368936 8024096: some javadoc tests may contain false positive results
bpatel
parents: 10190
diff changeset
   366
     */
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   367
    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
   368
        // Read contents of file
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   369
        String fileString;
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   370
        try {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   371
            fileString = readFile(outputDir, path);
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   372
        } catch (Error e) {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   373
            if (!expectedFound) {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   374
                failed("Error reading file: " + e);
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   375
                return;
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   376
            }
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   377
            throw e;
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   378
        }
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   379
        checkOutput(path, fileString, expectedFound, strings);
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   380
    }
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   381
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   382
    /**
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   383
     * 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
   384
     * 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
   385
     * 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
   386
     * @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
   387
     * @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
   388
     *  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
   389
     *  not found
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   390
     * @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
   391
     */
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   392
    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
   393
        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
   394
    }
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   395
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   396
    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
   397
        for (String stringToFind : strings) {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   398
//            log.logCheckOutput(path, expectedFound, stringToFind);
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   399
            checking("checkOutput");
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   400
            // Find string in file's contents
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   401
            boolean isFound = findString(fileString, stringToFind);
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   402
            if (isFound == expectedFound) {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   403
                passed(path + ": " + (isFound ? "found:" : "not found:") + "\n"
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   404
                        + stringToFind + "\n");
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   405
            } else {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   406
                failed(path + ": " + (isFound ? "found:" : "not found:") + "\n"
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   407
                        + stringToFind + "\n");
20238
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
        }
a08610368936 8024096: some javadoc tests may contain false positive results
bpatel
parents: 10190
diff changeset
   410
    }
a08610368936 8024096: some javadoc tests may contain false positive results
bpatel
parents: 10190
diff changeset
   411
a08610368936 8024096: some javadoc tests may contain false positive results
bpatel
parents: 10190
diff changeset
   412
    /**
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   413
     * 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
   414
     * @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
   415
     *  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
   416
     *  not found
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   417
     * @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
   418
     * */
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   419
    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
   420
        checkFiles(expectedFound, Arrays.asList(paths));
f293dbb81a53 8162353: javadoc should provide a way to disable use of frames
jjg
parents: 35426
diff changeset
   421
    }
f293dbb81a53 8162353: javadoc should provide a way to disable use of frames
jjg
parents: 35426
diff changeset
   422
f293dbb81a53 8162353: javadoc should provide a way to disable use of frames
jjg
parents: 35426
diff changeset
   423
    /**
f293dbb81a53 8162353: javadoc should provide a way to disable use of frames
jjg
parents: 35426
diff changeset
   424
     * 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
   425
     * @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
   426
     *  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
   427
     *  not found
f293dbb81a53 8162353: javadoc should provide a way to disable use of frames
jjg
parents: 35426
diff changeset
   428
     * @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
   429
     * */
f293dbb81a53 8162353: javadoc should provide a way to disable use of frames
jjg
parents: 35426
diff changeset
   430
    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
   431
        for (String path: paths) {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   432
//            log.logCheckFile(path, expectedFound);
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   433
            checking("checkFile");
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   434
            File file = new File(outputDir, path);
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   435
            boolean isFound = file.exists();
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   436
            if (isFound == expectedFound) {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   437
                passed(path + ": " + (isFound ? "found:" : "not found:") + "\n");
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   438
            } else {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   439
                failed(path + ": " + (isFound ? "found:" : "not found:") + "\n");
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   440
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   441
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   442
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   443
06bc494ca11e Initial load
duke
parents:
diff changeset
   444
    /**
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   445
     * 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
   446
     * the generated output.
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   447
     * @param path the file to check
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   448
     * @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
   449
     */
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   450
    public void checkOrder(String path, String... strings) {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   451
        String fileString = readOutputFile(path);
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   452
        int prevIndex = -1;
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   453
        for (String s : strings) {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   454
            s = s.replace("\n", NL); // normalize new lines
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   455
            int currentIndex = fileString.indexOf(s);
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   456
            checking(s + " at index " + currentIndex);
25004
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24399
diff changeset
   457
            if (currentIndex == -1) {
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24399
diff changeset
   458
                failed(s + " not found.");
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24399
diff changeset
   459
                continue;
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24399
diff changeset
   460
            }
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24399
diff changeset
   461
            if (currentIndex > prevIndex) {
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24399
diff changeset
   462
                passed(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
   463
            } else {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   464
                failed("file: " + path + ": " + s + " is in the wrong order.");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   465
            }
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   466
            prevIndex = currentIndex;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   467
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   468
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   469
06bc494ca11e Initial load
duke
parents:
diff changeset
   470
    /**
26270
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 26091
diff changeset
   471
     * 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
   472
     * 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
   473
     * duplicates once one is found.
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 26091
diff changeset
   474
     * @param path the file to check
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 26091
diff changeset
   475
     * @param strings ensure each are unique
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 26091
diff changeset
   476
     */
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 26091
diff changeset
   477
    public void checkUnique(String path, String... strings) {
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 26091
diff changeset
   478
        String fileString = readOutputFile(path);
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 26091
diff changeset
   479
        for (String s : strings) {
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 26091
diff changeset
   480
            int currentIndex = fileString.indexOf(s);
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 26091
diff changeset
   481
            checking(s + " at index " + currentIndex);
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 26091
diff changeset
   482
            if (currentIndex == -1) {
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 26091
diff changeset
   483
                failed(s + " not found.");
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 26091
diff changeset
   484
                continue;
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 26091
diff changeset
   485
            }
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 26091
diff changeset
   486
            int nextindex = fileString.indexOf(s, currentIndex + s.length());
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 26091
diff changeset
   487
            if (nextindex == -1) {
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 26091
diff changeset
   488
                passed(s + " is unique");
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 26091
diff changeset
   489
            } else {
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 26091
diff changeset
   490
                failed(s + " is not unique, found at " + nextindex);
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 26091
diff changeset
   491
            }
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 26091
diff changeset
   492
        }
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 26091
diff changeset
   493
    }
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 26091
diff changeset
   494
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 26091
diff changeset
   495
    /**
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   496
     * Compare a set of files in each of two directories.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   497
     *
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   498
     * @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
   499
     * @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
   500
     * @param files the set of files to be compared
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   501
     */
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   502
    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
   503
        File bd1 = new File(baseDir1);
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   504
        File bd2 = new File(baseDir2);
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   505
        for (String file : files) {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   506
            diff(bd1, bd2, file);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   507
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   508
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   509
06bc494ca11e Initial load
duke
parents:
diff changeset
   510
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   511
     * A utility to copy a directory from one place to another.
06bc494ca11e Initial load
duke
parents:
diff changeset
   512
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   513
     * @param targetDir the directory to copy.
06bc494ca11e Initial load
duke
parents:
diff changeset
   514
     * @param destDir the destination to copy the directory to.
06bc494ca11e Initial load
duke
parents:
diff changeset
   515
     */
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   516
    // 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
   517
    public void copyDir(String targetDir, String destDir) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   518
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   519
            File targetDirObj = new File(targetDir);
06bc494ca11e Initial load
duke
parents:
diff changeset
   520
            File destDirParentObj = new File(destDir);
06bc494ca11e Initial load
duke
parents:
diff changeset
   521
            File destDirObj = new File(destDirParentObj, targetDirObj.getName());
06bc494ca11e Initial load
duke
parents:
diff changeset
   522
            if (! destDirParentObj.exists()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   523
                destDirParentObj.mkdir();
06bc494ca11e Initial load
duke
parents:
diff changeset
   524
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   525
            if (! destDirObj.exists()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   526
                destDirObj.mkdir();
06bc494ca11e Initial load
duke
parents:
diff changeset
   527
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   528
            String[] files = targetDirObj.list();
24072
e7549dcbc4af 8040903: Clean up use of BUG_ID in javadoc tests
jjg
parents: 24065
diff changeset
   529
            for (String file : files) {
e7549dcbc4af 8040903: Clean up use of BUG_ID in javadoc tests
jjg
parents: 24065
diff changeset
   530
                File srcFile = new File(targetDirObj, file);
e7549dcbc4af 8040903: Clean up use of BUG_ID in javadoc tests
jjg
parents: 24065
diff changeset
   531
                File destFile = new File(destDirObj, file);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   532
                if (srcFile.isFile()) {
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   533
                    out.println("Copying " + srcFile + " to " + destFile);
24072
e7549dcbc4af 8040903: Clean up use of BUG_ID in javadoc tests
jjg
parents: 24065
diff changeset
   534
                    copyFile(destFile, srcFile);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   535
                } else if(srcFile.isDirectory()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   536
                    copyDir(srcFile.getAbsolutePath(), destDirObj.getAbsolutePath());
06bc494ca11e Initial load
duke
parents:
diff changeset
   537
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   538
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   539
        } catch (IOException exc) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   540
            throw new Error("Could not copy " + targetDir + " to " + destDir);
06bc494ca11e Initial load
duke
parents:
diff changeset
   541
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   542
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   543
06bc494ca11e Initial load
duke
parents:
diff changeset
   544
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   545
     * Copy source file to destination file.
06bc494ca11e Initial load
duke
parents:
diff changeset
   546
     *
24072
e7549dcbc4af 8040903: Clean up use of BUG_ID in javadoc tests
jjg
parents: 24065
diff changeset
   547
     * @param destfile the destination file
e7549dcbc4af 8040903: Clean up use of BUG_ID in javadoc tests
jjg
parents: 24065
diff changeset
   548
     * @param srcfile the source file
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   549
     * @throws IOException
06bc494ca11e Initial load
duke
parents:
diff changeset
   550
     */
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   551
    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
   552
        Files.copy(srcfile.toPath(), destfile.toPath());
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   553
    }
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   554
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   555
    /**
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   556
     * 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
   557
     *
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   558
     * @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
   559
     * @return          the file in string format
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   560
     */
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   561
    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
   562
        return readFile(outputDir, fileName);
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   563
    }
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   564
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   565
    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
   566
        return readFile(outputDir, fileName);
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   567
    }
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   568
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   569
    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
   570
        return readFile(new File(baseDir), fileName);
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   571
    }
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   572
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   573
    /**
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   574
     * 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
   575
     *
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   576
     * @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
   577
     * @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
   578
     * @return          the file in string format
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   579
     */
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   580
    private String readFile(File baseDir, String fileName) throws Error {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   581
        try {
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   582
            File file = new File(baseDir, fileName);
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   583
            SoftReference<String> ref = fileContentCache.get(file);
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   584
            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
   585
            if (content != null)
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   586
                return content;
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   587
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   588
            content = new String(Files.readAllBytes(file.toPath()));
40500
f293dbb81a53 8162353: javadoc should provide a way to disable use of frames
jjg
parents: 35426
diff changeset
   589
            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
   590
            return content;
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   591
        } catch (FileNotFoundException e) {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   592
            System.err.println(e);
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   593
            throw new Error("File not found: " + fileName);
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   594
        } catch (IOException e) {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   595
            System.err.println(e);
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   596
            throw new Error("Error reading file: " + fileName);
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   597
        }
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   598
    }
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   599
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   600
    protected void checking(String message) {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   601
        numTestsRun++;
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   602
        print("Starting subtest " + numTestsRun, message);
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   603
    }
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   604
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   605
    protected void passed(String message) {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   606
        numTestsPassed++;
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   607
        print("Passed", message);
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   608
    }
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   609
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   610
    protected void failed(String message) {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   611
        print("FAILED", message);
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   612
    }
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   613
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   614
    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
   615
        if (message.isEmpty())
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   616
            out.println(prefix);
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   617
        else {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   618
            out.print(prefix);
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   619
            out.print(": ");
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   620
            out.println(message.replace("\n", NL));
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   621
        }
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   622
    }
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   623
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   624
    /**
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   625
     * 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
   626
     */
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   627
    protected void printSummary() {
40500
f293dbb81a53 8162353: javadoc should provide a way to disable use of frames
jjg
parents: 35426
diff changeset
   628
        String javadocRuns = (javadocRunNum <= 1) ? ""
f293dbb81a53 8162353: javadoc should provide a way to disable use of frames
jjg
parents: 35426
diff changeset
   629
                : ", in " + javadocRunNum + " runs of javadoc";
f293dbb81a53 8162353: javadoc should provide a way to disable use of frames
jjg
parents: 35426
diff changeset
   630
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   631
        if (numTestsRun != 0 && numTestsPassed == numTestsRun) {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   632
            // Test passed
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   633
            out.println();
40500
f293dbb81a53 8162353: javadoc should provide a way to disable use of frames
jjg
parents: 35426
diff changeset
   634
            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
   635
        } else {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   636
            // Test failed
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   637
            throw new Error((numTestsRun - numTestsPassed)
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   638
                    + " of " + (numTestsRun)
40500
f293dbb81a53 8162353: javadoc should provide a way to disable use of frames
jjg
parents: 35426
diff changeset
   639
                    + " subtests failed"
f293dbb81a53 8162353: javadoc should provide a way to disable use of frames
jjg
parents: 35426
diff changeset
   640
                    + javadocRuns);
24399
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   641
        }
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   642
    }
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   643
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   644
    /**
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   645
     * 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
   646
     * if the string was found.
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   647
     *
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   648
     * @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
   649
     * @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
   650
     * @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
   651
     */
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   652
    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
   653
        // 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
   654
        // 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
   655
        // 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
   656
        stringToFind = stringToFind.replace("\n", NL);
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   657
        return fileString.contains(stringToFind);
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
     * Compare the two given files.
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 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
   664
     * @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
   665
     * @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
   666
     * @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
   667
     * 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
   668
     * @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
   669
     */
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   670
    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
   671
        String file1Contents = readFile(baseDir1, file);
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   672
        String file2Contents = readFile(baseDir2, file);
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   673
        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
   674
        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
   675
            passed("files are equal");
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   676
        } else {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   677
            failed("files differ");
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
    }
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
    /**
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   682
     * 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
   683
     * 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
   684
     */
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   685
    private static class StreamOutput {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   686
        // functional interface to set a stream.
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   687
        private interface Initializer {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   688
            void set(PrintStream s);
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   689
        }
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   690
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   691
        private final ByteArrayOutputStream baos = new ByteArrayOutputStream();
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   692
        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
   693
        private final PrintStream prev;
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   694
        private final Initializer init;
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   695
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   696
        StreamOutput(PrintStream s, Initializer init) {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   697
            prev = s;
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   698
            init.set(ps);
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   699
            this.init = init;
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   700
        }
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   701
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   702
        String close() {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   703
            init.set(prev);
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   704
            ps.close();
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   705
            return baos.toString();
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
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   709
    /**
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   710
     * 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
   711
     */
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   712
    private static class WriterOutput {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   713
        private final StringWriter sw = new StringWriter();
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   714
        final PrintWriter pw = new PrintWriter(sw);
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   715
        String close() {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   716
            pw.close();
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   717
            return sw.toString();
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   718
        }
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   719
    }
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   720
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   721
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   722
//    private final Logger log = new Logger();
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   723
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   724
    //--------- Logging --------------------------------------------------------
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   725
    //
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   726
    // 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
   727
    // 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
   728
    // 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
   729
    // facilities.
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   730
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   731
    static class Logger {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   732
        private static final int PREFIX = 40;
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   733
        private static final int SUFFIX = 20;
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   734
        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
   735
        List<String> tests = new ArrayList<>();
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   736
        String outDir;
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   737
        String rootDir = rootDir();
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   738
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   739
        static String rootDir() {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   740
            File f = new File(".").getAbsoluteFile();
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   741
            while (!new File(f, ".hg").exists())
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   742
                f = f.getParentFile();
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   743
            return f.getPath();
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   744
        }
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   745
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   746
        void setOutDir(File outDir) {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   747
            this.outDir = outDir.getPath();
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   748
        }
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   749
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   750
        void logCheckFile(String file, boolean positive) {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   751
            // 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
   752
            if (file.startsWith(outDir + "/"))
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   753
                file = file.substring(outDir.length() + 1);
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   754
            tests.add(file + " " + positive);
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   755
        }
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
        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
   758
            // 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
   759
            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
   760
            if (simpleText.length() > MAX)
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   761
                simpleText = simpleText.substring(0, PREFIX)
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   762
                        + "..." + simpleText.substring(simpleText.length() - SUFFIX);
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   763
            // 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
   764
            if (file.startsWith(outDir + "/"))
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   765
                file = file.substring(outDir.length() + 1);
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   766
            // 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
   767
            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
   768
        }
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   769
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   770
        void write() {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   771
            // 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
   772
            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
   773
            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
   774
                for (String t: tests) {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   775
                    bw.write(t);
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   776
                    bw.newLine();
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
            } catch (IOException e) {
af1a0220d0fa 8038730: Clean up the way JavadocTester is invoked, and checks for errors.
jjg
parents: 24217
diff changeset
   779
                throw new Error("problem writing log: " + e);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   780
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   781
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   782
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   783
}