/* * Copyright (c) 2014, 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.
*/
/** * @test * @library /test/lib * @modules jdk.compiler * jdk.jartool * jdk.jlink * @build BasicTest jdk.test.lib.compiler.CompilerUtils * @run testng BasicTest * @bug 8234076 * @summary Basic test of starting an application as a module
*/
/** * The initial module is loaded from a modular JAR file
*/ publicvoid testRunWithModularJar() throws Exception {
Path dir = Files.createTempDirectory(USER_DIR, "mlib");
Path jar = dir.resolve("m.jar");
/** * Attempt to run with the initial module packaged as a JMOD file.
*/ publicvoid testTryRunWithJMod() throws Exception {
Path dir = Files.createTempDirectory(USER_DIR, "mlib");
/** * Run the test with a non-existent file on the application module path. * It should be silently ignored.
*/ publicvoid testRunWithNonExistentEntry() throws Exception {
String mp = "DoesNotExist" + File.pathSeparator + MODS_DIR.toString();
String mid = TEST_MODULE + "/" + MAIN_CLASS;
/** * Attempt to run with -m specifying a main class that does not * exist.
*/ publicvoid testTryRunWithBadMainClass() throws Exception {
String modulepath = MODS_DIR.toString();
String mid = TEST_MODULE + "/p.rhubarb";
/** * Attempt to run with -m specifying a modular JAR that does not have * a MainClass attribute
*/ publicvoid testTryRunWithMissingMainClass() throws Exception {
Path dir = Files.createTempDirectory(USER_DIR, "mlib");
/** * Attempt to run with -m specifying a main class that is a different * module to that specified to -m
*/ publicvoid testTryRunWithMainClassInWrongModule() throws Exception {
String modulepath = MODS_DIR.toString();
String mid = "java.base/" + MAIN_CLASS;
/** * Helper method that creates a ProcessBuilder with command line arguments * while setting the _JAVA_LAUNCHER_DEBUG environment variable.
*/ private ProcessBuilder createProcessWithLauncherDebugging(String... cmds) {
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(Utils.addTestJavaOpts(cmds));
pb.environment().put("_JAVA_LAUNCHER_DEBUG", "true");
return pb;
}
/** * Test the ability for the Windows launcher to do proper application argument * detection and expansion, when using the long form module option and all passed in * command line arguments are prefixed with a dash. * * These tests are not expected to work on *nixes, and are ignored.
*/ publicvoid testWindowsWithLongFormModuleOption() throws Exception { if (!IS_WINDOWS) { return;
}
// java --module-path=mods --module=$TESTMODULE/$MAINCLASS --help // We should be able to find the argument --help as an application argument
ProcessTools.executeProcess(
createProcessWithLauncherDebugging( "--module-path=" + dir, "--module=" + mid, "--help"))
.outputTo(System.out)
.errorTo(System.out)
.shouldContain("F--help");
// java --module-path=mods --module=$TESTMODULE/$MAINCLASS <...src/test>/*.java --help // We should be able to see argument expansion happen
ProcessTools.executeProcess(
createProcessWithLauncherDebugging( "--module-path=" + dir, "--module=" + mid,
SRC_DIR.resolve(TEST_MODULE).toString() + "\\*.java", "--help"))
.outputTo(System.out)
.errorTo(System.out)
.shouldContain("F--help")
.shouldContain("module-info.java");
}
/** * Test that --module= is terminating for VM argument processing just like --module
*/ publicvoid testLongFormModuleOptionTermination() throws Exception {
String dir = MODS_DIR.toString();
String mid = TEST_MODULE + "/" + MAIN_CLASS;
// java --module-path=mods --module=$TESTMODULE/$MAINCLASS --module-path=mods --module=$TESTMODULE/$MAINCLASS // The first --module= will terminate the VM arguments processing. The second pair of module-path and module will be // deemed as application arguments
OutputAnalyzer output = ProcessTools.executeProcess(
createProcessWithLauncherDebugging( "--module-path=" + dir, "--module=" + mid, "--module-path=" + dir, "--module=" + mid))
.outputTo(System.out)
.errorTo(System.out)
.shouldContain("argv[ 0] = '--module-path=" + dir)
.shouldContain("argv[ 1] = '--module=" + mid);
if (IS_WINDOWS) {
output.shouldContain("F--module-path=" + dir).shouldContain("F--module=" + mid);
}
// java --module=$TESTMODULE/$MAINCLASS --module-path=mods // This command line will not work as --module= is terminating and the module will be not found int exitValue = exec("--module=" + mid, "--module-path" + dir);
assertTrue(exitValue != 0);
}
}
¤ Dauer der Verarbeitung: 0.17 Sekunden
(vorverarbeitet)
¤
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 ist noch experimentell.