jdk/test/tools/jmod/JmodTest.java
author alanb
Thu, 04 May 2017 07:26:55 +0000
changeset 45004 ea3137042a61
parent 43729 21db38703675
child 45286 cd809e28c082
permissions -rw-r--r--
8178380: Module system implementation refresh (5/2017) Reviewed-by: mchung, alanb, sspitsyn Contributed-by: alan.bateman@oracle.com, mandy.chung@oracle.com, chris.hegarty@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) 2015, 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
43067
3f011a470ce2 8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents: 42922
diff changeset
    26
 * @bug 8142968 8166568 8166286 8170618 8168149
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41916
diff changeset
    27
 * @summary Basic test for jmod
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    28
 * @library /lib/testlibrary
41484
834b7539ada3 8164689: Retrofit jar, jlink, jmod as a ToolProvider
mchung
parents: 39882
diff changeset
    29
 * @modules jdk.compiler
834b7539ada3 8164689: Retrofit jar, jlink, jmod as a ToolProvider
mchung
parents: 39882
diff changeset
    30
 *          jdk.jlink
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    31
 * @build jdk.testlibrary.FileUtils CompilerUtils
43192
0c05ac48a30b 8172870: test/tools/jmod/JmodTest.java fails on windows with AccessDeniedException
mchung
parents: 43109
diff changeset
    32
 * @run testng/othervm -Djava.io.tmpdir=. JmodTest
36511
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 java.io.*;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    36
import java.lang.module.ModuleDescriptor;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    37
import java.lang.reflect.Method;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    38
import java.nio.file.*;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    39
import java.util.*;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    40
import java.util.function.Consumer;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    41
import java.util.regex.Pattern;
41484
834b7539ada3 8164689: Retrofit jar, jlink, jmod as a ToolProvider
mchung
parents: 39882
diff changeset
    42
import java.util.spi.ToolProvider;
43192
0c05ac48a30b 8172870: test/tools/jmod/JmodTest.java fails on windows with AccessDeniedException
mchung
parents: 43109
diff changeset
    43
import java.util.stream.Collectors;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    44
import java.util.stream.Stream;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    45
import jdk.testlibrary.FileUtils;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    46
import org.testng.annotations.BeforeTest;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    47
import org.testng.annotations.Test;
39882
2a5433a2eca5 8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents: 36511
diff changeset
    48
2a5433a2eca5 8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents: 36511
diff changeset
    49
