test/jdk/tools/jlink/plugins/AddOptionsPluginTest.java
author mr
Tue, 29 Oct 2019 08:26:55 -0700
changeset 58842 6c255334120d
permissions -rw-r--r--
8232080: jlink plugins for vendor information and run-time options Reviewed-by: ihse, alanb, kvn, bobv, mchung
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
58842
6c255334120d 8232080: jlink plugins for vendor information and run-time options
mr
parents:
diff changeset
     1
/*
6c255334120d 8232080: jlink plugins for vendor information and run-time options
mr
parents:
diff changeset
     2
 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
6c255334120d 8232080: jlink plugins for vendor information and run-time options
mr
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6c255334120d 8232080: jlink plugins for vendor information and run-time options
mr
parents:
diff changeset
     4
 *
6c255334120d 8232080: jlink plugins for vendor information and run-time options
mr
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
6c255334120d 8232080: jlink plugins for vendor information and run-time options
mr
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
6c255334120d 8232080: jlink plugins for vendor information and run-time options
mr
parents:
diff changeset
     7
 * published by the Free Software Foundation.
6c255334120d 8232080: jlink plugins for vendor information and run-time options
mr
parents:
diff changeset
     8
 *
6c255334120d 8232080: jlink plugins for vendor information and run-time options
mr
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
6c255334120d 8232080: jlink plugins for vendor information and run-time options
mr
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6c255334120d 8232080: jlink plugins for vendor information and run-time options
mr
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
6c255334120d 8232080: jlink plugins for vendor information and run-time options
mr
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
6c255334120d 8232080: jlink plugins for vendor information and run-time options
mr
parents:
diff changeset
    13
 * accompanied this code).
6c255334120d 8232080: jlink plugins for vendor information and run-time options
mr
parents:
diff changeset
    14
 *
6c255334120d 8232080: jlink plugins for vendor information and run-time options
mr
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
6c255334120d 8232080: jlink plugins for vendor information and run-time options
mr
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
6c255334120d 8232080: jlink plugins for vendor information and run-time options
mr
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
6c255334120d 8232080: jlink plugins for vendor information and run-time options
mr
parents:
diff changeset
    18
 *
6c255334120d 8232080: jlink plugins for vendor information and run-time options
mr
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
6c255334120d 8232080: jlink plugins for vendor information and run-time options
mr
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
6c255334120d 8232080: jlink plugins for vendor information and run-time options
mr
parents:
diff changeset
    21
 * questions.
6c255334120d 8232080: jlink plugins for vendor information and run-time options
mr
parents:
diff changeset
    22
 */
6c255334120d 8232080: jlink plugins for vendor information and run-time options
mr
parents:
diff changeset
    23
6c255334120d 8232080: jlink plugins for vendor information and run-time options
mr
parents:
diff changeset
    24
import jdk.test.lib.process.*;
6c255334120d 8232080: jlink plugins for vendor information and run-time options
mr
parents:
diff changeset
    25
6c255334120d 8232080: jlink plugins for vendor information and run-time options
mr
parents:
diff changeset
    26
import tests.Helper;
6c255334120d 8232080: jlink plugins for vendor information and run-time options
mr
parents:
diff changeset
    27
6c255334120d 8232080: jlink plugins for vendor information and run-time options
mr
parents:
diff changeset
    28
/* @test
6c255334120d 8232080: jlink plugins for vendor information and run-time options
mr
parents:
diff changeset
    29
 * @bug 8232080
6c255334120d 8232080: jlink plugins for vendor information and run-time options
mr
parents:
diff changeset
    30
 * @summary Test the --add-options plugin
6c255334120d 8232080: jlink plugins for vendor information and run-time options
mr
parents:
diff changeset
    31
 * @library ../../lib
6c255334120d 8232080: jlink plugins for vendor information and run-time options
mr
parents:
diff changeset
    32
 * @library /test/lib
6c255334120d 8232080: jlink plugins for vendor information and run-time options
mr
parents:
diff changeset
    33
 * @modules java.base/jdk.internal.jimage
6c255334120d 8232080: jlink plugins for vendor information and run-time options
mr
parents:
diff changeset
    34
 *          jdk.jdeps/com.sun.tools.classfile
6c255334120d 8232080: jlink plugins for vendor information and run-time options
mr
parents:
diff changeset
    35
 *          jdk.jlink/jdk.tools.jlink.internal
6c255334120d 8232080: jlink plugins for vendor information and run-time options
mr
parents:
diff changeset
    36
 *          jdk.jlink/jdk.tools.jmod
6c255334120d 8232080: jlink plugins for vendor information and run-time options
mr
parents:
diff changeset
    37
 *          jdk.jlink/jdk.tools.jimage
6c255334120d 8232080: jlink plugins for vendor information and run-time options
mr
parents:
diff changeset
    38
 *          jdk.compiler
6c255334120d 8232080: jlink plugins for vendor information and run-time options
mr
parents:
diff changeset
    39
 * @build tests.*
6c255334120d 8232080: jlink plugins for vendor information and run-time options
mr
parents:
diff changeset
    40
 * @run main AddOptionsPluginTest
6c255334120d 8232080: jlink plugins for vendor information and run-time options
mr
parents:
diff changeset
    41
 */
