/* * Copyright (c) 2019, 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. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/
/** * @test * @bug 8233922 * @modules java.base/jdk.internal.module * @library /test/lib * @build ServiceBinding TestBootLayer * @run testng ServiceBinding * @summary Test service binding with incubator modules
*/
// boot layer: root=m1, incubator modules m2 and m3 should not be resolved
testBootLayer(mlib, Set.of("m1"), Set.of("m1"), Set.of("m2", "m3"))
.shouldNotMatch("WARNING:.*m2")
.shouldNotMatch("WARNING:.*m3");
// boot layer: root=m2, incubator module m3 should not be resolved
testBootLayer(mlib, Set.of("m2"), Set.of("m1", "m2"), Set.of("m3"))
.shouldMatch("WARNING:.*m2")
.shouldNotMatch("WARNING:.*m3");
// custom configuration: root=m1, incubator modules m2 and m3 should be resolved
testCustomConfiguration(mlib, Set.of("m1"), Set.of("m1", "m2", "m3"));
// custom configuration: root=m2, incubator module m3 should be resolved
testCustomConfiguration(mlib, Set.of("m2"), Set.of("m1", "m2", "m3"));
}
/** * Creates an exploded module on the file system. * * @param mlib the top-level module directory * @param descriptor the module descriptor of the module to write
*/ void writeModule(Path mlib, ModuleDescriptor descriptor) throws Exception {
writeModule(mlib, descriptor, false);
}
/** * Creates an exploded module on the file system. The module will be an * incubating module. * * @param mlib the top-level module directory * @param descriptor the module descriptor of the module to write
*/ void writeIncubatingModule(Path mlib, ModuleDescriptor descriptor) throws Exception {
writeModule(mlib, descriptor, true);
}
/** * Creates an exploded module on the file system. * * @param mlib the top-level module directory * @param descriptor the module descriptor of the module to write * @param incubating to create an incubating module
*/ void writeModule(Path mlib, ModuleDescriptor descriptor, boolean incubating) throws Exception
{ // create ModuleResolution attribute if incubating module
ModuleResolution mres = (incubating) ? ModuleResolution.empty().withIncubating() : null;
String name = descriptor.name();
// create directory for module
Path dir = Files.createDirectory(mlib.resolve(name));
// create a dummy class file for each package for (String pn : descriptor.packages()) {
Path subdir = dir.resolve(pn.replace('.', File.separatorChar));
Files.createDirectories(subdir);
Files.createFile(subdir.resolve("C.class"));
}
}
/** * Run TestBootLayer in a child VM with the given module path and the * --add-modules option with additional root modules. TestBootLayer checks * the modules in the boot layer. * * @param mlib the module path * @param roots the modules to specify to --add-modules * @param expected the names of modules that should be in the boot layer * @param notExpected the names of modules that should not be in boot layer
*/
OutputAnalyzer testBootLayer(Path mlib,
Set<String> roots,
Set<String> expected,
Set<String> notExpected) throws Exception
{ var opts = Stream.of("-p", mlib.toString(), "--add-modules", commaSeparated(roots), "TestBootLayer", commaSeparated(expected), commaSeparated(notExpected)); return ProcessTools.executeTestJava(opts.toArray(String[]::new))
.outputTo(System.out)
.errorTo(System.out)
.shouldHaveExitValue(0);
}
/** * Creates a Configuration by resolving a set of root modules, with service * binding, then checks that the Configuration includes the expected modules. * * @param mlib the module path * @param roots the names of the root modules * @param expected the names of modules that should be in the configuration
*/ void testCustomConfiguration(Path mlib, Set<String> roots, Set<String> expected) {
ModuleFinder finder = ModuleFinder.of(mlib);
Configuration cf = ModuleLayer.boot()
.configuration()
.resolveAndBind(finder, ModuleFinder.of(), roots);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.