Main.java revision 16787:d31e3036f0a8
1/*
2 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24package p5;
25
26import java.lang.reflect.Layer;
27import p3.Foo;
28import p3.Lib;
29
30/**
31 * This test verifies jlink support of requires static.
32 */
33public class Main {
34    public static void main(String... args) {
35        boolean libPresent = Layer.boot().findModule("m3").isPresent();
36        if (LibHelper.libClassFound != libPresent) {
37            throw new RuntimeException("Expected module m3 not in the boot layer");
38        }
39
40        if (libPresent) {
41            // p3.Lib must be present
42            LibHelper.concat("x", "y");
43        }
44    }
45
46    static class LibHelper {
47        @Foo
48        static final boolean libClassFound;
49
50        static {
51            boolean found = false;
52            try {
53                Class<?> c = Class.forName("p3.Lib");
54                found = true;
55            } catch (ClassNotFoundException e) {
56            }
57            libClassFound = found;
58        }
59
60        public static String concat(String x, String y) {
61            return Lib.concat(x, y);
62        }
63    }
64}
65