jdk/test/tools/jar/modularJar/Basic.java
author chegar
Thu, 16 Mar 2017 16:56:08 +0000
changeset 44267 00898a596f31
parent 43797 dab6fb7f37a3
child 44545 83b611b88ac8
permissions -rw-r--r--
8176772: jar tool support to report automatic module names Reviewed-by: alanb, mchung
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     1
/*
43095
336dfda4ae89 8172432: jar cleanup/update for module and mrm jar
sherman
parents: 42345
diff changeset
     2
 * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     4
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     7
 * published by the Free Software Foundation.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     8
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    13
 * accompanied this code).
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    14
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    18
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    21
 * questions.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    22
 */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    23
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    24
import java.io.*;
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
    25
import java.lang.module.ModuleDescriptor;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    26
import java.lang.reflect.Method;
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
    27
import java.nio.file.*;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    28
import java.nio.file.attribute.BasicFileAttributes;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    29
import java.util.*;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    30
import java.util.function.Consumer;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    31
import java.util.jar.JarEntry;
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
    32
import java.util.jar.JarFile;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    33
import java.util.jar.JarInputStream;
38468
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
    34
import java.util.jar.Manifest;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    35
import java.util.regex.Pattern;
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
    36
import java.util.stream.Collectors;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    37
import java.util.stream.Stream;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    38
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    39
import jdk.testlibrary.FileUtils;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    40
import jdk.testlibrary.JDKToolFinder;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    41
import org.testng.annotations.BeforeTest;
44267
00898a596f31 8176772: jar tool support to report automatic module names
chegar
parents: 43797
diff changeset
    42
import org.testng.annotations.DataProvider;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    43
import org.testng.annotations.Test;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    44
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    45
import static java.lang.String.format;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    46
import static java.lang.System.out;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    47
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    48
/*
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    49
 * @test
44267
00898a596f31 8176772: jar tool support to report automatic module names
chegar
parents: 43797
diff changeset
    50
 * @bug 8167328 8171830 8165640 8174248 8176772
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    51
 * @library /lib/testlibrary
38468
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
    52
 * @modules jdk.compiler
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
    53
 *          jdk.jartool
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    54
 * @build jdk.testlibrary.FileUtils jdk.testlibrary.JDKToolFinder
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    55
 * @compile Basic.java
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    56
 * @run testng Basic
38468
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
    57
 * @summary Tests for plain Modular jars & Multi-Release Modular jars
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    58
 */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    59
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    60
public class Basic {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    61
    static final Path TEST_SRC = Paths.get(System.getProperty("test.src", "."));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    62
    static final Path TEST_CLASSES = Paths.get(System.getProperty("test.classes", "."));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    63
    static final Path MODULE_CLASSES = TEST_CLASSES.resolve("build");
38468
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
    64
    static final Path MRJAR_DIR = MODULE_CLASSES.resolve("mrjar");
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    65
38762
2956ccc7cb77 8157850: Jar tests should pass through VM options
anazarov
parents: 38468
diff changeset
    66
    static final String VM_OPTIONS = System.getProperty("test.vm.opts", "");
2956ccc7cb77 8157850: Jar tests should pass through VM options
anazarov
parents: 38468
diff changeset
    67
    static final String TOOL_VM_OPTIONS = System.getProperty("test.tool.vm.opts", "");
2956ccc7cb77 8157850: Jar tests should pass through VM options
anazarov
parents: 38468
diff changeset
    68
    static final String JAVA_OPTIONS = System.getProperty("test.java.opts", "");
2956ccc7cb77 8157850: Jar tests should pass through VM options
anazarov
parents: 38468
diff changeset
    69
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    70
    // Details based on the checked in module source
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    71
    static TestModuleData FOO = new TestModuleData("foo",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    72
                                                   "1.123",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    73
                                                   "jdk.test.foo.Foo",
38468
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
    74
                                                   "Hello World!!!",
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
    75
                                                   null, // no hashes
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
    76
                                                   Set.of("java.base"),
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
    77
                                                   Set.of("jdk.test.foo"),
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
    78
                                                   null, // no uses
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
    79
                                                   null, // no provides
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
    80
                                                   Set.of("jdk.test.foo.internal",
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
    81
                                                          "jdk.test.foo.resources"));
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    82
    static TestModuleData BAR = new TestModuleData("bar",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    83
                                                   "4.5.6.7",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    84
                                                   "jdk.test.bar.Bar",
38468
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
    85
                                                   "Hello from Bar!",
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
    86
                                                   null, // no hashes
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
    87
                                                   Set.of("java.base", "foo"),
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
    88
                                                   null, // no exports
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
    89
                                                   null, // no uses
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
    90
                                                   null, // no provides
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
    91
                                                   Set.of("jdk.test.bar",
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
    92
                                                          "jdk.test.bar.internal"));
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    93
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    94
    static class TestModuleData {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    95
        final String moduleName;
38468
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
    96
        final Set<String> requires;
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
    97
        final Set<String> exports;
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
    98
        final Set<String> uses;
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
    99
        final Set<String> provides;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   100
        final String mainClass;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   101
        final String version;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   102
        final String message;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   103
        final String hashes;
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   104
        final Set<String> packages;
38468
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   105
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   106
        TestModuleData(String mn, String v, String mc, String m, String h,
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   107
                       Set<String> requires, Set<String> exports, Set<String> uses,
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   108
                       Set<String> provides, Set<String> contains) {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   109
            moduleName = mn; mainClass = mc; version = v; message = m; hashes = h;
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   110
            this.requires = requires != null ? requires : Collections.emptySet();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   111
            this.exports = exports != null ? exports : Collections.emptySet();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   112
            this.uses = uses != null ? uses : Collections.emptySet();;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   113
            this.provides = provides != null ? provides : Collections.emptySet();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   114
            this.packages = Stream.concat(this.exports.stream(), contains.stream())
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   115
                                  .collect(Collectors.toSet());
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   116
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   117
        static TestModuleData from(String s) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   118
            try {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   119
                BufferedReader reader = new BufferedReader(new StringReader(s));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   120
                String line;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   121
                String message = null;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   122
                String name = null, version = null, mainClass = null;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   123
                String hashes = null;
38468
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   124
                Set<String> requires, exports, uses, provides, conceals;
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   125
                requires = exports = uses = provides = conceals = null;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   126
                while ((line = reader.readLine()) != null) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   127
                    if (line.startsWith("message:")) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   128
                        message = line.substring("message:".length());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   129
                    } else if (line.startsWith("nameAndVersion:")) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   130
                        line = line.substring("nameAndVersion:".length());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   131
                        int i = line.indexOf('@');
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   132
                        if (i != -1) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   133
                            name = line.substring(0, i);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   134
                            version = line.substring(i + 1, line.length());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   135
                        } else {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   136
                            name = line;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   137
                        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   138
                    } else if (line.startsWith("mainClass:")) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   139
                        mainClass = line.substring("mainClass:".length());
38468
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   140
                    } else if (line.startsWith("requires:")) {
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   141
                        line = line.substring("requires:".length());
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   142
                        requires = stringToSet(line);
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   143
                    } else if (line.startsWith("exports:")) {
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   144
                        line = line.substring("exports:".length());
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   145
                        exports = stringToSet(line);
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   146
                    } else if (line.startsWith("uses:")) {
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   147
                        line = line.substring("uses:".length());
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   148
                        uses = stringToSet(line);
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   149
                    } else if (line.startsWith("provides:")) {
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   150
                        line = line.substring("provides:".length());
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   151
                        provides = stringToSet(line);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   152
                    } else if (line.startsWith("hashes:")) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   153
                        hashes = line.substring("hashes:".length());
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   154
                    } else if (line.startsWith("contains:")) {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   155
                        line = line.substring("contains:".length());
38468
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   156
                        conceals = stringToSet(line);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   157
                    } else {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   158
                        throw new AssertionError("Unknown value " + line);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   159
                    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   160
                }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   161
38468
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   162
                return new TestModuleData(name, version, mainClass, message,
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   163
                                          hashes, requires, exports, uses,
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   164
                                          provides, conceals);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   165
            } catch (IOException x) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   166
                throw new UncheckedIOException(x);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   167
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   168
        }
