jdk/test/java/lang/ClassLoader/getResource/modules/Main.java
author alanb
Thu, 01 Dec 2016 08:57:53 +0000
changeset 42338 a60f280f803c
parent 36511 9d0388c6b336
child 44545 83b611b88ac8
permissions -rw-r--r--
8169069: Module system implementation refresh (11/2016) Reviewed-by: plevart, chegar, psandoz, mchung, alanb, dfuchs, naoto, coffeys, weijun Contributed-by: alan.bateman@oracle.com, mandy.chung@oracle.com, claes.redestad@oracle.com, mark.reinhold@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.lang.reflect.Layer;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    28
import java.io.IOException;
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    29
import java.net.URL;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    30
import java.nio.file.Files;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    31
import java.nio.file.Path;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    32
import java.nio.file.Paths;
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    33
import java.util.ArrayList;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    34
import java.util.Enumeration;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    35
import java.util.List;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    36
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    37
/**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    38
 * Basic test of ClassLoader getResource and getResourceAsStream when
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    39
 * invoked from code in named modules.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    40
 */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    41
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    42
public class Main {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    43
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    44
    static final String NAME = "myresource";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    45
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    46
    public static void main(String[] args) throws IOException {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    47
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    48
        // create resources in m1
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    49
        createResource("m1", Paths.get("."), "m1");
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    50
        createResource("m1", Paths.get("p1"), "m1/p1");
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    51
        createResource("m1", Paths.get("p1", "impl"), "m1/p1.impl");
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    52
        createResource("m1", Paths.get("p1", "resources"), "m1/p1.resources");
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    53
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    54
        // create resources in m2
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    55
        createResource("m2", Paths.get("."), "m2");
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    56
        createResource("m2", Paths.get("p2"), "m2/p2");
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    57
        createResource("m2", Paths.get("p2", "impl"), "m2/p2.impl");
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    58
        createResource("m2", Paths.get("p2", "resources"), "m2/p2.resources");
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    59
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    60
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    61
        // invoke ClassLoader getResource from the unnamed module
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    62
        ClassLoader thisLoader = Main.class.getClassLoader();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    63
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    64
        URL url = thisLoader.getResource(NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    65
        assertNotNull(url);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    66
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    67
        url = thisLoader.getResource("p1/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    68
        assertNull(url);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    69
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    70
        url = thisLoader.getResource("p1/impl/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    71
        assertNull(url);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    72
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    73
        url = thisLoader.getResource("p1/resources/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    74
        assertEquals(readAllAsString(url), "m1/p1.resources");
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    75
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    76
        url = thisLoader.getResource("p2/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    77
        assertNull(url);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    78
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    79
        url = thisLoader.getResource("p2/impl/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    80
        assertNull(url);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    81
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    82
        url = thisLoader.getResource("p2/resources/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    83
        assertNull(url);
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
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    86
        // invoke ClassLoader getResource from module m1
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    87
        url = p1.Main.getResourceInClassLoader(NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    88
        assertNotNull(url);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    89
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    90
        url = p1.Main.getResourceInClassLoader("p1/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    91
        assertNull(url);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    92
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    93
        url = p1.Main.getResourceInClassLoader("p1/impl/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    94
        assertNull(url);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    95
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    96
        url = p1.Main.getResourceInClassLoader("p1/resources/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    97
        assertEquals(readAllAsString(url), "m1/p1.resources");
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    98
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    99
        url = p1.Main.getResourceInClassLoader("p2/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   100
        assertNull(url);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   101
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   102
        url = p1.Main.getResourceInClassLoader("p2/impl/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   103
        assertNull(url);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   104
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   105
        url = p1.Main.getResourceInClassLoader("p2/resources/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   106
        assertNull(url);
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
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   109
        // invoke ClassLoader getResource from module m2
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   110
        url = p2.Main.getResourceInClassLoader(NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   111
        assertNotNull(url);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   112
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   113
        url = p2.Main.getResourceInClassLoader("p1/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   114
        assertNull(url);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   115
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   116
        url = p2.Main.getResourceInClassLoader("p1/impl/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   117
        assertNull(url);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   118
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   119
        url = p2.Main.getResourceInClassLoader("p1/resources/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   120
        assertEquals(readAllAsString(url), "m1/p1.resources");
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   121
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   122
        url = p2.Main.getResourceInClassLoader("p2/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   123
        assertNull(url);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   124
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   125
        url = p2.Main.getResourceInClassLoader("p2/impl/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   126
        assertNull(url);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   127
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   128
        url = p2.Main.getResourceInClassLoader("p2/resources/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   129
        assertNull(url);
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
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   132
        // invoke ClassLoader getResources from the unnamed module
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   133
        Enumeration<URL> urls = thisLoader.getResources(NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   134
        List<String> resources = readAllAsStrings(urls);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   135
        assertTrue(resources.size() == 2);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   136
        assertTrue(resources.contains("m1"));
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   137
        assertTrue(resources.contains("m2"));
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   138
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   139
        urls = thisLoader.getResources("p1/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   140
        assertTrue(readAllAsStrings(urls).isEmpty());
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   141
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   142
        urls = thisLoader.getResources("p1/impl/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   143
        assertTrue(readAllAsStrings(urls).isEmpty());
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   144
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   145
        urls = thisLoader.getResources("p1/resources/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   146
        resources = readAllAsStrings(urls);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   147
        assertTrue(resources.size() == 1);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   148
        assertTrue(resources.contains("m1/p1.resources"));
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   149
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   150
        urls = thisLoader.getResources("p2/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   151
        assertTrue(readAllAsStrings(urls).isEmpty());
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   152
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   153
        urls = thisLoader.getResources("p2/impl/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   154
        assertTrue(readAllAsStrings(urls).isEmpty());
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   155
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   156
        urls = thisLoader.getResources("p2/resources/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   157
        assertTrue(readAllAsStrings(urls).isEmpty());
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
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   160
        // invoke ClassLoader getResources from m1
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   161
        urls = p1.Main.getResourcesInClassLoader(NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   162
        resources = readAllAsStrings(urls);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   163
        assertTrue(resources.size() == 2);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   164
        assertTrue(resources.contains("m1"));
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   165
        assertTrue(resources.contains("m2"));
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   166
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   167
        urls = p1.Main.getResourcesInClassLoader("p1/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   168
        assertTrue(readAllAsStrings(urls).isEmpty());
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   169
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   170
        urls = p1.Main.getResourcesInClassLoader("p1/impl/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   171
        assertTrue(readAllAsStrings(urls).isEmpty());
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   172
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   173
        urls = p1.Main.getResourcesInClassLoader("p1/resources/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   174
        resources = readAllAsStrings(urls);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   175
        assertTrue(resources.size() == 1);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   176
        assertTrue(resources.contains("m1/p1.resources"));
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   177
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   178
        urls = p1.Main.getResourcesInClassLoader("p2/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   179
        assertTrue(readAllAsStrings(urls).isEmpty());
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   180
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   181
        urls = p1.Main.getResourcesInClassLoader("p2/impl/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   182
        assertTrue(readAllAsStrings(urls).isEmpty());
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   183
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   184
        urls = p1.Main.getResourcesInClassLoader("p2/resources/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   185
        assertTrue(readAllAsStrings(urls).isEmpty());
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
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   188
        // invoke ClassLoader getResources from m2
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   189
        urls = p2.Main.getResourcesInClassLoader(NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   190
        resources = readAllAsStrings(urls);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   191
        assertTrue(resources.size() == 2);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   192
        assertTrue(resources.contains("m1"));
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   193
        assertTrue(resources.contains("m2"));
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   194
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   195
        urls = p2.Main.getResourcesInClassLoader("p1/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   196
        assertTrue(readAllAsStrings(urls).isEmpty());
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   197
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   198
        urls = p2.Main.getResourcesInClassLoader("p1/impl/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   199
        assertTrue(readAllAsStrings(urls).isEmpty());
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   200
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   201
        urls = p2.Main.getResourcesInClassLoader("p1/resources/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   202
        resources = readAllAsStrings(urls);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   203
        assertTrue(resources.size() == 1);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   204
        assertTrue(resources.contains("m1/p1.resources"));
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   205
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   206
        urls = p2.Main.getResourcesInClassLoader("p2/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   207
        assertTrue(readAllAsStrings(urls).isEmpty());
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   208
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   209
        urls = p2.Main.getResourcesInClassLoader("p2/impl/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   210
        assertTrue(readAllAsStrings(urls).isEmpty());
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   211
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   212
        urls = p2.Main.getResourcesInClassLoader("p2/resources/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   213
        assertTrue(readAllAsStrings(urls).isEmpty());
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   214
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   215
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   216
        // invoke ClassLoader getResourceAsStream from the unnamed module
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   217
        InputStream in = thisLoader.getResourceAsStream(NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   218
        assertNotNull(in);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   219
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   220
        in = thisLoader.getResourceAsStream("p1/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   221
        assertNull(in);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   222
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   223
        in = thisLoader.getResourceAsStream("p1/impl/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   224
        assertNull(in);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   225
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   226
        in = thisLoader.getResourceAsStream("p1/resources/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   227
        assertEquals(readAllAsString(in), "m1/p1.resources");
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   228
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   229
        in = thisLoader.getResourceAsStream("p2/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   230
        assertNull(in);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   231
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   232
        in = thisLoader.getResourceAsStream("p2/impl/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   233
        assertNull(in);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   234
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   235
        in = thisLoader.getResourceAsStream("p2/resources/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   236
        assertNull(in);
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
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   239
        // invoke ClassLoader getResource from modules m1
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   240
        in = p1.Main.getResourceAsStreamInClassLoader(NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   241
        assertNotNull(in);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   242
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   243
        in = p1.Main.getResourceAsStreamInClassLoader("p1/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   244
        assertNull(in);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   245
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   246
        in = p1.Main.getResourceAsStreamInClassLoader("p1/impl/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   247
        assertNull(in);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   248
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   249
        in = p1.Main.getResourceAsStreamInClassLoader("p1/resources/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   250
        assertEquals(readAllAsString(in), "m1/p1.resources");
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   251
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   252
        in = p1.Main.getResourceAsStreamInClassLoader("p2/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   253
        assertNull(in);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   254
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   255
        in = p1.Main.getResourceAsStreamInClassLoader("p2/impl/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   256
        assertNull(in);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   257
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   258
        in = p1.Main.getResourceAsStreamInClassLoader("p2/resources/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   259
        assertNull(in);
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
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   262
        // invoke ClassLoader getResource from modules m2
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   263
        in = p2.Main.getResourceAsStreamInClassLoader(NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   264
        assertNotNull(in);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   265
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   266
        in = p2.Main.getResourceAsStreamInClassLoader("p1/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   267
        assertNull(in);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   268
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   269
        in = p2.Main.getResourceAsStreamInClassLoader("p1/impl/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   270
        assertNull(in);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   271
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   272
        in = p2.Main.getResourceAsStreamInClassLoader("p1/resources/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   273
        assertEquals(readAllAsString(in), "m1/p1.resources");
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   274
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   275
        in = p2.Main.getResourceAsStreamInClassLoader("p2/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   276
        assertNull(in);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   277
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   278
        in = p2.Main.getResourceAsStreamInClassLoader("p2/impl/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   279
        assertNull(in);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   280
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   281
        in = p2.Main.getResourceAsStreamInClassLoader("p2/resources/" + NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   282
        assertNull(in);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   283
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   284
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   285
        // SecurityManager case
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   286
        System.setSecurityManager(new SecurityManager());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   287
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   288
        assertNull(Main.class.getClassLoader().getResource("/" + NAME));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   289
        assertNull(p1.Main.getResourceInClassLoader("/" + NAME));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   290
        assertNull(p2.Main.getResourceInClassLoader("/" + NAME));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   291
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   292
        assertNull(Main.class.getClassLoader().getResourceAsStream("/" + NAME));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   293
        assertNull(p1.Main.getResourceAsStreamInClassLoader("/" + NAME));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   294
        assertNull(p2.Main.getResourceAsStreamInClassLoader("/" + NAME));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   295
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   296
        System.out.println("Success!");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   297
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   298
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   299
    /**
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   300
     * 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
   301
     */
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   302
    static void createResource(String mn, Path subdir, String msg) throws IOException {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   303
        Path dir = directoryFor(mn).resolve(subdir);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   304
        Path file = dir.resolve(NAME);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   305
        Files.write(file, msg.getBytes("UTF-8"));
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
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   308
    /**
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   309
     * Returns the directory for the given module (by name).
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   310
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   311
    static Path directoryFor(String mn) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   312
        Configuration cf = Layer.boot().configuration();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   313
        ResolvedModule resolvedModule = cf.findModule(mn).orElse(null);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   314
        if (resolvedModule == null)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   315
            throw new RuntimeException("not found: " + mn);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   316
        Path dir = Paths.get(resolvedModule.reference().location().get());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   317
        if (!Files.isDirectory(dir))
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   318
            throw new RuntimeException("not a directory: " + dir);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   319
        return dir;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   320
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   321
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   322
    static String readAllAsString(InputStream in) throws IOException {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   323
        if (in == null)
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   324
            return null;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   325
        try (in) {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   326
            return new String(in.readAllBytes(), "UTF-8");
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
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   330
    static String readAllAsString(URL url) throws IOException {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   331
        if (url == null)
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   332
            return null;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   333
        InputStream in = url.openStream();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   334
        return readAllAsString(url.openStream());
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
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   337
    static List<String> readAllAsStrings(Enumeration<URL> urls) throws IOException {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   338
        List<String> result = new ArrayList<>();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   339
        while (urls.hasMoreElements()) {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   340
            URL url = urls.nextElement();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   341
            result.add(readAllAsString(url));
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   342
        }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   343
        return result;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   344
    }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   345
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   346
    static void assertTrue(boolean condition) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   347
        if (!condition) throw new RuntimeException();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   348
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   349
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   350
    static void assertFalse(boolean condition) {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   351
        if (condition) throw new RuntimeException();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   352
    }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   353
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   354
    static void assertNull(Object o) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   355
        assertTrue(o == null);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   356
    }
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   357
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   358
    static void assertNotNull(Object o) {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   359
        assertTrue(o != null);
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
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   362
    static void assertEquals(Object actual, Object expected) {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   363
        if (expected == null) {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   364
            assertNull(actual);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   365
        } else {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   366
            assertTrue(expected.equals(actual));
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
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   370
    static void assertNotEquals(Object actual, Object expected) {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   371
        if (expected == null) {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   372
            assertNotNull(actual);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   373
        } else {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   374
            assertTrue(!expected.equals(actual));
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   375
        }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
   376
    }
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   377
}
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   378