test/jdk/jdk/modules/incubator/TestBootLayer.java
author alanb
Tue, 19 Nov 2019 11:35:29 +0000
changeset 59133 580fb715b29d
permissions -rw-r--r--
8233922: Service binding augments module graph with observable incubator modules Reviewed-by: mchung
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
59133
580fb715b29d 8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff changeset
     1
/*
580fb715b29d 8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff changeset
     2
 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
580fb715b29d 8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
580fb715b29d 8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff changeset
     4
 *
580fb715b29d 8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
580fb715b29d 8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
580fb715b29d 8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff changeset
     7
 * published by the Free Software Foundation.
580fb715b29d 8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff changeset
     8
 *
580fb715b29d 8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
580fb715b29d 8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
580fb715b29d 8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
580fb715b29d 8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
580fb715b29d 8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff changeset
    13
 * accompanied this code).
580fb715b29d 8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff changeset
    14
 *
580fb715b29d 8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
580fb715b29d 8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
580fb715b29d 8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
580fb715b29d 8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff changeset
    18
 *
580fb715b29d 8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
580fb715b29d 8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
580fb715b29d 8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff changeset
    21
 * questions.
580fb715b29d 8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff changeset
    22
 */
580fb715b29d 8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff changeset
    23
580fb715b29d 8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff changeset
    24
import java.util.Set;
580fb715b29d 8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff changeset
    25
import java.util.function.Predicate;
580fb715b29d 8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff changeset
    26
import java.util.regex.Pattern;
580fb715b29d 8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff changeset
    27
import java.util.stream.Collectors;
580fb715b29d 8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff changeset
    28
580fb715b29d 8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff changeset
    29
/**
580fb715b29d 8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff changeset
    30
 * Launched by the test ServiceBinding to test modules in the boot layer.
580fb715b29d 8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff changeset
    31
 */
580fb715b29d 8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff changeset
    32
580fb715b29d 8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff changeset
    33
public class TestBootLayer {
580fb715b29d 8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff changeset
    34
    public static void main(String[] args) throws Exception {
580fb715b29d 8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff changeset
    35
        Pattern splitter = Pattern.compile(",");
580fb715b29d 8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff changeset
    36
580fb715b29d 8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff changeset
    37
        // the names of all modules in the boot layer
580fb715b29d 8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff changeset
    38
        Set<String> modules = ModuleLayer.boot().modules().stream()
580fb715b29d 8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff changeset
    39
                .map(Module::getName)
580fb715b29d 8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff changeset
    40
                .collect(Collectors.toSet());
580fb715b29d 8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff changeset
    41
580fb715b29d 8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff changeset
    42
        // throw exception if an expected module is not in the boot layer
580fb715b29d 8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff changeset
    43
        splitter.splitAsStream(args[0])
580fb715b29d 8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff changeset
    44
                .filter(Predicate.not(String::isEmpty))
580fb715b29d 8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff changeset
    45
                .filter(mn -> !modules.contains(mn))
580fb715b29d 8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff changeset
    46
                .findAny()
580fb715b29d 8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff changeset
    47
                .ifPresent(mn -> {
580fb715b29d 8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff changeset
    48
                    throw new RuntimeException(mn + " not in boot layer!!!");
580fb715b29d 8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff changeset
    49
                });
580fb715b29d 8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff changeset
    50
580fb715b29d 8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff changeset
    51
        // throw exception if an unexpected module is in the boot layer
580fb715b29d 8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff changeset
    52
        splitter.splitAsStream(args[1])
580fb715b29d 8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff changeset
    53
                .filter(Predicate.not(String::isEmpty))
580fb715b29d 8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff changeset
    54
                .filter(mn -> modules.contains(mn))
580fb715b29d 8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff changeset
    55
                .findAny()
580fb715b29d 8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff changeset
    56
                .ifPresent(mn -> {
580fb715b29d 8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff changeset
    57
                    throw new RuntimeException(mn + " in boot layer!!!!");
580fb715b29d 8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff changeset
    58
                });
580fb715b29d 8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff changeset
    59
    }
580fb715b29d 8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
diff changeset
    60
}