38468
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   169
        static Set<String> stringToSet(String commaList) {
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   170
            Set<String> s = new HashSet<>();
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   171
            int i = commaList.indexOf(',');
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   172
            if (i != -1) {
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   173
                String[] p = commaList.split(",");
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   174
                Stream.of(p).forEach(s::add);
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   175
            } else {
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   176
                s.add(commaList);
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   177
            }
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   178
            return s;
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   179
        }
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   180
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   181
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   182
    static void assertModuleData(Result r, TestModuleData expected) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   183
        //out.printf("%s%n", r.output);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   184
        TestModuleData received = TestModuleData.from(r.output);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   185
        if (expected.message != null)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   186
            assertTrue(expected.message.equals(received.message),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   187
                       "Expected message:", expected.message, ", got:", received.message);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   188
        assertTrue(expected.moduleName.equals(received.moduleName),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   189
                   "Expected moduleName: ", expected.moduleName, ", got:", received.moduleName);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   190
        assertTrue(expected.version.equals(received.version),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   191
                   "Expected version: ", expected.version, ", got:", received.version);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   192
        assertTrue(expected.mainClass.equals(received.mainClass),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   193
                   "Expected mainClass: ", expected.mainClass, ", got:", received.mainClass);
38468
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   194
        assertSetsEqual(expected.requires, received.requires);
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   195
        assertSetsEqual(expected.exports, received.exports);
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   196
        assertSetsEqual(expected.uses, received.uses);
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   197
        assertSetsEqual(expected.provides, received.provides);
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   198
        assertSetsEqual(expected.packages, received.packages);
