jdk/test/java/lang/ModuleLayer/BasicLayerTest.java
author alanb
Fri, 07 Apr 2017 08:05:54 +0000
changeset 44545 83b611b88ac8
child 45652 33342314ce89
permissions -rw-r--r--
8177530: Module system implementation refresh (4/2017) Reviewed-by: mchung, alanb Contributed-by: alan.bateman@oracle.com, mandy.chung@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
44545
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
     1
/*
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
     2
 * Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
     4
 *
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
     7
 * published by the Free Software Foundation.
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
     8
 *
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    13
 * accompanied this code).
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    14
 *
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    18
 *
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    21
 * questions.
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    22
 */
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    23
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    24
/**
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    25
 * @test
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    26
 * @library /lib/testlibrary
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    27
 * @modules java.base/jdk.internal.misc
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    28
 * @build BasicLayerTest ModuleUtils
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    29
 * @compile layertest/Test.java
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    30
 * @run testng BasicLayerTest
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    31
 * @summary Basic tests for java.lang.ModuleLayer
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    32
 */
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    33
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    34
import java.lang.module.Configuration;
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    35
import java.lang.module.ModuleDescriptor;
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    36
import java.lang.module.ModuleDescriptor.Requires;
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    37
import java.lang.module.ModuleFinder;
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    38
import java.util.HashMap;
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    39
import java.util.Map;
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    40
import java.util.Optional;
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    41
import java.util.Set;
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    42
import java.util.stream.Collectors;
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    43
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    44
import jdk.internal.misc.SharedSecrets;
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    45
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    46
import org.testng.annotations.DataProvider;
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    47
import org.testng.annotations.Test;
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    48
import static org.testng.Assert.*;
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    49
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    50
@Test
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    51
public class BasicLayerTest {
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    52
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    53
    /**
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    54
     * Creates a "non-strict" builder for building a module. This allows the
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    55
     * test the create ModuleDescriptor objects that do not require java.base.
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    56
     */
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    57
    private static ModuleDescriptor.Builder newBuilder(String mn) {
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    58
        return SharedSecrets.getJavaLangModuleAccess()
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    59
                .newModuleBuilder(mn, false, Set.of());
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    60
    }
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    61
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    62
    /**
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    63
     * Exercise ModuleLayer.empty()
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    64
     */
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    65
    public void testEmpty() {
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    66
        ModuleLayer emptyLayer = ModuleLayer.empty();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    67
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    68
        assertTrue(emptyLayer.parents().isEmpty());
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    69
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    70
        assertTrue(emptyLayer.configuration() == Configuration.empty());
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    71
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    72
        assertTrue(emptyLayer.modules().isEmpty());
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    73
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    74
        assertFalse(emptyLayer.findModule("java.base").isPresent());
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    75
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    76
        try {
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    77
            emptyLayer.findLoader("java.base");
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    78
            assertTrue(false);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    79
        } catch (IllegalArgumentException expected) { }
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    80
    }
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    81
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    82
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    83
    /**
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    84
     * Exercise ModuleLayer.boot()
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    85
     */
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    86
    public void testBoot() {
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    87
        ModuleLayer bootLayer = ModuleLayer.boot();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    88
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    89
        // configuration
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    90
        Configuration cf = bootLayer.configuration();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    91
        assertTrue(cf.findModule("java.base").get()
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    92
                .reference()
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    93
                .descriptor()
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    94
                .exports()
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    95
                .stream().anyMatch(e -> (e.source().equals("java.lang")
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    96
                                         && !e.isQualified())));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    97
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    98
        // modules
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    99
        Set<Module> modules = bootLayer.modules();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   100
        assertTrue(modules.contains(Object.class.getModule()));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   101
        int count = (int) modules.stream().map(Module::getName).count();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   102
        assertEquals(count, modules.size()); // module names are unique
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   103
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   104
        // findModule
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   105
        Module base = Object.class.getModule();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   106
        assertTrue(bootLayer.findModule("java.base").get() == base);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   107
        assertTrue(base.getLayer() == bootLayer);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   108
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   109
        // findLoader
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   110
        assertTrue(bootLayer.findLoader("java.base") == null);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   111
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   112
        // parents
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   113
        assertTrue(bootLayer.parents().size() == 1);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   114
        assertTrue(bootLayer.parents().get(0) == ModuleLayer.empty());
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   115
    }
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   116
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   117
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   118
    /**
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   119
     * Exercise defineModules, created with empty layer as parent
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   120
     */
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   121
    public void testLayerOnEmpty() {
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   122
        ModuleDescriptor descriptor1 = newBuilder("m1")
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   123
                .requires("m2")
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   124
                .exports("p1")
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   125
                .build();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   126
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   127
        ModuleDescriptor descriptor2 = newBuilder("m2")
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   128
                .requires("m3")
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   129
                .build();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   130
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   131
        ModuleDescriptor descriptor3 = newBuilder("m3")
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   132
                .build();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   133
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   134
        ModuleFinder finder
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   135
            = ModuleUtils.finderOf(descriptor1, descriptor2, descriptor3);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   136
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   137
        Configuration cf = resolve(finder, "m1");
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   138
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   139
        // map each module to its own class loader for this test
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   140
        ClassLoader loader1 = new ClassLoader() { };
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   141
        ClassLoader loader2 = new ClassLoader() { };
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   142
        ClassLoader loader3 = new ClassLoader() { };
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   143
        Map<String, ClassLoader> map = new HashMap<>();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   144
        map.put("m1", loader1);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   145
        map.put("m2", loader2);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   146
        map.put("m3", loader3);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   147
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   148
        ModuleLayer layer = ModuleLayer.empty().defineModules(cf, map::get);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   149
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   150
        // configuration
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   151
        assertTrue(layer.configuration() == cf);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   152
        assertTrue(layer.configuration().modules().size() == 3);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   153
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   154
        // modules
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   155
        Set<Module> modules = layer.modules();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   156
        assertTrue(modules.size() == 3);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   157
        Set<String> names = modules.stream()
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   158
            .map(Module::getName)
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   159
            .collect(Collectors.toSet());
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   160
        assertTrue(names.contains("m1"));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   161
        assertTrue(names.contains("m2"));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   162
        assertTrue(names.contains("m3"));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   163
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   164
        // findModule
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   165
        Module m1 = layer.findModule("m1").get();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   166
        Module m2 = layer.findModule("m2").get();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   167
        Module m3 = layer.findModule("m3").get();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   168
        assertEquals(m1.getName(), "m1");
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   169
        assertEquals(m2.getName(), "m2");
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   170
        assertEquals(m3.getName(), "m3");
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   171
        assertTrue(m1.getDescriptor() == descriptor1);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   172
        assertTrue(m2.getDescriptor() == descriptor2);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   173
        assertTrue(m3.getDescriptor() == descriptor3);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   174
        assertTrue(m1.getLayer() == layer);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   175
        assertTrue(m2.getLayer() == layer);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   176
        assertTrue(m3.getLayer() == layer);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   177
        assertTrue(modules.contains(m1));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   178
        assertTrue(modules.contains(m2));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   179
        assertTrue(modules.contains(m3));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   180
        assertFalse(layer.findModule("godot").isPresent());
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   181
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   182
        // findLoader
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   183
        assertTrue(layer.findLoader("m1") == loader1);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   184
        assertTrue(layer.findLoader("m2") == loader2);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   185
        assertTrue(layer.findLoader("m3") == loader3);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   186
        try {
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   187
            ClassLoader loader = layer.findLoader("godot");
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   188
            assertTrue(false);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   189
        } catch (IllegalArgumentException ignore) { }
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   190
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   191
        // parents
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   192
        assertTrue(layer.parents().size() == 1);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   193
        assertTrue(layer.parents().get(0) == ModuleLayer.empty());
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   194
    }
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   195
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   196
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   197
    /**
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   198
     * Exercise defineModules, created with boot layer as parent
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   199
     */
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   200
    public void testLayerOnBoot() {
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   201
        ModuleDescriptor descriptor1 = newBuilder("m1")
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   202
                .requires("m2")
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   203
                .requires("java.base")
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   204
                .exports("p1")
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   205
                .build();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   206
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   207
        ModuleDescriptor descriptor2 = newBuilder("m2")
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   208
                .requires("java.base")
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   209
                .build();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   210
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   211
        ModuleFinder finder
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   212
            = ModuleUtils.finderOf(descriptor1, descriptor2);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   213
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   214
        Configuration parent = ModuleLayer.boot().configuration();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   215
        Configuration cf = resolve(parent, finder, "m1");
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   216
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   217
        ClassLoader loader = new ClassLoader() { };
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   218
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   219
        ModuleLayer layer = ModuleLayer.boot().defineModules(cf, mn -> loader);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   220
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   221
        // configuration
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   222
        assertTrue(layer.configuration() == cf);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   223
        assertTrue(layer.configuration().modules().size() == 2);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   224
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   225
        // modules
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   226
        Set<Module> modules = layer.modules();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   227
        assertTrue(modules.size() == 2);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   228
        Set<String> names = modules.stream()
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   229
            .map(Module::getName)
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   230
            .collect(Collectors.toSet());
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   231
        assertTrue(names.contains("m1"));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   232
        assertTrue(names.contains("m2"));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   233
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   234
        // findModule
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   235
        Module m1 = layer.findModule("m1").get();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   236
        Module m2 = layer.findModule("m2").get();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   237
        assertEquals(m1.getName(), "m1");
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   238
        assertEquals(m2.getName(), "m2");
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   239
        assertTrue(m1.getDescriptor() == descriptor1);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   240
        assertTrue(m2.getDescriptor() == descriptor2);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   241
        assertTrue(m1.getLayer() == layer);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   242
        assertTrue(m2.getLayer() == layer);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   243
        assertTrue(modules.contains(m1));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   244
        assertTrue(modules.contains(m2));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   245
        assertTrue(layer.findModule("java.base").get() == Object.class.getModule());
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   246
        assertFalse(layer.findModule("godot").isPresent());
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   247
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   248
        // findLoader
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   249
        assertTrue(layer.findLoader("m1") == loader);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   250
        assertTrue(layer.findLoader("m2") == loader);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   251
        assertTrue(layer.findLoader("java.base") == null);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   252
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   253
        // parents
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   254
        assertTrue(layer.parents().size() == 1);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   255
        assertTrue(layer.parents().get(0) == ModuleLayer.boot());
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   256
    }
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   257
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   258
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   259
    /**
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   260
     * Exercise defineModules with a configuration of two modules that
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   261
     * have the same module-private package.
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   262
     */
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   263
    public void testPackageContainedInSelfAndOther() {
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   264
        ModuleDescriptor descriptor1 =  newBuilder("m1")
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   265
                .requires("m2")
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   266
                .packages(Set.of("p"))
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   267
                .build();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   268
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   269
        ModuleDescriptor descriptor2 = newBuilder("m2")
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   270
                .packages(Set.of("p"))
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   271
                .build();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   272
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   273
        ModuleFinder finder
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   274
            = ModuleUtils.finderOf(descriptor1, descriptor2);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   275
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   276
        Configuration cf = resolve(finder, "m1");
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   277
        assertTrue(cf.modules().size() == 2);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   278
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   279
        // one loader per module, should be okay
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   280
        ModuleLayer.empty().defineModules(cf, mn -> new ClassLoader() { });
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   281
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   282
        // same class loader
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   283
        try {
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   284
            ClassLoader loader = new ClassLoader() { };
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   285
            ModuleLayer.empty().defineModules(cf, mn -> loader);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   286
            assertTrue(false);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   287
        } catch (LayerInstantiationException expected) { }
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   288
    }
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   289
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   290
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   291
    /**
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   292
     * Exercise defineModules with a configuration that is a partitioned
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   293
     * graph. The same package is exported in both partitions.
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   294
     */
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   295
    public void testSameExportInPartitionedGraph() {
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   296
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   297
        // m1 reads m2, m2 exports p to m1
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   298
        ModuleDescriptor descriptor1 =  newBuilder("m1")
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   299
                .requires("m2")
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   300
                .build();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   301
        ModuleDescriptor descriptor2 =  newBuilder("m2")
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   302
                .exports("p", Set.of("m1"))
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   303
                .build();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   304
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   305
        // m3 reads m4, m4 exports p to m3
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   306
        ModuleDescriptor descriptor3 = newBuilder("m3")
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   307
                .requires("m4")
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   308
                .build();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   309
        ModuleDescriptor descriptor4 = newBuilder("m4")
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   310
                .exports("p", Set.of("m3"))
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   311
                .build();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   312
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   313
        ModuleFinder finder
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   314
            = ModuleUtils.finderOf(descriptor1,
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   315
                                   descriptor2,
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   316
                                   descriptor3,
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   317
                                   descriptor4);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   318
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   319
        Configuration cf = resolve(finder, "m1", "m3");
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   320
        assertTrue(cf.modules().size() == 4);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   321
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   322
        // one loader per module
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   323
        ModuleLayer.empty().defineModules(cf, mn -> new ClassLoader() { });
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   324
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   325
        // m1 & m2 in one loader, m3 & m4 in another loader
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   326
        ClassLoader loader1 = new ClassLoader() { };
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   327
        ClassLoader loader2 = new ClassLoader() { };
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   328
        Map<String, ClassLoader> map = new HashMap<>();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   329
        map.put("m1", loader1);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   330
        map.put("m2", loader1);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   331
        map.put("m3", loader2);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   332
        map.put("m4", loader2);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   333
        ModuleLayer.empty().defineModules(cf, map::get);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   334
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   335
        // same loader
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   336
        try {
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   337
            ClassLoader loader = new ClassLoader() { };
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   338
            ModuleLayer.empty().defineModules(cf, mn -> loader);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   339
            assertTrue(false);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   340
        } catch (LayerInstantiationException expected) { }
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   341
    }
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   342
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   343
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   344
    /**
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   345
     * Exercise defineModules with a configuration with a module that
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   346
     * contains a package that is the same name as a non-exported package in
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   347
     * a parent layer.
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   348
     */
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   349
    public void testContainsSamePackageAsBootLayer() {
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   350
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   351
        // check assumption that java.base contains sun.launcher
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   352
        ModuleDescriptor base = Object.class.getModule().getDescriptor();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   353
        assertTrue(base.packages().contains("sun.launcher"));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   354
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   355
        ModuleDescriptor descriptor = newBuilder("m1")
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   356
               .requires("java.base")
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   357
               .packages(Set.of("sun.launcher"))
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   358
               .build();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   359
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   360
        ModuleFinder finder = ModuleUtils.finderOf(descriptor);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   361
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   362
        Configuration parent = ModuleLayer.boot().configuration();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   363
        Configuration cf = parent.resolve(finder, ModuleFinder.of(), Set.of("m1"));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   364
        assertTrue(cf.modules().size() == 1);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   365
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   366
        ClassLoader loader = new ClassLoader() { };
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   367
        ModuleLayer layer = ModuleLayer.boot().defineModules(cf, mn -> loader);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   368
        assertTrue(layer.modules().size() == 1);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   369
   }
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   370
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   371
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   372
    /**
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   373
     * Test layers with implied readability.
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   374
     *
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   375
     * The test consists of three configurations:
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   376
     * - Configuration/layer1: m1, m2 requires transitive m1
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   377
     * - Configuration/layer2: m3 requires m1
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   378
     */
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   379
    public void testImpliedReadabilityWithLayers1() {
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   380
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   381
        // cf1: m1 and m2, m2 requires transitive m1
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   382
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   383
        ModuleDescriptor descriptor1 = newBuilder("m1")
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   384
                .build();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   385
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   386
        ModuleDescriptor descriptor2 = newBuilder("m2")
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   387
                .requires(Set.of(Requires.Modifier.TRANSITIVE), "m1")
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   388
                .build();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   389
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   390
        ModuleFinder finder1 = ModuleUtils.finderOf(descriptor1, descriptor2);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   391
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   392
        Configuration cf1 = resolve(finder1, "m2");
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   393
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   394
        ClassLoader cl1 = new ClassLoader() { };
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   395
        ModuleLayer layer1 = ModuleLayer.empty().defineModules(cf1, mn -> cl1);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   396
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   397
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   398
        // cf2: m3, m3 requires m2
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   399
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   400
        ModuleDescriptor descriptor3 = newBuilder("m3")
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   401
                .requires("m2")
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   402
                .build();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   403
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   404
        ModuleFinder finder2 = ModuleUtils.finderOf(descriptor3);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   405
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   406
        Configuration cf2 = resolve(cf1, finder2, "m3");
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   407
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   408
        ClassLoader cl2 = new ClassLoader() { };
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   409
        ModuleLayer layer2 = layer1.defineModules(cf2, mn -> cl2);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   410
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   411
        assertTrue(layer1.parents().size() == 1);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   412
        assertTrue(layer1.parents().get(0) == ModuleLayer.empty());
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   413
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   414
        assertTrue(layer2.parents().size() == 1);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   415
        assertTrue(layer2.parents().get(0) == layer1);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   416
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   417
        Module m1 = layer2.findModule("m1").get();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   418
        Module m2 = layer2.findModule("m2").get();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   419
        Module m3 = layer2.findModule("m3").get();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   420
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   421
        assertTrue(m1.getLayer() == layer1);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   422
        assertTrue(m2.getLayer() == layer1);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   423
        assertTrue(m3.getLayer() == layer2);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   424
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   425
        assertTrue(m1.getClassLoader() == cl1);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   426
        assertTrue(m2.getClassLoader() == cl1);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   427
        assertTrue(m3.getClassLoader() == cl2);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   428
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   429
        assertTrue(m1.canRead(m1));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   430
        assertFalse(m1.canRead(m2));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   431
        assertFalse(m1.canRead(m3));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   432
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   433
        assertTrue(m2.canRead(m1));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   434
        assertTrue(m2.canRead(m2));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   435
        assertFalse(m2.canRead(m3));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   436
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   437
        assertTrue(m3.canRead(m1));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   438
        assertTrue(m3.canRead(m2));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   439
        assertTrue(m3.canRead(m3));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   440
    }
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   441
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   442
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   443
    /**
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   444
     * Test layers with implied readability.
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   445
     *
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   446
     * The test consists of three configurations:
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   447
     * - Configuration/layer1: m1
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   448
     * - Configuration/layer2: m2 requires transitive m3, m3 requires m2
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   449
     */
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   450
    public void testImpliedReadabilityWithLayers2() {
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   451
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   452
        // cf1: m1
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   453
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   454
        ModuleDescriptor descriptor1 = newBuilder("m1").build();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   455
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   456
        ModuleFinder finder1 = ModuleUtils.finderOf(descriptor1);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   457
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   458
        Configuration cf1 = resolve(finder1, "m1");
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   459
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   460
        ClassLoader cl1 = new ClassLoader() { };
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   461
        ModuleLayer layer1 = ModuleLayer.empty().defineModules(cf1, mn -> cl1);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   462
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   463
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   464
        // cf2: m2, m3: m2 requires transitive m1, m3 requires m2
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   465
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   466
        ModuleDescriptor descriptor2 = newBuilder("m2")
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   467
                .requires(Set.of(Requires.Modifier.TRANSITIVE), "m1")
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   468
                .build();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   469
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   470
        ModuleDescriptor descriptor3 = newBuilder("m3")
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   471
                .requires("m2")
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   472
                .build();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   473
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   474
        ModuleFinder finder2 = ModuleUtils.finderOf(descriptor2, descriptor3);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   475
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   476
        Configuration cf2 = resolve(cf1, finder2, "m3");
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   477
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   478
        ClassLoader cl2 = new ClassLoader() { };
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   479
        ModuleLayer layer2 = layer1.defineModules(cf2, mn -> cl2);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   480
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   481
        assertTrue(layer1.parents().size() == 1);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   482
        assertTrue(layer1.parents().get(0) == ModuleLayer.empty());
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   483
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   484
        assertTrue(layer2.parents().size() == 1);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   485
        assertTrue(layer2.parents().get(0) == layer1);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   486
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   487
        Module m1 = layer2.findModule("m1").get();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   488
        Module m2 = layer2.findModule("m2").get();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   489
        Module m3 = layer2.findModule("m3").get();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   490
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   491
        assertTrue(m1.getLayer() == layer1);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   492
        assertTrue(m2.getLayer() == layer2);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   493
        assertTrue(m3.getLayer() == layer2);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   494
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   495
        assertTrue(m1.canRead(m1));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   496
        assertFalse(m1.canRead(m2));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   497
        assertFalse(m1.canRead(m3));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   498
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   499
        assertTrue(m2.canRead(m1));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   500
        assertTrue(m2.canRead(m2));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   501
        assertFalse(m2.canRead(m3));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   502
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   503
        assertTrue(m3.canRead(m1));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   504
        assertTrue(m3.canRead(m2));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   505
        assertTrue(m3.canRead(m3));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   506
    }
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   507
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   508
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   509
    /**
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   510
     * Test layers with implied readability.
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   511
     *
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   512
     * The test consists of three configurations:
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   513
     * - Configuration/layer1: m1
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   514
     * - Configuration/layer2: m2 requires transitive m1
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   515
     * - Configuration/layer3: m3 requires m1
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   516
     */
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   517
    public void testImpliedReadabilityWithLayers3() {
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   518
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   519
        // cf1: m1
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   520
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   521
        ModuleDescriptor descriptor1 = newBuilder("m1").build();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   522
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   523
        ModuleFinder finder1 = ModuleUtils.finderOf(descriptor1);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   524
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   525
        Configuration cf1 = resolve(finder1, "m1");
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   526
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   527
        ClassLoader cl1 = new ClassLoader() { };
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   528
        ModuleLayer layer1 = ModuleLayer.empty().defineModules(cf1, mn -> cl1);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   529
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   530
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   531
        // cf2: m2 requires transitive m1
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   532
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   533
        ModuleDescriptor descriptor2 = newBuilder("m2")
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   534
                .requires(Set.of(Requires.Modifier.TRANSITIVE), "m1")
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   535
                .build();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   536
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   537
        ModuleFinder finder2 = ModuleUtils.finderOf(descriptor2);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   538
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   539
        Configuration cf2 = resolve(cf1, finder2, "m2");
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   540
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   541
        ClassLoader cl2 = new ClassLoader() { };
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   542
        ModuleLayer layer2 = layer1.defineModules(cf2, mn -> cl2);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   543
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   544
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   545
        // cf3: m3 requires m2
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   546
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   547
        ModuleDescriptor descriptor3 = newBuilder("m3")
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   548
                .requires("m2")
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   549
                .build();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   550
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   551
        ModuleFinder finder3 = ModuleUtils.finderOf(descriptor3);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   552
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   553
        Configuration cf3 = resolve(cf2, finder3, "m3");
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   554
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   555
        ClassLoader cl3 = new ClassLoader() { };
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   556
        ModuleLayer layer3 = layer2.defineModules(cf3, mn -> cl3);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   557
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   558
        assertTrue(layer1.parents().size() == 1);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   559
        assertTrue(layer1.parents().get(0) == ModuleLayer.empty());
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   560
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   561
        assertTrue(layer2.parents().size() == 1);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   562
        assertTrue(layer2.parents().get(0) == layer1);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   563
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   564
        assertTrue(layer3.parents().size() == 1);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   565
        assertTrue(layer3.parents().get(0) == layer2);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   566
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   567
        Module m1 = layer3.findModule("m1").get();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   568
        Module m2 = layer3.findModule("m2").get();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   569
        Module m3 = layer3.findModule("m3").get();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   570
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   571
        assertTrue(m1.getLayer() == layer1);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   572
        assertTrue(m2.getLayer() == layer2);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   573
        assertTrue(m3.getLayer() == layer3);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   574
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   575
        assertTrue(m1.canRead(m1));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   576
        assertFalse(m1.canRead(m2));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   577
        assertFalse(m1.canRead(m3));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   578
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   579
        assertTrue(m2.canRead(m1));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   580
        assertTrue(m2.canRead(m2));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   581
        assertFalse(m2.canRead(m3));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   582
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   583
        assertTrue(m3.canRead(m1));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   584
        assertTrue(m3.canRead(m2));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   585
        assertTrue(m3.canRead(m3));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   586
    }
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   587
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   588
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   589
    /**
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   590
     * Test layers with implied readability.
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   591
     *
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   592
     * The test consists of two configurations:
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   593
     * - Configuration/layer1: m1, m2 requires transitive m1
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   594
     * - Configuration/layer2: m3 requires transitive m2, m4 requires m3
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   595
     */
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   596
    public void testImpliedReadabilityWithLayers4() {
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   597
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   598
        // cf1: m1, m2 requires transitive m1
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   599
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   600
        ModuleDescriptor descriptor1 = newBuilder("m1")
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   601
                .build();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   602
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   603
        ModuleDescriptor descriptor2 = newBuilder("m2")
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   604
                .requires(Set.of(Requires.Modifier.TRANSITIVE), "m1")
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   605
                .build();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   606
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   607
        ModuleFinder finder1 = ModuleUtils.finderOf(descriptor1, descriptor2);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   608
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   609
        Configuration cf1 = resolve(finder1, "m2");
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   610
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   611
        ClassLoader cl1 = new ClassLoader() { };
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   612
        ModuleLayer layer1 = ModuleLayer.empty().defineModules(cf1, mn -> cl1);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   613
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   614
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   615
        // cf2: m3 requires transitive m2, m4 requires m3
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   616
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   617
        ModuleDescriptor descriptor3 = newBuilder("m3")
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   618
                .requires(Set.of(Requires.Modifier.TRANSITIVE), "m2")
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   619
                .build();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   620
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   621
        ModuleDescriptor descriptor4 = newBuilder("m4")
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   622
                .requires("m3")
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   623
                .build();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   624
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   625
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   626
        ModuleFinder finder2 = ModuleUtils.finderOf(descriptor3, descriptor4);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   627
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   628
        Configuration cf2 = resolve(cf1, finder2, "m3", "m4");
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   629
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   630
        ClassLoader cl2 = new ClassLoader() { };
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   631
        ModuleLayer layer2 = layer1.defineModules(cf2, mn -> cl2);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   632
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   633
        assertTrue(layer1.parents().size() == 1);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   634
        assertTrue(layer1.parents().get(0) == ModuleLayer.empty());
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   635
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   636
        assertTrue(layer2.parents().size() == 1);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   637
        assertTrue(layer2.parents().get(0) == layer1);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   638
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   639
        Module m1 = layer2.findModule("m1").get();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   640
        Module m2 = layer2.findModule("m2").get();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   641
        Module m3 = layer2.findModule("m3").get();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   642
        Module m4 = layer2.findModule("m4").get();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   643
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   644
        assertTrue(m1.getLayer() == layer1);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   645
        assertTrue(m2.getLayer() == layer1);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   646
        assertTrue(m3.getLayer() == layer2);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   647
        assertTrue(m4.getLayer() == layer2);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   648
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   649
        assertTrue(m1.canRead(m1));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   650
        assertFalse(m1.canRead(m2));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   651
        assertFalse(m1.canRead(m3));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   652
        assertFalse(m1.canRead(m4));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   653
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   654
        assertTrue(m2.canRead(m1));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   655
        assertTrue(m2.canRead(m2));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   656
        assertFalse(m1.canRead(m3));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   657
        assertFalse(m1.canRead(m4));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   658
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   659
        assertTrue(m3.canRead(m1));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   660
        assertTrue(m3.canRead(m2));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   661
        assertTrue(m3.canRead(m3));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   662
        assertFalse(m3.canRead(m4));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   663
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   664
        assertTrue(m4.canRead(m1));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   665
        assertTrue(m4.canRead(m2));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   666
        assertTrue(m4.canRead(m3));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   667
        assertTrue(m4.canRead(m4));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   668
    }
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   669
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   670
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   671
    /**
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   672
     * Test layers with a qualified export. The module exporting the package
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   673
     * does not read the target module.
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   674
     *
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   675
     * m1 { exports p to m2 }
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   676
     * m2 { }
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   677
     */
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   678
    public void testQualifiedExports1() {
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   679
        ModuleDescriptor descriptor1 = newBuilder("m1").
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   680
                exports("p", Set.of("m2"))
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   681
                .build();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   682
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   683
        ModuleDescriptor descriptor2 = newBuilder("m2")
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   684
                .build();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   685
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   686
        ModuleFinder finder1 = ModuleUtils.finderOf(descriptor1, descriptor2);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   687
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   688
        Configuration cf = resolve(finder1, "m1", "m2");
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   689
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   690
        ClassLoader cl = new ClassLoader() { };
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   691
        ModuleLayer layer = ModuleLayer.empty().defineModules(cf, mn -> cl);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   692
        assertTrue(layer.modules().size() == 2);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   693
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   694
        Module m1 = layer.findModule("m1").get();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   695
        Module m2 = layer.findModule("m2").get();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   696
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   697
        // check m1 exports p to m2
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   698
        assertFalse(m1.isExported("p"));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   699
        assertTrue(m1.isExported("p", m2));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   700
        assertFalse(m1.isOpen("p", m2));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   701
    }
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   702
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   703
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   704
    /**
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   705
     * Test layers with a qualified export. The module exporting the package
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   706
     * reads the target module.
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   707
     *
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   708
     * m1 { exports p to m2; }
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   709
     * m2 { requires m1; }
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   710
     */
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   711
    public void testQualifiedExports2() {
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   712
        ModuleDescriptor descriptor1 = newBuilder("m1")
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   713
                .exports("p", Set.of("m2"))
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   714
                .build();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   715
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   716
        ModuleDescriptor descriptor2 = newBuilder("m2")
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   717
                .requires("m1")
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   718
                .build();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   719
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   720
        ModuleFinder finder1 = ModuleUtils.finderOf(descriptor1, descriptor2);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   721
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   722
        Configuration cf = resolve(finder1, "m2");
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   723
        ClassLoader cl = new ClassLoader() { };
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   724
        ModuleLayer layer = ModuleLayer.empty().defineModules(cf, mn -> cl);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   725
        assertTrue(layer.modules().size() == 2);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   726
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   727
        Module m1 = layer.findModule("m1").get();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   728
        Module m2 = layer.findModule("m2").get();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   729
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   730
        // check m1 exports p to m2
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   731
        assertFalse(m1.isExported("p"));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   732
        assertTrue(m1.isExported("p", m2));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   733
        assertFalse(m1.isOpen("p", m2));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   734
    }
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   735
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   736
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   737
    /**
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   738
     * Test layers with a qualified export. The module exporting the package
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   739
     * does not read the target module in the parent layer.
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   740
     *
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   741
     * - Configuration/layer1: m1 { }
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   742
     * - Configuration/layer2: m2 { exports p to m1; }
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   743
     */
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   744
    public void testQualifiedExports3() {
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   745
        // create layer1 with m1
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   746
        ModuleDescriptor descriptor1 = newBuilder("m1").build();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   747
        ModuleFinder finder1 = ModuleUtils.finderOf(descriptor1);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   748
        Configuration cf1 = resolve(finder1, "m1");
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   749
        ClassLoader cl1 = new ClassLoader() { };
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   750
        ModuleLayer layer1 = ModuleLayer.empty().defineModules(cf1, mn -> cl1);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   751
        assertTrue(layer1.modules().size() == 1);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   752
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   753
        // create layer2 with m2
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   754
        ModuleDescriptor descriptor2 = newBuilder("m2")
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   755
                .exports("p", Set.of("m1"))
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   756
                .build();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   757
        ModuleFinder finder2 = ModuleUtils.finderOf(descriptor2);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   758
        Configuration cf2 = resolve(cf1, finder2, "m2");
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   759
        ClassLoader cl2 = new ClassLoader() { };
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   760
        ModuleLayer layer2 = layer1.defineModules(cf2, mn -> cl2);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   761
        assertTrue(layer2.modules().size() == 1);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   762
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   763
        Module m1 = layer1.findModule("m1").get();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   764
        Module m2 = layer2.findModule("m2").get();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   765
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   766
        // check m2 exports p to layer1/m1
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   767
        assertFalse(m2.isExported("p"));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   768
        assertTrue(m2.isExported("p", m1));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   769
        assertFalse(m2.isOpen("p", m1));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   770
    }
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   771
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   772
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   773
    /**
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   774
     * Test layers with a qualified export. The module exporting the package
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   775
     * reads the target module in the parent layer.
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   776
     *
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   777
     * - Configuration/layer1: m1 { }
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   778
     * - Configuration/layer2: m2 { requires m1; exports p to m1; }
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   779
     */
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   780
    public void testQualifiedExports4() {
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   781
        // create layer1 with m1
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   782
        ModuleDescriptor descriptor1 = newBuilder("m1").build();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   783
        ModuleFinder finder1 = ModuleUtils.finderOf(descriptor1);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   784
        Configuration cf1 = resolve(finder1, "m1");
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   785
        ClassLoader cl1 = new ClassLoader() { };
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   786
        ModuleLayer layer1 = ModuleLayer.empty().defineModules(cf1, mn -> cl1);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   787
        assertTrue(layer1.modules().size() == 1);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   788
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   789
        // create layer2 with m2
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   790
        ModuleDescriptor descriptor2 = newBuilder("m2")
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   791
                .requires("m1")
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   792
                .exports("p", Set.of("m1"))
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   793
                .build();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   794
        ModuleFinder finder2 = ModuleUtils.finderOf(descriptor2);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   795
        Configuration cf2 = resolve(cf1, finder2, "m2");
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   796
        ClassLoader cl2 = new ClassLoader() { };
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   797
        ModuleLayer layer2 = layer1.defineModules(cf2, mn -> cl2);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   798
        assertTrue(layer2.modules().size() == 1);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   799
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   800
        Module m1 = layer1.findModule("m1").get();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   801
        Module m2 = layer2.findModule("m2").get();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   802
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   803
        // check m2 exports p to layer1/m1
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   804
        assertFalse(m2.isExported("p"));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   805
        assertTrue(m2.isExported("p", m1));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   806
        assertFalse(m2.isOpen("p", m1));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   807
    }
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   808
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   809
    /**
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   810
     * Test layers with a qualified export. The module exporting the package
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   811
     * does not read the target module.
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   812
     *
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   813
     * - Configuration/layer1: m1
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   814
     * - Configuration/layer2: m1, m2 { exports p to m1; }
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   815
     */
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   816
    public void testQualifiedExports5() {
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   817
        // create layer1 with m1
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   818
        ModuleDescriptor descriptor1 = newBuilder("m1").build();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   819
        ModuleFinder finder1 = ModuleUtils.finderOf(descriptor1);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   820
        Configuration cf1 = resolve(finder1, "m1");
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   821
        ClassLoader cl1 = new ClassLoader() { };
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   822
        ModuleLayer layer1 = ModuleLayer.empty().defineModules(cf1, mn -> cl1);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   823
        assertTrue(layer1.modules().size() == 1);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   824
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   825
        // create layer2 with m1 and m2
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   826
        ModuleDescriptor descriptor2 = newBuilder("m2").exports("p", Set.of("m1")).build();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   827
        ModuleFinder finder2 = ModuleUtils.finderOf(descriptor1, descriptor2);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   828
        Configuration cf2 = resolve(cf1, finder2, "m1", "m2");
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   829
        ClassLoader cl2 = new ClassLoader() { };
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   830
        ModuleLayer layer2 = layer1.defineModules(cf2, mn -> cl2);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   831
        assertTrue(layer2.modules().size() == 2);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   832
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   833
        Module m1_v1 = layer1.findModule("m1").get();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   834
        Module m1_v2 = layer2.findModule("m1").get();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   835
        Module m2 = layer2.findModule("m2").get();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   836
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   837
        // check m2 exports p to layer2/m2
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   838
        assertFalse(m2.isExported("p"));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   839
        assertTrue(m2.isExported("p", m1_v2));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   840
        assertFalse(m2.isExported("p", m1_v1));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   841
    }
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   842
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   843
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   844
    /**
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   845
     * Test layers with a qualified export. The module exporting the package
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   846
     * reads the target module in the parent layer (due to requires transitive).
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   847
     *
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   848
     * - Configuration/layer1: m1, m2 { requires transitive m1; }
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   849
     * - Configuration/layer2: m1, m3 { requires m2; exports p to m1; }
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   850
     */
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   851
    public void testQualifiedExports6() {
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   852
        // create layer1 with m1 and m2
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   853
        ModuleDescriptor descriptor1 = newBuilder("m1").build();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   854
        ModuleDescriptor descriptor2 = newBuilder("m2")
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   855
                .requires(Set.of(Requires.Modifier.TRANSITIVE), "m1")
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   856
                .build();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   857
        ModuleFinder finder1 = ModuleUtils.finderOf(descriptor1, descriptor2);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   858
        Configuration cf1 = resolve(finder1, "m2");
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   859
        ClassLoader loader1 = new ClassLoader() { };
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   860
        ModuleLayer layer1 = ModuleLayer.empty().defineModules(cf1, mn -> loader1);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   861
        assertTrue(layer1.modules().size() == 2);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   862
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   863
        // create layer2 with m1 and m3
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   864
        ModuleDescriptor descriptor3 = newBuilder("m3")
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   865
                .requires("m2")
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   866
                .exports("p", Set.of("m1"))
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   867
                .build();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   868
        ModuleFinder finder2 = ModuleUtils.finderOf(descriptor1, descriptor3);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   869
        Configuration cf2 = resolve(cf1, finder2, "m1", "m3");
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   870
        ClassLoader loader2 = new ClassLoader() { };
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   871
        ModuleLayer layer2 = layer1.defineModules(cf2, mn -> loader2);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   872
        assertTrue(layer2.modules().size() == 2);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   873
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   874
        Module m1_v1 = layer1.findModule("m1").get();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   875
        Module m2 = layer1.findModule("m2").get();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   876
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   877
        Module m1_v2 = layer2.findModule("m1").get();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   878
        Module m3 = layer2.findModule("m3").get();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   879
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   880
        assertTrue(m3.canRead(m1_v1));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   881
        assertFalse(m3.canRead(m1_v2));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   882
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   883
        assertFalse(m3.isExported("p"));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   884
        assertTrue(m3.isExported("p", m1_v1));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   885
        assertFalse(m3.isExported("p", m1_v2));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   886
        assertFalse(m3.isExported("p", m2));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   887
    }
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   888
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   889
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   890
    /**
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   891
     * Test layers with a qualified export. The target module is not in any layer.
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   892
     *
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   893
     * - Configuration/layer1: m1 { }
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   894
     * - Configuration/layer2: m2 { exports p to m3; }
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   895
     */
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   896
    public void testQualifiedExports7() {
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   897
        // create layer1 with m1
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   898
        ModuleDescriptor descriptor1 = newBuilder("m1").build();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   899
        ModuleFinder finder1 = ModuleUtils.finderOf(descriptor1);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   900
        Configuration cf1 = resolve(finder1, "m1");
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   901
        ClassLoader cl1 = new ClassLoader() { };
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   902
        ModuleLayer layer1 = ModuleLayer.empty().defineModules(cf1, mn -> cl1);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   903
        assertTrue(layer1.modules().size() == 1);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   904
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   905
        // create layer2 with m2
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   906
        ModuleDescriptor descriptor2 = newBuilder("m2")
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   907
                .exports("p", Set.of("m3"))
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   908
                .build();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   909
        ModuleFinder finder2 = ModuleUtils.finderOf(descriptor2);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   910
        Configuration cf2 = resolve(cf1, finder2, "m2");
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   911
        ClassLoader cl2 = new ClassLoader() { };
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   912
        ModuleLayer layer2 = layer1.defineModules(cf2, mn -> cl2);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   913
        assertTrue(layer2.modules().size() == 1);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   914
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   915
        Module m1 = layer1.findModule("m1").get();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   916
        Module m2 = layer2.findModule("m2").get();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   917
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   918
        // check m2 does not export p to anyone
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   919
        assertFalse(m2.isExported("p"));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   920
        assertFalse(m2.isExported("p", m1));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   921
    }
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   922
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   923
    /**
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   924
     * Attempt to use defineModules to create a layer with a module defined
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   925
     * to a class loader that already has a module of the same name defined
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   926
     * to the class loader.
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   927
     */
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   928
    @Test(expectedExceptions = { LayerInstantiationException.class })
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   929
    public void testModuleAlreadyDefinedToLoader() {
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   930
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   931
        ModuleDescriptor md = newBuilder("m")
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   932
                .requires("java.base")
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   933
                .build();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   934
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   935
        ModuleFinder finder = ModuleUtils.finderOf(md);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   936
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   937
        Configuration parent = ModuleLayer.boot().configuration();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   938
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   939
        Configuration cf = parent.resolve(finder, ModuleFinder.of(), Set.of("m"));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   940
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   941
        ClassLoader loader = new ClassLoader() { };
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   942
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   943
        ModuleLayer.boot().defineModules(cf, mn -> loader);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   944
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   945
        // should throw LayerInstantiationException as m1 already defined to loader
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   946
        ModuleLayer.boot().defineModules(cf, mn -> loader);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   947
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   948
    }
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   949
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   950
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   951
    /**
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   952
     * Attempt to use defineModules to create a layer with a module containing
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   953
     * package {@code p} where the class loader already has a module defined
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   954
     * to it containing package {@code p}.
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   955
     */
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   956
    @Test(expectedExceptions = { LayerInstantiationException.class })
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   957
    public void testPackageAlreadyInNamedModule() {
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   958
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   959
        ModuleDescriptor md1 = newBuilder("m1")
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   960
                .packages(Set.of("p"))
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   961
                .requires("java.base")
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   962
                .build();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   963
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   964
        ModuleDescriptor md2 = newBuilder("m2")
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   965
                .packages(Set.of("p"))
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   966
                .requires("java.base")
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   967
                .build();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   968
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   969
        ModuleFinder finder = ModuleUtils.finderOf(md1, md2);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   970
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   971
        ClassLoader loader = new ClassLoader() { };
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   972
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   973
        // define m1 containing package p to class loader
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   974
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   975
        Configuration parent = ModuleLayer.boot().configuration();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   976
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   977
        Configuration cf1 = parent.resolve(finder, ModuleFinder.of(), Set.of("m1"));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   978
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   979
        ModuleLayer layer1 = ModuleLayer.boot().defineModules(cf1, mn -> loader);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   980
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   981
        // attempt to define m2 containing package p to class loader
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   982
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   983
        Configuration cf2 = parent.resolve(finder, ModuleFinder.of(), Set.of("m2"));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   984
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   985
        // should throw exception because p already in m1
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   986
        ModuleLayer layer2 = ModuleLayer.boot().defineModules(cf2, mn -> loader);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   987
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   988
    }
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   989
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   990
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   991
    /**
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   992
     * Attempt to use defineModules to create a layer with a module
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   993
     * containing a package in which a type is already loaded by the class
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   994
     * loader.
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   995
     */
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   996
    @Test(expectedExceptions = { LayerInstantiationException.class })
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   997
    public void testPackageAlreadyInUnnamedModule() throws Exception {
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   998
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
   999
        Class<?> c = layertest.Test.class;
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1000
        assertFalse(c.getModule().isNamed());  // in unnamed module
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1001
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1002
        ModuleDescriptor md = newBuilder("m")
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1003
                .packages(Set.of(c.getPackageName()))
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1004
                .requires("java.base")
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1005
                .build();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1006
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1007
        ModuleFinder finder = ModuleUtils.finderOf(md);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1008
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1009
        Configuration parent = ModuleLayer.boot().configuration();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1010
        Configuration cf = parent.resolve(finder, ModuleFinder.of(), Set.of("m"));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1011
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1012
        ModuleLayer.boot().defineModules(cf, mn -> c.getClassLoader());
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1013
    }
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1014
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1015
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1016
    /**
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1017
     * Attempt to create a layer with a module named "java.base".
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1018
     */
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1019
    public void testLayerWithJavaBase() {
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1020
        ModuleDescriptor descriptor = newBuilder("java.base")
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1021
                .exports("java.lang")
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1022
                .build();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1023
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1024
        ModuleFinder finder = ModuleUtils.finderOf(descriptor);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1025
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1026
        Configuration cf = ModuleLayer.boot()
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1027
            .configuration()
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1028
            .resolve(finder, ModuleFinder.of(), Set.of("java.base"));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1029
        assertTrue(cf.modules().size() == 1);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1030
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1031
        ClassLoader scl = ClassLoader.getSystemClassLoader();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1032
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1033
        try {
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1034
            ModuleLayer.boot().defineModules(cf, mn -> new ClassLoader() { });
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1035
            assertTrue(false);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1036
        } catch (LayerInstantiationException e) { }
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1037
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1038
        try {
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1039
            ModuleLayer.boot().defineModulesWithOneLoader(cf, scl);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1040
            assertTrue(false);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1041
        } catch (LayerInstantiationException e) { }
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1042
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1043
        try {
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1044
            ModuleLayer.boot().defineModulesWithManyLoaders(cf, scl);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1045
            assertTrue(false);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1046
        } catch (LayerInstantiationException e) { }
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1047
    }
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1048
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1049
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1050
    @DataProvider(name = "javaPackages")
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1051
    public Object[][] javaPackages() {
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1052
        return new Object[][] { { "m1", "java" }, { "m2", "java.x" } };
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1053
    }
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1054
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1055
    /**
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1056
     * Attempt to create a layer with a module containing a "java" package.
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1057
     * This should only be allowed when the module is defined to the platform
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1058
     * class loader.
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1059
     */
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1060
    @Test(dataProvider = "javaPackages")
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1061
    public void testLayerWithJavaPackage(String mn, String pn) {
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1062
        ModuleDescriptor descriptor = newBuilder(mn).packages(Set.of(pn)).build();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1063
        ModuleFinder finder = ModuleUtils.finderOf(descriptor);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1064
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1065
        Configuration cf = ModuleLayer.boot()
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1066
                .configuration()
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1067
                .resolve(finder, ModuleFinder.of(), Set.of(mn));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1068
        assertTrue(cf.modules().size() == 1);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1069
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1070
        ClassLoader pcl = ClassLoader.getPlatformClassLoader();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1071
        ClassLoader scl = ClassLoader.getSystemClassLoader();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1072
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1073
        try {
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1074
            ModuleLayer.boot().defineModules(cf, _mn -> new ClassLoader() { });
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1075
            assertTrue(false);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1076
        } catch (LayerInstantiationException e) { }
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1077
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1078
        try {
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1079
            ModuleLayer.boot().defineModulesWithOneLoader(cf, scl);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1080
            assertTrue(false);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1081
        } catch (LayerInstantiationException e) { }
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1082
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1083
        try {
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1084
            ModuleLayer.boot().defineModulesWithManyLoaders(cf, scl);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1085
            assertTrue(false);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1086
        } catch (LayerInstantiationException e) { }
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1087
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1088
        // create layer with module defined to platform class loader
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1089
        ModuleLayer layer = ModuleLayer.boot().defineModules(cf, _mn -> pcl);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1090
        Optional<Module> om = layer.findModule(mn);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1091
        assertTrue(om.isPresent());
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1092
        Module foo = om.get();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1093
        assertTrue(foo.getClassLoader() == pcl);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1094
        assertTrue(foo.getPackages().size() == 1);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1095
        assertTrue(foo.getPackages().iterator().next().equals(pn));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1096
    }
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1097
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1098
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1099
    /**
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1100
     * Attempt to create a layer with a module defined to the boot loader
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1101
     */
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1102
    @Test(expectedExceptions = { LayerInstantiationException.class })
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1103
    public void testLayerWithBootLoader() {
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1104
        ModuleDescriptor descriptor = newBuilder("m1")
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1105
                .build();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1106
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1107
        ModuleFinder finder = ModuleUtils.finderOf(descriptor);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1108
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1109
        Configuration cf = ModuleLayer.boot()
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1110
            .configuration()
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1111
            .resolve(finder, ModuleFinder.of(), Set.of("m1"));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1112
        assertTrue(cf.modules().size() == 1);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1113
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1114
        ModuleLayer.boot().defineModules(cf, mn -> null );
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1115
    }
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1116
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1117
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1118
    /**
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1119
     * Parent of configuration != configuration of parent layer
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1120
     */
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1121
    @Test(expectedExceptions = { IllegalArgumentException.class })
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1122
    public void testIncorrectParent1() {
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1123
        ModuleDescriptor descriptor1 = newBuilder("m1")
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1124
                .requires("java.base")
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1125
                .build();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1126
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1127
        ModuleFinder finder = ModuleUtils.finderOf(descriptor1);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1128
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1129
        Configuration parent = ModuleLayer.boot().configuration();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1130
        Configuration cf = parent.resolve(finder, ModuleFinder.of(), Set.of("m1"));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1131
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1132
        ClassLoader loader = new ClassLoader() { };
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1133
        ModuleLayer.empty().defineModules(cf, mn -> loader);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1134
    }
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1135
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1136
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1137
    /**
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1138
     * Parent of configuration != configuration of parent layer
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1139
     */
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1140
    @Test(expectedExceptions = { IllegalArgumentException.class })
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1141
    public void testIncorrectParent2() {
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1142
        ModuleDescriptor descriptor1 = newBuilder("m1").build();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1143
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1144
        ModuleFinder finder = ModuleUtils.finderOf(descriptor1);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1145
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1146
        Configuration cf = resolve(finder, "m1");
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1147
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1148
        ClassLoader loader = new ClassLoader() { };
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1149
        ModuleLayer.boot().defineModules(cf, mn -> loader);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1150
    }
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1151
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1152
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1153
    // null handling
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1154
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1155
    @Test(expectedExceptions = { NullPointerException.class })
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1156
    public void testCreateWithNull1() {
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1157
        ClassLoader loader = new ClassLoader() { };
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1158
        ModuleLayer.empty().defineModules(null, mn -> loader);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1159
    }
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1160
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1161
    @Test(expectedExceptions = { NullPointerException.class })
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1162
    public void testCreateWithNull2() {
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1163
        Configuration cf = resolve(ModuleLayer.boot().configuration(), ModuleFinder.of());
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1164
        ModuleLayer.boot().defineModules(cf, null);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1165
    }
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1166
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1167
    @Test(expectedExceptions = { NullPointerException.class })
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1168
    public void testCreateWithNull3() {
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1169
        ClassLoader scl = ClassLoader.getSystemClassLoader();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1170
        ModuleLayer.empty().defineModulesWithOneLoader(null, scl);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1171
    }
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1172
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1173
    @Test(expectedExceptions = { NullPointerException.class })
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1174
    public void testCreateWithNull4() {
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1175
        ClassLoader scl = ClassLoader.getSystemClassLoader();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1176
        ModuleLayer.empty().defineModulesWithManyLoaders(null, scl);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1177
    }
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1178
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1179
    @Test(expectedExceptions = { NullPointerException.class })
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1180
    public void testFindModuleWithNull() {
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1181
        ModuleLayer.boot().findModule(null);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1182
    }
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1183
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1184
    @Test(expectedExceptions = { NullPointerException.class })
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1185
    public void testFindLoaderWithNull() {
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1186
        ModuleLayer.boot().findLoader(null);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1187
    }
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1188
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1189
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1190
    // immutable sets
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1191
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1192
    @Test(expectedExceptions = { UnsupportedOperationException.class })
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1193
    public void testImmutableSet() {
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1194
        Module base = Object.class.getModule();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1195
        ModuleLayer.boot().modules().add(base);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1196
    }
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1197
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1198
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1199
    /**
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1200
     * Resolve the given modules, by name, and returns the resulting
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1201
     * Configuration.
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1202
     */
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1203
    private static Configuration resolve(Configuration cf,
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1204
                                         ModuleFinder finder,
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1205
                                         String... roots) {
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1206
        return cf.resolve(finder, ModuleFinder.of(), Set.of(roots));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1207
    }
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1208
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1209
    private static Configuration resolve(ModuleFinder finder,
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1210
                                         String... roots) {
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1211
        return resolve(Configuration.empty(), finder, roots);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1212
    }
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
  1213
}