langtools/test/tools/javadoc/ReleaseOption.java
author amurillo
Thu, 13 Aug 2015 15:50:52 -0700
changeset 32224 dae855d05f6c
parent 31936 02f1cfc234a0
child 40308 274367a99f98
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
31936
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
     1
/*
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
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
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
    24
import com.sun.tools.javadoc.Main;
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;
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
    31
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
    32
/**
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
    33
 * @test
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
    34
 * @bug 8086737
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
    35
 * @summary Test -release option in javadoc
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
    36
 * @run main ReleaseOption
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
public class ReleaseOption {
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
    39
    public static void main(String... args) {
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
    40
        new ReleaseOption().run();
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
    41
    }
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
    42
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
    43
    void run() {
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
    44
        doRunTest(0, out -> out.contains("compiler.err.doesnt.exist: java.util.stream"), "-release", "7");
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
    45
        doRunTest(0, out -> !out.contains("compiler.err.doesnt.exist: java.util.stream"), "-release", "8");
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
    46
        doRunTest(1, out -> true, "-release", "7", "-source", "7");
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
    47
        doRunTest(1, out -> true, "-release", "7", "-bootclasspath", "any");
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
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
    50
    void doRunTest(int expectedResult, Predicate<String> validate, String... args) {
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
    51
        System.err.println("running with args: " + Arrays.asList(args));
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
    52
        List<String> options = new ArrayList<>();
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
    53
        options.addAll(Arrays.asList(args));
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
    54
        options.add("-XDrawDiagnostics");
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
    55
        options.add(System.getProperty("test.src", ".") + java.io.File.separatorChar + "ReleaseOptionSource.java");
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
    56
        StringWriter out = new StringWriter();
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
    57
        PrintWriter pw = new PrintWriter(out);
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
    58
        int actualResult = Main.execute("javadoc", pw, pw, pw, "com.sun.tools.doclets.formats.html.HtmlDoclet", options.toArray(new String[0]));
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
    59
        System.err.println("actual result=" + actualResult);
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
    60
        System.err.println("actual output=" + out.toString());
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
    61
        if (actualResult != expectedResult)
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
    62
            throw new Error();
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
    63
        if (!validate.test(out.toString())) {
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
    64
            throw new Error("Not an expected error output: " + out.toString());
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
    65
        }
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
    66
    }
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents:
diff changeset
    67
}