38468
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   199
    }
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   200
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   201
    static void assertSetsEqual(Set<String> s1, Set<String> s2) {
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   202
        if (!s1.equals(s2)) {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   203
            org.testng.Assert.assertTrue(false, s1 + " vs " + s2);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   204
        }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   205
     }
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   206
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   207
    @BeforeTest
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   208
    public void compileModules() throws Exception {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   209
        compileModule(FOO.moduleName);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   210
        compileModule(BAR.moduleName, MODULE_CLASSES);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   211
        compileModule("baz");  // for service provider consistency checking
38468
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   212
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   213
        // copy resources
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   214
        copyResource(TEST_SRC.resolve("src").resolve(FOO.moduleName),
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   215
                     MODULE_CLASSES.resolve(FOO.moduleName),
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   216
                     "jdk/test/foo/resources/foo.properties");
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   217
38468
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   218
        setupMRJARModuleInfo(FOO.moduleName);
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   219
        setupMRJARModuleInfo(BAR.moduleName);
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   220
        setupMRJARModuleInfo("baz");
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   221
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   222
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   223
    @Test
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   224
    public void createFoo() throws IOException {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   225
        Path mp = Paths.get("createFoo");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   226
        createTestDir(mp);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   227
        Path modClasses = MODULE_CLASSES.resolve(FOO.moduleName);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   228
        Path modularJar = mp.resolve(FOO.moduleName + ".jar");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   229
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   230
        jar("--create",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   231
            "--file=" + modularJar.toString(),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   232
            "--main-class=" + FOO.mainClass,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   233
            "--module-version=" + FOO.version,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   234
            "--no-manifest",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   235
            "-C", modClasses.toString(), ".")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   236
            .assertSuccess();
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   237
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   238
        assertSetsEqual(readPackagesAttribute(modularJar),
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   239
                        Set.of("jdk.test.foo",
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   240
                               "jdk.test.foo.resources",
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   241
                               "jdk.test.foo.internal"));
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   242
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   243
        java(mp, FOO.moduleName + "/" + FOO.mainClass)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   244
            .assertSuccess()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   245
            .resultChecker(r -> assertModuleData(r, FOO));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   246
        try (InputStream fis = Files.newInputStream(modularJar);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   247
             JarInputStream jis = new JarInputStream(fis)) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   248
            assertTrue(!jarContains(jis, "./"),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   249
                       "Unexpected ./ found in ", modularJar.toString());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   250
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   251
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   252
38468
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   253
    /** Similar to createFoo, but with a Multi-Release Modular jar. */
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   254
    @Test
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   255
    public void createMRMJarFoo() throws IOException {
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   256
        Path mp = Paths.get("createMRMJarFoo");
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   257
        createTestDir(mp);
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   258
        Path modClasses = MODULE_CLASSES.resolve(FOO.moduleName);
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   259
        Path mrjarDir = MRJAR_DIR.resolve(FOO.moduleName);
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   260
        Path modularJar = mp.resolve(FOO.moduleName + ".jar");
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   261
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   262
        // Positive test, create
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   263
        jar("--create",
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   264
            "--file=" + modularJar.toString(),
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   265
            "--main-class=" + FOO.mainClass,
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   266
            "--module-version=" + FOO.version,
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   267
            "-m", mrjarDir.resolve("META-INF/MANIFEST.MF").toRealPath().toString(),
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   268
            "-C", mrjarDir.toString(), "META-INF/versions/9/module-info.class",
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   269
            "-C", modClasses.toString(), ".")
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   270
            .assertSuccess();
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   271
        java(mp, FOO.moduleName + "/" + FOO.mainClass)
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   272
            .assertSuccess()
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   273
            .resultChecker(r -> assertModuleData(r, FOO));
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   274
    }
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   275
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   276
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   277
    @Test
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   278
    public void updateFoo() throws IOException {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   279
        Path mp = Paths.get("updateFoo");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   280
        createTestDir(mp);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   281
        Path modClasses = MODULE_CLASSES.resolve(FOO.moduleName);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   282
        Path modularJar = mp.resolve(FOO.moduleName + ".jar");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   283
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   284
        jar("--create",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   285
            "--file=" + modularJar.toString(),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   286
            "--no-manifest",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   287
            "-C", modClasses.toString(), "jdk")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   288
            .assertSuccess();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   289
        jar("--update",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   290
            "--file=" + modularJar.toString(),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   291
            "--main-class=" + FOO.mainClass,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   292
            "--module-version=" + FOO.version,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   293
            "--no-manifest",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   294
            "-C", modClasses.toString(), "module-info.class")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   295
            .assertSuccess();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   296
        java(mp, FOO.moduleName + "/" + FOO.mainClass)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   297
            .assertSuccess()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   298
            .resultChecker(r -> assertModuleData(r, FOO));
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
    @Test
38468
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   302
    public void updateMRMJarFoo() throws IOException {
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   303
        Path mp = Paths.get("updateMRMJarFoo");
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   304
        createTestDir(mp);
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   305
        Path modClasses = MODULE_CLASSES.resolve(FOO.moduleName);
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   306
        Path mrjarDir = MRJAR_DIR.resolve(FOO.moduleName);
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   307
        Path modularJar = mp.resolve(FOO.moduleName + ".jar");
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   308
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   309
        jar("--create",
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   310
            "--file=" + modularJar.toString(),
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   311
            "--no-manifest",
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   312
            "-C", modClasses.toString(), "jdk")
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   313
            .assertSuccess();
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   314
        jar("--update",
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   315
            "--file=" + modularJar.toString(),
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   316
            "--main-class=" + FOO.mainClass,
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   317
            "--module-version=" + FOO.version,
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   318
            "-m", mrjarDir.resolve("META-INF/MANIFEST.MF").toRealPath().toString(),
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   319
            "-C", mrjarDir.toString(), "META-INF/versions/9/module-info.class",
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   320
            "-C", modClasses.toString(), "module-info.class")
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   321
            .assertSuccess();
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   322
        java(mp, FOO.moduleName + "/" + FOO.mainClass)
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   323
            .assertSuccess()
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   324
            .resultChecker(r -> assertModuleData(r, FOO));
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   325
    }
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   326
43797
dab6fb7f37a3 8174248: partialUpdateFooMainClass test in tools/jar/modularJar/Basic.java needs to be re-examined
sherman
parents: 43731
diff changeset
   327
    @Test
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   328
    public void partialUpdateFooMainClass() throws IOException {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   329
        Path mp = Paths.get("partialUpdateFooMainClass");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   330
        createTestDir(mp);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   331
        Path modClasses = MODULE_CLASSES.resolve(FOO.moduleName);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   332
        Path modularJar = mp.resolve(FOO.moduleName + ".jar");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   333
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   334
        // A "bad" main class in first create ( and no version )
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   335
        jar("--create",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   336
            "--file=" + modularJar.toString(),
43797
dab6fb7f37a3 8174248: partialUpdateFooMainClass test in tools/jar/modularJar/Basic.java needs to be re-examined
sherman
parents: 43731
diff changeset
   337
            "--main-class=" + "jdk.test.foo.IAmNotTheEntryPoint",
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   338
            "--no-manifest",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   339
            "-C", modClasses.toString(), ".")  // includes module-info.class
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   340
           .assertSuccess();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   341
        jar("--update",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   342
            "--file=" + modularJar.toString(),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   343
            "--main-class=" + FOO.mainClass,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   344
            "--module-version=" + FOO.version,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   345
            "--no-manifest")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   346
            .assertSuccess();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   347
        java(mp, FOO.moduleName + "/" + FOO.mainClass)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   348
            .assertSuccess()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   349
            .resultChecker(r -> assertModuleData(r, FOO));
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
    @Test
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   353
    public void partialUpdateFooVersion() throws IOException {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   354
        Path mp = Paths.get("partialUpdateFooVersion");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   355
        createTestDir(mp);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   356
        Path modClasses = MODULE_CLASSES.resolve(FOO.moduleName);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   357
        Path modularJar = mp.resolve(FOO.moduleName + ".jar");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   358
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   359
        // A "bad" version in first create ( and no main class )
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   360
        jar("--create",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   361
            "--file=" + modularJar.toString(),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   362
            "--module-version=" + "100000000",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   363
            "--no-manifest",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   364
            "-C", modClasses.toString(), ".")  // includes module-info.class
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   365
            .assertSuccess();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   366
        jar("--update",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   367
            "--file=" + modularJar.toString(),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   368
            "--main-class=" + FOO.mainClass,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   369
            "--module-version=" + FOO.version,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   370
            "--no-manifest")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   371
            .assertSuccess();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   372
        java(mp, FOO.moduleName + "/" + FOO.mainClass)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   373
            .assertSuccess()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   374
            .resultChecker(r -> assertModuleData(r, FOO));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   375
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   376
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   377
    @Test
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   378
    public void partialUpdateFooNotAllFiles() throws IOException {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   379
        Path mp = Paths.get("partialUpdateFooNotAllFiles");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   380
        createTestDir(mp);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   381
        Path modClasses = MODULE_CLASSES.resolve(FOO.moduleName);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   382
        Path modularJar = mp.resolve(FOO.moduleName + ".jar");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   383
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   384
        // Not all files, and none from non-exported packages,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   385
        // i.e. no concealed list in first create
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   386
        jar("--create",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   387
            "--file=" + modularJar.toString(),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   388
            "--no-manifest",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   389
            "-C", modClasses.toString(), "module-info.class",
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   390
            "-C", modClasses.toString(), "jdk/test/foo/Foo.class",
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   391
            "-C", modClasses.toString(), "jdk/test/foo/resources/foo.properties")
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   392
            .assertSuccess();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   393
        jar("--update",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   394
            "--file=" + modularJar.toString(),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   395
            "--main-class=" + FOO.mainClass,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   396
            "--module-version=" + FOO.version,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   397
            "--no-manifest",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   398
            "-C", modClasses.toString(), "jdk/test/foo/internal/Message.class")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   399
            .assertSuccess();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   400
        java(mp, FOO.moduleName + "/" + FOO.mainClass)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   401
            .assertSuccess()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   402
            .resultChecker(r -> assertModuleData(r, FOO));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   403
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   404
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   405
    @Test
38468
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   406
    public void partialUpdateMRMJarFooNotAllFiles() throws IOException {
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   407
        Path mp = Paths.get("partialUpdateMRMJarFooNotAllFiles");
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   408
        createTestDir(mp);
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   409
        Path modClasses = MODULE_CLASSES.resolve(FOO.moduleName);
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   410
        Path mrjarDir = MRJAR_DIR.resolve(FOO.moduleName);
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   411
        Path modularJar = mp.resolve(FOO.moduleName + ".jar");
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   412
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   413
        jar("--create",
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   414
            "--file=" + modularJar.toString(),
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   415
            "--module-version=" + FOO.version,
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   416
            "-C", modClasses.toString(), ".")
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   417
            .assertSuccess();
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   418
        jar("--update",
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   419
            "--file=" + modularJar.toString(),
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   420
            "--main-class=" + FOO.mainClass,
43095
336dfda4ae89 8172432: jar cleanup/update for module and mrm jar
sherman
parents: 42345
diff changeset
   421
            "--module-version=" + FOO.version,
38468
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   422
            "-m", mrjarDir.resolve("META-INF/MANIFEST.MF").toRealPath().toString(),
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   423
            "-C", mrjarDir.toString(), "META-INF/versions/9/module-info.class")
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   424
            .assertSuccess();
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   425
        java(mp, FOO.moduleName + "/" + FOO.mainClass)
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   426
            .assertSuccess()
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   427
            .resultChecker(r -> assertModuleData(r, FOO));
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   428
    }
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   429
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   430
    @Test
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   431
    public void partialUpdateFooAllFilesAndAttributes() throws IOException {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   432
        Path mp = Paths.get("partialUpdateFooAllFilesAndAttributes");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   433
        createTestDir(mp);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   434
        Path modClasses = MODULE_CLASSES.resolve(FOO.moduleName);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   435
        Path modularJar = mp.resolve(FOO.moduleName + ".jar");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   436
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   437
        // all attributes and files
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   438
        jar("--create",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   439
            "--file=" + modularJar.toString(),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   440
            "--main-class=" + FOO.mainClass,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   441
            "--module-version=" + FOO.version,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   442
            "--no-manifest",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   443
            "-C", modClasses.toString(), ".")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   444
            .assertSuccess();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   445
        jar("--update",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   446
            "--file=" + modularJar.toString(),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   447
            "--main-class=" + FOO.mainClass,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   448
            "--module-version=" + FOO.version,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   449
            "--no-manifest",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   450
            "-C", modClasses.toString(), ".")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   451
            .assertSuccess();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   452
        java(mp, FOO.moduleName + "/" + FOO.mainClass)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   453
            .assertSuccess()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   454
            .resultChecker(r -> assertModuleData(r, FOO));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   455
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   456
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   457
    @Test
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   458
    public void partialUpdateFooModuleInfo() throws IOException {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   459
        Path mp = Paths.get("partialUpdateFooModuleInfo");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   460
        createTestDir(mp);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   461
        Path modClasses = MODULE_CLASSES.resolve(FOO.moduleName);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   462
        Path modularJar = mp.resolve(FOO.moduleName + ".jar");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   463
        Path barModInfo = MODULE_CLASSES.resolve(BAR.moduleName);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   464
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   465
        jar("--create",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   466
            "--file=" + modularJar.toString(),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   467
            "--main-class=" + FOO.mainClass,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   468
            "--module-version=" + FOO.version,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   469
            "--no-manifest",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   470
            "-C", modClasses.toString(), ".")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   471
            .assertSuccess();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   472
        jar("--update",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   473
            "--file=" + modularJar.toString(),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   474
            "--no-manifest",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   475
            "-C", barModInfo.toString(), "module-info.class")  // stuff in bar's info
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   476
            .assertSuccess();
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 38762
diff changeset
   477
        jar("-d",
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   478
            "--file=" + modularJar.toString())
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   479
            .assertSuccess()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   480
            .resultChecker(r -> {
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   481
                // Expect similar output: "bar, requires mandated foo, ...
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   482
                // conceals jdk.test.foo, conceals jdk.test.foo.internal"
43731
bc7110b230c1 8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents: 43712
diff changeset
   483
                Pattern p = Pattern.compile("module bar \\(module-info.class\\)\\s+requires\\s++foo");
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   484
                assertTrue(p.matcher(r.output).find(),
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   485
                           "Expecting to find \"bar, requires foo,...\"",
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   486
                           "in output, but did not: [" + r.output + "]");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   487
                p = Pattern.compile(
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   488
                        "contains\\s+jdk.test.foo\\s+contains\\s+jdk.test.foo.internal");
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   489
                assertTrue(p.matcher(r.output).find(),
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   490
                           "Expecting to find \"contains jdk.test.foo,...\"",
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   491
                           "in output, but did not: [" + r.output + "]");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   492
            });
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   493
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   494
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   495
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   496
    @Test
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   497
    public void partialUpdateFooPackagesAttribute() throws IOException {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   498
        Path mp = Paths.get("partialUpdateFooPackagesAttribute");
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   499
        createTestDir(mp);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   500
        Path modClasses = MODULE_CLASSES.resolve(FOO.moduleName);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   501
        Path modularJar = mp.resolve(FOO.moduleName + ".jar");
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   502
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   503
        // Not all files, and none from non-exported packages,
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   504
        // i.e. no concealed list in first create
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   505
        jar("--create",
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   506
            "--file=" + modularJar.toString(),
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   507
            "--no-manifest",
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   508
            "-C", modClasses.toString(), "module-info.class",
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   509
            "-C", modClasses.toString(), "jdk/test/foo/Foo.class")
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   510
            .assertSuccess();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   511
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   512
        assertSetsEqual(readPackagesAttribute(modularJar),
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   513
                        Set.of("jdk.test.foo"));
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   514
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   515
        jar("--update",
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   516
            "--file=" + modularJar.toString(),
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   517
            "-C", modClasses.toString(), "jdk/test/foo/resources/foo.properties")
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   518
            .assertSuccess();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   519
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   520
        assertSetsEqual(readPackagesAttribute(modularJar),
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   521
                        Set.of("jdk.test.foo", "jdk.test.foo.resources"));
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   522
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   523
        jar("--update",
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   524
            "--file=" + modularJar.toString(),
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   525
            "--main-class=" + FOO.mainClass,
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   526
            "--module-version=" + FOO.version,
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   527
            "--no-manifest",
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   528
            "-C", modClasses.toString(), "jdk/test/foo/internal/Message.class")
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   529
            .assertSuccess();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   530
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   531
        assertSetsEqual(readPackagesAttribute(modularJar),
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   532
                        Set.of("jdk.test.foo",
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   533
                               "jdk.test.foo.resources",
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   534
                               "jdk.test.foo.internal"));
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   535
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   536
        java(mp, FOO.moduleName + "/" + FOO.mainClass)
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   537
            .assertSuccess()
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   538
            .resultChecker(r -> assertModuleData(r, FOO));
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   539
    }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   540
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   541
    private Set<String> readPackagesAttribute(Path jar) {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   542
        return getModuleDescriptor(jar).packages();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   543
    }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   544
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   545
    @Test
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   546
    public void hashBarInFooModule() throws IOException {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   547
        Path mp = Paths.get("dependencesFooBar");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   548
        createTestDir(mp);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   549
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   550
        Path modClasses = MODULE_CLASSES.resolve(BAR.moduleName);
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   551
        Path modularJar = mp.resolve(BAR.moduleName + ".jar");
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   552
        jar("--create",
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   553
            "--file=" + modularJar.toString(),
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   554
            "--main-class=" + BAR.mainClass,
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   555
            "--module-version=" + BAR.version,
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   556
            "--no-manifest",
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   557
            "-C", modClasses.toString(), ".")
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   558
            .assertSuccess();
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   559
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   560
        modClasses = MODULE_CLASSES.resolve(FOO.moduleName);
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   561
        modularJar = mp.resolve(FOO.moduleName + ".jar");
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   562
        jar("--create",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   563
            "--file=" + modularJar.toString(),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   564
            "--main-class=" + FOO.mainClass,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   565
            "--module-version=" + FOO.version,
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 38762
diff changeset
   566
            "--module-path=" + mp.toString(),
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   567
            "--hash-modules=" + "bar",
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   568
            "--no-manifest",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   569
            "-C", modClasses.toString(), ".")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   570
            .assertSuccess();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   571
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   572
        java(mp, BAR.moduleName + "/" + BAR.mainClass,
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   573
             "--add-exports", "java.base/jdk.internal.misc=bar",
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 38762
diff changeset
   574
             "--add-exports", "java.base/jdk.internal.module=bar")
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   575
            .assertSuccess()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   576
            .resultChecker(r -> {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   577
                assertModuleData(r, BAR);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   578
                TestModuleData received = TestModuleData.from(r.output);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   579
                assertTrue(received.hashes != null, "Expected non-null hashes value.");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   580
            });
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   581
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   582
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   583
    @Test
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   584
    public void invalidHashInFooModule() throws IOException {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   585
        Path mp = Paths.get("badDependencyFooBar");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   586
        createTestDir(mp);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   587
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   588
        Path barClasses = MODULE_CLASSES.resolve(BAR.moduleName);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   589
        Path barJar = mp.resolve(BAR.moduleName + ".jar");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   590
        jar("--create",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   591
            "--file=" + barJar.toString(),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   592
            "--main-class=" + BAR.mainClass,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   593
            "--module-version=" + BAR.version,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   594
            "--no-manifest",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   595
            "-C", barClasses.toString(), ".").assertSuccess();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   596
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   597
        Path fooClasses = MODULE_CLASSES.resolve(FOO.moduleName);
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   598
        Path fooJar = mp.resolve(FOO.moduleName + ".jar");
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   599
        jar("--create",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   600
            "--file=" + fooJar.toString(),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   601
            "--main-class=" + FOO.mainClass,
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   602
            "--module-version=" + FOO.version,
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 38762
diff changeset
   603
            "-p", mp.toString(),  // test short-form
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   604
            "--hash-modules=" + "bar",
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   605
            "--no-manifest",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   606
            "-C", fooClasses.toString(), ".").assertSuccess();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   607
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   608
        // Rebuild bar.jar with a change that will cause its hash to be different
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   609
        FileUtils.deleteFileWithRetry(barJar);
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   610
        jar("--create",
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   611
            "--file=" + barJar.toString(),
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   612
            "--main-class=" + BAR.mainClass,
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   613
            "--module-version=" + BAR.version + ".1", // a newer version
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   614
            "--no-manifest",
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   615
            "-C", barClasses.toString(), ".").assertSuccess();
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   616
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   617
        java(mp, BAR.moduleName + "/" + BAR.mainClass,
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   618
             "--add-exports", "java.base/jdk.internal.misc=bar",
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 38762
diff changeset
   619
             "--add-exports", "java.base/jdk.internal.module=bar")
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   620
            .assertFailure()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   621
            .resultChecker(r -> {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   622
                // Expect similar output: "java.lang.module.ResolutionException: Hash
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   623
                // of bar (WdktSIQSkd4+CEacpOZoeDrCosMATNrIuNub9b5yBeo=) differs to
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   624
                // expected hash (iepvdv8xTeVrFgMtUhcFnmetSub6qQHCHc92lSaSEg0=)"
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   625
                Pattern p = Pattern.compile(".*Hash of bar.*differs to expected hash.*");
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   626
                assertTrue(p.matcher(r.output).find(),
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   627
                      "Expecting error message containing \"Hash of bar ... differs to"
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   628
                              + " expected hash...\" but got: [", r.output + "]");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   629
            });
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   630
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   631
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   632
    @Test
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   633
    public void badOptionsFoo() throws IOException {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   634
        Path mp = Paths.get("badOptionsFoo");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   635
        createTestDir(mp);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   636
        Path modClasses = MODULE_CLASSES.resolve(FOO.moduleName);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   637
        Path modularJar = mp.resolve(FOO.moduleName + ".jar");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   638
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   639
        jar("--create",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   640
            "--file=" + modularJar.toString(),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   641
            "--module-version=" + 1.1,   // no module-info.class
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   642
            "-C", modClasses.toString(), "jdk")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   643
            .assertFailure();      // TODO: expected failure message
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   644
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   645
         jar("--create",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   646
             "--file=" + modularJar.toString(),
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   647
             "--hash-modules=" + ".*",   // no module-info.class
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   648
             "-C", modClasses.toString(), "jdk")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   649
             .assertFailure();      // TODO: expected failure message
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   650
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   651
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   652
    @Test
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   653
    public void servicesCreateWithoutFailure() throws IOException {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   654
        Path mp = Paths.get("servicesCreateWithoutFailure");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   655
        createTestDir(mp);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   656
        Path modClasses = MODULE_CLASSES.resolve("baz");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   657
        Path modularJar = mp.resolve("baz" + ".jar");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   658
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   659
        // Positive test, create
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   660
        jar("--create",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   661
            "--file=" + modularJar.toString(),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   662
            "-C", modClasses.toString(), "module-info.class",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   663
            "-C", modClasses.toString(), "jdk/test/baz/BazService.class",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   664
            "-C", modClasses.toString(), "jdk/test/baz/internal/BazServiceImpl.class")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   665
            .assertSuccess();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   666
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   667
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   668
    @Test
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   669
    public void servicesCreateWithoutServiceImpl() throws IOException {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   670
        Path mp = Paths.get("servicesWithoutServiceImpl");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   671
        createTestDir(mp);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   672
        Path modClasses = MODULE_CLASSES.resolve("baz");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   673
        Path modularJar = mp.resolve("baz" + ".jar");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   674
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   675
        // Omit service impl
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   676
        jar("--create",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   677
            "--file=" + modularJar.toString(),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   678
            "-C", modClasses.toString(), "module-info.class",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   679
            "-C", modClasses.toString(), "jdk/test/baz/BazService.class")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   680
            .assertFailure();
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
    @Test
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   684
    public void servicesUpdateWithoutFailure() throws IOException {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   685
        Path mp = Paths.get("servicesUpdateWithoutFailure");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   686
        createTestDir(mp);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   687
        Path modClasses = MODULE_CLASSES.resolve("baz");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   688
        Path modularJar = mp.resolve("baz" + ".jar");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   689
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   690
        // Positive test, update
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   691
        jar("--create",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   692
            "--file=" + modularJar.toString(),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   693
            "-C", modClasses.toString(), "jdk/test/baz/BazService.class",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   694
            "-C", modClasses.toString(), "jdk/test/baz/internal/BazServiceImpl.class")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   695
            .assertSuccess();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   696
        jar("--update",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   697
            "--file=" + modularJar.toString(),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   698
            "-C", modClasses.toString(), "module-info.class")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   699
            .assertSuccess();
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
    @Test
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   703
    public void servicesUpdateWithoutServiceImpl() throws IOException {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   704
        Path mp = Paths.get("servicesUpdateWithoutServiceImpl");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   705
        createTestDir(mp);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   706
        Path modClasses = MODULE_CLASSES.resolve("baz");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   707
        Path modularJar = mp.resolve("baz" + ".jar");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   708
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   709
        // Omit service impl
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   710
        jar("--create",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   711
            "--file=" + modularJar.toString(),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   712
            "-C", modClasses.toString(), "jdk/test/baz/BazService.class")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   713
            .assertSuccess();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   714
        jar("--update",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   715
            "--file=" + modularJar.toString(),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   716
            "-C", modClasses.toString(), "module-info.class")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   717
            .assertFailure();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   718
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   719
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   720
    @Test
38468
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   721
    public void servicesCreateWithoutFailureMRMJAR() throws IOException {
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   722
        Path mp = Paths.get("servicesCreateWithoutFailureMRMJAR");
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   723
        createTestDir(mp);
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   724
        Path modClasses = MODULE_CLASSES.resolve("baz");
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   725
        Path mrjarDir = MRJAR_DIR.resolve("baz");
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   726
        Path modularJar = mp.resolve("baz" + ".jar");
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   727
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   728
        jar("--create",
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   729
            "--file=" + modularJar.toString(),
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   730
            "-m", mrjarDir.resolve("META-INF/MANIFEST.MF").toRealPath().toString(),
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   731
            "-C", modClasses.toString(), "module-info.class",
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   732
            "-C", mrjarDir.toString(), "META-INF/versions/9/module-info.class",
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   733
            "-C", modClasses.toString(), "jdk/test/baz/BazService.class",
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   734
            "-C", modClasses.toString(), "jdk/test/baz/internal/BazServiceImpl.class")
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   735
            .assertSuccess();
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   736
    }
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   737
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   738
    @Test
43731
bc7110b230c1 8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents: 43712
diff changeset
   739
    public void servicesCreateWithoutFailureNonRootMRMJAR() throws IOException {
bc7110b230c1 8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents: 43712
diff changeset
   740
        // without a root module-info.class
bc7110b230c1 8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents: 43712
diff changeset
   741
        Path mp = Paths.get("servicesCreateWithoutFailureNonRootMRMJAR");
bc7110b230c1 8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents: 43712
diff changeset
   742
        createTestDir(mp);
bc7110b230c1 8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents: 43712
diff changeset
   743
        Path modClasses = MODULE_CLASSES.resolve("baz");
bc7110b230c1 8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents: 43712
diff changeset
   744
        Path mrjarDir = MRJAR_DIR.resolve("baz");
bc7110b230c1 8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents: 43712
diff changeset
   745
        Path modularJar = mp.resolve("baz.jar");
bc7110b230c1 8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents: 43712
diff changeset
   746
bc7110b230c1 8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents: 43712
diff changeset
   747
        jar("--create",
bc7110b230c1 8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents: 43712
diff changeset
   748
            "--file=" + modularJar.toString(),
bc7110b230c1 8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents: 43712
diff changeset
   749
            "--main-class=" + "jdk.test.baz.Baz",
bc7110b230c1 8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents: 43712
diff changeset
   750
            "-m", mrjarDir.resolve("META-INF/MANIFEST.MF").toRealPath().toString(),
bc7110b230c1 8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents: 43712
diff changeset
   751
            "-C", mrjarDir.toString(), "META-INF/versions/9/module-info.class",
bc7110b230c1 8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents: 43712
diff changeset
   752
            "-C", modClasses.toString(), "jdk/test/baz/BazService.class",
bc7110b230c1 8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents: 43712
diff changeset
   753
            "-C", modClasses.toString(), "jdk/test/baz/Baz.class",
bc7110b230c1 8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents: 43712
diff changeset
   754
            "-C", modClasses.toString(), "jdk/test/baz/internal/BazServiceImpl.class")
bc7110b230c1 8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents: 43712
diff changeset
   755
            .assertSuccess();
bc7110b230c1 8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents: 43712
diff changeset
   756
bc7110b230c1 8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents: 43712
diff changeset
   757
44267
00898a596f31 8176772: jar tool support to report automatic module names
chegar
parents: 43797
diff changeset
   758
        for (String option : new String[]  {"--describe-module", "-d" }) {
43731
bc7110b230c1 8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents: 43712
diff changeset
   759
bc7110b230c1 8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents: 43712
diff changeset
   760
            jar(option,
bc7110b230c1 8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents: 43712
diff changeset
   761
                "--file=" + modularJar.toString())
bc7110b230c1 8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents: 43712
diff changeset
   762
                .assertSuccess()
bc7110b230c1 8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents: 43712
diff changeset
   763
                .resultChecker(r ->
bc7110b230c1 8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents: 43712
diff changeset
   764
                    assertTrue(r.output.contains("main-class jdk.test.baz.Baz"),
bc7110b230c1 8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents: 43712
diff changeset
   765
                              "Expected to find ", "main-class jdk.test.baz.Baz",
bc7110b230c1 8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents: 43712
diff changeset
   766
                               " in [", r.output, "]"));
bc7110b230c1 8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents: 43712
diff changeset
   767
bc7110b230c1 8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents: 43712
diff changeset
   768
            jarWithStdin(modularJar.toFile(),  option)
bc7110b230c1 8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents: 43712
diff changeset
   769
                .assertSuccess()
bc7110b230c1 8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents: 43712
diff changeset
   770
                .resultChecker(r ->
bc7110b230c1 8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents: 43712
diff changeset
   771
                    assertTrue(r.output.contains("main-class jdk.test.baz.Baz"),
bc7110b230c1 8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents: 43712
diff changeset
   772
                              "Expected to find ", "main-class jdk.test.baz.Baz",
bc7110b230c1 8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents: 43712
diff changeset
   773
                               " in [", r.output, "]"));
bc7110b230c1 8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents: 43712
diff changeset
   774
bc7110b230c1 8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents: 43712
diff changeset
   775
        }
bc7110b230c1 8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents: 43712
diff changeset
   776
        // run module maain class
bc7110b230c1 8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents: 43712
diff changeset
   777
        java(mp, "baz/jdk.test.baz.Baz")
bc7110b230c1 8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents: 43712
diff changeset
   778
            .assertSuccess()
bc7110b230c1 8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents: 43712
diff changeset
   779
            .resultChecker(r ->
bc7110b230c1 8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents: 43712
diff changeset
   780
               assertTrue(r.output.contains("mainClass:jdk.test.baz.Baz"),
bc7110b230c1 8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents: 43712
diff changeset
   781
                          "Expected to find ", "mainClass:jdk.test.baz.Baz",
bc7110b230c1 8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents: 43712
diff changeset
   782
                          " in [", r.output, "]"));
bc7110b230c1 8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents: 43712
diff changeset
   783
    }
bc7110b230c1 8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents: 43712
diff changeset
   784
bc7110b230c1 8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents: 43712
diff changeset
   785
    @Test
43095
336dfda4ae89 8172432: jar cleanup/update for module and mrm jar
sherman
parents: 42345
diff changeset
   786
    public void exportCreateWithMissingPkg() throws IOException {
336dfda4ae89 8172432: jar cleanup/update for module and mrm jar
sherman
parents: 42345
diff changeset
   787
336dfda4ae89 8172432: jar cleanup/update for module and mrm jar
sherman
parents: 42345
diff changeset
   788
        Path foobar = TEST_SRC.resolve("src").resolve("foobar");
336dfda4ae89 8172432: jar cleanup/update for module and mrm jar
sherman
parents: 42345
diff changeset
   789
        Path dst = Files.createDirectories(MODULE_CLASSES.resolve("foobar"));
336dfda4ae89 8172432: jar cleanup/update for module and mrm jar
sherman
parents: 42345
diff changeset
   790
        javac(dst, null, sourceList(foobar));
336dfda4ae89 8172432: jar cleanup/update for module and mrm jar
sherman
parents: 42345
diff changeset
   791
336dfda4ae89 8172432: jar cleanup/update for module and mrm jar
sherman
parents: 42345
diff changeset
   792
        Path mp = Paths.get("exportWithMissingPkg");
336dfda4ae89 8172432: jar cleanup/update for module and mrm jar
sherman
parents: 42345
diff changeset
   793
        createTestDir(mp);
336dfda4ae89 8172432: jar cleanup/update for module and mrm jar
sherman
parents: 42345
diff changeset
   794
        Path modClasses = dst;
336dfda4ae89 8172432: jar cleanup/update for module and mrm jar
sherman
parents: 42345
diff changeset
   795
        Path modularJar = mp.resolve("foofoo.jar");
336dfda4ae89 8172432: jar cleanup/update for module and mrm jar
sherman
parents: 42345
diff changeset
   796
336dfda4ae89 8172432: jar cleanup/update for module and mrm jar
sherman
parents: 42345
diff changeset
   797
        jar("--create",
336dfda4ae89 8172432: jar cleanup/update for module and mrm jar
sherman
parents: 42345
diff changeset
   798
            "--file=" + modularJar.toString(),
336dfda4ae89 8172432: jar cleanup/update for module and mrm jar
sherman
parents: 42345
diff changeset
   799
            "-C", modClasses.toString(), "module-info.class",
336dfda4ae89 8172432: jar cleanup/update for module and mrm jar
sherman
parents: 42345
diff changeset
   800
            "-C", modClasses.toString(), "jdk/test/foo/Foo.class")
336dfda4ae89 8172432: jar cleanup/update for module and mrm jar
sherman
parents: 42345
diff changeset
   801
            .assertFailure();
336dfda4ae89 8172432: jar cleanup/update for module and mrm jar
sherman
parents: 42345
diff changeset
   802
    }
336dfda4ae89 8172432: jar cleanup/update for module and mrm jar
sherman
parents: 42345
diff changeset
   803
336dfda4ae89 8172432: jar cleanup/update for module and mrm jar
sherman
parents: 42345
diff changeset
   804
    @Test
44267
00898a596f31 8176772: jar tool support to report automatic module names
chegar
parents: 43797
diff changeset
   805
    public void describeModuleFoo() throws IOException {
00898a596f31 8176772: jar tool support to report automatic module names
chegar
parents: 43797
diff changeset
   806
        Path mp = Paths.get("describeModuleFoo");
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   807
        createTestDir(mp);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   808
        Path modClasses = MODULE_CLASSES.resolve(FOO.moduleName);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   809
        Path modularJar = mp.resolve(FOO.moduleName + ".jar");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   810
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   811
        jar("--create",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   812
            "--file=" + modularJar.toString(),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   813
            "--main-class=" + FOO.mainClass,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   814
            "--module-version=" + FOO.version,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   815
            "--no-manifest",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   816
            "-C", modClasses.toString(), ".")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   817
            .assertSuccess();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   818
44267
00898a596f31 8176772: jar tool support to report automatic module names
chegar
parents: 43797
diff changeset
   819
        for (String option : new String[]  {"--describe-module", "-d" }) {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   820
            jar(option,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   821
                "--file=" + modularJar.toString())
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   822
                .assertSuccess()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   823
                .resultChecker(r ->
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   824
                    assertTrue(r.output.contains(FOO.moduleName + "@" + FOO.version),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   825
                               "Expected to find ", FOO.moduleName + "@" + FOO.version,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   826
                               " in [", r.output, "]")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   827
                );
42345
cead5ce4ca27 8167328: jar -d m.jar hangs
sherman
parents: 42338
diff changeset
   828
cead5ce4ca27 8167328: jar -d m.jar hangs
sherman
parents: 42338
diff changeset
   829
            jar(option,
cead5ce4ca27 8167328: jar -d m.jar hangs
sherman
parents: 42338
diff changeset
   830
                "--file=" + modularJar.toString(),
cead5ce4ca27 8167328: jar -d m.jar hangs
sherman
parents: 42338
diff changeset
   831
                modularJar.toString())
cead5ce4ca27 8167328: jar -d m.jar hangs
sherman
parents: 42338
diff changeset
   832
            .assertFailure();
cead5ce4ca27 8167328: jar -d m.jar hangs
sherman
parents: 42338
diff changeset
   833
cead5ce4ca27 8167328: jar -d m.jar hangs
sherman
parents: 42338
diff changeset
   834
            jar(option, modularJar.toString())
cead5ce4ca27 8167328: jar -d m.jar hangs
sherman
parents: 42338
diff changeset
   835
            .assertFailure();
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   836
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   837
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   838
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   839
    @Test
44267
00898a596f31 8176772: jar tool support to report automatic module names
chegar
parents: 43797
diff changeset
   840
    public void describeModuleFooFromStdin() throws IOException {
00898a596f31 8176772: jar tool support to report automatic module names
chegar
parents: 43797
diff changeset
   841
        Path mp = Paths.get("describeModuleFooFromStdin");
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   842
        createTestDir(mp);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   843
        Path modClasses = MODULE_CLASSES.resolve(FOO.moduleName);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   844
        Path modularJar = mp.resolve(FOO.moduleName + ".jar");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   845
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   846
        jar("--create",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   847
            "--file=" + modularJar.toString(),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   848
            "--main-class=" + FOO.mainClass,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   849
            "--module-version=" + FOO.version,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   850
            "--no-manifest",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   851
            "-C", modClasses.toString(), ".")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   852
            .assertSuccess();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   853
44267
00898a596f31 8176772: jar tool support to report automatic module names
chegar
parents: 43797
diff changeset
   854
        for (String option : new String[]  {"--describe-module", "-d" }) {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   855
            jarWithStdin(modularJar.toFile(),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   856
                         option)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   857
                         .assertSuccess()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   858
                         .resultChecker(r ->
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   859
                             assertTrue(r.output.contains(FOO.moduleName + "@" + FOO.version),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   860
                                "Expected to find ", FOO.moduleName + "@" + FOO.version,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   861
                                " in [", r.output, "]")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   862
                );
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   863
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   864
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   865
44267
00898a596f31 8176772: jar tool support to report automatic module names
chegar
parents: 43797
diff changeset
   866
00898a596f31 8176772: jar tool support to report automatic module names
chegar
parents: 43797
diff changeset
   867
    @DataProvider(name = "autoNames")
00898a596f31 8176772: jar tool support to report automatic module names
chegar
parents: 43797
diff changeset
   868
    public Object[][] autoNames() {
00898a596f31 8176772: jar tool support to report automatic module names
chegar
parents: 43797
diff changeset
   869
        return new Object[][] {
00898a596f31 8176772: jar tool support to report automatic module names
chegar
parents: 43797
diff changeset
   870
            // JAR file name                module-name[@version]
00898a596f31 8176772: jar tool support to report automatic module names
chegar
parents: 43797
diff changeset
   871
            { "foo.jar",                    "foo" },
00898a596f31 8176772: jar tool support to report automatic module names
chegar
parents: 43797
diff changeset
   872
            { "foo4j.jar",                  "foo4j", },
00898a596f31 8176772: jar tool support to report automatic module names
chegar
parents: 43797
diff changeset
   873
            { "foo1.2.3.jar",               "foo" },
00898a596f31 8176772: jar tool support to report automatic module names
chegar
parents: 43797
diff changeset
   874
            { "foo-1.2.3.4.jar",            "foo@1.2.3.4" },
00898a596f31 8176772: jar tool support to report automatic module names
chegar
parents: 43797
diff changeset
   875
            { "foo-bar.jar",                "foo.bar" },
00898a596f31 8176772: jar tool support to report automatic module names
chegar
parents: 43797
diff changeset
   876
            { "foo-1.2-SNAPSHOT.jar",       "foo@1.2-SNAPSHOT" },
00898a596f31 8176772: jar tool support to report automatic module names
chegar
parents: 43797
diff changeset
   877
        };
00898a596f31 8176772: jar tool support to report automatic module names
chegar
parents: 43797
diff changeset
   878
    }
00898a596f31 8176772: jar tool support to report automatic module names
chegar
parents: 43797
diff changeset
   879
00898a596f31 8176772: jar tool support to report automatic module names
chegar
parents: 43797
diff changeset
   880
    @Test(dataProvider = "autoNames")
00898a596f31 8176772: jar tool support to report automatic module names
chegar
parents: 43797
diff changeset
   881
    public void describeAutomaticModule(String jarName, String mid)
00898a596f31 8176772: jar tool support to report automatic module names
chegar
parents: 43797
diff changeset
   882
        throws IOException
00898a596f31 8176772: jar tool support to report automatic module names
chegar
parents: 43797
diff changeset
   883
    {
00898a596f31 8176772: jar tool support to report automatic module names
chegar
parents: 43797
diff changeset
   884
        Path mp = Paths.get("describeAutomaticModule");
00898a596f31 8176772: jar tool support to report automatic module names
chegar
parents: 43797
diff changeset
   885
        createTestDir(mp);
00898a596f31 8176772: jar tool support to report automatic module names
chegar
parents: 43797
diff changeset
   886
        Path regularJar = mp.resolve(jarName);
00898a596f31 8176772: jar tool support to report automatic module names
chegar
parents: 43797
diff changeset
   887
        Path t = Paths.get("t");
00898a596f31 8176772: jar tool support to report automatic module names
chegar
parents: 43797
diff changeset
   888
        if (Files.notExists(t))
00898a596f31 8176772: jar tool support to report automatic module names
chegar
parents: 43797
diff changeset
   889
            Files.createFile(t);
00898a596f31 8176772: jar tool support to report automatic module names
chegar
parents: 43797
diff changeset
   890
00898a596f31 8176772: jar tool support to report automatic module names
chegar
parents: 43797
diff changeset
   891
        jar("--create",
00898a596f31 8176772: jar tool support to report automatic module names
chegar
parents: 43797
diff changeset
   892
            "--file=" + regularJar.toString(),
00898a596f31 8176772: jar tool support to report automatic module names
chegar
parents: 43797
diff changeset
   893
            t.toString())
00898a596f31 8176772: jar tool support to report automatic module names
chegar
parents: 43797
diff changeset
   894
            .assertSuccess();
00898a596f31 8176772: jar tool support to report automatic module names
chegar
parents: 43797
diff changeset
   895
00898a596f31 8176772: jar tool support to report automatic module names
chegar
parents: 43797
diff changeset
   896
        for (String option : new String[]  {"--describe-module", "-d" }) {
00898a596f31 8176772: jar tool support to report automatic module names
chegar
parents: 43797
diff changeset
   897
            jar(option,
00898a596f31 8176772: jar tool support to report automatic module names
chegar
parents: 43797
diff changeset
   898
                "--file=" + regularJar.toString())
00898a596f31 8176772: jar tool support to report automatic module names
chegar
parents: 43797
diff changeset
   899
                .assertSuccess()
00898a596f31 8176772: jar tool support to report automatic module names
chegar
parents: 43797
diff changeset
   900
                .resultChecker(r -> {
00898a596f31 8176772: jar tool support to report automatic module names
chegar
parents: 43797
diff changeset
   901
                    assertTrue(r.output.contains("No module descriptor found"));
00898a596f31 8176772: jar tool support to report automatic module names
chegar
parents: 43797
diff changeset
   902
                    assertTrue(r.output.contains("Derived automatic module"));
00898a596f31 8176772: jar tool support to report automatic module names
chegar
parents: 43797
diff changeset
   903
                    assertTrue(r.output.contains("module " + mid),
00898a596f31 8176772: jar tool support to report automatic module names
chegar
parents: 43797
diff changeset
   904
                               "Expected [", "module " + mid,"] in [", r.output, "]");
00898a596f31 8176772: jar tool support to report automatic module names
chegar
parents: 43797
diff changeset
   905
                    }
00898a596f31 8176772: jar tool support to report automatic module names
chegar
parents: 43797
diff changeset
   906
                );
00898a596f31 8176772: jar tool support to report automatic module names
chegar
parents: 43797
diff changeset
   907
        }
00898a596f31 8176772: jar tool support to report automatic module names
chegar
parents: 43797
diff changeset
   908
    }
00898a596f31 8176772: jar tool support to report automatic module names
chegar
parents: 43797
diff changeset
   909
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   910
    // -- Infrastructure
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   911
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   912
    static Result jarWithStdin(File stdinSource, String... args) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   913
        String jar = getJDKTool("jar");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   914
        List<String> commands = new ArrayList<>();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   915
        commands.add(jar);
38762
2956ccc7cb77 8157850: Jar tests should pass through VM options
anazarov
parents: 38468
diff changeset
   916
        if (!TOOL_VM_OPTIONS.isEmpty()) {
2956ccc7cb77 8157850: Jar tests should pass through VM options
anazarov
parents: 38468
diff changeset
   917
            commands.addAll(Arrays.asList(TOOL_VM_OPTIONS.split("\\s+", -1)));
2956ccc7cb77 8157850: Jar tests should pass through VM options
anazarov
parents: 38468
diff changeset
   918
        }
2956ccc7cb77 8157850: Jar tests should pass through VM options
anazarov
parents: 38468
diff changeset
   919
        Stream.of(args).forEach(commands::add);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   920
        ProcessBuilder p = new ProcessBuilder(commands);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   921
        if (stdinSource != null)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   922
            p.redirectInput(stdinSource);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   923
        return run(p);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   924
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   925
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   926
    static Result jar(String... args) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   927
        return jarWithStdin(null, args);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   928
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   929
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   930
    static Path compileModule(String mn) throws IOException {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   931
        return compileModule(mn, null);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   932
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   933
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   934
    static Path compileModule(String mn, Path mp)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   935
        throws IOException
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   936
    {
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   937
        Path sourcePath = TEST_SRC.resolve("src").resolve(mn);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   938
        Path build = Files.createDirectories(MODULE_CLASSES.resolve(mn));
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   939
        javac(build, mp, sourceList(sourcePath));
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   940
        return build;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   941
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   942
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   943
    static void copyResource(Path srcDir, Path dir, String resource)
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   944
        throws IOException
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   945
    {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   946
        Path dest = dir.resolve(resource);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   947
        Files.deleteIfExists(dest);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   948
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   949
        Files.createDirectories(dest.getParent());
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   950
        Files.copy(srcDir.resolve(resource), dest);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   951
    }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   952
38468
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   953
    static void setupMRJARModuleInfo(String moduleName) throws IOException {
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   954
        Path modClasses = MODULE_CLASSES.resolve(moduleName);
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   955
        Path metaInfDir = MRJAR_DIR.resolve(moduleName).resolve("META-INF");
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   956
        Path versionSection = metaInfDir.resolve("versions").resolve("9");
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   957
        createTestDir(versionSection);
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   958
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   959
        Path versionModuleInfo = versionSection.resolve("module-info.class");
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   960
        System.out.println("copying " + modClasses.resolve("module-info.class") + " to " + versionModuleInfo);
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   961
        Files.copy(modClasses.resolve("module-info.class"), versionModuleInfo);
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   962
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   963
        Manifest manifest = new Manifest();
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   964
        manifest.getMainAttributes().putValue("Manifest-Version", "1.0");
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   965
        manifest.getMainAttributes().putValue("Multi-Release", "true");
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   966
        try (OutputStream os = Files.newOutputStream(metaInfDir.resolve("MANIFEST.MF"))) {
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   967
            manifest.write(os);
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   968
        }
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   969
    }
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
   970
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   971
    static ModuleDescriptor getModuleDescriptor(Path jar) {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   972
        ClassLoader cl = ClassLoader.getSystemClassLoader();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   973
        try (JarFile jf = new JarFile(jar.toFile())) {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   974
            JarEntry entry = jf.getJarEntry("module-info.class");
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   975
            try (InputStream in = jf.getInputStream(entry)) {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   976
                return ModuleDescriptor.read(in);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   977
            }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   978
        } catch (IOException ioe) {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   979
            throw new UncheckedIOException(ioe);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   980
        }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   981
    }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   982
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   983
    // Re-enable when there is support in javax.tools for module path
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   984
//    static void javac(Path dest, Path... sourceFiles) throws IOException {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   985
//        out.printf("Compiling %d source files %s%n", sourceFiles.length,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   986
//                   Arrays.asList(sourceFiles));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   987
//        JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   988
//        try (StandardJavaFileManager fileManager =
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   989
//                     compiler.getStandardFileManager(null, null, null)) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   990
//
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   991
//            List<File> files = Stream.of(sourceFiles)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   992
//                                     .map(p -> p.toFile())
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   993
//                                     .collect(Collectors.toList());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   994
//            List<File> dests = Stream.of(dest)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   995
//                                     .map(p -> p.toFile())
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   996
//                                     .collect(Collectors.toList());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   997
//            Iterable<? extends JavaFileObject> compilationUnits =
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   998
//                    fileManager.getJavaFileObjectsFromFiles(files);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   999
//            fileManager.setLocation(StandardLocation.CLASS_OUTPUT, dests);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1000
//            JavaCompiler.CompilationTask task =
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1001
//                    compiler.getTask(null, fileManager, null, null, null, compilationUnits);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1002
//            boolean passed = task.call();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1003
//            if (!passed)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1004
//                throw new RuntimeException("Error compiling " + files);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1005
//        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1006
//    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1007
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1008
    static void javac(Path dest, Path... sourceFiles) throws IOException {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1009
        javac(dest, null, sourceFiles);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1010
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1011
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1012
    static void javac(Path dest, Path modulePath, Path... sourceFiles)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1013
        throws IOException
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1014
    {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1015
        String javac = getJDKTool("javac");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1016
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1017
        List<String> commands = new ArrayList<>();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1018
        commands.add(javac);
38762
2956ccc7cb77 8157850: Jar tests should pass through VM options
anazarov
parents: 38468
diff changeset
  1019
        if (!TOOL_VM_OPTIONS.isEmpty()) {
2956ccc7cb77 8157850: Jar tests should pass through VM options
anazarov
parents: 38468
diff changeset
  1020
            commands.addAll(Arrays.asList(TOOL_VM_OPTIONS.split("\\s+", -1)));
2956ccc7cb77 8157850: Jar tests should pass through VM options
anazarov
parents: 38468
diff changeset
  1021
        }
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1022
        commands.add("-d");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1023
        commands.add(dest.toString());
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 38762
diff changeset
  1024
        if (dest.toString().contains("bar")) {
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 38762
diff changeset
  1025
            commands.add("--add-exports");
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
  1026
            commands.add("java.base/jdk.internal.misc=bar");
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
  1027
            commands.add("--add-exports");
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 38762
diff changeset
  1028
            commands.add("java.base/jdk.internal.module=bar");
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 38762
diff changeset
  1029
        }
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1030
        if (modulePath != null) {
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 38762
diff changeset
  1031
            commands.add("--module-path");
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1032
            commands.add(modulePath.toString());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1033
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1034
        Stream.of(sourceFiles).map(Object::toString).forEach(x -> commands.add(x));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1035
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1036
        quickFail(run(new ProcessBuilder(commands)));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1037
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1038
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1039
    static Result java(Path modulePath, String entryPoint, String... args) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1040
        String java = getJDKTool("java");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1041
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1042
        List<String> commands = new ArrayList<>();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1043
        commands.add(java);
38762
2956ccc7cb77 8157850: Jar tests should pass through VM options
anazarov
parents: 38468
diff changeset
  1044
        if (!VM_OPTIONS.isEmpty()) {
2956ccc7cb77 8157850: Jar tests should pass through VM options
anazarov
parents: 38468
diff changeset
  1045
            commands.addAll(Arrays.asList(VM_OPTIONS.split("\\s+", -1)));
2956ccc7cb77 8157850: Jar tests should pass through VM options
anazarov
parents: 38468
diff changeset
  1046
        }
2956ccc7cb77 8157850: Jar tests should pass through VM options
anazarov
parents: 38468
diff changeset
  1047
        if (!JAVA_OPTIONS.isEmpty()) {
2956ccc7cb77 8157850: Jar tests should pass through VM options
anazarov
parents: 38468
diff changeset
  1048
            commands.addAll(Arrays.asList(JAVA_OPTIONS.split("\\s+", -1)));
2956ccc7cb77 8157850: Jar tests should pass through VM options
anazarov
parents: 38468
diff changeset
  1049
        }
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1050
        Stream.of(args).forEach(x -> commands.add(x));
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 38762
diff changeset
  1051
        commands.add("--module-path");
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1052
        commands.add(modulePath.toString());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1053
        commands.add("-m");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1054
        commands.add(entryPoint);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1055
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1056
        return run(new ProcessBuilder(commands));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1057
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1058
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
  1059
    static Path[] sourceList(Path directory) throws IOException {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
  1060
        return Files.find(directory, Integer.MAX_VALUE,
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
  1061
                          (file, attrs) -> (file.toString().endsWith(".java")))
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
  1062
                    .toArray(Path[]::new);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1063
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1064
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1065
    static void createTestDir(Path p) throws IOException{
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1066
        if (Files.exists(p))
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1067
            FileUtils.deleteFileTreeWithRetry(p);
38468
d459a0f8fe72 8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents: 37779
diff changeset
  1068
        Files.createDirectories(p);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1069
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1070
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1071
    static boolean jarContains(JarInputStream jis, String entryName)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1072
        throws IOException
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1073
    {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1074
        JarEntry e;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1075
        while((e = jis.getNextJarEntry()) != null) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1076
            if (e.getName().equals(entryName))
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1077
                return true;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1078
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1079
        return false;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1080
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1081
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1082
    static void quickFail(Result r) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1083
        if (r.ec != 0)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1084
            throw new RuntimeException(r.output);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1085
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1086
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1087
    static Result run(ProcessBuilder pb) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1088
        Process p;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1089
        out.printf("Running: %s%n", pb.command());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1090
        try {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1091
            p = pb.start();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1092
        } catch (IOException e) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1093
            throw new RuntimeException(
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1094
                    format("Couldn't start process '%s'", pb.command()), e);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1095
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1096
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1097
        String output;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1098
        try {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1099
            output = toString(p.getInputStream(), p.getErrorStream());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1100
        } catch (IOException e) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1101
            throw new RuntimeException(
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1102
                    format("Couldn't read process output '%s'", pb.command()), e);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1103
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1104
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1105
        try {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1106
            p.waitFor();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1107
        } catch (InterruptedException e) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1108
            throw new RuntimeException(
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1109
                    format("Process hasn't finished '%s'", pb.command()), e);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1110
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1111
        return new Result(p.exitValue(), output);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1112
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1113
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1114
    static final String DEFAULT_IMAGE_BIN = System.getProperty("java.home")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1115
            + File.separator + "bin" + File.separator;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1116
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1117
    static String getJDKTool(String name) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1118
        try {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1119
            return JDKToolFinder.getJDKTool(name);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1120
        } catch (Exception x) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1121
            return DEFAULT_IMAGE_BIN + name;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1122
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1123
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1124
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1125
    static String toString(InputStream in1, InputStream in2) throws IOException {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1126
        try (ByteArrayOutputStream dst = new ByteArrayOutputStream();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1127
             InputStream concatenated = new SequenceInputStream(in1, in2)) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1128
            concatenated.transferTo(dst);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1129
            return new String(dst.toByteArray(), "UTF-8");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1130
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1131
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1132
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1133
    static class Result {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1134
        final int ec;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1135
        final String output;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1136
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1137
        private Result(int ec, String output) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1138
            this.ec = ec;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1139
            this.output = output;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1140
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1141
        Result assertSuccess() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1142
            assertTrue(ec == 0, "Expected ec 0, got: ", ec, " , output [", output, "]");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1143
            return this;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1144
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1145
        Result assertFailure() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1146
            assertTrue(ec != 0, "Expected ec != 0, got:", ec, " , output [", output, "]");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1147
            return this;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1148
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1149
        Result resultChecker(Consumer<Result> r) { r.accept(this); return this; }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1150
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1151
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1152
    static void assertTrue(boolean cond, Object ... failedArgs) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1153
        if (cond)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1154
            return;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1155
        StringBuilder sb = new StringBuilder();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1156
        for (Object o : failedArgs)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1157
            sb.append(o);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1158
        org.testng.Assert.assertTrue(false, sb.toString());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1159
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1160
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1161
    // Standalone entry point.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1162
    public static void main(String[] args) throws Throwable {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1163
        Basic test = new Basic();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1164
        test.compileModules();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1165
        for (Method m : Basic.class.getDeclaredMethods()) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1166
            if (m.getAnnotation(Test.class) != null) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1167
                System.out.println("Invoking " + m.getName());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1168
                m.invoke(test);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1169
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1170
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1171
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1172
}