test/jdk/tools/jlink/JLinkNegativeTest.java
author prr
Fri, 25 May 2018 12:12:24 -0700
changeset 50347 b2f046ae8eb6
parent 47399 fb677b3f0888
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     1
/**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     4
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     7
 * published by the Free Software Foundation.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     8
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    13
 * accompanied this code).
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    14
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    18
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    21
 * questions.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    22
 */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    23
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    24
/*
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    25
 * @test
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    26
 * @summary Negative tests for jlink
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    27
 * @bug 8130861
43796
c204d2d789dc 8174718: "Module <name>'s descriptor returns inconsistent package set" confusing
sundar
parents: 43729
diff changeset
    28
 * @bug 8174718
47399
fb677b3f0888 8189671: jlink should clearly report error when an automatic module is used
sundar
parents: 47216
diff changeset
    29
 * @bug 8189671
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    30
 * @author Andrei Eremeev
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    31
 * @library ../lib
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    32
 * @modules java.base/jdk.internal.jimage
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    33
 *          java.base/jdk.internal.module
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    34
 *          jdk.jdeps/com.sun.tools.classfile
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    35
 *          jdk.jlink/jdk.tools.jlink.internal
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    36
 *          jdk.jlink/jdk.tools.jmod
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    37
 *          jdk.jlink/jdk.tools.jimage
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    38
 *          jdk.compiler
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    39
 * @build tests.*
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    40
 * @run testng JLinkNegativeTest
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    41
 */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    42
47399
fb677b3f0888 8189671: jlink should clearly report error when an automatic module is used
sundar
parents: 47216
diff changeset
    43
import java.io.File;
fb677b3f0888 8189671: jlink should clearly report error when an automatic module is used
sundar
parents: 47216
diff changeset
    44
import java.io.FileOutputStream;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    45
import java.io.IOException;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    46
import java.io.OutputStream;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    47
import java.lang.module.ModuleDescriptor;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    48
import java.nio.file.FileVisitResult;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    49
import java.nio.file.Files;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    50
import java.nio.file.Path;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    51
import java.nio.file.Paths;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    52
import java.nio.file.SimpleFileVisitor;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    53
import java.nio.file.attribute.BasicFileAttributes;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    54
import java.util.Arrays;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    55
import java.util.Collections;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    56
import java.util.List;
43796
c204d2d789dc 8174718: "Module <name>'s descriptor returns inconsistent package set" confusing
sundar
parents: 43729
diff changeset
    57
import java.util.Set;
47399
fb677b3f0888 8189671: jlink should clearly report error when an automatic module is used
sundar
parents: 47216
diff changeset
    58
import java.util.jar.JarEntry;
fb677b3f0888 8189671: jlink should clearly report error when an automatic module is used
sundar
parents: 47216
diff changeset
    59
