jdk/test/tools/launcher/modules/listmods/ListModsTest.java
author iignatyev
Tue, 06 Jun 2017 19:54:08 -0700
changeset 45393 de4e1efc8eec
parent 45004 ea3137042a61
permissions -rw-r--r--
8181335: remove packageless CompilerUtils Reviewed-by: alanb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     1
/*
45004
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44545
diff changeset
     2
 * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     4
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     7
 * published by the Free Software Foundation.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     8
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    13
 * accompanied this code).
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    14
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    18
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    21
 * questions.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    22
 */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    23
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    24
/**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    25
 * @test
45393
de4e1efc8eec 8181335: remove packageless CompilerUtils
iignatyev
parents: 45004
diff changeset
    26
 * @library /lib/testlibrary /test/lib
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    27
 * @modules java.se
45393
de4e1efc8eec 8181335: remove packageless CompilerUtils
iignatyev
parents: 45004
diff changeset
    28
 * @build ListModsTest jdk.test.lib.compiler.CompilerUtils jdk.testlibrary.*
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    29
 * @run testng ListModsTest
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 36511
diff changeset
    30
 * @summary Basic test for java --list-modules
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    31
 */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    32
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    33
import java.nio.file.Path;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    34
import java.nio.file.Paths;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    35
45393
de4e1efc8eec 8181335: remove packageless CompilerUtils
iignatyev
parents: 45004
diff changeset
    36
import jdk.test.lib.compiler.CompilerUtils;
45004
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44545
diff changeset
    37
import jdk.testlibrary.ProcessTools;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    38
import jdk.testlibrary.OutputAnalyzer;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    39
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    40
import org.testng.annotations.BeforeTest;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    41
import org.testng.annotations.Test;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    42
import static org.testng.Assert.*;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    43
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    44
/**
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 36511
diff changeset
    45
 * Basic tests for java --list-modules
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    46
 */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    47
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    48
public class ListModsTest {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    49
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    50
    private static final String TEST_SRC = System.getProperty("test.src");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    51
    private static final Path SRC_DIR = Paths.get(TEST_SRC, "src");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    52
    private static final Path MODS_DIR = Paths.get("mods");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    53
    private static final Path UPGRADEMODS_DIR = Paths.get("upgrademods");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    54
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    55
    @BeforeTest
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    56
    public void setup() throws Exception {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    57
        boolean compiled;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    58
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 36511
diff changeset
    59
        // javac -d mods/m1 --module-path mods src/m1/**
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    60
        compiled = CompilerUtils.compile(
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    61
                SRC_DIR.resolve("m1"),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    62
                MODS_DIR.resolve("m1"));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    63
        assertTrue(compiled);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    64
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 36511
diff changeset
    65
        // javac -d upgrademods/java.transaction --module-path mods src/java.transaction/**
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    66
        compiled = CompilerUtils.compile(
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    67
                SRC_DIR.resolve("java.transaction"),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    68
                UPGRADEMODS_DIR.resolve("java.transaction"));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    69
        assertTrue(compiled);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    70
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    71
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    72
    @Test
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    73
    public void testListAll() throws Exception {
45004
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44545
diff changeset
    74
        exec("--list-modules")
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44545
diff changeset
    75
                .shouldContain("java.base")
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44545
diff changeset
    76
                .shouldContain("java.xml")
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44545
diff changeset
    77
                .shouldHaveExitValue(0);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    78
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    79
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    80
    @Test
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    81
    public void testListWithModulePath() throws Exception {
45004
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44545
diff changeset
    82
        exec("--list-modules", "--module-path", MODS_DIR.toString())
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44545
diff changeset
    83
                .shouldContain("java.base")
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44545
diff changeset
    84
                .shouldContain("m1")
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44545
diff changeset
    85
                .shouldHaveExitValue(0);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    86
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    87
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    88
    @Test
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    89
    public void testListWithUpgradeModulePath() throws Exception {
45004
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44545
diff changeset
    90
        String dir = UPGRADEMODS_DIR.toString();
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44545
diff changeset
    91
        exec("--list-modules", "--upgrade-module-path", dir)
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44545
diff changeset
    92
                .shouldContain(UPGRADEMODS_DIR.toString())
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44545
diff changeset
    93
                .shouldHaveExitValue(0);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    94
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    95
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    96
    @Test
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    97
    public void testListWithLimitMods1() throws Exception {
45004
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44545
diff changeset
    98
        exec("--limit-modules", "java.management.rmi", "--list-modules")
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44545
diff changeset
    99
                .shouldContain("java.rmi")
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44545
diff changeset
   100
                .shouldContain("java.base")
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44545
diff changeset
   101
                .shouldNotContain("java.scripting")
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44545
diff changeset
   102
                .shouldHaveExitValue(0);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   103
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   104
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   105
    @Test
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   106
    public void testListWithLimitMods2() throws Exception {
45004
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44545
diff changeset
   107
        exec("--list-modules",
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44545
diff changeset
   108
                    "--module-path", MODS_DIR.toString(),
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44545
diff changeset
   109
                    "--limit-modules", "java.management")
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44545
diff changeset
   110
                .shouldContain("java.base")
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44545
diff changeset
   111
                .shouldNotContain("m1")
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44545
diff changeset
   112
                .shouldHaveExitValue(0);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   113
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   114
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   115
    /**
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 36511
diff changeset
   116
     * java -version --list-modules => should print version and exit
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   117
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   118
    @Test
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   119
    public void testListWithPrintVersion1() throws Exception {
45004
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44545
diff changeset
   120
        exec("-version", "--list-modules")
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44545
diff changeset
   121
                .shouldNotContain("java.base")
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44545
diff changeset
   122
                .shouldContain("Runtime Environment")
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44545
diff changeset
   123
                .shouldHaveExitValue(0);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   124
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   125
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   126
    /**
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 36511
diff changeset
   127
     * java --list-modules -version => should list modules and exit
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   128
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   129
    @Test
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   130
    public void testListWithPrintVersion2() throws Exception {
45004
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44545
diff changeset
   131
        exec("--list-modules", "-version")
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44545
diff changeset
   132
                .shouldContain("java.base")
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44545
diff changeset
   133
                .shouldNotContain("Runtime Environment")
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44545
diff changeset
   134
                .shouldHaveExitValue(0);
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44545
diff changeset
   135
    }
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44545
diff changeset
   136
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44545
diff changeset
   137
    /**
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44545
diff changeset
   138
     * java args... returning the OutputAnalyzer to analyzer the output
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44545
diff changeset
   139
     */
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44545
diff changeset
   140
    private OutputAnalyzer exec(String... args) throws Exception {
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44545
diff changeset
   141
        return ProcessTools.executeTestJava(args)
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   142
                .outputTo(System.out)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   143
                .errorTo(System.out);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   144
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   145
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   146
}