import static java.io.File.pathSeparator;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    50
import static java.lang.module.ModuleDescriptor.Version;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    51
import static java.nio.charset.StandardCharsets.UTF_8;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    52
import static java.util.stream.Collectors.toSet;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    53
import static org.testng.Assert.*;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    54
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    55
public class JmodTest {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    56
41484
834b7539ada3 8164689: Retrofit jar, jlink, jmod as a ToolProvider
mchung
parents: 39882
diff changeset
    57
    static final ToolProvider JMOD_TOOL = ToolProvider.findFirst("jmod")
834b7539ada3 8164689: Retrofit jar, jlink, jmod as a ToolProvider
mchung
parents: 39882
diff changeset
    58
        .orElseThrow(() ->
834b7539ada3 8164689: Retrofit jar, jlink, jmod as a ToolProvider
mchung
parents: 39882
diff changeset
    59
            new RuntimeException("jmod tool not found")
834b7539ada3 8164689: Retrofit jar, jlink, jmod as a ToolProvider
mchung
parents: 39882
diff changeset
    60
        );
834b7539ada3 8164689: Retrofit jar, jlink, jmod as a ToolProvider
mchung
parents: 39882
diff changeset
    61
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    62
    static final String TEST_SRC = System.getProperty("test.src", ".");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    63
    static final Path SRC_DIR = Paths.get(TEST_SRC, "src");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    64
    static final Path EXPLODED_DIR = Paths.get("build");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    65
    static final Path MODS_DIR = Paths.get("jmods");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    66
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    67
    static final String CLASSES_PREFIX = "classes/";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    68
    static final String CMDS_PREFIX = "bin/";
43729
21db38703675 8174739: Rename JMOD section name for native libraries from native to lib
mchung
parents: 43242
diff changeset
    69
    static final String LIBS_PREFIX = "lib/";
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    70
    static final String CONFIGS_PREFIX = "conf/";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    71
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    72
    @BeforeTest
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    73
    public void buildExplodedModules() throws IOException {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    74
        if (Files.exists(EXPLODED_DIR))
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    75
            FileUtils.deleteFileTreeWithRetry(EXPLODED_DIR);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    76
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    77
        for (String name : new String[] { "foo"/*, "bar", "baz"*/ } ) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    78
            Path dir = EXPLODED_DIR.resolve(name);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    79
            assertTrue(compileModule(name, dir.resolve("classes")));
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41916
diff changeset
    80
            copyResource(SRC_DIR.resolve("foo"),
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41916
diff changeset
    81
                         dir.resolve("classes"),
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41916
diff changeset
    82
                         "jdk/test/foo/resources/foo.properties");
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    83
            createCmds(dir.resolve("bin"));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    84
            createLibs(dir.resolve("lib"));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    85
            createConfigs(dir.resolve("conf"));
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
        if (Files.exists(MODS_DIR))
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    89
            FileUtils.deleteFileTreeWithRetry(MODS_DIR);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    90
        Files.createDirectories(MODS_DIR);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    91
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    92
41916
eb4aa81c6c5f 8166286: jmod fails on symlink to directory
sundar
parents: 41484
diff changeset
    93
    // JDK-8166286 - jmod fails on symlink to directory
eb4aa81c6c5f 8166286: jmod fails on symlink to directory
sundar
parents: 41484
diff changeset
    94
    @Test
eb4aa81c6c5f 8166286: jmod fails on symlink to directory
sundar
parents: 41484
diff changeset
    95
    public void testSymlinks() throws IOException {
eb4aa81c6c5f 8166286: jmod fails on symlink to directory
sundar
parents: 41484
diff changeset
    96
        Path apaDir = EXPLODED_DIR.resolve("apa");
eb4aa81c6c5f 8166286: jmod fails on symlink to directory
sundar
parents: 41484
diff changeset
    97
        Path classesDir = EXPLODED_DIR.resolve("apa").resolve("classes");
eb4aa81c6c5f 8166286: jmod fails on symlink to directory
sundar
parents: 41484
diff changeset
    98
        assertTrue(compileModule("apa", classesDir));
eb4aa81c6c5f 8166286: jmod fails on symlink to directory
sundar
parents: 41484
diff changeset
    99
        Path libDir = apaDir.resolve("lib");
eb4aa81c6c5f 8166286: jmod fails on symlink to directory
sundar
parents: 41484
diff changeset
   100
        createFiles(libDir, List.of("foo/bar/libfoo.so"));
eb4aa81c6c5f 8166286: jmod fails on symlink to directory
sundar
parents: 41484
diff changeset
   101
        try {
eb4aa81c6c5f 8166286: jmod fails on symlink to directory
sundar
parents: 41484
diff changeset
   102
            Path link = Files.createSymbolicLink(
eb4aa81c6c5f 8166286: jmod fails on symlink to directory
sundar
parents: 41484
diff changeset
   103
                libDir.resolve("baz"), libDir.resolve("foo").toAbsolutePath());
eb4aa81c6c5f 8166286: jmod fails on symlink to directory
sundar
parents: 41484
diff changeset
   104
            assertTrue(Files.exists(link));
eb4aa81c6c5f 8166286: jmod fails on symlink to directory
sundar
parents: 41484
diff changeset
   105
        } catch (UnsupportedOperationException uoe) {
eb4aa81c6c5f 8166286: jmod fails on symlink to directory
sundar
parents: 41484
diff changeset
   106
            // OS does not support symlinks. Nothing to test!
eb4aa81c6c5f 8166286: jmod fails on symlink to directory
sundar
parents: 41484
diff changeset
   107
            return;
eb4aa81c6c5f 8166286: jmod fails on symlink to directory
sundar
parents: 41484
diff changeset
   108
        }
eb4aa81c6c5f 8166286: jmod fails on symlink to directory
sundar
parents: 41484
diff changeset
   109
eb4aa81c6c5f 8166286: jmod fails on symlink to directory
sundar
parents: 41484
diff changeset
   110
        Path jmod = MODS_DIR.resolve("apa.jmod");
eb4aa81c6c5f 8166286: jmod fails on symlink to directory
sundar
parents: 41484
diff changeset
   111
        jmod("create",
eb4aa81c6c5f 8166286: jmod fails on symlink to directory
sundar
parents: 41484
diff changeset
   112
             "--libs=", libDir.toString(),
eb4aa81c6c5f 8166286: jmod fails on symlink to directory
sundar
parents: 41484
diff changeset
   113
             "--class-path", classesDir.toString(),
eb4aa81c6c5f 8166286: jmod fails on symlink to directory
sundar
parents: 41484
diff changeset
   114
             jmod.toString())
eb4aa81c6c5f 8166286: jmod fails on symlink to directory
sundar
parents: 41484
diff changeset
   115
            .assertSuccess();
eb4aa81c6c5f 8166286: jmod fails on symlink to directory
sundar
parents: 41484
diff changeset
   116
    }
eb4aa81c6c5f 8166286: jmod fails on symlink to directory
sundar
parents: 41484
diff changeset
   117
42922
9111fb672357 8170618: jmod should validate if any exported or open package is missing
sundar
parents: 42703
diff changeset
   118
    // JDK-8170618 - jmod should validate if any exported or open package is missing
9111fb672357 8170618: jmod should validate if any exported or open package is missing
sundar
parents: 42703
diff changeset
   119
    @Test
9111fb672357 8170618: jmod should validate if any exported or open package is missing
sundar
parents: 42703
diff changeset
   120
    public void testMissingPackages() throws IOException {
9111fb672357 8170618: jmod should validate if any exported or open package is missing
sundar
parents: 42703
diff changeset
   121
        Path apaDir = EXPLODED_DIR.resolve("apa");
9111fb672357 8170618: jmod should validate if any exported or open package is missing
sundar
parents: 42703
diff changeset
   122
        Path classesDir = EXPLODED_DIR.resolve("apa").resolve("classes");
9111fb672357 8170618: jmod should validate if any exported or open package is missing
sundar
parents: 42703
diff changeset
   123
        if (Files.exists(classesDir))
9111fb672357 8170618: jmod should validate if any exported or open package is missing
sundar
parents: 42703
diff changeset
   124
            FileUtils.deleteFileTreeWithRetry(classesDir);
9111fb672357 8170618: jmod should validate if any exported or open package is missing
sundar
parents: 42703
diff changeset
   125
        assertTrue(compileModule("apa", classesDir));
9111fb672357 8170618: jmod should validate if any exported or open package is missing
sundar
parents: 42703
diff changeset
   126
        FileUtils.deleteFileTreeWithRetry(classesDir.resolve("jdk"));
9111fb672357 8170618: jmod should validate if any exported or open package is missing
sundar
parents: 42703
diff changeset
   127
        Path jmod = MODS_DIR.resolve("apa.jmod");
9111fb672357 8170618: jmod should validate if any exported or open package is missing
sundar
parents: 42703
diff changeset
   128
        jmod("create",
9111fb672357 8170618: jmod should validate if any exported or open package is missing
sundar
parents: 42703
diff changeset
   129
             "--class-path", classesDir.toString(),
9111fb672357 8170618: jmod should validate if any exported or open package is missing
sundar
parents: 42703
diff changeset
   130
             jmod.toString())
9111fb672357 8170618: jmod should validate if any exported or open package is missing
sundar
parents: 42703
diff changeset
   131
            .assertFailure()
9111fb672357 8170618: jmod should validate if any exported or open package is missing
sundar
parents: 42703
diff changeset
   132
            .resultChecker(r -> {
9111fb672357 8170618: jmod should validate if any exported or open package is missing
sundar
parents: 42703
diff changeset
   133
                assertContains(r.output, "Packages that are exported or open in apa are not present: [jdk.test.apa]");
9111fb672357 8170618: jmod should validate if any exported or open package is missing
sundar
parents: 42703
diff changeset
   134
            });
9111fb672357 8170618: jmod should validate if any exported or open package is missing
sundar
parents: 42703
diff changeset
   135
        if (Files.exists(classesDir))
9111fb672357 8170618: jmod should validate if any exported or open package is missing
sundar
parents: 42703
diff changeset
   136
            FileUtils.deleteFileTreeWithRetry(classesDir);
9111fb672357 8170618: jmod should validate if any exported or open package is missing
sundar
parents: 42703
diff changeset
   137
    }
9111fb672357 8170618: jmod should validate if any exported or open package is missing
sundar
parents: 42703
diff changeset
   138
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   139
    @Test
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   140
    public void testList() throws IOException {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   141
        String cp = EXPLODED_DIR.resolve("foo").resolve("classes").toString();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   142
        jmod("create",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   143
             "--class-path", cp,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   144
             MODS_DIR.resolve("foo.jmod").toString())
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   145
            .assertSuccess();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   146
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   147
        jmod("list",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   148
             MODS_DIR.resolve("foo.jmod").toString())
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   149
            .assertSuccess()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   150
            .resultChecker(r -> {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   151
                // asserts dependent on the exact contents of foo
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   152
                assertContains(r.output, CLASSES_PREFIX + "module-info.class");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   153
                assertContains(r.output, CLASSES_PREFIX + "jdk/test/foo/Foo.class");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   154
                assertContains(r.output, CLASSES_PREFIX + "jdk/test/foo/internal/Message.class");
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41916
diff changeset
   155
                assertContains(r.output, CLASSES_PREFIX + "jdk/test/foo/resources/foo.properties");
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   156
            });
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   157
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   158
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   159
    @Test
42468
7a9555a7e080 8166568: Add jmod extract subcommand
chegar
parents: 42338
diff changeset
   160
    public void testExtractCWD() throws IOException {
7a9555a7e080 8166568: Add jmod extract subcommand
chegar
parents: 42338
diff changeset
   161
        Path cp = EXPLODED_DIR.resolve("foo").resolve("classes");
7a9555a7e080 8166568: Add jmod extract subcommand
chegar
parents: 42338
diff changeset
   162
        jmod("create",
7a9555a7e080 8166568: Add jmod extract subcommand
chegar
parents: 42338
diff changeset
   163
             "--class-path", cp.toString(),
7a9555a7e080 8166568: Add jmod extract subcommand
chegar
parents: 42338
diff changeset
   164
             MODS_DIR.resolve("fooExtractCWD.jmod").toString())
7a9555a7e080 8166568: Add jmod extract subcommand
chegar
parents: 42338
diff changeset
   165
            .assertSuccess();
7a9555a7e080 8166568: Add jmod extract subcommand
chegar
parents: 42338
diff changeset
   166
7a9555a7e080 8166568: Add jmod extract subcommand
chegar
parents: 42338
diff changeset
   167
        jmod("extract",
7a9555a7e080 8166568: Add jmod extract subcommand
chegar
parents: 42338
diff changeset
   168
             MODS_DIR.resolve("fooExtractCWD.jmod").toString())
7a9555a7e080 8166568: Add jmod extract subcommand
chegar
parents: 42338
diff changeset
   169
            .assertSuccess()
7a9555a7e080 8166568: Add jmod extract subcommand
chegar
parents: 42338
diff changeset
   170
            .resultChecker(r -> {
7a9555a7e080 8166568: Add jmod extract subcommand
chegar
parents: 42338
diff changeset
   171
                // module-info should exist, but jmod will have added its Packages attr.
7a9555a7e080 8166568: Add jmod extract subcommand
chegar
parents: 42338
diff changeset
   172
                assertTrue(Files.exists(Paths.get("classes/module-info.class")));
7a9555a7e080 8166568: Add jmod extract subcommand
chegar
parents: 42338
diff changeset
   173
                assertSameContent(cp.resolve("jdk/test/foo/Foo.class"),
7a9555a7e080 8166568: Add jmod extract subcommand
chegar
parents: 42338
diff changeset
   174
                                  Paths.get("classes/jdk/test/foo/Foo.class"));
7a9555a7e080 8166568: Add jmod extract subcommand
chegar
parents: 42338
diff changeset
   175
                assertSameContent(cp.resolve("jdk/test/foo/internal/Message.class"),
7a9555a7e080 8166568: Add jmod extract subcommand
chegar
parents: 42338
diff changeset
   176
                                  Paths.get("classes/jdk/test/foo/internal/Message.class"));
7a9555a7e080 8166568: Add jmod extract subcommand
chegar
parents: 42338
diff changeset
   177
                assertSameContent(cp.resolve("jdk/test/foo/resources/foo.properties"),
7a9555a7e080 8166568: Add jmod extract subcommand
chegar
parents: 42338
diff changeset
   178
                                  Paths.get("classes/jdk/test/foo/resources/foo.properties"));
7a9555a7e080 8166568: Add jmod extract subcommand
chegar
parents: 42338
diff changeset
   179
            });
7a9555a7e080 8166568: Add jmod extract subcommand
chegar
parents: 42338
diff changeset
   180
    }
7a9555a7e080 8166568: Add jmod extract subcommand
chegar
parents: 42338
diff changeset
   181
7a9555a7e080 8166568: Add jmod extract subcommand
chegar
parents: 42338
diff changeset
   182
    @Test
7a9555a7e080 8166568: Add jmod extract subcommand
chegar
parents: 42338
diff changeset
   183
    public void testExtractDir() throws IOException {
7a9555a7e080 8166568: Add jmod extract subcommand
chegar
parents: 42338
diff changeset
   184
        if (Files.exists(Paths.get("extractTestDir")))
7a9555a7e080 8166568: Add jmod extract subcommand
chegar
parents: 42338
diff changeset
   185
            FileUtils.deleteFileTreeWithRetry(Paths.get("extractTestDir"));
7a9555a7e080 8166568: Add jmod extract subcommand
chegar
parents: 42338
diff changeset
   186
        Path cp = EXPLODED_DIR.resolve("foo").resolve("classes");
7a9555a7e080 8166568: Add jmod extract subcommand
chegar
parents: 42338
diff changeset
   187
        Path bp = EXPLODED_DIR.resolve("foo").resolve("bin");
7a9555a7e080 8166568: Add jmod extract subcommand
chegar
parents: 42338
diff changeset
   188
        Path lp = EXPLODED_DIR.resolve("foo").resolve("lib");
7a9555a7e080 8166568: Add jmod extract subcommand
chegar
parents: 42338
diff changeset
   189
        Path cf = EXPLODED_DIR.resolve("foo").resolve("conf");
7a9555a7e080 8166568: Add jmod extract subcommand
chegar
parents: 42338
diff changeset
   190
7a9555a7e080 8166568: Add jmod extract subcommand
chegar
parents: 42338
diff changeset
   191
        jmod("create",
7a9555a7e080 8166568: Add jmod extract subcommand
chegar
parents: 42338
diff changeset
   192
             "--conf", cf.toString(),
7a9555a7e080 8166568: Add jmod extract subcommand
chegar
parents: 42338
diff changeset
   193
             "--cmds", bp.toString(),
7a9555a7e080 8166568: Add jmod extract subcommand
chegar
parents: 42338
diff changeset
   194
             "--libs", lp.toString(),
7a9555a7e080 8166568: Add jmod extract subcommand
chegar
parents: 42338
diff changeset
   195
             "--class-path", cp.toString(),
7a9555a7e080 8166568: Add jmod extract subcommand
chegar
parents: 42338
diff changeset
   196
             MODS_DIR.resolve("fooExtractDir.jmod").toString())
7a9555a7e080 8166568: Add jmod extract subcommand
chegar
parents: 42338
diff changeset
   197
            .assertSuccess();
7a9555a7e080 8166568: Add jmod extract subcommand
chegar
parents: 42338
diff changeset
   198
7a9555a7e080 8166568: Add jmod extract subcommand
chegar
parents: 42338
diff changeset
   199
        jmod("extract",
7a9555a7e080 8166568: Add jmod extract subcommand
chegar
parents: 42338
diff changeset
   200
             "--dir", "extractTestDir",
7a9555a7e080 8166568: Add jmod extract subcommand
chegar
parents: 42338
diff changeset
   201
             MODS_DIR.resolve("fooExtractDir.jmod").toString())
7a9555a7e080 8166568: Add jmod extract subcommand
chegar
parents: 42338
diff changeset
   202
            .assertSuccess();
7a9555a7e080 8166568: Add jmod extract subcommand
chegar
parents: 42338
diff changeset
   203
7a9555a7e080 8166568: Add jmod extract subcommand
chegar
parents: 42338
diff changeset
   204
        jmod("extract",
7a9555a7e080 8166568: Add jmod extract subcommand
chegar
parents: 42338
diff changeset
   205
             "--dir", "extractTestDir",
7a9555a7e080 8166568: Add jmod extract subcommand
chegar
parents: 42338
diff changeset
   206
             MODS_DIR.resolve("fooExtractDir.jmod").toString())
7a9555a7e080 8166568: Add jmod extract subcommand
chegar
parents: 42338
diff changeset
   207
            .assertSuccess()
7a9555a7e080 8166568: Add jmod extract subcommand
chegar
parents: 42338
diff changeset
   208
            .resultChecker(r -> {
7a9555a7e080 8166568: Add jmod extract subcommand
chegar
parents: 42338
diff changeset
   209
                // check a sample of the extracted files
7a9555a7e080 8166568: Add jmod extract subcommand
chegar
parents: 42338
diff changeset
   210
                Path p = Paths.get("extractTestDir");
7a9555a7e080 8166568: Add jmod extract subcommand
chegar
parents: 42338
diff changeset
   211
                assertTrue(Files.exists(p.resolve("classes/module-info.class")));
7a9555a7e080 8166568: Add jmod extract subcommand
chegar
parents: 42338
diff changeset
   212
                assertSameContent(cp.resolve("jdk/test/foo/Foo.class"),
7a9555a7e080 8166568: Add jmod extract subcommand
chegar
parents: 42338
diff changeset
   213
                                  p.resolve("classes/jdk/test/foo/Foo.class"));
7a9555a7e080 8166568: Add jmod extract subcommand
chegar
parents: 42338
diff changeset
   214
                assertSameContent(bp.resolve("first"),
7a9555a7e080 8166568: Add jmod extract subcommand
chegar
parents: 42338
diff changeset
   215
                                  p.resolve(CMDS_PREFIX).resolve("first"));
7a9555a7e080 8166568: Add jmod extract subcommand
chegar
parents: 42338
diff changeset
   216
                assertSameContent(lp.resolve("first.so"),
7a9555a7e080 8166568: Add jmod extract subcommand
chegar
parents: 42338
diff changeset
   217
                                  p.resolve(LIBS_PREFIX).resolve("second.so"));
7a9555a7e080 8166568: Add jmod extract subcommand
chegar
parents: 42338
diff changeset
   218
                assertSameContent(cf.resolve("second.cfg"),
7a9555a7e080 8166568: Add jmod extract subcommand
chegar
parents: 42338
diff changeset
   219
                                  p.resolve(CONFIGS_PREFIX).resolve("second.cfg"));
7a9555a7e080 8166568: Add jmod extract subcommand
chegar
parents: 42338
diff changeset
   220
            });
7a9555a7e080 8166568: Add jmod extract subcommand
chegar
parents: 42338
diff changeset
   221
    }
7a9555a7e080 8166568: Add jmod extract subcommand
chegar
parents: 42338
diff changeset
   222
7a9555a7e080 8166568: Add jmod extract subcommand
chegar
parents: 42338
diff changeset
   223
    @Test
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   224
    public void testMainClass() throws IOException {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   225
        Path jmod = MODS_DIR.resolve("fooMainClass.jmod");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   226
        FileUtils.deleteFileIfExistsWithRetry(jmod);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   227
        String cp = EXPLODED_DIR.resolve("foo").resolve("classes").toString();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   228
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   229
        jmod("create",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   230
             "--class-path", cp,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   231
             "--main-class", "jdk.test.foo.Foo",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   232
             jmod.toString())
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   233
            .assertSuccess()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   234
            .resultChecker(r -> {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   235
                Optional<String> omc = getModuleDescriptor(jmod).mainClass();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   236
                assertTrue(omc.isPresent());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   237
                assertEquals(omc.get(), "jdk.test.foo.Foo");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   238
            });
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   239
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   240
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   241
    @Test
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   242
    public void testModuleVersion() throws IOException {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   243
        Path jmod = MODS_DIR.resolve("fooVersion.jmod");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   244
        FileUtils.deleteFileIfExistsWithRetry(jmod);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   245
        String cp = EXPLODED_DIR.resolve("foo").resolve("classes").toString();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   246
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   247
        jmod("create",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   248
             "--class-path", cp,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   249
             "--module-version", "5.4.3",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   250
             jmod.toString())
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   251
            .assertSuccess()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   252
            .resultChecker(r -> {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   253
                Optional<Version> ov = getModuleDescriptor(jmod).version();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   254
                assertTrue(ov.isPresent());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   255
                assertEquals(ov.get().toString(), "5.4.3");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   256
            });
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   257
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   258
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   259
    @Test
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   260
    public void testConfig() throws IOException {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   261
        Path jmod = MODS_DIR.resolve("fooConfig.jmod");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   262
        FileUtils.deleteFileIfExistsWithRetry(jmod);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   263
        Path cp = EXPLODED_DIR.resolve("foo").resolve("classes");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   264
        Path cf = EXPLODED_DIR.resolve("foo").resolve("conf");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   265
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   266
        jmod("create",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   267
             "--class-path", cp.toString(),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   268
             "--config", cf.toString(),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   269
             jmod.toString())
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   270
            .assertSuccess()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   271
            .resultChecker(r -> {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   272
                try (Stream<String> s1 = findFiles(cf).map(p -> CONFIGS_PREFIX + p);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   273
                     Stream<String> s2 = findFiles(cp).map(p -> CLASSES_PREFIX + p)) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   274
                    Set<String> expectedFilenames = Stream.concat(s1, s2)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   275
                                                          .collect(toSet());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   276
                    assertJmodContent(jmod, expectedFilenames);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   277
                }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   278
            });
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   279
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   280
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   281
    @Test
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   282
    public void testCmds() throws IOException {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   283
        Path jmod = MODS_DIR.resolve("fooCmds.jmod");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   284
        FileUtils.deleteFileIfExistsWithRetry(jmod);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   285
        Path cp = EXPLODED_DIR.resolve("foo").resolve("classes");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   286
        Path bp = EXPLODED_DIR.resolve("foo").resolve("bin");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   287
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   288
        jmod("create",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   289
             "--cmds", bp.toString(),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   290
             "--class-path", cp.toString(),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   291
             jmod.toString())
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   292
            .assertSuccess()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   293
            .resultChecker(r -> {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   294
                try (Stream<String> s1 = findFiles(bp).map(p -> CMDS_PREFIX + p);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   295
                     Stream<String> s2 = findFiles(cp).map(p -> CLASSES_PREFIX + p)) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   296
                    Set<String> expectedFilenames = Stream.concat(s1,s2)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   297
                                                          .collect(toSet());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   298
                    assertJmodContent(jmod, expectedFilenames);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   299
                }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   300
            });
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   301
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   302
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   303
    @Test
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   304
    public void testLibs() throws IOException {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   305
        Path jmod = MODS_DIR.resolve("fooLibs.jmod");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   306
        FileUtils.deleteFileIfExistsWithRetry(jmod);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   307
        Path cp = EXPLODED_DIR.resolve("foo").resolve("classes");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   308
        Path lp = EXPLODED_DIR.resolve("foo").resolve("lib");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   309
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   310
        jmod("create",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   311
             "--libs=", lp.toString(),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   312
             "--class-path", cp.toString(),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   313
             jmod.toString())
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   314
            .assertSuccess()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   315
            .resultChecker(r -> {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   316
                try (Stream<String> s1 = findFiles(lp).map(p -> LIBS_PREFIX + p);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   317
                     Stream<String> s2 = findFiles(cp).map(p -> CLASSES_PREFIX + p)) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   318
                    Set<String> expectedFilenames = Stream.concat(s1,s2)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   319
                                                          .collect(toSet());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   320
                    assertJmodContent(jmod, expectedFilenames);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   321
                }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   322
            });
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   323
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   324
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   325
    @Test
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   326
    public void testAll() throws IOException {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   327
        Path jmod = MODS_DIR.resolve("fooAll.jmod");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   328
        FileUtils.deleteFileIfExistsWithRetry(jmod);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   329
        Path cp = EXPLODED_DIR.resolve("foo").resolve("classes");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   330
        Path bp = EXPLODED_DIR.resolve("foo").resolve("bin");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   331
        Path lp = EXPLODED_DIR.resolve("foo").resolve("lib");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   332
        Path cf = EXPLODED_DIR.resolve("foo").resolve("conf");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   333
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   334
        jmod("create",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   335
             "--conf", cf.toString(),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   336
             "--cmds=", bp.toString(),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   337
             "--libs=", lp.toString(),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   338
             "--class-path", cp.toString(),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   339
             jmod.toString())
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   340
            .assertSuccess()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   341
            .resultChecker(r -> {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   342
                try (Stream<String> s1 = findFiles(lp).map(p -> LIBS_PREFIX + p);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   343
                     Stream<String> s2 = findFiles(cp).map(p -> CLASSES_PREFIX + p);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   344
                     Stream<String> s3 = findFiles(bp).map(p -> CMDS_PREFIX + p);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   345
                     Stream<String> s4 = findFiles(cf).map(p -> CONFIGS_PREFIX + p)) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   346
                    Set<String> expectedFilenames = Stream.concat(Stream.concat(s1,s2),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   347
                                                                  Stream.concat(s3, s4))
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   348
                                                          .collect(toSet());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   349
                    assertJmodContent(jmod, expectedFilenames);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   350
                }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   351
            });
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   352
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   353
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   354
    @Test
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   355
    public void testExcludes() throws IOException {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   356
        Path jmod = MODS_DIR.resolve("fooLibs.jmod");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   357
        FileUtils.deleteFileIfExistsWithRetry(jmod);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   358
        Path cp = EXPLODED_DIR.resolve("foo").resolve("classes");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   359
        Path lp = EXPLODED_DIR.resolve("foo").resolve("lib");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   360
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   361
        jmod("create",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   362
             "--libs=", lp.toString(),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   363
             "--class-path", cp.toString(),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   364
             "--exclude", "**internal**",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   365
             "--exclude", "first.so",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   366
             jmod.toString())
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   367
             .assertSuccess()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   368
             .resultChecker(r -> {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   369
                 Set<String> expectedFilenames = new HashSet<>();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   370
                 expectedFilenames.add(CLASSES_PREFIX + "module-info.class");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   371
                 expectedFilenames.add(CLASSES_PREFIX + "jdk/test/foo/Foo.class");
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41916
diff changeset
   372
                 expectedFilenames.add(CLASSES_PREFIX + "jdk/test/foo/resources/foo.properties");
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   373
                 expectedFilenames.add(LIBS_PREFIX + "second.so");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   374
                 expectedFilenames.add(LIBS_PREFIX + "third/third.so");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   375
                 assertJmodContent(jmod, expectedFilenames);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   376
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   377
                 Set<String> unexpectedFilenames = new HashSet<>();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   378
                 unexpectedFilenames.add(CLASSES_PREFIX + "jdk/test/foo/internal/Message.class");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   379
                 unexpectedFilenames.add(LIBS_PREFIX + "first.so");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   380
                 assertJmodDoesNotContain(jmod, unexpectedFilenames);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   381
             });
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   382
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   383
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   384
    @Test
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   385
    public void describe() throws IOException {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   386
        String cp = EXPLODED_DIR.resolve("foo").resolve("classes").toString();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   387
        jmod("create",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   388
             "--class-path", cp,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   389
              MODS_DIR.resolve("describeFoo.jmod").toString())
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   390
             .assertSuccess();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   391
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   392
        jmod("describe",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   393
             MODS_DIR.resolve("describeFoo.jmod").toString())
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   394
             .assertSuccess()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   395
             .resultChecker(r -> {
45004
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 43729
diff changeset
   396
                 // Expect similar output: "foo... exports jdk.test.foo ...
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 43729
diff changeset
   397
                 //   ... requires java.base mandated... contains jdk.test.foo.internal"
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 43729
diff changeset
   398
                 Pattern p = Pattern.compile("foo\\s+exports\\s+jdk.test.foo");
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   399
                 assertTrue(p.matcher(r.output).find(),
45004
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 43729
diff changeset
   400
                           "Expecting to find \"foo... exports jdk.test.foo\"" +
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   401
                                "in output, but did not: [" + r.output + "]");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   402
                 p = Pattern.compile(
45004
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 43729
diff changeset
   403
                        "requires\\s+java.base\\s+mandated\\s+contains\\s+jdk.test.foo.internal");
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   404
                 assertTrue(p.matcher(r.output).find(),
45004
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 43729
diff changeset
   405
                           "Expecting to find \"requires java.base mandated..., " +
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 43729
diff changeset
   406
                                "contains jdk.test.foo.internal ...\"" +
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   407
                                "in output, but did not: [" + r.output + "]");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   408
             });
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   409
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   410
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   411
    @Test
39882
2a5433a2eca5 8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents: 36511
diff changeset
   412
    public void testDuplicateEntries() throws IOException {
2a5433a2eca5 8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents: 36511
diff changeset
   413
        Path jmod = MODS_DIR.resolve("testDuplicates.jmod");
2a5433a2eca5 8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents: 36511
diff changeset
   414
        FileUtils.deleteFileIfExistsWithRetry(jmod);
2a5433a2eca5 8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents: 36511
diff changeset
   415
        String cp = EXPLODED_DIR.resolve("foo").resolve("classes").toString();
2a5433a2eca5 8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents: 36511
diff changeset
   416
        Path lp = EXPLODED_DIR.resolve("foo").resolve("lib");
2a5433a2eca5 8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents: 36511
diff changeset
   417
2a5433a2eca5 8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents: 36511
diff changeset
   418
        jmod("create",
2a5433a2eca5 8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents: 36511
diff changeset
   419
             "--class-path", cp + pathSeparator + cp,
2a5433a2eca5 8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents: 36511
diff changeset
   420
             jmod.toString())
2a5433a2eca5 8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents: 36511
diff changeset
   421
             .assertSuccess()
2a5433a2eca5 8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents: 36511
diff changeset
   422
             .resultChecker(r ->
2a5433a2eca5 8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents: 36511
diff changeset
   423
                 assertContains(r.output, "Warning: ignoring duplicate entry")
2a5433a2eca5 8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents: 36511
diff changeset
   424
             );
2a5433a2eca5 8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents: 36511
diff changeset
   425
2a5433a2eca5 8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents: 36511
diff changeset
   426
        FileUtils.deleteFileIfExistsWithRetry(jmod);
2a5433a2eca5 8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents: 36511
diff changeset
   427
        jmod("create",
2a5433a2eca5 8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents: 36511
diff changeset
   428
             "--class-path", cp,
2a5433a2eca5 8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents: 36511
diff changeset
   429
             "--libs", lp.toString() + pathSeparator + lp.toString(),
2a5433a2eca5 8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents: 36511
diff changeset
   430
             jmod.toString())
2a5433a2eca5 8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents: 36511
diff changeset
   431
             .assertSuccess()
2a5433a2eca5 8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents: 36511
diff changeset
   432
             .resultChecker(r ->
2a5433a2eca5 8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents: 36511
diff changeset
   433
                 assertContains(r.output, "Warning: ignoring duplicate entry")
2a5433a2eca5 8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents: 36511
diff changeset
   434
             );
2a5433a2eca5 8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents: 36511
diff changeset
   435
    }
2a5433a2eca5 8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents: 36511
diff changeset
   436
2a5433a2eca5 8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents: 36511
diff changeset
   437
    @Test
2a5433a2eca5 8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents: 36511
diff changeset
   438
    public void testIgnoreModuleInfoInOtherSections() throws IOException {
2a5433a2eca5 8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents: 36511
diff changeset
   439
        Path jmod = MODS_DIR.resolve("testIgnoreModuleInfoInOtherSections.jmod");
2a5433a2eca5 8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents: 36511
diff changeset
   440
        FileUtils.deleteFileIfExistsWithRetry(jmod);
2a5433a2eca5 8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents: 36511
diff changeset
   441
        String cp = EXPLODED_DIR.resolve("foo").resolve("classes").toString();
2a5433a2eca5 8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents: 36511
diff changeset
   442
2a5433a2eca5 8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents: 36511
diff changeset
   443
        jmod("create",
2a5433a2eca5 8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents: 36511
diff changeset
   444
            "--class-path", cp,
2a5433a2eca5 8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents: 36511
diff changeset
   445
            "--libs", cp,
2a5433a2eca5 8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents: 36511
diff changeset
   446
            jmod.toString())
2a5433a2eca5 8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents: 36511
diff changeset
   447
            .assertSuccess()
2a5433a2eca5 8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents: 36511
diff changeset
   448
            .resultChecker(r ->
2a5433a2eca5 8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents: 36511
diff changeset
   449
                assertContains(r.output, "Warning: ignoring entry")
2a5433a2eca5 8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents: 36511
diff changeset
   450
            );
2a5433a2eca5 8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents: 36511
diff changeset
   451
2a5433a2eca5 8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents: 36511
diff changeset
   452
        FileUtils.deleteFileIfExistsWithRetry(jmod);
2a5433a2eca5 8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents: 36511
diff changeset
   453
        jmod("create",
2a5433a2eca5 8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents: 36511
diff changeset
   454
             "--class-path", cp,
2a5433a2eca5 8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents: 36511
diff changeset
   455
             "--cmds", cp,
2a5433a2eca5 8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents: 36511
diff changeset
   456
             jmod.toString())
2a5433a2eca5 8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents: 36511
diff changeset
   457
             .assertSuccess()
2a5433a2eca5 8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents: 36511
diff changeset
   458
             .resultChecker(r ->
2a5433a2eca5 8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents: 36511
diff changeset
   459
                 assertContains(r.output, "Warning: ignoring entry")
2a5433a2eca5 8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents: 36511
diff changeset
   460
             );
2a5433a2eca5 8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents: 36511
diff changeset
   461
    }
2a5433a2eca5 8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents: 36511
diff changeset
   462
2a5433a2eca5 8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents: 36511
diff changeset
   463
    @Test
43067
3f011a470ce2 8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents: 42922
diff changeset
   464
    public void testLastOneWins() throws IOException {
3f011a470ce2 8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents: 42922
diff changeset
   465
        Path workDir = Paths.get("lastOneWins");
3f011a470ce2 8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents: 42922
diff changeset
   466
        if (Files.exists(workDir))
3f011a470ce2 8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents: 42922
diff changeset
   467
            FileUtils.deleteFileTreeWithRetry(workDir);
3f011a470ce2 8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents: 42922
diff changeset
   468
        Files.createDirectory(workDir);
3f011a470ce2 8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents: 42922
diff changeset
   469
        Path jmod = MODS_DIR.resolve("lastOneWins.jmod");
3f011a470ce2 8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents: 42922
diff changeset
   470
        FileUtils.deleteFileIfExistsWithRetry(jmod);
3f011a470ce2 8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents: 42922
diff changeset
   471
        Path cp = EXPLODED_DIR.resolve("foo").resolve("classes");
3f011a470ce2 8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents: 42922
diff changeset
   472
        Path bp = EXPLODED_DIR.resolve("foo").resolve("bin");
3f011a470ce2 8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents: 42922
diff changeset
   473
        Path lp = EXPLODED_DIR.resolve("foo").resolve("lib");
3f011a470ce2 8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents: 42922
diff changeset
   474
        Path cf = EXPLODED_DIR.resolve("foo").resolve("conf");
3f011a470ce2 8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents: 42922
diff changeset
   475
3f011a470ce2 8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents: 42922
diff changeset
   476
        Path shouldNotBeAdded = workDir.resolve("shouldNotBeAdded");
3f011a470ce2 8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents: 42922
diff changeset
   477
        Files.createDirectory(shouldNotBeAdded);
3f011a470ce2 8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents: 42922
diff changeset
   478
        Files.write(shouldNotBeAdded.resolve("aFile"), "hello".getBytes(UTF_8));
3f011a470ce2 8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents: 42922
diff changeset
   479
3f011a470ce2 8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents: 42922
diff changeset
   480
        // Pairs of options. For options with required arguments the last one
3f011a470ce2 8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents: 42922
diff changeset
   481
        // should win ( first should be effectively ignored, but may still be
3f011a470ce2 8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents: 42922
diff changeset
   482
        // validated ).
3f011a470ce2 8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents: 42922
diff changeset
   483
        jmod("create",
3f011a470ce2 8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents: 42922
diff changeset
   484
             "--conf", shouldNotBeAdded.toString(),
3f011a470ce2 8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents: 42922
diff changeset
   485
             "--conf", cf.toString(),
3f011a470ce2 8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents: 42922
diff changeset
   486
             "--cmds", shouldNotBeAdded.toString(),
3f011a470ce2 8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents: 42922
diff changeset
   487
             "--cmds", bp.toString(),
3f011a470ce2 8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents: 42922
diff changeset
   488
             "--libs", shouldNotBeAdded.toString(),
3f011a470ce2 8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents: 42922
diff changeset
   489
             "--libs", lp.toString(),
3f011a470ce2 8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents: 42922
diff changeset
   490
             "--class-path", shouldNotBeAdded.toString(),
3f011a470ce2 8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents: 42922
diff changeset
   491
             "--class-path", cp.toString(),
3f011a470ce2 8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents: 42922
diff changeset
   492
             "--main-class", "does.NotExist",
3f011a470ce2 8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents: 42922
diff changeset
   493
             "--main-class", "jdk.test.foo.Foo",
3f011a470ce2 8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents: 42922
diff changeset
   494
             "--module-version", "00001",
3f011a470ce2 8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents: 42922
diff changeset
   495
             "--module-version", "5.4.3",
3f011a470ce2 8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents: 42922
diff changeset
   496
             "--do-not-resolve-by-default",
3f011a470ce2 8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents: 42922
diff changeset
   497
             "--do-not-resolve-by-default",
3f011a470ce2 8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents: 42922
diff changeset
   498
             "--warn-if-resolved=incubating",
3f011a470ce2 8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents: 42922
diff changeset
   499
             "--warn-if-resolved=deprecated",
3f011a470ce2 8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents: 42922
diff changeset
   500
             MODS_DIR.resolve("lastOneWins.jmod").toString())
3f011a470ce2 8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents: 42922
diff changeset
   501
            .assertSuccess()
3f011a470ce2 8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents: 42922
diff changeset
   502
            .resultChecker(r -> {
3f011a470ce2 8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents: 42922
diff changeset
   503
                ModuleDescriptor md = getModuleDescriptor(jmod);
3f011a470ce2 8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents: 42922
diff changeset
   504
                Optional<String> omc = md.mainClass();
3f011a470ce2 8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents: 42922
diff changeset
   505
                assertTrue(omc.isPresent());
3f011a470ce2 8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents: 42922
diff changeset
   506
                assertEquals(omc.get(), "jdk.test.foo.Foo");
3f011a470ce2 8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents: 42922
diff changeset
   507
                Optional<Version> ov = md.version();
3f011a470ce2 8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents: 42922
diff changeset
   508
                assertTrue(ov.isPresent());
3f011a470ce2 8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents: 42922
diff changeset
   509
                assertEquals(ov.get().toString(), "5.4.3");
3f011a470ce2 8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents: 42922
diff changeset
   510
3f011a470ce2 8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents: 42922
diff changeset
   511
                try (Stream<String> s1 = findFiles(lp).map(p -> LIBS_PREFIX + p);
3f011a470ce2 8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents: 42922
diff changeset
   512
                     Stream<String> s2 = findFiles(cp).map(p -> CLASSES_PREFIX + p);
3f011a470ce2 8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents: 42922
diff changeset
   513
                     Stream<String> s3 = findFiles(bp).map(p -> CMDS_PREFIX + p);
3f011a470ce2 8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents: 42922
diff changeset
   514
                     Stream<String> s4 = findFiles(cf).map(p -> CONFIGS_PREFIX + p)) {
3f011a470ce2 8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents: 42922
diff changeset
   515
                    Set<String> expectedFilenames = Stream.concat(Stream.concat(s1,s2),
3f011a470ce2 8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents: 42922
diff changeset
   516
                                                                  Stream.concat(s3, s4))
3f011a470ce2 8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents: 42922
diff changeset
   517
                                                          .collect(toSet());
3f011a470ce2 8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents: 42922
diff changeset
   518
                    assertJmodContent(jmod, expectedFilenames);
3f011a470ce2 8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents: 42922
diff changeset
   519
                }
3f011a470ce2 8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents: 42922
diff changeset
   520
            });
3f011a470ce2 8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents: 42922
diff changeset
   521
3f011a470ce2 8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents: 42922
diff changeset
   522
        jmod("extract",
3f011a470ce2 8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents: 42922
diff changeset
   523
             "--dir", "blah",
3f011a470ce2 8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents: 42922
diff changeset
   524
             "--dir", "lastOneWinsExtractDir",
3f011a470ce2 8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents: 42922
diff changeset
   525
             jmod.toString())
3f011a470ce2 8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents: 42922
diff changeset
   526
            .assertSuccess()
3f011a470ce2 8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents: 42922
diff changeset
   527
            .resultChecker(r -> {
3f011a470ce2 8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents: 42922
diff changeset
   528
                assertTrue(Files.exists(Paths.get("lastOneWinsExtractDir")));
3f011a470ce2 8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents: 42922
diff changeset
   529
                assertTrue(Files.notExists(Paths.get("blah")));
3f011a470ce2 8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents: 42922
diff changeset
   530
            });
3f011a470ce2 8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents: 42922
diff changeset
   531
    }
3f011a470ce2 8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents: 42922
diff changeset
   532
3f011a470ce2 8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents: 42922
diff changeset
   533
    @Test
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41916
diff changeset
   534
    public void testPackagesAttribute() throws IOException {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41916
diff changeset
   535
        Path jmod = MODS_DIR.resolve("foo.jmod");
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41916
diff changeset
   536
        FileUtils.deleteFileIfExistsWithRetry(jmod);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41916
diff changeset
   537
        String cp = EXPLODED_DIR.resolve("foo").resolve("classes").toString();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41916
diff changeset
   538
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41916
diff changeset
   539
        Set<String> expectedPackages = Set.of("jdk.test.foo",
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41916
diff changeset
   540
                                              "jdk.test.foo.internal",
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41916
diff changeset
   541
                                              "jdk.test.foo.resources");
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41916
diff changeset
   542
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41916
diff changeset
   543
        jmod("create",
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41916
diff changeset
   544
             "--class-path", cp,
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41916
diff changeset
   545
             jmod.toString())
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41916
diff changeset
   546
             .assertSuccess()
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41916
diff changeset
   547
             .resultChecker(r -> {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41916
diff changeset
   548
                 Set<String> pkgs = getModuleDescriptor(jmod).packages();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41916
diff changeset
   549
                 assertEquals(pkgs, expectedPackages);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41916
diff changeset
   550
             });
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41916
diff changeset
   551
        }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41916
diff changeset
   552
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41916
diff changeset
   553
    @Test
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   554
    public void testVersion() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   555
        jmod("--version")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   556
            .assertSuccess()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   557
            .resultChecker(r -> {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   558
                assertContains(r.output, System.getProperty("java.version"));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   559
            });
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   560
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   561
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   562
    @Test
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   563
    public void testHelp() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   564
        jmod("--help")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   565
            .assertSuccess()
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42468
diff changeset
   566
            .resultChecker(r -> {
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42468
diff changeset
   567
                assertTrue(r.output.startsWith("Usage: jmod"), "Help not printed");
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42468
diff changeset
   568
                assertFalse(r.output.contains("--do-not-resolve-by-default"));
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42468
diff changeset
   569
                assertFalse(r.output.contains("--warn-if-resolved"));
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42468
diff changeset
   570
            });
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42468
diff changeset
   571
    }
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42468
diff changeset
   572
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42468
diff changeset
   573
    @Test
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42468
diff changeset
   574
    public void testHelpExtra() {
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42468
diff changeset
   575
        jmod("--help-extra")
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42468
diff changeset
   576
            .assertSuccess()
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42468
diff changeset
   577
            .resultChecker(r -> {
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42468
diff changeset
   578
                assertTrue(r.output.startsWith("Usage: jmod"), "Extra help not printed");
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42468
diff changeset
   579
                assertContains(r.output, "--do-not-resolve-by-default");
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42468
diff changeset
   580
                assertContains(r.output, "--warn-if-resolved");
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42468
diff changeset
   581
            });
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   582
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   583
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   584
    @Test
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   585
    public void testTmpFileRemoved() throws IOException {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   586
        // Implementation detail: jmod tool creates <jmod-file>.tmp
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   587
        // Ensure that it is removed in the event of a failure.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   588
        // The failure in this case is a class in the unnamed package.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   589
43242
6c33c81be927 8173096: jmod files are not world-readable
mchung
parents: 43192
diff changeset
   590
        Path jmod = MODS_DIR.resolve("testTmpFileRemoved.jmod");
6c33c81be927 8173096: jmod files are not world-readable
mchung
parents: 43192
diff changeset
   591
        Path tmp = MODS_DIR.resolve(".testTmpFileRemoved.jmod.tmp");
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   592
        FileUtils.deleteFileIfExistsWithRetry(jmod);
43242
6c33c81be927 8173096: jmod files are not world-readable
mchung
parents: 43192
diff changeset
   593
        FileUtils.deleteFileIfExistsWithRetry(tmp);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   594
        String cp = EXPLODED_DIR.resolve("foo").resolve("classes") + File.pathSeparator +
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   595
                    EXPLODED_DIR.resolve("foo").resolve("classes")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   596
                                .resolve("jdk").resolve("test").resolve("foo").toString();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   597
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   598
        jmod("create",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   599
             "--class-path", cp,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   600
             jmod.toString())
43242
6c33c81be927 8173096: jmod files are not world-readable
mchung
parents: 43192
diff changeset
   601
            .assertFailure()
6c33c81be927 8173096: jmod files are not world-readable
mchung
parents: 43192
diff changeset
   602
            .resultChecker(r -> {
6c33c81be927 8173096: jmod files are not world-readable
mchung
parents: 43192
diff changeset
   603
                assertContains(r.output, "unnamed package");
6c33c81be927 8173096: jmod files are not world-readable
mchung
parents: 43192
diff changeset
   604
                assertTrue(Files.notExists(tmp), "Unexpected tmp file:" + tmp);
6c33c81be927 8173096: jmod files are not world-readable
mchung
parents: 43192
diff changeset
   605
            });
43109
fe275140c3f1 8160286: jmod hash is creating unlinkable modules
mchung
parents: 43067
diff changeset
   606
    }
fe275140c3f1 8160286: jmod hash is creating unlinkable modules
mchung
parents: 43067
diff changeset
   607
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   608
    // ---
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   609
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   610
    static boolean compileModule(String name, Path dest) throws IOException {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   611
        return CompilerUtils.compile(SRC_DIR.resolve(name), dest);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   612
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   613
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   614
    static void assertContains(String output, String subString) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   615
        if (output.contains(subString))
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   616
            assertTrue(true);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   617
        else
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   618
            assertTrue(false,"Expected to find [" + subString + "], in output ["
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   619
                           + output + "]" + "\n");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   620
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   621
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   622
    static ModuleDescriptor getModuleDescriptor(Path jmod) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   623
        ClassLoader cl = ClassLoader.getSystemClassLoader();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   624
        try (FileSystem fs = FileSystems.newFileSystem(jmod, cl)) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   625
            String p = "/classes/module-info.class";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   626
            try (InputStream is = Files.newInputStream(fs.getPath(p))) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   627
                return ModuleDescriptor.read(is);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   628
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   629
        } catch (IOException ioe) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   630
            throw new UncheckedIOException(ioe);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   631
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   632
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   633
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   634
    static Stream<String> findFiles(Path dir) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   635
        try {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   636
            return Files.find(dir, Integer.MAX_VALUE, (p, a) -> a.isRegularFile())
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   637
                        .map(dir::relativize)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   638
                        .map(Path::toString)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   639
                        .map(p -> p.replace(File.separator, "/"));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   640
        } catch (IOException x) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   641
            throw new UncheckedIOException(x);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   642
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   643
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   644
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   645
    static Set<String> getJmodContent(Path jmod) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   646
        JmodResult r = jmod("list", jmod.toString()).assertSuccess();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   647
        return Stream.of(r.output.split("\r?\n")).collect(toSet());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   648
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   649
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   650
    static void assertJmodContent(Path jmod, Set<String> expected) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   651
        Set<String> actual = getJmodContent(jmod);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   652
        if (!Objects.equals(actual, expected)) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   653
            Set<String> unexpected = new HashSet<>(actual);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   654
            unexpected.removeAll(expected);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   655
            Set<String> notFound = new HashSet<>(expected);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   656
            notFound.removeAll(actual);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   657
            StringBuilder sb = new StringBuilder();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   658
            sb.append("Unexpected but found:\n");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   659
            unexpected.forEach(s -> sb.append("\t" + s + "\n"));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   660
            sb.append("Expected but not found:\n");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   661
            notFound.forEach(s -> sb.append("\t" + s + "\n"));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   662
            assertTrue(false, "Jmod content check failed.\n" + sb.toString());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   663
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   664
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   665
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   666
    static void assertJmodDoesNotContain(Path jmod, Set<String> unexpectedNames) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   667
        Set<String> actual = getJmodContent(jmod);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   668
        Set<String> unexpected = new HashSet<>();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   669
        for (String name : unexpectedNames) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   670
            if (actual.contains(name))
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   671
                unexpected.add(name);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   672
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   673
        if (!unexpected.isEmpty()) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   674
            StringBuilder sb = new StringBuilder();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   675
            for (String s : unexpected)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   676
                sb.append("Unexpected but found: " + s + "\n");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   677
            sb.append("In :");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   678
            for (String s : actual)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   679
                sb.append("\t" + s + "\n");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   680
            assertTrue(false, "Jmod content check failed.\n" + sb.toString());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   681
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   682
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   683
42468
7a9555a7e080 8166568: Add jmod extract subcommand
chegar
parents: 42338
diff changeset
   684
    static void assertSameContent(Path p1, Path p2) {
7a9555a7e080 8166568: Add jmod extract subcommand
chegar
parents: 42338
diff changeset
   685
        try {
7a9555a7e080 8166568: Add jmod extract subcommand
chegar
parents: 42338
diff changeset
   686
            byte[] ba1 = Files.readAllBytes(p1);
7a9555a7e080 8166568: Add jmod extract subcommand
chegar
parents: 42338
diff changeset
   687
            byte[] ba2 = Files.readAllBytes(p2);
7a9555a7e080 8166568: Add jmod extract subcommand
chegar
parents: 42338
diff changeset
   688
            assertEquals(ba1, ba2);
7a9555a7e080 8166568: Add jmod extract subcommand
chegar
parents: 42338
diff changeset
   689
        } catch (IOException x) {
7a9555a7e080 8166568: Add jmod extract subcommand
chegar
parents: 42338
diff changeset
   690
            throw new UncheckedIOException(x);
7a9555a7e080 8166568: Add jmod extract subcommand
chegar
parents: 42338
diff changeset
   691
        }
7a9555a7e080 8166568: Add jmod extract subcommand
chegar
parents: 42338
diff changeset
   692
    }
7a9555a7e080 8166568: Add jmod extract subcommand
chegar
parents: 42338
diff changeset
   693
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   694
    static JmodResult jmod(String... args) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   695
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   696
        PrintStream ps = new PrintStream(baos);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   697
        System.out.println("jmod " + Arrays.asList(args));
41484
834b7539ada3 8164689: Retrofit jar, jlink, jmod as a ToolProvider
mchung
parents: 39882
diff changeset
   698
        int ec = JMOD_TOOL.run(ps, ps, args);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   699
        return new JmodResult(ec, new String(baos.toByteArray(), UTF_8));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   700
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   701
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   702
    static class JmodResult {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   703
        final int exitCode;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   704
        final String output;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   705
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   706
        JmodResult(int exitValue, String output) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   707
            this.exitCode = exitValue;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   708
            this.output = output;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   709
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   710
        JmodResult assertSuccess() { assertTrue(exitCode == 0, output); return this; }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   711
        JmodResult assertFailure() { assertTrue(exitCode != 0, output); return this; }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   712
        JmodResult resultChecker(Consumer<JmodResult> r) { r.accept(this); return this; }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   713
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   714
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   715
    static void createCmds(Path dir) throws IOException {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   716
        List<String> files = Arrays.asList(
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   717
                "first", "second", "third" + File.separator + "third");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   718
        createFiles(dir, files);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   719
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   720
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   721
    static void createLibs(Path dir) throws IOException {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   722
        List<String> files = Arrays.asList(
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   723
                "first.so", "second.so", "third" + File.separator + "third.so");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   724
        createFiles(dir, files);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   725
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   726
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   727
    static void createConfigs(Path dir) throws IOException {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   728
        List<String> files = Arrays.asList(
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   729
                "first.cfg", "second.cfg", "third" + File.separator + "third.cfg");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   730
        createFiles(dir, files);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   731
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   732
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   733
    static void createFiles(Path dir, List<String> filenames) throws IOException {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   734
        for (String name : filenames) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   735
            Path file = dir.resolve(name);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   736
            Files.createDirectories(file.getParent());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   737
            Files.createFile(file);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   738
            try (OutputStream os  = Files.newOutputStream(file)) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   739
                os.write("blahblahblah".getBytes(UTF_8));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   740
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   741
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   742
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   743
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41916
diff changeset
   744
    static void copyResource(Path srcDir, Path dir, String resource) throws IOException {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41916
diff changeset
   745
        Path dest = dir.resolve(resource);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41916
diff changeset
   746
        Files.deleteIfExists(dest);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41916
diff changeset
   747
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41916
diff changeset
   748
        Files.createDirectories(dest.getParent());
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41916
diff changeset
   749
        Files.copy(srcDir.resolve(resource), dest);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41916
diff changeset
   750
    }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41916
diff changeset
   751
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   752
    // Standalone entry point.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   753
    public static void main(String[] args) throws Throwable {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   754
        JmodTest test = new JmodTest();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   755
        test.buildExplodedModules();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   756
        for (Method m : JmodTest.class.getDeclaredMethods()) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   757
            if (m.getAnnotation(Test.class) != null) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   758
                System.out.println("Invoking " + m.getName());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   759
                m.invoke(test);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   760
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   761
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   762
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   763
}