import java.util.jar.JarOutputStream;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    60
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    61
import jdk.internal.module.ModuleInfoWriter;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    62
import org.testng.SkipException;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    63
import org.testng.annotations.BeforeClass;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    64
import org.testng.annotations.Test;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    65
import tests.Helper;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    66
import tests.JImageGenerator;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    67
import tests.JImageGenerator.InMemoryFile;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    68
import tests.Result;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    69
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    70
@Test
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    71
public class JLinkNegativeTest {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    72
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    73
    private Helper helper;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    74
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    75
    @BeforeClass
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    76
    public void setUp() throws IOException {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    77
        helper = Helper.newHelper();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    78
        if (helper == null) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    79
            throw new SkipException("Not run");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    80
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    81
        helper.generateDefaultModules();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    82
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    83
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    84
    private void deleteDirectory(Path dir) throws IOException {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    85
        Files.walkFileTree(dir, new SimpleFileVisitor<Path>() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    86
            @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    87
            public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    88
                Files.delete(file);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    89
                return FileVisitResult.CONTINUE;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    90
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    91
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    92
            @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    93
            public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    94
                Files.delete(dir);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    95
                return FileVisitResult.CONTINUE;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    96
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    97
        });
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    98
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    99
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   100
    public void testModuleNotExist() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   101
        helper.generateDefaultImage("failure1").assertFailure("Error: Module failure1 not found");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   102
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   103
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   104
    public void testNotExistInAddMods() {
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 36511
diff changeset
   105
        // cannot find jmod from --add-modules
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   106
        JImageGenerator.getJLinkTask()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   107
                .modulePath(".")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   108
                .addMods("not_exist")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   109
                .output(helper.getImageDir().resolve("failure2"))
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   110
                .call().assertFailure("Error: Module not_exist not found");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   111
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   112
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   113
    public void test() throws IOException {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   114
        helper.generateDefaultJModule("failure3");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   115
        Path image = helper.generateDefaultImage("failure3").assertSuccess();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   116
        JImageGenerator.getJLinkTask()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   117
                .modulePath(helper.defaultModulePath())
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   118
                .output(image)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   119
                .addMods("leaf1")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   120
                .limitMods("leaf1")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   121
                .call().assertFailure("Error: directory already exists: .*failure3.image(\n|\r|.)*");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   122
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   123
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   124
    public void testOutputIsFile() throws IOException {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   125
        // output == file
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   126
        Path image = helper.createNewImageDir("failure4");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   127
        Files.createFile(image);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   128
        JImageGenerator.getJLinkTask()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   129
                .modulePath(helper.defaultModulePath())
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   130
                .output(image)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   131
                .addMods("leaf1")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   132
                .call().assertFailure("Error: directory already exists: .*failure4.image(\n|\r|.)*");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   133
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   134
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   135
    public void testModuleNotFound() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   136
        // limit module is not found
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   137
        Path imageFile = helper.createNewImageDir("test");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   138
        JImageGenerator.getJLinkTask()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   139
                .output(imageFile)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   140
                .addMods("leaf1")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   141
                .limitMods("leaf1")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   142
                .limitMods("failure5")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   143
                .modulePath(helper.defaultModulePath())
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   144
                .call().assertFailure("Error: Module failure5 not found");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   145
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   146
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   147
    public void testJmodIsDir() throws IOException {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   148
        Path imageFile = helper.createNewImageDir("test");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   149
        Path dirJmod = helper.createNewJmodFile("dir");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   150
        Files.createDirectory(dirJmod);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   151
        try {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   152
            JImageGenerator.getJLinkTask()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   153
                    .output(imageFile)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   154
                    .addMods("dir")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   155
                    .modulePath(helper.defaultModulePath())
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   156
                    .call().assertFailure("Error: Module dir not found");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   157
        } finally {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   158
            deleteDirectory(dirJmod);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   159
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   160
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   161
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   162
    public void testJarIsDir() throws IOException {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   163
        Path imageFile = helper.createNewImageDir("test");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   164
        Path dirJar = helper.createNewJarFile("dir");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   165
        Files.createDirectory(dirJar);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   166
        try {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   167
            JImageGenerator.getJLinkTask()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   168
                    .output(imageFile)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   169
                    .addMods("dir")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   170
                    .modulePath(helper.defaultModulePath())
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   171
                    .call().assertFailure("Error: Module dir not found");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   172
        } finally {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   173
            deleteDirectory(dirJar);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   174
        }
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
    public void testMalformedJar() throws IOException {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   178
        Path imageFile = helper.createNewImageDir("test");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   179
        Path jar = helper.createNewJarFile("not_zip");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   180
        Files.createFile(jar);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   181
        try {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   182
            JImageGenerator.getJLinkTask()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   183
                    .output(imageFile)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   184
                    .addMods("not_zip")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   185
                    .modulePath(helper.defaultModulePath())
45004
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44359
diff changeset
   186
                    .call().assertFailure("Error: Error reading");
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   187
        } finally {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   188
            deleteDirectory(jar);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   189
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   190
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   191
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   192
    public void testMalformedJmod() throws IOException {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   193
        Path imageFile = helper.createNewImageDir("test");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   194
        Path jmod = helper.createNewJmodFile("not_zip");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   195
        Files.createFile(jmod);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   196
        try {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   197
            JImageGenerator.getJLinkTask()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   198
                    .output(imageFile)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   199
                    .addMods("not_zip")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   200
                    .modulePath(helper.defaultModulePath())
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43796
diff changeset
   201
                    .call().assertFailure("Error: java.io.IOException: Invalid JMOD file");
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   202
        } finally {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   203
            deleteDirectory(jmod);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   204
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   205
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   206
47399
fb677b3f0888 8189671: jlink should clearly report error when an automatic module is used
sundar
parents: 47216
diff changeset
   207
    private static File createJarFile(File dir, String filename, String pkg, String name) throws IOException {
fb677b3f0888 8189671: jlink should clearly report error when an automatic module is used
sundar
parents: 47216
diff changeset
   208
        File jarFile = new File(dir, filename + ".jar");
fb677b3f0888 8189671: jlink should clearly report error when an automatic module is used
sundar
parents: 47216
diff changeset
   209
fb677b3f0888 8189671: jlink should clearly report error when an automatic module is used
sundar
parents: 47216
diff changeset
   210
        try (JarOutputStream output = new JarOutputStream(new FileOutputStream(jarFile))) {
fb677b3f0888 8189671: jlink should clearly report error when an automatic module is used
sundar
parents: 47216
diff changeset
   211
            JarEntry entry = new JarEntry(filename + "/" + pkg + "/" + name);
fb677b3f0888 8189671: jlink should clearly report error when an automatic module is used
sundar
parents: 47216
diff changeset
   212
            output.putNextEntry(entry);
fb677b3f0888 8189671: jlink should clearly report error when an automatic module is used
sundar
parents: 47216
diff changeset
   213
        }
fb677b3f0888 8189671: jlink should clearly report error when an automatic module is used
sundar
parents: 47216
diff changeset
   214
fb677b3f0888 8189671: jlink should clearly report error when an automatic module is used
sundar
parents: 47216
diff changeset
   215
        return jarFile;
fb677b3f0888 8189671: jlink should clearly report error when an automatic module is used
sundar
parents: 47216
diff changeset
   216
    }
fb677b3f0888 8189671: jlink should clearly report error when an automatic module is used
sundar
parents: 47216
diff changeset
   217
fb677b3f0888 8189671: jlink should clearly report error when an automatic module is used
sundar
parents: 47216
diff changeset
   218
    public void testAutomaticModuleAsRoot() throws IOException {
fb677b3f0888 8189671: jlink should clearly report error when an automatic module is used
sundar
parents: 47216
diff changeset
   219
        Path imageFile = helper.createNewImageDir("test");
fb677b3f0888 8189671: jlink should clearly report error when an automatic module is used
sundar
parents: 47216
diff changeset
   220
        String jarName = "myautomod";
fb677b3f0888 8189671: jlink should clearly report error when an automatic module is used
sundar
parents: 47216
diff changeset
   221
        File jarFile = createJarFile(new File("jars"), jarName, "com/acme", "Bar.class");
fb677b3f0888 8189671: jlink should clearly report error when an automatic module is used
sundar
parents: 47216
diff changeset
   222
        try {
fb677b3f0888 8189671: jlink should clearly report error when an automatic module is used
sundar
parents: 47216
diff changeset
   223
            JImageGenerator.getJLinkTask()
fb677b3f0888 8189671: jlink should clearly report error when an automatic module is used
sundar
parents: 47216
diff changeset
   224
                    .output(imageFile)
fb677b3f0888 8189671: jlink should clearly report error when an automatic module is used
sundar
parents: 47216
diff changeset
   225
                    .addMods(jarName)
fb677b3f0888 8189671: jlink should clearly report error when an automatic module is used
sundar
parents: 47216
diff changeset
   226
                    .modulePath(helper.defaultModulePath())
fb677b3f0888 8189671: jlink should clearly report error when an automatic module is used
sundar
parents: 47216
diff changeset
   227
                    .call().assertFailure("Error: automatic module cannot be used with jlink: " + jarName);
fb677b3f0888 8189671: jlink should clearly report error when an automatic module is used
sundar
parents: 47216
diff changeset
   228
        } finally {
fb677b3f0888 8189671: jlink should clearly report error when an automatic module is used
sundar
parents: 47216
diff changeset
   229
            jarFile.delete();
fb677b3f0888 8189671: jlink should clearly report error when an automatic module is used
sundar
parents: 47216
diff changeset
   230
        }
fb677b3f0888 8189671: jlink should clearly report error when an automatic module is used
sundar
parents: 47216
diff changeset
   231
    }
fb677b3f0888 8189671: jlink should clearly report error when an automatic module is used
sundar
parents: 47216
diff changeset
   232
fb677b3f0888 8189671: jlink should clearly report error when an automatic module is used
sundar
parents: 47216
diff changeset
   233
    public void testAutomaticModuleAsDependency() throws IOException {
fb677b3f0888 8189671: jlink should clearly report error when an automatic module is used
sundar
parents: 47216
diff changeset
   234
        Path imageFile = helper.createNewImageDir("test");
fb677b3f0888 8189671: jlink should clearly report error when an automatic module is used
sundar
parents: 47216
diff changeset
   235
        String autoJarName = "myautomod";
fb677b3f0888 8189671: jlink should clearly report error when an automatic module is used
sundar
parents: 47216
diff changeset
   236
        File autoJarFile = createJarFile(new File("jars"), autoJarName, "com/acme", "Bar.class");
fb677b3f0888 8189671: jlink should clearly report error when an automatic module is used
sundar
parents: 47216
diff changeset
   237
        String rootMod = "autodepender";
fb677b3f0888 8189671: jlink should clearly report error when an automatic module is used
sundar
parents: 47216
diff changeset
   238
        helper.generateDefaultJModule(rootMod, autoJarName).assertSuccess();
fb677b3f0888 8189671: jlink should clearly report error when an automatic module is used
sundar
parents: 47216
diff changeset
   239
        try {
fb677b3f0888 8189671: jlink should clearly report error when an automatic module is used
sundar
parents: 47216
diff changeset
   240
            JImageGenerator.getJLinkTask()
fb677b3f0888 8189671: jlink should clearly report error when an automatic module is used
sundar
parents: 47216
diff changeset
   241
                    .output(imageFile)
fb677b3f0888 8189671: jlink should clearly report error when an automatic module is used
sundar
parents: 47216
diff changeset
   242
                    .addMods(rootMod)
fb677b3f0888 8189671: jlink should clearly report error when an automatic module is used
sundar
parents: 47216
diff changeset
   243
                    .modulePath(helper.defaultModulePath())
fb677b3f0888 8189671: jlink should clearly report error when an automatic module is used
sundar
parents: 47216
diff changeset
   244
                    .call().assertFailure("Error: automatic module cannot be used with jlink: " + autoJarName);
fb677b3f0888 8189671: jlink should clearly report error when an automatic module is used
sundar
parents: 47216
diff changeset
   245
        } finally {
fb677b3f0888 8189671: jlink should clearly report error when an automatic module is used
sundar
parents: 47216
diff changeset
   246
            autoJarFile.delete();
fb677b3f0888 8189671: jlink should clearly report error when an automatic module is used
sundar
parents: 47216
diff changeset
   247
        }
fb677b3f0888 8189671: jlink should clearly report error when an automatic module is used
sundar
parents: 47216
diff changeset
   248
    }
fb677b3f0888 8189671: jlink should clearly report error when an automatic module is used
sundar
parents: 47216
diff changeset
   249
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   250
    // Temporarily exclude; the jmod tool can no longer be used to create a jmod
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   251
    // with a class in the unnamed package. Find another way, or remove.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   252
//    public void testAddDefaultPackage() throws IOException {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   253
//        String moduleName = "hacked1";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   254
//        Path module = helper.generateModuleCompiledClasses(helper.getJmodSrcDir(), helper.getJmodClassesDir(),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   255
//                moduleName, Arrays.asList("hacked1.Main", "A", "B"), "leaf1");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   256
//        JImageGenerator
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   257
//                .getJModTask()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   258
//                .addClassPath(module)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   259
//                .jmod(helper.getJmodDir().resolve(moduleName + ".jmod"))
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   260
//                .create().assertSuccess();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   261
//        Path image = helper.generateDefaultImage(moduleName).assertSuccess();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   262
//        helper.checkImage(image, moduleName, null, null);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   263
//    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   264
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   265
    public void testAddSomeTopLevelFiles() throws IOException {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   266
        String moduleName = "hacked2";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   267
        Path module = helper.generateModuleCompiledClasses(helper.getJmodSrcDir(), helper.getJmodClassesDir(),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   268
                moduleName);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   269
        Files.createFile(module.resolve("top-level-file"));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   270
        Path jmod = JImageGenerator
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   271
                .getJModTask()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   272
                .addClassPath(module)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   273
                .jmod(helper.getJmodDir().resolve(moduleName + ".jmod"))
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   274
                .create().assertSuccess();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   275
        try {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   276
            Path image = helper.generateDefaultImage(moduleName).assertSuccess();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   277
            helper.checkImage(image, moduleName, null, null);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   278
        } finally {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   279
            deleteDirectory(jmod);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   280
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   281
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   282
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   283
    public void testAddNonStandardSection() throws IOException {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   284
        String moduleName = "hacked3";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   285
        Path module = helper.generateDefaultJModule(moduleName).assertSuccess();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   286
        JImageGenerator.addFiles(module, new InMemoryFile("unknown/A.class", new byte[0]));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   287
        try {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   288
            Result result = helper.generateDefaultImage(moduleName);
41352
f9844bad9052 8166860: Add magic number to jmod file
mchung
parents: 40261
diff changeset
   289
            System.err.println(result.getMessage());
f9844bad9052 8166860: Add magic number to jmod file
mchung
parents: 40261
diff changeset
   290
            if (result.getExitCode() == 0) {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   291
                throw new AssertionError("Crash expected");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   292
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   293
        } finally {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   294
            deleteDirectory(module);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   295
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   296
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   297
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   298
    @Test(enabled = true)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   299
    public void testSectionsAreFiles() throws IOException {
41352
f9844bad9052 8166860: Add magic number to jmod file
mchung
parents: 40261
diff changeset
   300
        String moduleName = "hacked4";
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   301
        Path jmod = helper.generateDefaultJModule(moduleName).assertSuccess();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   302
        JImageGenerator.addFiles(jmod,
43729
21db38703675 8174739: Rename JMOD section name for native libraries from native to lib
mchung
parents: 43712
diff changeset
   303
                new InMemoryFile("/lib", new byte[0]),
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   304
                new InMemoryFile("/conf", new byte[0]),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   305
                new InMemoryFile("/bin", new byte[0]));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   306
        try {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   307
            Result result = helper.generateDefaultImage(moduleName);
41352
f9844bad9052 8166860: Add magic number to jmod file
mchung
parents: 40261
diff changeset
   308
            System.err.println(result.getMessage());
f9844bad9052 8166860: Add magic number to jmod file
mchung
parents: 40261
diff changeset
   309
            if (result.getExitCode() == 0) {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   310
                throw new AssertionError("Crash expected");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   311
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   312
        } finally {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   313
            deleteDirectory(jmod);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   314
        }
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
    public void testDuplicateModule1() throws IOException {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   318
        String moduleName1 = "dupRes1Jmod1";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   319
        String moduleName2 = "dupRes1Jmod2";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   320
        List<String> classNames = Arrays.asList("java.A", "javax.B");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   321
        Path module1 = helper.generateModuleCompiledClasses(
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   322
                helper.getJmodSrcDir(), helper.getJmodClassesDir(), moduleName1, classNames);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   323
        Path module2 = helper.generateModuleCompiledClasses(
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   324
                helper.getJmodSrcDir(), helper.getJmodClassesDir(), moduleName2, classNames);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   325
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   326
        try (OutputStream out = Files.newOutputStream(module2.resolve("module-info.class"))) {
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42338
diff changeset
   327
            ModuleInfoWriter.write(ModuleDescriptor.newModule(moduleName1)
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   328
                    .requires("java.base").build(), out);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   329
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   330
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   331
        Path jmod1 = JImageGenerator.getJModTask()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   332
                .addClassPath(module1)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   333
                .jmod(helper.createNewJmodFile(moduleName1))
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   334
                .create()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   335
                .assertSuccess();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   336
        Path jmod2 = JImageGenerator.getJModTask()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   337
                .addClassPath(module2)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   338
                .jmod(helper.createNewJmodFile(moduleName2))
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   339
                .create()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   340
                .assertSuccess();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   341
        try {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   342
            helper.generateDefaultImage(moduleName1)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   343
                    .assertFailure("Error: Two versions of module dupRes1Jmod1 found in");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   344
        } finally {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   345
            deleteDirectory(jmod1);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   346
            deleteDirectory(jmod2);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   347
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   348
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   349
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   350
    public void testDuplicateModule2() throws IOException {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   351
        String moduleName = "dupRes2Jmod";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   352
        List<String> classNames = Arrays.asList("java.A", "javax.B");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   353
        Path module1 = helper.generateModuleCompiledClasses(
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   354
                helper.getJmodSrcDir(), helper.getJmodClassesDir(), moduleName, classNames);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   355
        Path module2 = helper.generateModuleCompiledClasses(
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   356
                helper.getJarSrcDir(), helper.getJarClassesDir(), moduleName, classNames);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   357
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   358
        Path jmod = JImageGenerator.getJModTask()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   359
                .addClassPath(module1)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   360
                .jmod(helper.createNewJmodFile(moduleName))
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   361
                .create()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   362
                .assertSuccess();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   363
        Path jar = JImageGenerator.createJarFile(helper.getJarDir().resolve(moduleName + ".jar"), module2);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   364
        Path newJar = helper.getJmodDir().resolve(jar.getFileName());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   365
        Files.move(jar, newJar);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   366
        try {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   367
            helper.generateDefaultImage(moduleName)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   368
                    .assertFailure("Error: Two versions of module dupRes2Jmod found in");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   369
        } finally {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   370
            deleteDirectory(jmod);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   371
            deleteDirectory(newJar);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   372
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   373
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   374
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   375
    public void testDuplicateModule3() throws IOException {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   376
        String moduleName1 = "dupRes3Jar1";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   377
        String moduleName2 = "dupRes3Jar2";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   378
        List<String> classNames = Arrays.asList("java.A", "javax.B");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   379
        Path module1 = helper.generateModuleCompiledClasses(
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   380
                helper.getJarSrcDir(), helper.getJarClassesDir(), moduleName1, classNames);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   381
        Path module2 = helper.generateModuleCompiledClasses(
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   382
                helper.getJarSrcDir(), helper.getJarClassesDir(), moduleName2, classNames);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   383
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   384
        try (OutputStream out = Files.newOutputStream(module2.resolve("module-info.class"))) {
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42338
diff changeset
   385
            ModuleInfoWriter.write(ModuleDescriptor.newModule(moduleName1)
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   386
                    .requires("java.base").build(), out);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   387
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   388
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   389
        Path jar1 = JImageGenerator.createJarFile(helper.getJarDir().resolve(moduleName1 + ".jar"), module1);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   390
        Path jar2 = JImageGenerator.createJarFile(helper.getJarDir().resolve(moduleName2 + ".jar"), module2);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   391
        try {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   392
            helper.generateDefaultImage(moduleName1)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   393
                    .assertFailure("Error: Two versions of module dupRes3Jar1 found in");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   394
        } finally {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   395
            deleteDirectory(jar1);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   396
            deleteDirectory(jar2);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   397
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   398
    }
43796
c204d2d789dc 8174718: "Module <name>'s descriptor returns inconsistent package set" confusing
sundar
parents: 43729
diff changeset
   399
c204d2d789dc 8174718: "Module <name>'s descriptor returns inconsistent package set" confusing
sundar
parents: 43729
diff changeset
   400
    public void testInconsistentModuleInfo() throws IOException {
c204d2d789dc 8174718: "Module <name>'s descriptor returns inconsistent package set" confusing
sundar
parents: 43729
diff changeset
   401
        String moduleName = "inconsistentJar";
c204d2d789dc 8174718: "Module <name>'s descriptor returns inconsistent package set" confusing
sundar
parents: 43729
diff changeset
   402
        List<String> classNames = Arrays.asList("xorg.acme.internal.B");
c204d2d789dc 8174718: "Module <name>'s descriptor returns inconsistent package set" confusing
sundar
parents: 43729
diff changeset
   403
        Path module = helper.generateModuleCompiledClasses(
c204d2d789dc 8174718: "Module <name>'s descriptor returns inconsistent package set" confusing
sundar
parents: 43729
diff changeset
   404
                helper.getJarSrcDir(), helper.getJarClassesDir(), moduleName, classNames);
c204d2d789dc 8174718: "Module <name>'s descriptor returns inconsistent package set" confusing
sundar
parents: 43729
diff changeset
   405
c204d2d789dc 8174718: "Module <name>'s descriptor returns inconsistent package set" confusing
sundar
parents: 43729
diff changeset
   406
        try (OutputStream out = Files.newOutputStream(module.resolve("module-info.class"))) {
c204d2d789dc 8174718: "Module <name>'s descriptor returns inconsistent package set" confusing
sundar
parents: 43729
diff changeset
   407
            ModuleInfoWriter.write(ModuleDescriptor.newModule(moduleName)
c204d2d789dc 8174718: "Module <name>'s descriptor returns inconsistent package set" confusing
sundar
parents: 43729
diff changeset
   408
                    .requires("java.base")
c204d2d789dc 8174718: "Module <name>'s descriptor returns inconsistent package set" confusing
sundar
parents: 43729
diff changeset
   409
                    .packages(Set.of("org.acme.internal"))
c204d2d789dc 8174718: "Module <name>'s descriptor returns inconsistent package set" confusing
sundar
parents: 43729
diff changeset
   410
                    .build(), out);
c204d2d789dc 8174718: "Module <name>'s descriptor returns inconsistent package set" confusing
sundar
parents: 43729
diff changeset
   411
        }
c204d2d789dc 8174718: "Module <name>'s descriptor returns inconsistent package set" confusing
sundar
parents: 43729
diff changeset
   412
c204d2d789dc 8174718: "Module <name>'s descriptor returns inconsistent package set" confusing
sundar
parents: 43729
diff changeset
   413
        Path jar = JImageGenerator.createJarFile(helper.getJarDir().resolve(moduleName + ".jar"), module);
c204d2d789dc 8174718: "Module <name>'s descriptor returns inconsistent package set" confusing
sundar
parents: 43729
diff changeset
   414
        try {
c204d2d789dc 8174718: "Module <name>'s descriptor returns inconsistent package set" confusing
sundar
parents: 43729
diff changeset
   415
            helper.generateDefaultImage(moduleName)
c204d2d789dc 8174718: "Module <name>'s descriptor returns inconsistent package set" confusing
sundar
parents: 43729
diff changeset
   416
                  .assertFailure("Module inconsistentJar's descriptor indicates the set of packages is : " +
c204d2d789dc 8174718: "Module <name>'s descriptor returns inconsistent package set" confusing
sundar
parents: 43729
diff changeset
   417
                  "[org.acme.internal], but module contains packages: [xorg.acme.internal]");
c204d2d789dc 8174718: "Module <name>'s descriptor returns inconsistent package set" confusing
sundar
parents: 43729
diff changeset
   418
        } finally {
c204d2d789dc 8174718: "Module <name>'s descriptor returns inconsistent package set" confusing
sundar
parents: 43729
diff changeset
   419
            deleteDirectory(jar);
c204d2d789dc 8174718: "Module <name>'s descriptor returns inconsistent package set" confusing
sundar
parents: 43729
diff changeset
   420
        }
c204d2d789dc 8174718: "Module <name>'s descriptor returns inconsistent package set" confusing
sundar
parents: 43729
diff changeset
   421
    }
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   422
}