test/langtools/jdk/javadoc/tool/ReleaseOption.java
author bobv
Tue, 07 Nov 2017 10:30:53 -0500
changeset 47801 c7b50c23ea71
parent 47216 71c04702a3d5
permissions -rw-r--r--
8190283: Default heap sizing options select a MaxHeapSize larger than available physical memory in some cases Reviewed-by: tschatzl, sjohanss
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
31936
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
     1
/*
44287
829205b133d4 8175219: javadoc should exit when it encounters compilation errors.
ksrini
parents: 41451
diff changeset
     2
 * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
31936
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
     4
 *
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
     7
 * published by the Free Software Foundation.
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
     8
 *
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
    13
 * accompanied this code).
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
    14
 *
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
    18
 *
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
    21
 * questions.
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
    22
 */
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
    23
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 36526
diff changeset
    24
import java.io.File;
31936
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
    25
import java.io.PrintWriter;
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
    26
import java.io.StringWriter;
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
    27
import java.util.ArrayList;
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
    28
import java.util.Arrays;
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
    29
import java.util.List;
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
    30
import java.util.function.Predicate;
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40763
diff changeset
    31
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
    32
import jdk.javadoc.internal.tool.Main;
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40763
diff changeset
    33
import jdk.javadoc.internal.tool.Main.Result;
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40763
diff changeset
    34
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40763
diff changeset
    35
import static jdk.javadoc.internal.tool.Main.Result.*;
31936
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
    36
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
    37
/**
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
    38
 * @test
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
    39
 * @bug 8086737
40763
209113892b0d 8165109: langtools/test switches to use new CLI options
mchung
parents: 40308
diff changeset
    40
 * @summary Test --release option in javadoc
31936
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
    41
 * @run main ReleaseOption
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35426
diff changeset
    42
 * @modules jdk.javadoc/jdk.javadoc.internal.tool
31936
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
    43
 */
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
    44
public class ReleaseOption {
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
    45
    public static void main(String... args) {
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
    46
        new ReleaseOption().run();
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
    47
    }
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
    48
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
    49
    void run() {
44287
829205b133d4 8175219: javadoc should exit when it encounters compilation errors.
ksrini
parents: 41451
diff changeset
    50
        doRunTest(ERROR, out -> out.contains("compiler.err.doesnt.exist: java.util.stream"), "--release", "7");
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40763
diff changeset
    51
        doRunTest(OK, out -> !out.contains("compiler.err.doesnt.exist: java.util.stream"), "--release", "8");
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40763
diff changeset
    52
        doRunTest(CMDERR, out -> true, "--release", "7", "-source", "7");
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40763
diff changeset
    53
        doRunTest(CMDERR, out -> true, "--release", "7", "-bootclasspath", "any");
31936
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
    54
    }
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
    55
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40763
diff changeset
    56
    void doRunTest(Result expectedResult, Predicate<String> validate, String... args) {
31936
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
    57
        System.err.println("running with args: " + Arrays.asList(args));
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
    58
        List<String> options = new ArrayList<>();
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
    59
        options.addAll(Arrays.asList(args));
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
    60
        options.add("-XDrawDiagnostics");
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 36526
diff changeset
    61
        options.add(new File(System.getProperty("test.src", "."), "ReleaseOptionSource.java").getPath());
31936
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
    62
        StringWriter out = new StringWriter();
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
    63
        PrintWriter pw = new PrintWriter(out);
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 31936
diff changeset
    64
        int actualResult = Main.execute(options.toArray(new String[0]), pw);
31936
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
    65
        System.err.println("actual result=" + actualResult);
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
    66
        System.err.println("actual output=" + out.toString());
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40763
diff changeset
    67
        if (actualResult != expectedResult.exitCode)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 36526
diff changeset
    68
            throw new Error("Exit code not as expected");
31936
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
    69
        if (!validate.test(out.toString())) {
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 36526
diff changeset
    70
            throw new Error("Output not as expected");
31936
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
    71
        }
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
    72
    }
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
    73
}