< prev index next >
test/jdk/modules/etc/VerifyModuleDelegation.java
Print this page
*** 1,7 ****
/*
! * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
--- 1,7 ----
/*
! * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*** 24,41 ****
--- 24,44 ----
/**
* @test
* @summary Verify the defining class loader of each module never delegates
* to its child class loader. Also sanity check java.compact2
* requires.
+ * @modules java.compact2
* @run testng/othervm --add-modules=ALL-SYSTEM VerifyModuleDelegation
*/
import java.lang.module.ModuleDescriptor;
import java.lang.module.ModuleFinder;
import java.lang.module.ModuleReference;
import java.lang.reflect.Layer;
+ import java.lang.reflect.Module;
import java.util.Set;
+ import static java.util.stream.Collectors.toSet;
import static java.lang.module.ModuleDescriptor.Requires.Modifier.*;
import org.testng.annotations.*;
*** 56,95 ****
.requires(Set.of(PUBLIC), "java.rmi")
.requires(Set.of(PUBLIC), "java.sql")
.requires(Set.of(PUBLIC), "java.xml")
.build();
! private static final Set<ModuleReference> MREFS
! = ModuleFinder.ofSystem().findAll();
private void check(ModuleDescriptor md, ModuleDescriptor ref) {
assertTrue(md.requires().size() == ref.requires().size());
assertTrue(md.requires().containsAll(ref.requires()));
}
@Test
public void checkJavaBase() {
ModuleDescriptor md =
! MREFS.stream().map(ModuleReference::descriptor)
.filter(d -> d.name().equals(JAVA_BASE))
.findFirst().orElseThrow(Error::new);
check(md, BASE);
}
@Test
public void checkCompact2() {
ModuleDescriptor md =
! MREFS.stream().map(ModuleReference::descriptor)
.filter(d -> d.name().equals(JAVA_COMPACT2))
.findFirst().orElseThrow(Error::new);
check(md, COMPACT2);
}
@Test
public void checkLoaderDelegation() {
Layer boot = Layer.boot();
! MREFS.stream().map(ModuleReference::descriptor)
.forEach(md -> md.requires().stream().forEach(req ->
{
// check if M requires D and D's loader must be either the
// same or an ancestor of M's loader
ClassLoader loader1 = boot.findLoader(md.name());
--- 59,99 ----
.requires(Set.of(PUBLIC), "java.rmi")
.requires(Set.of(PUBLIC), "java.sql")
.requires(Set.of(PUBLIC), "java.xml")
.build();
! private static final Set<ModuleDescriptor> MREFS
! = Layer.boot().modules().stream().map(Module::getDescriptor)
! .collect(toSet());
private void check(ModuleDescriptor md, ModuleDescriptor ref) {
assertTrue(md.requires().size() == ref.requires().size());
assertTrue(md.requires().containsAll(ref.requires()));
}
@Test
public void checkJavaBase() {
ModuleDescriptor md =
! MREFS.stream()
.filter(d -> d.name().equals(JAVA_BASE))
.findFirst().orElseThrow(Error::new);
check(md, BASE);
}
@Test
public void checkCompact2() {
ModuleDescriptor md =
! MREFS.stream()
.filter(d -> d.name().equals(JAVA_COMPACT2))
.findFirst().orElseThrow(Error::new);
check(md, COMPACT2);
}
@Test
public void checkLoaderDelegation() {
Layer boot = Layer.boot();
! MREFS.stream()
.forEach(md -> md.requires().stream().forEach(req ->
{
// check if M requires D and D's loader must be either the
// same or an ancestor of M's loader
ClassLoader loader1 = boot.findLoader(md.name());
< prev index next >