Path: blob/master/test/jdk/java/lang/Package/bootclasspath/GetPackageFromBootClassPath.java
41152 views
/*1* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 821841926* @library /test/lib27* @modules jdk.compiler28* @build jdk.test.lib.compiler.CompilerUtils29* @run driver GetPackageFromBootClassPath setup30* @run main/othervm -Xbootclasspath/a:boot GetPackageFromBootClassPath31*/3233import java.lang.annotation.Annotation;34import java.nio.file.Path;35import java.nio.file.Paths;36import java.util.Arrays;3738public class GetPackageFromBootClassPath {39public static void main(String... args) throws Exception {40if (args.length == 0) {41test();42} else {43setupBootLib();44}45}4647private static void test() throws Exception {48Class<?> c = Class.forName("foo.Foo", false, null);49Package p = c.getPackage();50Annotation[] annotations = p.getAnnotations();51Class<?> annType = Class.forName("foo.MyAnnotation", false, null);52if (annotations.length != 1 ||53annotations[0].annotationType() != annType) {54throw new RuntimeException("Expected foo.MyAnnotation but got " +55Arrays.toString(annotations));56}57}5859private static void setupBootLib() throws Exception {60Path testSrc = Paths.get(System.getProperty("test.src"), "boot");61Path bootDir = Paths.get("boot");62if (!jdk.test.lib.compiler.CompilerUtils.compile(testSrc, bootDir)) {63throw new RuntimeException("compilation fails");64}65}66}676869