jdk/test/tools/jlink/plugins/SystemModuleDescriptors/UserModuleTest.java
author mli
Tue, 31 May 2016 22:04:00 -0700
changeset 38766 12239516ceb1
parent 38748 jdk/test/tools/jlink/plugins/InstalledModuleDescriptors/UserModuleTest.java@47b8a7137d42
child 40261 86a49ba76f52
permissions -rw-r--r--
8158194: Rename the directory “InstalledModuleDescriptors” and any reference to “installed” to “system” in the tests Reviewed-by: mchung
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) 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
import java.io.File;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    25
import java.nio.file.Files;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    26
import java.nio.file.Path;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    27
import java.nio.file.Paths;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    28
import java.util.Arrays;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    29
import java.util.stream.Collectors;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    30
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    31
import jdk.testlibrary.FileUtils;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    32
import static jdk.testlibrary.ProcessTools.*;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    33
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    34
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    35
import org.testng.annotations.BeforeTest;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    36
import org.testng.annotations.Test;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    37
import static org.testng.Assert.*;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    38
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    39
/**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    40
 * @test
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    41
 * @library /lib/testlibrary
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    42
 * @modules jdk.compiler
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    43
 * @build UserModuleTest CompilerUtils jdk.testlibrary.FileUtils jdk.testlibrary.ProcessTools
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    44
 * @run testng UserModuleTest
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    45
 */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    46
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    47
public class UserModuleTest {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    48
    private static final String JAVA_HOME = System.getProperty("java.home");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    49
    private static final String TEST_SRC = System.getProperty("test.src");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    50
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 IMAGE = Paths.get("image");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    54
    private static final Path JMODS = Paths.get(JAVA_HOME, "jmods");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    55
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    56
    // the names of the modules in this test
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    57
    private static String[] modules = new String[] {"m1", "m2", "m3"};
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    58
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    59
    private static boolean hasJmods() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    60
        if (!Files.exists(JMODS)) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    61
            System.err.println("Test skipped. NO jmods directory");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    62
            return false;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    63
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    64
        return true;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    65
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    66
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    67
    /*
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    68
     * Compiles all modules used by the test
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    69
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    70
    @BeforeTest
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    71
    public void compileAll() throws Throwable {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    72
        if (!hasJmods()) return;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    73
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    74
        for (String mn : modules) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    75
            Path msrc = SRC_DIR.resolve(mn);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    76
            assertTrue(CompilerUtils.compile(msrc, MODS_DIR, "-modulesourcepath", SRC_DIR.toString()));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    77
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    78
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    79
        if (Files.exists(IMAGE)) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    80
            FileUtils.deleteFileTreeUnchecked(IMAGE);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    81
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    82
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    83
        createImage(IMAGE, "java.base", "m1");
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
    private void createImage(Path outputDir, String... modules) throws Throwable {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    87
        Path jlink = Paths.get(JAVA_HOME, "bin", "jlink");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    88
        String mp = JMODS.toString() + File.pathSeparator + MODS_DIR.toString();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    89
        assertTrue(executeProcess(jlink.toString(), "--output", outputDir.toString(),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    90
                        "--addmods", Arrays.stream(modules).collect(Collectors.joining(",")),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    91
                        "--modulepath", mp)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    92
                        .outputTo(System.out)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    93
                        .errorTo(System.out)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    94
                        .getExitValue() == 0);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    95
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    96
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    97
    /*
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    98
     * Test the image created when linking with a module with
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    99
     * no ConcealedPackages attribute
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   100
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   101
    @Test
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   102
    public void test() throws Throwable {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   103
        if (!hasJmods()) return;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   104
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   105
        Path java = IMAGE.resolve("bin").resolve("java");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   106
        assertTrue(executeProcess(java.toString(), "-m", "m1/p1.Main")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   107
                        .outputTo(System.out)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   108
                        .errorTo(System.out)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   109
                        .getExitValue() == 0);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   110
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   111
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   112
    /*
38766
12239516ceb1 8158194: Rename the directory “InstalledModuleDescriptors” and any reference to “installed” to “system” in the tests
mli
parents: 38748
diff changeset
   113
     * Disable the fast loading of system modules.
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   114
     * Parsing module-info.class
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   115
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   116
    @Test
38766
12239516ceb1 8158194: Rename the directory “InstalledModuleDescriptors” and any reference to “installed” to “system” in the tests
mli
parents: 38748
diff changeset
   117
    public void disableSystemModules() throws Throwable {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   118
        if (!hasJmods()) return;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   119
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   120
        Path java = IMAGE.resolve("bin").resolve("java");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   121
        assertTrue(executeProcess(java.toString(),
38748
47b8a7137d42 8158149: test bug for SystemModuleFinder when fast path is supported
mli
parents: 36511
diff changeset
   122
                                  "-Djdk.system.module.finder.disabledFastPath",
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   123
                                  "-m", "m1/p1.Main")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   124
                        .outputTo(System.out)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   125
                        .errorTo(System.out)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   126
                        .getExitValue() == 0);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   127
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   128
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   129
    /*
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   130
     * Test the optimization that deduplicates Set<String> on targets of exports,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   131
     * uses, provides.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   132
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   133
    @Test
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   134
    public void testDedupSet() throws Throwable {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   135
        if (!hasJmods()) return;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   136
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   137
        Path dir = Paths.get("newImage");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   138
        createImage(dir, "java.base", "m1", "m2", "m3");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   139
        Path java = dir.resolve("bin").resolve("java");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   140
        assertTrue(executeProcess(java.toString(), "-m", "m1/p1.Main")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   141
                        .outputTo(System.out)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   142
                        .errorTo(System.out)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   143
                        .getExitValue() == 0);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   144
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   145
}