jdk/test/java/lang/ClassLoader/getResource/modules/Main.java
author alanb
Fri, 07 Apr 2017 08:05:54 +0000
changeset 44545 83b611b88ac8
parent 42338 a60f280f803c
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:
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     1
/*
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     2
 * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     4
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     7
 * published by the Free Software Foundation.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     8
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    13
 * accompanied this code).
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    14
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    18
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    21
 * questions.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    22
 */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    23
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    24
import java.io.InputStream;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    25
import java.lang.module.Configuration;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    26
import java.lang.module.ResolvedModule;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    27
import java.io.IOException;
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    28
import java.net.URL;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    29
import java.nio.file.Files;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    30
import java.nio.file.Path;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    31
import java.nio.file.Paths;
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    32
import java.util.ArrayList;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    33
import java.util.Enumeration;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    34
import java.util.List;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    35
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    36
/**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    37
 * Basic test of ClassLoader getResource and getResourceAsStream when
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    38
 * invoked from code in named modules.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    39
 */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    40
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    41
public class Main {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    42
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    43
    static final String NAME = "myresource";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    44
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    45
    public static void main(String[] args) throws IOException {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    46
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    47
        // create resources in m1
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    48
        createResource("m1", Paths.get("."), "m1");
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    49
        createResource("m1", Paths.get("p1"), "m1/p1");
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    50
        createResource("m1", Paths.get("p1", "impl"), "m1/p1.impl");
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    51
        createResource("m1", Paths.get("p1", "resources"), "m1/p1.resources");
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    52
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    53
        // create resources in m2
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    54
        createResource("m2", Paths.get("."), "m2");
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    55
        createResource("m2", Paths.get("p2"), "m2/p2");
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    56
        createResource("m2", Paths.get("p2", "impl"), "m2/p2.impl");
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    57
        createResource("m2", Paths.get("p2", "resources"), "m2/p2.resources");
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    58
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    59
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    60
        // invoke ClassLoader getResource from the unnamed module
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    61
        ClassLoader thisLoader = Main.class.getClassLoader();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    62
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    63
        URL url = thisLoader.getResource(NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    64
        assertNotNull(url);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    65
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    66
        url = thisLoader.getResource("p1/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    67
        assertNull(url);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    68
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    69
        url = thisLoader.getResource("p1/impl/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    70
        assertNull(url);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    71
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    72
        url = thisLoader.getResource("p1/resources/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    73
        assertEquals(readAllAsString(url), "m1/p1.resources");
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    74
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    75
        url = thisLoader.getResource("p2/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    76
        assertNull(url);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    77
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    78
        url = thisLoader.getResource("p2/impl/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    79
        assertNull(url);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    80
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    81
        url = thisLoader.getResource("p2/resources/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    82
        assertNull(url);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    83
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    84
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    85
        // invoke ClassLoader getResource from module m1
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    86
        url = p1.Main.getResourceInClassLoader(NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    87
        assertNotNull(url);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    88
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    89
        url = p1.Main.getResourceInClassLoader("p1/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    90
        assertNull(url);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    91
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    92
        url = p1.Main.getResourceInClassLoader("p1/impl/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    93
        assertNull(url);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    94
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    95
        url = p1.Main.getResourceInClassLoader("p1/resources/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    96
        assertEquals(readAllAsString(url), "m1/p1.resources");
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    97
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    98
        url = p1.Main.getResourceInClassLoader("p2/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    99
        assertNull(url);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   100
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   101
        url = p1.Main.getResourceInClassLoader("p2/impl/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   102
        assertNull(url);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   103
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   104
        url = p1.Main.getResourceInClassLoader("p2/resources/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   105
        assertNull(url);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   106
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   107
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   108
        // invoke ClassLoader getResource from module m2
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   109
        url = p2.Main.getResourceInClassLoader(NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   110
        assertNotNull(url);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   111
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   112
        url = p2.Main.getResourceInClassLoader("p1/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   113
        assertNull(url);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   114
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   115
        url = p2.Main.getResourceInClassLoader("p1/impl/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   116
        assertNull(url);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   117
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   118
        url = p2.Main.getResourceInClassLoader("p1/resources/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   119
        assertEquals(readAllAsString(url), "m1/p1.resources");
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   120
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   121
        url = p2.Main.getResourceInClassLoader("p2/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   122
        assertNull(url);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   123
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   124
        url = p2.Main.getResourceInClassLoader("p2/impl/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   125
        assertNull(url);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   126
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   127
        url = p2.Main.getResourceInClassLoader("p2/resources/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   128
        assertNull(url);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   129
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   130
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   131
        // invoke ClassLoader getResources from the unnamed module
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   132
        Enumeration<URL> urls = thisLoader.getResources(NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   133
        List<String> resources = readAllAsStrings(urls);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   134
        assertTrue(resources.size() == 2);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   135
        assertTrue(resources.contains("m1"));
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   136
        assertTrue(resources.contains("m2"));
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   137
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   138
        urls = thisLoader.getResources("p1/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   139
        assertTrue(readAllAsStrings(urls).isEmpty());
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   140
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   141
        urls = thisLoader.getResources("p1/impl/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   142
        assertTrue(readAllAsStrings(urls).isEmpty());
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   143
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   144
        urls = thisLoader.getResources("p1/resources/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   145
        resources = readAllAsStrings(urls);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   146
        assertTrue(resources.size() == 1);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   147
        assertTrue(resources.contains("m1/p1.resources"));
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   148
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   149
        urls = thisLoader.getResources("p2/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   150
        assertTrue(readAllAsStrings(urls).isEmpty());
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   151
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   152
        urls = thisLoader.getResources("p2/impl/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   153
        assertTrue(readAllAsStrings(urls).isEmpty());
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   154
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   155
        urls = thisLoader.getResources("p2/resources/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   156
        assertTrue(readAllAsStrings(urls).isEmpty());
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   157
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   158
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   159
        // invoke ClassLoader getResources from m1
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   160
        urls = p1.Main.getResourcesInClassLoader(NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   161
        resources = readAllAsStrings(urls);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   162
        assertTrue(resources.size() == 2);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   163
        assertTrue(resources.contains("m1"));
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   164
        assertTrue(resources.contains("m2"));
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   165
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   166
        urls = p1.Main.getResourcesInClassLoader("p1/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   167
        assertTrue(readAllAsStrings(urls).isEmpty());
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   168
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   169
        urls = p1.Main.getResourcesInClassLoader("p1/impl/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   170
        assertTrue(readAllAsStrings(urls).isEmpty());
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   171
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   172
        urls = p1.Main.getResourcesInClassLoader("p1/resources/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   173
        resources = readAllAsStrings(urls);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   174
        assertTrue(resources.size() == 1);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   175
        assertTrue(resources.contains("m1/p1.resources"));
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   176
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   177
        urls = p1.Main.getResourcesInClassLoader("p2/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   178
        assertTrue(readAllAsStrings(urls).isEmpty());
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   179
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   180
        urls = p1.Main.getResourcesInClassLoader("p2/impl/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   181
        assertTrue(readAllAsStrings(urls).isEmpty());
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   182
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   183
        urls = p1.Main.getResourcesInClassLoader("p2/resources/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   184
        assertTrue(readAllAsStrings(urls).isEmpty());
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   185
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   186
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   187
        // invoke ClassLoader getResources from m2
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   188
        urls = p2.Main.getResourcesInClassLoader(NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   189
        resources = readAllAsStrings(urls);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   190
        assertTrue(resources.size() == 2);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   191
        assertTrue(resources.contains("m1"));
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   192
        assertTrue(resources.contains("m2"));
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   193
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   194
        urls = p2.Main.getResourcesInClassLoader("p1/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   195
        assertTrue(readAllAsStrings(urls).isEmpty());
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   196
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   197
        urls = p2.Main.getResourcesInClassLoader("p1/impl/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   198
        assertTrue(readAllAsStrings(urls).isEmpty());
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   199
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   200
        urls = p2.Main.getResourcesInClassLoader("p1/resources/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   201
        resources = readAllAsStrings(urls);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   202
        assertTrue(resources.size() == 1);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   203
        assertTrue(resources.contains("m1/p1.resources"));
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   204
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   205
        urls = p2.Main.getResourcesInClassLoader("p2/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   206
        assertTrue(readAllAsStrings(urls).isEmpty());
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   207
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   208
        urls = p2.Main.getResourcesInClassLoader("p2/impl/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   209
        assertTrue(readAllAsStrings(urls).isEmpty());
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   210
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   211
        urls = p2.Main.getResourcesInClassLoader("p2/resources/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   212
        assertTrue(readAllAsStrings(urls).isEmpty());
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   213
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   214
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   215
        // invoke ClassLoader getResourceAsStream from the unnamed module
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   216
        InputStream in = thisLoader.getResourceAsStream(NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   217
        assertNotNull(in);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   218
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   219
        in = thisLoader.getResourceAsStream("p1/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   220
        assertNull(in);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   221
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   222
        in = thisLoader.getResourceAsStream("p1/impl/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   223
        assertNull(in);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   224
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   225
        in = thisLoader.getResourceAsStream("p1/resources/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   226
        assertEquals(readAllAsString(in), "m1/p1.resources");
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   227
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   228
        in = thisLoader.getResourceAsStream("p2/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   229
        assertNull(in);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   230
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   231
        in = thisLoader.getResourceAsStream("p2/impl/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   232
        assertNull(in);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   233
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   234
        in = thisLoader.getResourceAsStream("p2/resources/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   235
        assertNull(in);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   236
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   237
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   238
        // invoke ClassLoader getResource from modules m1
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   239
        in = p1.Main.getResourceAsStreamInClassLoader(NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   240
        assertNotNull(in);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   241
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   242
        in = p1.Main.getResourceAsStreamInClassLoader("p1/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   243
        assertNull(in);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   244
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   245
        in = p1.Main.getResourceAsStreamInClassLoader("p1/impl/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   246
        assertNull(in);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   247
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   248
        in = p1.Main.getResourceAsStreamInClassLoader("p1/resources/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   249
        assertEquals(readAllAsString(in), "m1/p1.resources");
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   250
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   251
        in = p1.Main.getResourceAsStreamInClassLoader("p2/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   252
        assertNull(in);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   253
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   254
        in = p1.Main.getResourceAsStreamInClassLoader("p2/impl/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   255
        assertNull(in);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   256
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   257
        in = p1.Main.getResourceAsStreamInClassLoader("p2/resources/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   258
        assertNull(in);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   259
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   260
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   261
        // invoke ClassLoader getResource from modules m2
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   262
        in = p2.Main.getResourceAsStreamInClassLoader(NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   263
        assertNotNull(in);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   264
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   265
        in = p2.Main.getResourceAsStreamInClassLoader("p1/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   266
        assertNull(in);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   267
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   268
        in = p2.Main.getResourceAsStreamInClassLoader("p1/impl/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   269
        assertNull(in);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   270
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   271
        in = p2.Main.getResourceAsStreamInClassLoader("p1/resources/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   272
        assertEquals(readAllAsString(in), "m1/p1.resources");
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   273
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   274
        in = p2.Main.getResourceAsStreamInClassLoader("p2/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   275
        assertNull(in);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   276
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   277
        in = p2.Main.getResourceAsStreamInClassLoader("p2/impl/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   278
        assertNull(in);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   279
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   280
        in = p2.Main.getResourceAsStreamInClassLoader("p2/resources/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   281
        assertNull(in);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   282
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   283
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   284
        // SecurityManager case
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   285
        System.setSecurityManager(new SecurityManager());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   286
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   287
        assertNull(Main.class.getClassLoader().getResource("/" + NAME));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   288
        assertNull(p1.Main.getResourceInClassLoader("/" + NAME));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   289
        assertNull(p2.Main.getResourceInClassLoader("/" + NAME));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   290
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   291
        assertNull(Main.class.getClassLoader().getResourceAsStream("/" + NAME));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   292
        assertNull(p1.Main.getResourceAsStreamInClassLoader("/" + NAME));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   293
        assertNull(p2.Main.getResourceAsStreamInClassLoader("/" + NAME));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   294
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   295
        System.out.println("Success!");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   296
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   297
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   298
    /**
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   299
     * Create a resource in the sub-directory of the given exploded module
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   300
     */
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   301
    static void createResource(String mn, Path subdir, String msg) throws IOException {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   302
        Path dir = directoryFor(mn).resolve(subdir);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   303
        Path file = dir.resolve(NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   304
        Files.write(file, msg.getBytes("UTF-8"));
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   305
    }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   306
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   307
    /**
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   308
     * Returns the directory for the given module (by name).
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   309
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   310
    static Path directoryFor(String mn) {
44545
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 42338
diff changeset
   311
        Configuration cf = ModuleLayer.boot().configuration();
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   312
        ResolvedModule resolvedModule = cf.findModule(mn).orElse(null);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   313
        if (resolvedModule == null)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   314
            throw new RuntimeException("not found: " + mn);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   315
        Path dir = Paths.get(resolvedModule.reference().location().get());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   316
        if (!Files.isDirectory(dir))
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   317
            throw new RuntimeException("not a directory: " + dir);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   318
        return dir;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   319
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   320
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   321
    static String readAllAsString(InputStream in) throws IOException {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   322
        if (in == null)
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   323
            return null;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   324
        try (in) {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   325
            return new String(in.readAllBytes(), "UTF-8");
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   326
        }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   327
    }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   328
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   329
    static String readAllAsString(URL url) throws IOException {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   330
        if (url == null)
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   331
            return null;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   332
        InputStream in = url.openStream();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   333
        return readAllAsString(url.openStream());
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   334
    }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   335
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   336
    static List<String> readAllAsStrings(Enumeration<URL> urls) throws IOException {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   337
        List<String> result = new ArrayList<>();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   338
        while (urls.hasMoreElements()) {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   339
            URL url = urls.nextElement();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   340
            result.add(readAllAsString(url));
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   341
        }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   342
        return result;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   343
    }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   344
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   345
    static void assertTrue(boolean condition) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   346
        if (!condition) throw new RuntimeException();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   347
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   348
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   349
    static void assertFalse(boolean condition) {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   350
        if (condition) throw new RuntimeException();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   351
    }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   352
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   353
    static void assertNull(Object o) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   354
        assertTrue(o == null);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   355
    }
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   356
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   357
    static void assertNotNull(Object o) {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   358
        assertTrue(o != null);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   359
    }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   360
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   361
    static void assertEquals(Object actual, Object expected) {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   362
        if (expected == null) {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   363
            assertNull(actual);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   364
        } else {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   365
            assertTrue(expected.equals(actual));
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   366
        }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   367
    }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   368
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   369
    static void assertNotEquals(Object actual, Object expected) {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   370
        if (expected == null) {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   371
            assertNotNull(actual);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   372
        } else {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   373
            assertTrue(!expected.equals(actual));
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   374
        }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   375
    }
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   376
}
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   377