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