6c255334120d 8232080: jlink plugins for vendor information and run-time options
mr
parents:
diff changeset
    42
6c255334120d 8232080: jlink plugins for vendor information and run-time options
mr
parents:
diff changeset
    43
public class AddOptionsPluginTest {
6c255334120d 8232080: jlink plugins for vendor information and run-time options
mr
parents:
diff changeset
    44
6c255334120d 8232080: jlink plugins for vendor information and run-time options
mr
parents:
diff changeset
    45
    private static final String PROP = "add.options.plugin.test";
6c255334120d 8232080: jlink plugins for vendor information and run-time options
mr
parents:
diff changeset
    46
    private static final String VALUE = "xyzzy";
6c255334120d 8232080: jlink plugins for vendor information and run-time options
mr
parents:
diff changeset
    47
    private static final String OPTS = "-D" + PROP + "=" + VALUE;
6c255334120d 8232080: jlink plugins for vendor information and run-time options
mr
parents:
diff changeset
    48
6c255334120d 8232080: jlink plugins for vendor information and run-time options
mr
parents:
diff changeset
    49
    public static void main(String[] args) throws Throwable {
6c255334120d 8232080: jlink plugins for vendor information and run-time options
mr
parents:
diff changeset
    50
6c255334120d 8232080: jlink plugins for vendor information and run-time options
mr
parents:
diff changeset
    51
        Helper helper = Helper.newHelper();
6c255334120d 8232080: jlink plugins for vendor information and run-time options
mr
parents:
diff changeset
    52
        if (helper == null) {
6c255334120d 8232080: jlink plugins for vendor information and run-time options
mr
parents:
diff changeset
    53
            System.err.println("Test not run");
6c255334120d 8232080: jlink plugins for vendor information and run-time options
mr
parents:
diff changeset
    54
            return;
6c255334120d 8232080: jlink plugins for vendor information and run-time options
mr
parents:
diff changeset
    55
        }
6c255334120d 8232080: jlink plugins for vendor information and run-time options
mr
parents:
diff changeset
    56
6c255334120d 8232080: jlink plugins for vendor information and run-time options
mr
parents:
diff changeset
    57
        var module = "addoptions";
6c255334120d 8232080: jlink plugins for vendor information and run-time options
mr
parents:
diff changeset
    58
        helper.generateDefaultJModule(module);
6c255334120d 8232080: jlink plugins for vendor information and run-time options
mr
parents:
diff changeset
    59
        var image = helper.generateDefaultImage(new String[] { "--add-options", OPTS },
6c255334120d 8232080: jlink plugins for vendor information and run-time options
mr
parents:
diff changeset
    60
                                                module)
6c255334120d 8232080: jlink plugins for vendor information and run-time options
mr
parents:
diff changeset
    61
            .assertSuccess();
6c255334120d 8232080: jlink plugins for vendor information and run-time options
mr
parents:
diff changeset
    62
        helper.checkImage(image, module, null, null);
6c255334120d 8232080: jlink plugins for vendor information and run-time options
mr
parents:
diff changeset
    63
6c255334120d 8232080: jlink plugins for vendor information and run-time options
mr
parents:
diff changeset
    64
        var launcher = image.resolve("bin/java"
6c255334120d 8232080: jlink plugins for vendor information and run-time options
mr
parents:
diff changeset
    65
                                     + (System.getProperty("os.name").startsWith("Windows")
6c255334120d 8232080: jlink plugins for vendor information and run-time options
mr
parents:
diff changeset
    66
                                        ? ".exe" : ""));
6c255334120d 8232080: jlink plugins for vendor information and run-time options
mr
parents:
diff changeset
    67
        var oa = ProcessTools.executeProcess(launcher.toString(),
6c255334120d 8232080: jlink plugins for vendor information and run-time options
mr
parents:
diff changeset
    68
                                             "-XshowSettings:properties", "--version");
6c255334120d 8232080: jlink plugins for vendor information and run-time options
mr
parents:
diff changeset
    69
        oa.stderrShouldMatch("^ +" + PROP + " = " + VALUE + "$");
6c255334120d 8232080: jlink plugins for vendor information and run-time options
mr
parents:
diff changeset
    70
6c255334120d 8232080: jlink plugins for vendor information and run-time options
mr
parents:
diff changeset
    71
    }
6c255334120d 8232080: jlink plugins for vendor information and run-time options
mr
parents:
diff changeset
    72
6c255334120d 8232080: jlink plugins for vendor information and run-time options
mr
parents:
diff changeset
    73
}