/* * Copyright (c) 2015, 2018, 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.
*/
Helper helper = Helper.newHelper(); if (helper == null) {
System.err.println("Test not run"); return;
}
helper.generateDefaultModules(); // expected num. of plugins from jdk.jlink module int expectedJLinkPlugins = getNumJlinkPlugins(); int totalPlugins = 0;
{ // number of built-in plugins
List<Plugin> builtInPlugins = new ArrayList<>();
builtInPlugins.addAll(PluginRepository.getPlugins(ModuleLayer.boot()));
totalPlugins = builtInPlugins.size(); // actual num. of plugins loaded from jdk.jlink module int actualJLinkPlugins = 0; for (Plugin p : builtInPlugins) {
p.getState();
p.getType(); if (isOfJLinkModule(p)) {
actualJLinkPlugins++;
}
} if (expectedJLinkPlugins != actualJLinkPlugins) { thrownew AssertionError("Actual plugins loaded from jdk.jlink: " +
actualJLinkPlugins + " which doesn't match expected number : " +
expectedJLinkPlugins);
}
}
{ // No --module-path specified. $JAVA_HOME/jmods should be assumed. // The following should succeed as it uses only system modules.
String imageDir = "bug818977-no-modulepath";
JImageGenerator.getJLinkTask()
.output(helper.createNewImageDir(imageDir))
.addMods("jdk.jshell")
.call().assertSuccess();
}
{ // invalid --module-path specified. java.base not found it it. // $JAVA_HOME/jmods should be added automatically. // The following should succeed as it uses only system modules.
String imageDir = "bug8189777-invalid-modulepath";
JImageGenerator.getJLinkTask()
.modulePath("does_not_exist_path")
.output(helper.createNewImageDir(imageDir))
.addMods("jdk.jshell")
.call().assertSuccess();
}
{
String moduleName = "bug8134651";
JImageGenerator.getJLinkTask()
.modulePath(helper.defaultModulePath())
.output(helper.createNewImageDir(moduleName))
.addMods("leaf1")
.call().assertSuccess();
JImageGenerator.getJLinkTask()
.modulePath(helper.defaultModulePath())
.addMods("leaf1")
.option("--output")
.call().assertFailure("Error: no value given for --output");
JImageGenerator.getJLinkTask()
.modulePath("")
.output(helper.createNewImageDir(moduleName))
.addMods("leaf1")
.call().assertFailure("Error: no value given for --module-path"); // do not include standard module path - should be added automatically
JImageGenerator.getJLinkTask()
.modulePath(helper.defaultModulePath(false))
.output(helper.createNewImageDir(moduleName))
.addMods("leaf1")
.call().assertSuccess(); // no --module-path. default sys mod path is assumed - but that won't contain 'leaf1' module
JImageGenerator.getJLinkTask()
.output(helper.createNewImageDir(moduleName))
.addMods("leaf1")
.call().assertFailure("Error: Module leaf1 not found");
}
{
String moduleName = "m_8165735"; // JDK-8165735
helper.generateDefaultJModule(moduleName+"dependency").assertSuccess();
Path jmod = helper.generateDefaultJModule(moduleName, moduleName+"dependency").assertSuccess();
JImageGenerator.getJLinkTask()
.modulePath(helper.defaultModulePath())
.repeatedModulePath(".") // second --module-path overrides the first one
.output(helper.createNewImageDir(moduleName))
.addMods(moduleName) // second --module-path does not have that module
.call().assertFailure("Error: Module m_8165735 not found");
JImageGenerator.getJLinkTask()
.modulePath(".") // first --module-path overridden later
.repeatedModulePath(helper.defaultModulePath())
.output(helper.createNewImageDir(moduleName))
.addMods(moduleName) // second --module-path has that module
.call().assertSuccess();
JImageGenerator.getJLinkTask()
.modulePath(helper.defaultModulePath())
.output(helper.createNewImageDir(moduleName))
.limitMods(moduleName)
.repeatedLimitMods("java.base") // second --limit-modules overrides first
.addMods(moduleName)
.call().assertFailure("Error: Module m_8165735dependency not found, required by m_8165735");
JImageGenerator.getJLinkTask()
.modulePath(helper.defaultModulePath())
.output(helper.createNewImageDir(moduleName))
.limitMods("java.base")
.repeatedLimitMods(moduleName) // second --limit-modules overrides first
.addMods(moduleName)
.call().assertSuccess();
}
{ // Help
StringWriter writer = new StringWriter();
PrintWriter pw = new PrintWriter(writer);
JLINK_TOOL.run(pw, pw, "--help");
String output = writer.toString(); if (output.split("\n").length < 10) {
System.err.println(output); thrownew AssertionError("Help");
}
}
{ // List plugins
StringWriter writer = new StringWriter();
PrintWriter pw = new PrintWriter(writer);
JLINK_TOOL.run(pw, pw, "--list-plugins");
String output = writer.toString();
List<String> commands = Stream.of(output.split("\\R"))
.filter((s) -> s.matches(" --.*"))
.collect(Collectors.toList()); int number = commands.size(); if (number != totalPlugins) {
System.err.println(output); thrownew AssertionError("Found: " + number + " expected " + totalPlugins);
}
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.