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