jdk/test/tools/launcher/modules/addmods/AddModsTest.java
author alanb
Thu, 17 Mar 2016 19:04:16 +0000
changeset 36511 9d0388c6b336
child 37779 7c84df693837
permissions -rw-r--r--
8142968: Module System implementation Summary: Initial integration of JEP 200, JEP 260, JEP 261, and JEP 282 Reviewed-by: alanb, mchung, naoto, rriggs, psandoz, plevart, mullan, ascarpino, vinnie, prr, sherman, dfuchs, mhaupt Contributed-by: alan.bateman@oracle.com, alex.buckley@oracle.com, jonathan.gibbons@oracle.com, karen.kinnear@oracle.com, mandy.chung@oracle.com, mark.reinhold@oracle.com, chris.hegarty@oracle.com, alexandr.scherbatiy@oracle.com, amy.lu@oracle.com, calvin.cheung@oracle.com, daniel.fuchs@oracle.com, erik.joelsson@oracle.com, harold.seigel@oracle.com, jaroslav.bachorik@oracle.com, jean-francois.denise@oracle.com, jan.lahoda@oracle.com, james.laskey@oracle.com, lois.foltan@oracle.com, miroslav.kos@oracle.com, huaming.li@oracle.com, sean.mullan@oracle.com, naoto.sato@oracle.com, masayoshi.okutsu@oracle.com, peter.levart@gmail.com, philip.race@oracle.com, claes.redestad@oracle.com, sergey.bylokhov@oracle.com, alexandre.iline@oracle.com, volker.simonis@gmail.com, staffan.larsen@oracle.com, stuart.marks@oracle.com, semyon.sadetsky@oracle.com, serguei.spitsyn@oracle.com, sundararajan.athijegannathan@oracle.com, valerie.peng@oracle.com, vincent.x.ryan@oracle.com, weijun.wang@oracle.com, yuri.nesterenko@oracle.com, yekaterina.kantserova@oracle.com, alexander.kulyakhtin@oracle.com, felix.yang@oracle.com, andrei.eremeev@oracle.com, frank.yuan@oracle.com, sergei.pikalev@oracle.com, sibabrata.sahoo@oracle.com, tiantian.du@oracle.com, sha.jiang@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     1
/*
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     2
 * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
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
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    26
 * @library /lib/testlibrary
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    27
 * @modules jdk.jlink/jdk.tools.jmod
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    28
 *          jdk.compiler
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    29
 * @build AddModsTest CompilerUtils jdk.testlibrary.*
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    30
 * @run testng AddModsTest
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    31
 * @summary Basic test for java -addmods
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    32
 */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    33
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    34
import java.nio.file.Path;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    35
import java.nio.file.Paths;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    36
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    37
import static jdk.testlibrary.ProcessTools.*;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    38
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    39
import org.testng.annotations.BeforeTest;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    40
import org.testng.annotations.Test;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    41
import static org.testng.Assert.*;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    42
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    43
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    44
@Test
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    45
public class AddModsTest {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    46
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    47
    private static final String TEST_SRC = System.getProperty("test.src");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    48
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    49
    private static final Path SRC_DIR = Paths.get(TEST_SRC, "src");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    50
    private static final Path MODS_DIR = Paths.get("mods");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    51
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    52
    // the module name of the library module
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    53
    private static final String LIB_MODULE = "lib";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    54
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    55
    // application source directory
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    56
    private static final String APP_SRC = "app";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    57
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    58
    // application is compiled to classes
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    59
    private static final Path CLASSES_DIR = Paths.get("classes");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    60
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    61
    // application main class
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    62
    private static final String MAIN_CLASS = "app.Main";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    63
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    64
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    65
    @BeforeTest
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    66
    public void compile() throws Exception {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    67
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    68
        // javac -d mods/$LIB_MODULE src/$LIB_MODULE/**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    69
        boolean compiled = CompilerUtils.compile(
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    70
            SRC_DIR.resolve(LIB_MODULE),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    71
            MODS_DIR.resolve(LIB_MODULE)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    72
        );
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    73
        assertTrue(compiled, "library module did not compile");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    74
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    75
        // javac -d classes -mp mods src/$APP_DIR/**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    76
        compiled = CompilerUtils.compile(
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    77
            SRC_DIR.resolve(APP_SRC),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    78
            CLASSES_DIR,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    79
            "-mp", MODS_DIR.toString(),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    80
            "-addmods", LIB_MODULE
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    81
        );
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    82
        assertTrue(compiled, "app did not compile");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    83
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    84
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    85
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    86
    /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    87
     * Basic test of -addmods ALL-SYSTEM, using the output of -listmods to
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    88
     * check that the a sample of the system modules are resolved.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    89
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    90
    public void testAddSystemModules() throws Exception {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    91
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    92
        executeTestJava("-addmods", "ALL-SYSTEM",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    93
                        "-listmods",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    94
                        "-m", "java.base")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    95
            .outputTo(System.out)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    96
            .errorTo(System.out)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    97
            .shouldContain("java.sql")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    98
            .shouldContain("java.corba");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    99
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   100
        // no exit value to check as -m java.base will likely fail
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   101
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   102
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
     * Run application on class path that makes use of module on the
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   106
     * application module path. Uses {@code -addmods lib}
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   107
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   108
    public void testRunWithAddMods() throws Exception {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   109
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   110
        // java -mp mods -addmods lib -cp classes app.Main
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   111
        int exitValue
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   112
            = executeTestJava("-mp", MODS_DIR.toString(),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   113
                              "-addmods", LIB_MODULE,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   114
                              "-cp", CLASSES_DIR.toString(),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   115
                              MAIN_CLASS)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   116
                .outputTo(System.out)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   117
                .errorTo(System.out)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   118
                .getExitValue();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   119
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   120
        assertTrue(exitValue == 0);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   121
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   122
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   123
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   124
    /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   125
     * Run application on class path that makes use of module on the
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   126
     * application module path. Uses {@code -addmods ALL-MODULE-PATH}.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   127
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   128
    public void testAddAllModulePath() throws Exception {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   129
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   130
        // java -mp mods -addmods lib -cp classes app.Main
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   131
        int exitValue
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   132
            = executeTestJava("-mp", MODS_DIR.toString(),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   133
                              "-addmods", "ALL-MODULE-PATH",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   134
                              "-cp", CLASSES_DIR.toString(),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   135
                              MAIN_CLASS)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   136
                .outputTo(System.out)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   137
                .errorTo(System.out)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   138
                .getExitValue();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   139
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   140
        assertTrue(exitValue == 0);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   141
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   142
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   143
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
     * Run application on class path that makes use of module on the
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   147
     * application module path. Does not use -addmods and so will
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   148
     * fail at run-time.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   149
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   150
    public void testRunMissingAddMods() throws Exception {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   151
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   152
        // java -mp mods -cp classes app.Main
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   153
        int exitValue
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   154
            = executeTestJava("-mp", MODS_DIR.toString(),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   155
                              "-cp", CLASSES_DIR.toString(),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   156
                              MAIN_CLASS)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   157
                .outputTo(System.out)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   158
                .errorTo(System.out)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   159
                .getExitValue();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   160
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   161
        // CNFE or other error/exception
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   162
        assertTrue(exitValue != 0);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   163
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   164
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   165
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   166
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   167
    /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   168
     * Attempt to run with a bad module name specified to -addmods
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   169
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   170
    public void testRunWithBadAddMods() throws Exception {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   171
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   172
        // java -mp mods -addmods,DoesNotExist lib -cp classes app.Main
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   173
        int exitValue
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   174
            = executeTestJava("-mp", MODS_DIR.toString(),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   175
                              "-addmods", LIB_MODULE + ",DoesNotExist",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   176
                              "-cp", CLASSES_DIR.toString(),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   177
                              MAIN_CLASS)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   178
                .outputTo(System.out)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   179
                .errorTo(System.out)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   180
                .getExitValue();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   181
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   182
        assertTrue(exitValue != 0);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   183
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   184
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   185
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   186
}