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