8145163: Test Task for Platform Logging API and Service -- for moduralization
Reviewed-by: dfuchs
This commit is contained in:
parent
fdb24eea0b
commit
e01f0e3580
jdk/test/java/lang/System/LoggerFinder/modules
Base.javaJDKLoggerForImageTest.javaJDKLoggerForJDKTest.javaLoggerInImageTest.javaNamedLoggerForImageTest.javaNamedLoggerForJDKTest.javaUnnamedLoggerForImageTest.javaUnnamedLoggerForJDKTest.java
boot_client
boot_usage
named_client/m.t.a
named_logger/m.l.a
patched_client
patched_usage/java.base/java/lang
unnamed_client/pkg/b/t
unnamed_logger
273
jdk/test/java/lang/System/LoggerFinder/modules/Base.java
Normal file
273
jdk/test/java/lang/System/LoggerFinder/modules/Base.java
Normal file
@ -0,0 +1,273 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, 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. Oracle designates this
|
||||||
|
* particular file as subject to the "Classpath" exception as provided
|
||||||
|
* by Oracle in the LICENSE file that accompanied this code.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.nio.file.StandardCopyOption;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
import jdk.testlibrary.JDKToolFinder;
|
||||||
|
|
||||||
|
import static jdk.testlibrary.ProcessTools.executeCommand;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Base class for tests.
|
||||||
|
* The tests focuse on that LoggerFinder works well in jigsaw environment,
|
||||||
|
* i.e. make sure correct Logger can be retrieved,
|
||||||
|
* also verify that basic functionality of retrieved Logger's works well.
|
||||||
|
*
|
||||||
|
* Note: As the test will take long time, to avoid timeout,
|
||||||
|
* split it as several tests, this class is the base class for tests.
|
||||||
|
*/
|
||||||
|
public class Base {
|
||||||
|
protected static final String JAVA_HOME = System.getProperty("java.home");
|
||||||
|
protected static final Path JDK_IMAGE = Paths.get(JAVA_HOME);
|
||||||
|
protected static final Path JMODS = Paths.get(JAVA_HOME, "jmods");
|
||||||
|
|
||||||
|
protected static final String TEST_SRC = System.getProperty("test.src");
|
||||||
|
|
||||||
|
// logger client to get logger from java.base module, it should get a lazy logger
|
||||||
|
// which wraps the underlying real logger implementation
|
||||||
|
protected static final Path SRC_PATCHED_USAGE =
|
||||||
|
Paths.get(TEST_SRC, "patched_usage", "java.base");
|
||||||
|
protected static final Path DEST_PATCHED_USAGE = Paths.get("patched_usage", "java.base");
|
||||||
|
protected static final Path SRC_PATCHED_CLIENT = Paths.get(TEST_SRC, "patched_client");
|
||||||
|
protected static final Path DEST_PATCHED_CLIENT = Paths.get("patched_client");
|
||||||
|
|
||||||
|
// logger client to get logger from bootclasspath/a, it should get a lazy logger
|
||||||
|
// which wraps the underlying real logger implementation
|
||||||
|
protected static final Path SRC_BOOT_USAGE = Paths.get(TEST_SRC, "boot_usage");
|
||||||
|
protected static final Path DEST_BOOT_USAGE = Paths.get("boot_usage");
|
||||||
|
protected static final Path SRC_BOOT_CLIENT = Paths.get(TEST_SRC, "boot_client");
|
||||||
|
protected static final Path DEST_BOOT_CLIENT = Paths.get("boot_client");
|
||||||
|
|
||||||
|
// logger provider in named module m.l.a
|
||||||
|
protected static final Path SRC_NAMED_LOGGER = Paths.get(TEST_SRC, "named_logger");
|
||||||
|
protected static final Path DEST_NAMED_LOGGER = Paths.get("mods_named_logger");
|
||||||
|
|
||||||
|
// logger provider in unnamed module
|
||||||
|
protected static final Path SRC_UNNAMED_LOGGER = Paths.get(TEST_SRC, "unnamed_logger");
|
||||||
|
protected static final Path DEST_UNNAMED_LOGGER = Paths.get("cp_unnamed_logger");
|
||||||
|
protected static final Path SRC_UNNAMED_LOGGER_SERVICE_FILE =
|
||||||
|
SRC_UNNAMED_LOGGER.resolve("META-INF/services/java.lang.System$LoggerFinder");
|
||||||
|
protected static final Path DEST_UNNAMED_LOGGER_SERVICE_DIR =
|
||||||
|
DEST_UNNAMED_LOGGER.resolve("META-INF/services");
|
||||||
|
protected static final Path DEST_UNNAMED_LOGGER_SERVICE_FILE =
|
||||||
|
DEST_UNNAMED_LOGGER.resolve("META-INF/services/java.lang.System$LoggerFinder");
|
||||||
|
|
||||||
|
// logger client in named module m.t.a
|
||||||
|
protected static final Path SRC_NAMED_CLIENT = Paths.get(TEST_SRC, "named_client");
|
||||||
|
protected static final Path DEST_NAMED_CLIENT = Paths.get("mods_named_client");
|
||||||
|
|
||||||
|
// logger client in unnamed module
|
||||||
|
protected static final Path SRC_UNNAMED_CLIENT = Paths.get(TEST_SRC, "unnamed_client");
|
||||||
|
protected static final Path DEST_UNNAMED_CLIENT = Paths.get("cp_unnamed_client");
|
||||||
|
|
||||||
|
// customized image with only module java.base
|
||||||
|
protected static final Path IMAGE = Paths.get("image");
|
||||||
|
// customized image with java.base and logger provider module m.l.a
|
||||||
|
protected static final Path IMAGE_LOGGER = Paths.get("image_logger");
|
||||||
|
// customized image with module java.base and logger client module m.t.a
|
||||||
|
protected static final Path IMAGE_CLIENT = Paths.get("image_client");
|
||||||
|
// customized image with module java.base, logger provider module m.l.a
|
||||||
|
// and logger client module m.t.a
|
||||||
|
protected static final Path IMAGE_CLIENT_LOGGER = Paths.get("image_all");
|
||||||
|
|
||||||
|
// lazy logger class which wraps the underlying real logger implementation
|
||||||
|
protected static final String LAZY_LOGGER =
|
||||||
|
"jdk.internal.logger.LazyLoggers$JdkLazyLogger";
|
||||||
|
// JUL logger class which wraps java.util.logging.Logger
|
||||||
|
protected static final String JUL_LOGGER =
|
||||||
|
"sun.util.logging.internal.LoggingProviderImpl$JULWrapper";
|
||||||
|
// default simple logger class when no logger provider can be found
|
||||||
|
protected static final String SIMPLE_LOGGER =
|
||||||
|
"jdk.internal.logger.SimpleConsoleLogger";
|
||||||
|
// logger class in named module m.l.a
|
||||||
|
protected static final String LOGGER_A = "pkg.a.l.LoggerA";
|
||||||
|
// logger class in unnamed module m.l.b
|
||||||
|
protected static final String LOGGER_B = "pkg.b.l.LoggerB";
|
||||||
|
|
||||||
|
// logger client in named module
|
||||||
|
protected static final String CLIENT_A = "m.t.a/pkg.a.t.TestA";
|
||||||
|
// logger client in unnamed module
|
||||||
|
protected static final String CLIENT_B = "pkg.b.t.TestB";
|
||||||
|
// logger client which gets logger through boot class BootUsage
|
||||||
|
protected static final String BOOT_CLIENT = "BootClient";
|
||||||
|
// logger client which gets logger through patched class
|
||||||
|
// java.base/java.lang.PatchedUsage
|
||||||
|
protected static final String PATCHED_CLIENT = "PatchedClient";
|
||||||
|
|
||||||
|
protected void setupAllClient() throws Throwable {
|
||||||
|
// compiles logger client which will get logger through patched
|
||||||
|
// class java.base/java.lang.PatchedUsage
|
||||||
|
compile(SRC_BOOT_USAGE, DEST_BOOT_USAGE);
|
||||||
|
compile(SRC_BOOT_CLIENT, DEST_BOOT_CLIENT,
|
||||||
|
"--class-path", DEST_BOOT_USAGE.toString());
|
||||||
|
|
||||||
|
// compiles logger client which will get logger through boot
|
||||||
|
// class BootUsage
|
||||||
|
compile(SRC_PATCHED_USAGE, DEST_PATCHED_USAGE,
|
||||||
|
"--patch-module", "java.base=" + SRC_PATCHED_USAGE.toString());
|
||||||
|
compile(SRC_PATCHED_CLIENT, DEST_PATCHED_CLIENT,
|
||||||
|
"--patch-module", "java.base=" + DEST_PATCHED_USAGE.toString());
|
||||||
|
|
||||||
|
// compiles logger client in unnamed module
|
||||||
|
compile(SRC_UNNAMED_CLIENT, DEST_UNNAMED_CLIENT,
|
||||||
|
"--source-path", SRC_UNNAMED_CLIENT.toString());
|
||||||
|
|
||||||
|
// compiles logger client in named module m.t.a
|
||||||
|
compile(SRC_NAMED_CLIENT, DEST_NAMED_CLIENT,
|
||||||
|
"--module-source-path", SRC_NAMED_CLIENT.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setupNamedLogger() throws Throwable {
|
||||||
|
// compiles logger provider in named module m.l.a
|
||||||
|
compile(SRC_NAMED_LOGGER, DEST_NAMED_LOGGER,
|
||||||
|
"--module-source-path", SRC_NAMED_LOGGER.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setupUnnamedLogger() throws Throwable {
|
||||||
|
// compiles logger provider in unnamed module
|
||||||
|
compile(SRC_UNNAMED_LOGGER, DEST_UNNAMED_LOGGER,
|
||||||
|
"--source-path", SRC_UNNAMED_LOGGER.toString());
|
||||||
|
Files.createDirectories(DEST_UNNAMED_LOGGER_SERVICE_DIR);
|
||||||
|
Files.copy(SRC_UNNAMED_LOGGER_SERVICE_FILE, DEST_UNNAMED_LOGGER_SERVICE_FILE,
|
||||||
|
StandardCopyOption.REPLACE_EXISTING);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean checkJMODS() throws Throwable {
|
||||||
|
// if $JAVA_HOME/jmods does not exist, skip below steps
|
||||||
|
// as there is no way to build customized images by jlink
|
||||||
|
if (Files.notExists(JMODS)) {
|
||||||
|
System.err.println("Skip tests which require image");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setupJavaBaseImage() throws Throwable {
|
||||||
|
if (!checkJMODS()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// build image with just java.base module
|
||||||
|
String mpath = JMODS.toString();
|
||||||
|
execTool("jlink",
|
||||||
|
"--module-path", mpath,
|
||||||
|
"--add-modules", "java.base",
|
||||||
|
"--output", IMAGE.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setupLoggerImage() throws Throwable {
|
||||||
|
if (!checkJMODS()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// build image with java.base + m.l.a modules
|
||||||
|
String mpath = DEST_NAMED_LOGGER.toString() + File.pathSeparator + JMODS.toString();
|
||||||
|
execTool("jlink",
|
||||||
|
"--module-path", mpath,
|
||||||
|
"--add-modules", "m.l.a",
|
||||||
|
"--output", IMAGE_LOGGER.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setupClientImage() throws Throwable {
|
||||||
|
if (!checkJMODS()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// build image with java.base + m.t.a modules
|
||||||
|
String mpath = DEST_NAMED_CLIENT.toString() + File.pathSeparator + JMODS.toString();
|
||||||
|
execTool("jlink",
|
||||||
|
"--module-path", mpath,
|
||||||
|
"--add-modules", "m.t.a",
|
||||||
|
"--output", IMAGE_CLIENT.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setupFullImage() throws Throwable {
|
||||||
|
if (!checkJMODS()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// build image with java.base + m.l.a + m.t.a modules
|
||||||
|
String mpath = DEST_NAMED_LOGGER.toString() + File.pathSeparator
|
||||||
|
+ DEST_NAMED_CLIENT.toString() + File.pathSeparator + JMODS.toString();
|
||||||
|
execTool("jlink",
|
||||||
|
"--module-path", mpath,
|
||||||
|
"--add-modules", "m.l.a,m.t.a",
|
||||||
|
"--output", IMAGE_CLIENT_LOGGER.toString());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static void assertTrue(boolean b) {
|
||||||
|
if (!b) {
|
||||||
|
throw new RuntimeException("expected true, but get false.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* run test with supplied java image which could be jdk image or customized image
|
||||||
|
*/
|
||||||
|
protected void runTest(Path image, String... opts) throws Throwable {
|
||||||
|
String[] options = Stream.concat(Stream.of(getJava(image)), Stream.of(opts))
|
||||||
|
.toArray(String[]::new);
|
||||||
|
|
||||||
|
ProcessBuilder pb = new ProcessBuilder(options);
|
||||||
|
int exitValue = executeCommand(pb).outputTo(System.out)
|
||||||
|
.errorTo(System.err)
|
||||||
|
.getExitValue();
|
||||||
|
assertTrue(exitValue == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void compile(Path src, Path dest, String... params) throws Throwable {
|
||||||
|
assertTrue(CompilerUtils.compile(src, dest, params));
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getJava(Path image) {
|
||||||
|
boolean isWindows = System.getProperty("os.name").startsWith("Windows");
|
||||||
|
Path java = image.resolve("bin").resolve(isWindows ? "java.exe" : "java");
|
||||||
|
if (Files.notExists(java))
|
||||||
|
throw new RuntimeException(java + " not found");
|
||||||
|
return java.toAbsolutePath().toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void execTool(String tool, String... args) throws Throwable {
|
||||||
|
String path = JDKToolFinder.getJDKTool(tool);
|
||||||
|
List<String> commands = new ArrayList<>();
|
||||||
|
commands.add(path);
|
||||||
|
Stream.of(args).forEach(commands::add);
|
||||||
|
ProcessBuilder pb = new ProcessBuilder(commands);
|
||||||
|
|
||||||
|
int exitValue = executeCommand(pb).outputTo(System.out)
|
||||||
|
.errorTo(System.out)
|
||||||
|
.shouldNotContain("no module is recorded in hash")
|
||||||
|
.getExitValue();
|
||||||
|
assertTrue(exitValue == 0);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,92 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, 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. Oracle designates this
|
||||||
|
* particular file as subject to the "Classpath" exception as provided
|
||||||
|
* by Oracle in the LICENSE file that accompanied this code.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.nio.file.StandardCopyOption;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
import jdk.testlibrary.JDKToolFinder;
|
||||||
|
|
||||||
|
import static jdk.testlibrary.ProcessTools.executeCommand;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @test
|
||||||
|
* @modules jdk.compiler
|
||||||
|
* @summary Test cases which run against customized image, check the situation where
|
||||||
|
* 1. logger provider is the default one supplied by java.base,
|
||||||
|
* 2. clients are in named/unnamed module,
|
||||||
|
* patched system module, or Xbootclasspath
|
||||||
|
* This test does not require existence of java.logging module,
|
||||||
|
* but require jdk.compiler module
|
||||||
|
* @library /lib/testlibrary
|
||||||
|
* @build Base CompilerUtils jdk.testlibrary.*
|
||||||
|
* @run main/othervm JDKLoggerForImageTest
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class JDKLoggerForImageTest extends Base {
|
||||||
|
|
||||||
|
public static void main(String args[]) throws Throwable {
|
||||||
|
JDKLoggerForImageTest t = new JDKLoggerForImageTest();
|
||||||
|
t.setup();
|
||||||
|
t.test();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setup() throws Throwable {
|
||||||
|
setupAllClient();
|
||||||
|
|
||||||
|
setupJavaBaseImage();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void test() throws Throwable {
|
||||||
|
if (!checkJMODS()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// logger client is in named module m.t.a
|
||||||
|
runTest(IMAGE,
|
||||||
|
"--module-path", DEST_NAMED_CLIENT.toString(),
|
||||||
|
"-m", CLIENT_A, "system", SIMPLE_LOGGER);
|
||||||
|
// logger client is in unnamed module
|
||||||
|
runTest(IMAGE,
|
||||||
|
"--class-path", DEST_UNNAMED_CLIENT.toString(),
|
||||||
|
CLIENT_B, "system", SIMPLE_LOGGER);
|
||||||
|
// logger client gets logger through boot class BootUsage
|
||||||
|
runTest(IMAGE,
|
||||||
|
"-Xbootclasspath/a:" + DEST_BOOT_USAGE.toString(),
|
||||||
|
"--class-path", DEST_BOOT_CLIENT.toString(),
|
||||||
|
BOOT_CLIENT, "system", SIMPLE_LOGGER);
|
||||||
|
// logger client gets logger through patched class
|
||||||
|
// java.base/java.lang.PatchedUsage
|
||||||
|
runTest(IMAGE,
|
||||||
|
"--patch-module", "java.base=" + DEST_PATCHED_USAGE.toString(),
|
||||||
|
"--class-path", DEST_PATCHED_CLIENT.toString(),
|
||||||
|
PATCHED_CLIENT, "system", SIMPLE_LOGGER);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,86 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, 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. Oracle designates this
|
||||||
|
* particular file as subject to the "Classpath" exception as provided
|
||||||
|
* by Oracle in the LICENSE file that accompanied this code.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.nio.file.StandardCopyOption;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
import jdk.testlibrary.JDKToolFinder;
|
||||||
|
|
||||||
|
import static jdk.testlibrary.ProcessTools.executeCommand;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @test
|
||||||
|
* @modules java.logging
|
||||||
|
* @modules jdk.compiler
|
||||||
|
* @summary Test cases which run against the JDK image, check the situation where
|
||||||
|
* 1. logger provider is the default one supplied by the JDK,
|
||||||
|
* 2. clients are in named/unnamed module,
|
||||||
|
* patched system module, or Xbootclasspath
|
||||||
|
* This test DOES require existence of java.logging module
|
||||||
|
* @library /lib/testlibrary
|
||||||
|
* @build Base CompilerUtils jdk.testlibrary.*
|
||||||
|
* @run main/othervm JDKLoggerForJDKTest
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class JDKLoggerForJDKTest extends Base {
|
||||||
|
|
||||||
|
public static void main(String args[]) throws Throwable {
|
||||||
|
JDKLoggerForJDKTest t = new JDKLoggerForJDKTest();
|
||||||
|
t.setup();
|
||||||
|
t.test();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setup() throws Throwable {
|
||||||
|
setupAllClient();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void test() throws Throwable {
|
||||||
|
// logger client is in named module m.t.a
|
||||||
|
runTest(JDK_IMAGE,
|
||||||
|
"--module-path", DEST_NAMED_CLIENT.toString(),
|
||||||
|
"-m", CLIENT_A, "system", JUL_LOGGER);
|
||||||
|
// logger client is in unnamed module
|
||||||
|
runTest(JDK_IMAGE,
|
||||||
|
"--class-path", DEST_UNNAMED_CLIENT.toString(),
|
||||||
|
CLIENT_B, "system", JUL_LOGGER);
|
||||||
|
// logger client gets logger through boot class BootUsage
|
||||||
|
runTest(JDK_IMAGE,
|
||||||
|
"-Xbootclasspath/a:" + DEST_BOOT_USAGE.toString(),
|
||||||
|
"--class-path", DEST_BOOT_CLIENT.toString(),
|
||||||
|
BOOT_CLIENT, "system", LAZY_LOGGER, JUL_LOGGER);
|
||||||
|
// logger client gets logger through patched class
|
||||||
|
// java.base/java.lang.PatchedUsage
|
||||||
|
runTest(JDK_IMAGE,
|
||||||
|
"--patch-module", "java.base=" + DEST_PATCHED_USAGE.toString(),
|
||||||
|
"--class-path", DEST_PATCHED_CLIENT.toString(),
|
||||||
|
PATCHED_CLIENT, "system", LAZY_LOGGER, JUL_LOGGER);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,98 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, 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. Oracle designates this
|
||||||
|
* particular file as subject to the "Classpath" exception as provided
|
||||||
|
* by Oracle in the LICENSE file that accompanied this code.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.nio.file.StandardCopyOption;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
import jdk.testlibrary.JDKToolFinder;
|
||||||
|
|
||||||
|
import static jdk.testlibrary.ProcessTools.executeCommand;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @test
|
||||||
|
* @modules jdk.compiler
|
||||||
|
* @summary Test cases which run against customized image, check the situation where
|
||||||
|
* 1. logger providers are in the customized image too,
|
||||||
|
* 2. clients are in named/unnamed module, image,
|
||||||
|
* patched system module, or Xbootclasspath
|
||||||
|
* This test does not require existence of java.logging module,
|
||||||
|
* but require jdk.compiler module
|
||||||
|
* @library /lib/testlibrary
|
||||||
|
* @build Base CompilerUtils jdk.testlibrary.*
|
||||||
|
* @run main/othervm LoggerInImageTest
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class LoggerInImageTest extends Base {
|
||||||
|
|
||||||
|
public static void main(String args[]) throws Throwable {
|
||||||
|
LoggerInImageTest t = new LoggerInImageTest();
|
||||||
|
t.setup();
|
||||||
|
t.test();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setup() throws Throwable {
|
||||||
|
setupAllClient();
|
||||||
|
|
||||||
|
setupNamedLogger();
|
||||||
|
|
||||||
|
setupLoggerImage();
|
||||||
|
setupFullImage();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void test() throws Throwable {
|
||||||
|
if (!checkJMODS()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// logger client is in named module m.t.a which is also in customized image
|
||||||
|
runTest(IMAGE_CLIENT_LOGGER,
|
||||||
|
"-m", CLIENT_A, "named", LOGGER_A);
|
||||||
|
// logger client in named module m.t.a
|
||||||
|
runTest(IMAGE_LOGGER,
|
||||||
|
"--module-path", DEST_NAMED_CLIENT.toString(),
|
||||||
|
"-m", CLIENT_A, "named", LOGGER_A);
|
||||||
|
// logger client is in unnamed module
|
||||||
|
runTest(IMAGE_LOGGER,
|
||||||
|
"--class-path", DEST_UNNAMED_CLIENT.toString(),
|
||||||
|
CLIENT_B, "named", LOGGER_A);
|
||||||
|
// logger client gets logger through boot class BootUsage
|
||||||
|
runTest(IMAGE_LOGGER,
|
||||||
|
"-Xbootclasspath/a:" + DEST_BOOT_USAGE.toString(),
|
||||||
|
"--class-path", DEST_BOOT_CLIENT.toString(),
|
||||||
|
BOOT_CLIENT, "system", LAZY_LOGGER, LOGGER_A);
|
||||||
|
// logger client gets logger through patched class
|
||||||
|
// java.base/java.lang.PatchedUsage
|
||||||
|
runTest(IMAGE_LOGGER,
|
||||||
|
"--patch-module", "java.base=" + DEST_PATCHED_USAGE.toString(),
|
||||||
|
"--class-path", DEST_PATCHED_CLIENT.toString(),
|
||||||
|
PATCHED_CLIENT, "system", LAZY_LOGGER, LOGGER_A);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,103 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, 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. Oracle designates this
|
||||||
|
* particular file as subject to the "Classpath" exception as provided
|
||||||
|
* by Oracle in the LICENSE file that accompanied this code.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.nio.file.StandardCopyOption;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
import jdk.testlibrary.JDKToolFinder;
|
||||||
|
|
||||||
|
import static jdk.testlibrary.ProcessTools.executeCommand;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @test
|
||||||
|
* @modules jdk.compiler
|
||||||
|
* @summary Test cases which run against customized image, check the situation where
|
||||||
|
* 1. logger providers are in named module,
|
||||||
|
* 2. clients are in named/unnamed module, image,
|
||||||
|
* patched system module, or Xbootclasspath
|
||||||
|
* This test does not require existence of java.logging module,
|
||||||
|
* but require jdk.compiler module
|
||||||
|
* @library /lib/testlibrary
|
||||||
|
* @build Base CompilerUtils jdk.testlibrary.*
|
||||||
|
* @run main/othervm NamedLoggerForImageTest
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class NamedLoggerForImageTest extends Base {
|
||||||
|
|
||||||
|
public static void main(String args[]) throws Throwable {
|
||||||
|
NamedLoggerForImageTest t = new NamedLoggerForImageTest();
|
||||||
|
t.setup();
|
||||||
|
t.test();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setup() throws Throwable {
|
||||||
|
setupAllClient();
|
||||||
|
|
||||||
|
setupNamedLogger();
|
||||||
|
|
||||||
|
setupJavaBaseImage();
|
||||||
|
setupClientImage();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void test() throws Throwable {
|
||||||
|
if (!checkJMODS()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// logger client is in named module m.t.a
|
||||||
|
runTest(IMAGE,
|
||||||
|
"--module-path", DEST_NAMED_LOGGER.toString()
|
||||||
|
+ File.pathSeparator + DEST_NAMED_CLIENT.toString(),
|
||||||
|
"-m", CLIENT_A, "named", LOGGER_A);
|
||||||
|
// logger client is in unnamed module
|
||||||
|
runTest(IMAGE,
|
||||||
|
"--module-path", DEST_NAMED_LOGGER.toString(),
|
||||||
|
"--class-path", DEST_UNNAMED_CLIENT.toString(),
|
||||||
|
CLIENT_B, "named", LOGGER_A);
|
||||||
|
// logger client is in named module m.t.a which is in customized image
|
||||||
|
runTest(IMAGE_CLIENT,
|
||||||
|
"--module-path", DEST_NAMED_LOGGER.toString(),
|
||||||
|
"-m", CLIENT_A, "named", LOGGER_A);
|
||||||
|
// logger client gets logger through boot class BootUsage
|
||||||
|
runTest(IMAGE,
|
||||||
|
"--module-path", DEST_NAMED_LOGGER.toString(),
|
||||||
|
"-Xbootclasspath/a:" + DEST_BOOT_USAGE.toString(),
|
||||||
|
"--class-path", DEST_BOOT_CLIENT.toString(),
|
||||||
|
BOOT_CLIENT, "system", LAZY_LOGGER, LOGGER_A);
|
||||||
|
// logger client gets logger through patched class
|
||||||
|
// java.base/java.lang.PatchedUsage
|
||||||
|
runTest(IMAGE,
|
||||||
|
"--module-path", DEST_NAMED_LOGGER.toString(),
|
||||||
|
"--patch-module", "java.base=" + DEST_PATCHED_USAGE.toString(),
|
||||||
|
"--class-path", DEST_PATCHED_CLIENT.toString(),
|
||||||
|
PATCHED_CLIENT, "system", LAZY_LOGGER, LOGGER_A);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,92 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, 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. Oracle designates this
|
||||||
|
* particular file as subject to the "Classpath" exception as provided
|
||||||
|
* by Oracle in the LICENSE file that accompanied this code.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.nio.file.StandardCopyOption;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
import jdk.testlibrary.JDKToolFinder;
|
||||||
|
|
||||||
|
import static jdk.testlibrary.ProcessTools.executeCommand;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @test
|
||||||
|
* @modules jdk.compiler
|
||||||
|
* @summary Test cases which run against the JDK image, check the situation where
|
||||||
|
* 1. logger providers are in named module,
|
||||||
|
* 2. clients are in named/unnamed module,
|
||||||
|
* patched system module, or Xbootclasspath
|
||||||
|
* This test does not require existence of java.logging module,
|
||||||
|
* but require jdk.compiler module
|
||||||
|
* @library /lib/testlibrary
|
||||||
|
* @build Base CompilerUtils jdk.testlibrary.*
|
||||||
|
* @run main/othervm NamedLoggerForJDKTest
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class NamedLoggerForJDKTest extends Base {
|
||||||
|
|
||||||
|
public static void main(String args[]) throws Throwable {
|
||||||
|
NamedLoggerForJDKTest t = new NamedLoggerForJDKTest();
|
||||||
|
t.setup();
|
||||||
|
t.test();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setup() throws Throwable {
|
||||||
|
setupAllClient();
|
||||||
|
|
||||||
|
setupNamedLogger();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void test() throws Throwable {
|
||||||
|
// logger client is in named module m.t.a
|
||||||
|
runTest(JDK_IMAGE,
|
||||||
|
"--module-path", DEST_NAMED_LOGGER.toString()
|
||||||
|
+ File.pathSeparator + DEST_NAMED_CLIENT.toString(),
|
||||||
|
"-m", CLIENT_A, "named", LOGGER_A);
|
||||||
|
// logger client is in unnamed module
|
||||||
|
runTest(JDK_IMAGE,
|
||||||
|
"--module-path", DEST_NAMED_LOGGER.toString(),
|
||||||
|
"--class-path", DEST_UNNAMED_CLIENT.toString(),
|
||||||
|
CLIENT_B, "named", LOGGER_A);
|
||||||
|
// logger client gets logger through boot class BootUsage
|
||||||
|
runTest(JDK_IMAGE,
|
||||||
|
"--module-path", DEST_NAMED_LOGGER.toString(),
|
||||||
|
"-Xbootclasspath/a:" + DEST_BOOT_USAGE.toString(),
|
||||||
|
"--class-path", DEST_BOOT_CLIENT.toString(),
|
||||||
|
BOOT_CLIENT, "system", LAZY_LOGGER, LOGGER_A);
|
||||||
|
// logger client gets logger through patched class
|
||||||
|
// java.base/java.lang.PatchedUsage
|
||||||
|
runTest(JDK_IMAGE,
|
||||||
|
"--module-path", DEST_NAMED_LOGGER.toString(),
|
||||||
|
"--patch-module", "java.base=" + DEST_PATCHED_USAGE.toString(),
|
||||||
|
"--class-path", DEST_PATCHED_CLIENT.toString(),
|
||||||
|
PATCHED_CLIENT, "system", LAZY_LOGGER, LOGGER_A);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,103 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, 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. Oracle designates this
|
||||||
|
* particular file as subject to the "Classpath" exception as provided
|
||||||
|
* by Oracle in the LICENSE file that accompanied this code.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.nio.file.StandardCopyOption;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
import jdk.testlibrary.JDKToolFinder;
|
||||||
|
|
||||||
|
import static jdk.testlibrary.ProcessTools.executeCommand;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @test
|
||||||
|
* @modules jdk.compiler
|
||||||
|
* @summary Test cases which run against customized image, check the situation where
|
||||||
|
* 1. logger providers are in unnamed module,
|
||||||
|
* 2. clients are in named/unnamed module, image,
|
||||||
|
* patched system module, or Xbootclasspath
|
||||||
|
* This test does not require existence of java.logging module,
|
||||||
|
* but require jdk.compiler module
|
||||||
|
* @library /lib/testlibrary
|
||||||
|
* @build Base CompilerUtils jdk.testlibrary.*
|
||||||
|
* @run main/othervm UnnamedLoggerForImageTest
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class UnnamedLoggerForImageTest extends Base {
|
||||||
|
|
||||||
|
public static void main(String args[]) throws Throwable {
|
||||||
|
UnnamedLoggerForImageTest t = new UnnamedLoggerForImageTest();
|
||||||
|
t.setup();
|
||||||
|
t.test();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setup() throws Throwable {
|
||||||
|
setupAllClient();
|
||||||
|
|
||||||
|
setupUnnamedLogger();
|
||||||
|
|
||||||
|
setupJavaBaseImage();
|
||||||
|
setupClientImage();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void test() throws Throwable {
|
||||||
|
if (!checkJMODS()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// logger client is in unnamed module
|
||||||
|
runTest(IMAGE,
|
||||||
|
"--class-path", DEST_UNNAMED_LOGGER.toString()
|
||||||
|
+ File.pathSeparator + DEST_UNNAMED_CLIENT.toString(),
|
||||||
|
CLIENT_B, "unnamed", LOGGER_B);
|
||||||
|
// logger client is in named module m.t.a
|
||||||
|
runTest(IMAGE,
|
||||||
|
"--class-path", DEST_UNNAMED_LOGGER.toString(),
|
||||||
|
"--module-path", DEST_NAMED_CLIENT.toString(),
|
||||||
|
"-m", CLIENT_A, "unnamed", LOGGER_B);
|
||||||
|
// logger client is in named module m.t.a which is in customized image
|
||||||
|
runTest(IMAGE_CLIENT,
|
||||||
|
"--class-path", DEST_UNNAMED_LOGGER.toString(),
|
||||||
|
"-m", CLIENT_A, "unnamed", LOGGER_B);
|
||||||
|
// logger client gets logger through boot class BootUsage
|
||||||
|
runTest(IMAGE,
|
||||||
|
"--class-path", DEST_UNNAMED_LOGGER.toString()
|
||||||
|
+ File.pathSeparator + DEST_BOOT_CLIENT.toString(),
|
||||||
|
"-Xbootclasspath/a:" + DEST_BOOT_USAGE.toString(),
|
||||||
|
BOOT_CLIENT, "system", LAZY_LOGGER, LOGGER_B);
|
||||||
|
// logger client gets logger through patched class
|
||||||
|
// java.base/java.lang.PatchedUsage
|
||||||
|
runTest(IMAGE,
|
||||||
|
"--class-path", DEST_UNNAMED_LOGGER.toString()
|
||||||
|
+ File.pathSeparator + DEST_PATCHED_CLIENT.toString(),
|
||||||
|
"--patch-module", "java.base=" + DEST_PATCHED_USAGE.toString(),
|
||||||
|
PATCHED_CLIENT, "system", LAZY_LOGGER, LOGGER_B);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,92 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, 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. Oracle designates this
|
||||||
|
* particular file as subject to the "Classpath" exception as provided
|
||||||
|
* by Oracle in the LICENSE file that accompanied this code.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.nio.file.StandardCopyOption;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
import jdk.testlibrary.JDKToolFinder;
|
||||||
|
|
||||||
|
import static jdk.testlibrary.ProcessTools.executeCommand;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @test
|
||||||
|
* @modules jdk.compiler
|
||||||
|
* @summary Test cases which run against the JDK image, check the situation where
|
||||||
|
* 1. logger providers are in unnamed module,
|
||||||
|
* 2. clients are in named/unnamed module,
|
||||||
|
* patched system module, or Xbootclasspath
|
||||||
|
* This test does not require existence of java.logging module,
|
||||||
|
* but require jdk.compiler module
|
||||||
|
* @library /lib/testlibrary
|
||||||
|
* @build Base CompilerUtils jdk.testlibrary.*
|
||||||
|
* @run main/othervm UnnamedLoggerForJDKTest
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class UnnamedLoggerForJDKTest extends Base {
|
||||||
|
|
||||||
|
public static void main(String args[]) throws Throwable {
|
||||||
|
UnnamedLoggerForJDKTest t = new UnnamedLoggerForJDKTest();
|
||||||
|
t.setup();
|
||||||
|
t.test();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setup() throws Throwable {
|
||||||
|
setupAllClient();
|
||||||
|
|
||||||
|
setupUnnamedLogger();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void test() throws Throwable {
|
||||||
|
// logger client is in named module m.t.a
|
||||||
|
runTest(JDK_IMAGE,
|
||||||
|
"--class-path", DEST_UNNAMED_LOGGER.toString(),
|
||||||
|
"--module-path", DEST_NAMED_CLIENT.toString(),
|
||||||
|
"-m", CLIENT_A, "unnamed", LOGGER_B);
|
||||||
|
// logger client is also in unnamed module
|
||||||
|
runTest(JDK_IMAGE,
|
||||||
|
"--class-path", DEST_UNNAMED_LOGGER.toString()
|
||||||
|
+ File.pathSeparator + DEST_UNNAMED_CLIENT.toString(),
|
||||||
|
CLIENT_B, "unnamed", LOGGER_B);
|
||||||
|
// logger client gets logger through boot class BootUsage
|
||||||
|
runTest(JDK_IMAGE,
|
||||||
|
"--class-path", DEST_UNNAMED_LOGGER.toString()
|
||||||
|
+ File.pathSeparator + DEST_BOOT_CLIENT.toString(),
|
||||||
|
"-Xbootclasspath/a:" + DEST_BOOT_USAGE.toString(),
|
||||||
|
BOOT_CLIENT, "system", LAZY_LOGGER, LOGGER_B);
|
||||||
|
// logger client gets logger through patched class
|
||||||
|
// java.base/java.lang.PatchedUsage
|
||||||
|
runTest(JDK_IMAGE,
|
||||||
|
"--class-path", DEST_UNNAMED_LOGGER.toString()
|
||||||
|
+ File.pathSeparator + DEST_PATCHED_CLIENT.toString(),
|
||||||
|
"--patch-module", "java.base=" + DEST_PATCHED_USAGE.toString(),
|
||||||
|
PATCHED_CLIENT, "system", LAZY_LOGGER, LOGGER_B);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,161 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, 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. Oracle designates this
|
||||||
|
* particular file as subject to the "Classpath" exception as provided
|
||||||
|
* by Oracle in the LICENSE file that accompanied this code.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.lang.System.Logger;
|
||||||
|
import java.util.ResourceBundle;
|
||||||
|
import java.util.ListResourceBundle;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Tests when logger client is in Xbootclasspath
|
||||||
|
*/
|
||||||
|
public final class BootClient {
|
||||||
|
|
||||||
|
public static void main(String[] args) throws Exception {
|
||||||
|
assertTrue(args.length >= 2);
|
||||||
|
String loggerMode = args[0];
|
||||||
|
String loggerClassName = args[1];
|
||||||
|
String underlyingLoggerClassName = args.length >= 3 ? args[2] : null;
|
||||||
|
|
||||||
|
testLogger(loggerMode, loggerClassName, underlyingLoggerClassName);
|
||||||
|
testLog(underlyingLoggerClassName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Tests System.getLogger(String) get expected logger.
|
||||||
|
*/
|
||||||
|
private static void testLogger(String loggerMode, String loggerClassName,
|
||||||
|
String underlyingLoggerClassName) {
|
||||||
|
String name = "test.boot";
|
||||||
|
Logger logger = getLogger(name);
|
||||||
|
printLogger(logger);
|
||||||
|
|
||||||
|
final Module lm = logger.getClass().getModule();
|
||||||
|
final ClassLoader loggerCL = lm.getClassLoader();
|
||||||
|
if (loggerMode.equals("system")) {
|
||||||
|
assertTrue(lm.isNamed());
|
||||||
|
assertTrue(loggerCL == null);
|
||||||
|
} else if(loggerMode.equals("unnamed")) {
|
||||||
|
assertTrue(!lm.isNamed());
|
||||||
|
assertTrue(loggerCL != null);
|
||||||
|
} else {
|
||||||
|
throw new RuntimeException("wrong parameter");
|
||||||
|
}
|
||||||
|
|
||||||
|
assertTrue(loggerClassName.equals(logger.getClass().getName()));
|
||||||
|
if (underlyingLoggerClassName != null) {
|
||||||
|
String loggerName = logger.getName();
|
||||||
|
if (underlyingLoggerClassName.equals(
|
||||||
|
"sun.util.logging.internal.LoggingProviderImpl$JULWrapper")) {
|
||||||
|
assertTrue(loggerName.equals(name));
|
||||||
|
} else {
|
||||||
|
assertTrue(loggerName.equals(underlyingLoggerClassName));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Tests Logger retrieved by System.getLogger(String, ResourceBundle) and
|
||||||
|
* System.getLogger(String) works well.
|
||||||
|
*/
|
||||||
|
private static void testLog(String underlyingLoggerClassName) throws Exception {
|
||||||
|
if (underlyingLoggerClassName == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (underlyingLoggerClassName.equals("pkg.a.l.LoggerA")
|
||||||
|
|| underlyingLoggerClassName.equals("pkg.b.l.LoggerB")) {
|
||||||
|
|
||||||
|
String name = "test.boot.logger";
|
||||||
|
String plainMsg = "this is test log message #1";
|
||||||
|
ResourceBundle rb = new MyResourcesBoot();
|
||||||
|
Throwable ex = new Throwable("this is an expected exception to be logged");
|
||||||
|
Class<?> clazz = Class.forName(underlyingLoggerClassName);
|
||||||
|
Method method = clazz.getMethod("checkLog", String.class,
|
||||||
|
System.Logger.Level.class,
|
||||||
|
ResourceBundle.class, String.class,
|
||||||
|
Throwable.class, Object[].class);
|
||||||
|
|
||||||
|
Logger logger = getLogger(name);
|
||||||
|
printLogger(logger);
|
||||||
|
assertTrue(logger.getClass().getName()
|
||||||
|
.equals("jdk.internal.logger.LazyLoggers$JdkLazyLogger"));
|
||||||
|
assertTrue(logger.getName().equals(underlyingLoggerClassName));
|
||||||
|
logger.log(Logger.Level.WARNING, plainMsg);
|
||||||
|
boolean pass = (boolean)method.invoke(null, name, Logger.Level.WARNING,
|
||||||
|
null, plainMsg, ex, (Object)null);
|
||||||
|
assertTrue(pass);
|
||||||
|
pass = (boolean)method.invoke(null, name, Logger.Level.INFO,
|
||||||
|
rb, MyResourcesBoot.VALUE, (Throwable)null,
|
||||||
|
(Object)null);
|
||||||
|
assertTrue(!pass);
|
||||||
|
|
||||||
|
logger = getLogger(name, rb);
|
||||||
|
printLogger(logger);
|
||||||
|
assertTrue(logger.getClass().getName()
|
||||||
|
.equals("jdk.internal.logger.LocalizedLoggerWrapper"));
|
||||||
|
assertTrue(logger.getName().equals(underlyingLoggerClassName));
|
||||||
|
logger.log(Logger.Level.INFO, MyResourcesBoot.KEY);
|
||||||
|
pass = (boolean)method.invoke(null, name, Logger.Level.INFO,
|
||||||
|
rb, MyResourcesBoot.VALUE, (Throwable)null,
|
||||||
|
(Object)null);
|
||||||
|
assertTrue(pass);
|
||||||
|
pass = (boolean)method.invoke(null, name, Logger.Level.WARNING,
|
||||||
|
null, plainMsg, ex, (Object)null);
|
||||||
|
assertTrue(pass);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class MyResourcesBoot extends ListResourceBundle {
|
||||||
|
static final String KEY = "this is the key in MyResourcesBoot";
|
||||||
|
static final String VALUE = "THIS IS THE VALUE IN MyResourcesBoot";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Object[][] getContents() {
|
||||||
|
return new Object[][] {
|
||||||
|
{KEY, VALUE}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Logger getLogger(String name) {
|
||||||
|
return BootUsage.getLogger(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Logger getLogger(String name, ResourceBundle rb) {
|
||||||
|
return BootUsage.getLogger(name, rb);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void printLogger(Logger logger) {
|
||||||
|
System.err.println("logger name: " + logger.getName()
|
||||||
|
+ ", logger class: " + logger.getClass());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void assertTrue(boolean b) {
|
||||||
|
if (!b) {
|
||||||
|
throw new RuntimeException("expected true, but get false.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,57 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, 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. Oracle designates this
|
||||||
|
* particular file as subject to the "Classpath" exception as provided
|
||||||
|
* by Oracle in the LICENSE file that accompanied this code.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import java.lang.System.Logger;
|
||||||
|
import java.util.ResourceBundle;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* BootUsage is put to Xbootclasspath, it will be used by
|
||||||
|
* BootClient to test when logger client is in boot classpath
|
||||||
|
*/
|
||||||
|
public final class BootUsage {
|
||||||
|
|
||||||
|
public static Logger getLogger(String name) {
|
||||||
|
check();
|
||||||
|
return System.getLogger(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Logger getLogger(String name, ResourceBundle rb) {
|
||||||
|
check();
|
||||||
|
return System.getLogger(name, rb);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void check() {
|
||||||
|
final Module m = BootUsage.class.getModule();
|
||||||
|
final ClassLoader moduleCL = m.getClassLoader();
|
||||||
|
assertTrue(!m.isNamed());
|
||||||
|
assertTrue(moduleCL == null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void assertTrue(boolean b) {
|
||||||
|
if (!b) {
|
||||||
|
throw new RuntimeException("expected true, but get false.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,29 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, 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. Oracle designates this
|
||||||
|
* particular file as subject to the "Classpath" exception as provided
|
||||||
|
* by Oracle in the LICENSE file that accompanied this code.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
module m.t.a {
|
||||||
|
exports pkg.a.t;
|
||||||
|
uses System.LoggerFinder;
|
||||||
|
}
|
157
jdk/test/java/lang/System/LoggerFinder/modules/named_client/m.t.a/pkg/a/t/TestA.java
Normal file
157
jdk/test/java/lang/System/LoggerFinder/modules/named_client/m.t.a/pkg/a/t/TestA.java
Normal file
@ -0,0 +1,157 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, 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. Oracle designates this
|
||||||
|
* particular file as subject to the "Classpath" exception as provided
|
||||||
|
* by Oracle in the LICENSE file that accompanied this code.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package pkg.a.t;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.lang.System.Logger;
|
||||||
|
import java.util.ResourceBundle;
|
||||||
|
import java.util.ListResourceBundle;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Tests when logger client is in named module m.l.a
|
||||||
|
*/
|
||||||
|
public class TestA {
|
||||||
|
|
||||||
|
public static void main(String[] args) throws Exception {
|
||||||
|
assertTrue(args.length == 2);
|
||||||
|
String loggerMode = args[0];
|
||||||
|
String loggerClassName = args[1];
|
||||||
|
|
||||||
|
testLogger(loggerMode, loggerClassName);
|
||||||
|
testLog(loggerClassName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Tests System.getLogger(String) get expected logger.
|
||||||
|
*/
|
||||||
|
private static void testLogger(String loggerMode, String loggerClassName) {
|
||||||
|
final Module m = TestA.class.getModule();
|
||||||
|
final ClassLoader moduleCL = m.getClassLoader();
|
||||||
|
assertTrue(m.isNamed());
|
||||||
|
assertTrue(moduleCL != null);
|
||||||
|
|
||||||
|
String name = "test.a";
|
||||||
|
Logger logger = getLogger(name);
|
||||||
|
printLogger(logger);
|
||||||
|
|
||||||
|
final Module lm = logger.getClass().getModule();
|
||||||
|
final ClassLoader loggerCL = lm.getClassLoader();
|
||||||
|
if (loggerMode.equals("system")) {
|
||||||
|
assertTrue(lm.isNamed());
|
||||||
|
assertTrue(loggerCL == null);
|
||||||
|
} else if(loggerMode.equals("named")) {
|
||||||
|
assertTrue(lm.isNamed());
|
||||||
|
assertTrue(loggerCL != null);
|
||||||
|
} else if(loggerMode.equals("unnamed")) {
|
||||||
|
assertTrue(!lm.isNamed());
|
||||||
|
assertTrue(loggerCL != null);
|
||||||
|
} else {
|
||||||
|
throw new RuntimeException("wrong parameter");
|
||||||
|
}
|
||||||
|
|
||||||
|
assertTrue(loggerClassName.equals(logger.getClass().getName()));
|
||||||
|
assertTrue(!loggerClassName.equals("jdk.internal.logger.LazyLoggers$JdkLazyLogger"));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Tests Logger retrieved by System.getLogger(String, ResourceBundle) and
|
||||||
|
* System.getLogger(String) works well.
|
||||||
|
*/
|
||||||
|
private static void testLog(String loggerClassName) throws Exception {
|
||||||
|
if (loggerClassName.equals("pkg.a.l.LoggerA")
|
||||||
|
|| loggerClassName.equals("pkg.b.l.LoggerB")) {
|
||||||
|
|
||||||
|
String name = "test.a.A";
|
||||||
|
String plainMsg = "this is test log message #1";
|
||||||
|
ResourceBundle rb = new MyResourcesA();
|
||||||
|
Throwable ex = new Throwable("this is an expected exception to be logged");
|
||||||
|
Class<?> clazz = Class.forName(loggerClassName);
|
||||||
|
Method method = clazz.getMethod("checkLog", String.class,
|
||||||
|
System.Logger.Level.class,
|
||||||
|
ResourceBundle.class, String.class,
|
||||||
|
Throwable.class, Object[].class);
|
||||||
|
|
||||||
|
Logger logger = getLogger(name);
|
||||||
|
printLogger(logger);
|
||||||
|
assertTrue(logger.getClass().getName().equals(loggerClassName));
|
||||||
|
assertTrue(logger.getName().equals(loggerClassName));
|
||||||
|
logger.log(Logger.Level.WARNING, plainMsg);
|
||||||
|
boolean pass = (boolean)method.invoke(null, name,
|
||||||
|
Logger.Level.WARNING,
|
||||||
|
null, plainMsg, ex, (Object)null);
|
||||||
|
assertTrue(pass);
|
||||||
|
pass = (boolean)method.invoke(null, name, Logger.Level.INFO,
|
||||||
|
rb, MyResourcesA.VALUE, (Throwable)null,
|
||||||
|
(Object)null);
|
||||||
|
assertTrue(!pass);
|
||||||
|
|
||||||
|
logger = getLogger(name, rb);
|
||||||
|
printLogger(logger);
|
||||||
|
assertTrue(logger.getClass().getName()
|
||||||
|
.equals("jdk.internal.logger.LocalizedLoggerWrapper"));
|
||||||
|
assertTrue(logger.getName().equals(loggerClassName));
|
||||||
|
logger.log(Logger.Level.INFO, MyResourcesA.KEY);
|
||||||
|
pass = (boolean)method.invoke(null, name, Logger.Level.INFO,
|
||||||
|
rb, MyResourcesA.VALUE, (Throwable)null,
|
||||||
|
(Object)null);
|
||||||
|
assertTrue(pass);
|
||||||
|
pass = (boolean)method.invoke(null, name, Logger.Level.WARNING,
|
||||||
|
null, plainMsg, ex, (Object)null);
|
||||||
|
assertTrue(pass);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class MyResourcesA extends ListResourceBundle {
|
||||||
|
static final String KEY = "this is the key in MyResourcesA";
|
||||||
|
static final String VALUE = "THIS IS THE VALUE IN MyResourcesA";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Object[][] getContents() {
|
||||||
|
return new Object[][] {
|
||||||
|
{KEY, VALUE}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Logger getLogger(String name) {
|
||||||
|
return System.getLogger(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Logger getLogger(String name, ResourceBundle rb) {
|
||||||
|
return System.getLogger(name, rb);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void printLogger(Logger logger) {
|
||||||
|
System.err.println("logger name: " + logger.getName()
|
||||||
|
+ ", logger class: " + logger.getClass());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void assertTrue(boolean b) {
|
||||||
|
if (!b) {
|
||||||
|
throw new RuntimeException("expected true, but get false.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,29 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, 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. Oracle designates this
|
||||||
|
* particular file as subject to the "Classpath" exception as provided
|
||||||
|
* by Oracle in the LICENSE file that accompanied this code.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
module m.l.a {
|
||||||
|
opens pkg.a.l;
|
||||||
|
provides java.lang.System.LoggerFinder with pkg.a.p.LoggerFinderA;
|
||||||
|
}
|
129
jdk/test/java/lang/System/LoggerFinder/modules/named_logger/m.l.a/pkg/a/l/LoggerA.java
Normal file
129
jdk/test/java/lang/System/LoggerFinder/modules/named_logger/m.l.a/pkg/a/l/LoggerA.java
Normal file
@ -0,0 +1,129 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, 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. Oracle designates this
|
||||||
|
* particular file as subject to the "Classpath" exception as provided
|
||||||
|
* by Oracle in the LICENSE file that accompanied this code.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package pkg.a.l;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Queue;
|
||||||
|
import java.util.ResourceBundle;
|
||||||
|
|
||||||
|
public class LoggerA implements System.Logger {
|
||||||
|
|
||||||
|
// ---- test utility fields and methods ----
|
||||||
|
|
||||||
|
private static Map<String, LoggerA> map = new HashMap<>();
|
||||||
|
|
||||||
|
public static LoggerA getLogger(String name) {
|
||||||
|
return map.computeIfAbsent(name, (n) -> new LoggerA());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean checkLog(String name, Level level, ResourceBundle bundle,
|
||||||
|
String format, Throwable throwable, Object... params) {
|
||||||
|
LoggerA logger = map.get(name);
|
||||||
|
LogEvent event = new LogEvent(level, bundle, format, null, params);
|
||||||
|
for (LogEvent l : logger.queue) {
|
||||||
|
if (l.equals(event)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---- logger implementation ----
|
||||||
|
|
||||||
|
private Queue<LogEvent> queue = new LinkedList<>();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return this.getClass().getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isLoggable(Level level) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void log(Level level, ResourceBundle bundle, String format, Object... params) {
|
||||||
|
String msg = bundle != null ? bundle.getString(format) : format;
|
||||||
|
log(new LogEvent(level, bundle, msg, null, params));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void log(Level level, ResourceBundle bundle, String format, Throwable throwable) {
|
||||||
|
String msg = bundle != null ? bundle.getString(format) : format;
|
||||||
|
log(new LogEvent(level, bundle, msg, throwable, (Object)null));
|
||||||
|
}
|
||||||
|
|
||||||
|
void log(LogEvent l) {
|
||||||
|
print(l);
|
||||||
|
queue.add(l);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void print(LogEvent l) {
|
||||||
|
System.err.println("LoggerA Message"+ l);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Queue<LogEvent> getLogEvent() {
|
||||||
|
return queue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class LogEvent {
|
||||||
|
public LogEvent(Level level, ResourceBundle bundle, String format,
|
||||||
|
Throwable throwable, Object... params) {
|
||||||
|
this.level = level;
|
||||||
|
this.bundle = bundle;
|
||||||
|
this.format = format;
|
||||||
|
this.throwable = throwable;
|
||||||
|
this.params = params;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (o instanceof LogEvent) {
|
||||||
|
LogEvent e = (LogEvent)o;
|
||||||
|
return level == e.level
|
||||||
|
&& bundle == e.bundle
|
||||||
|
&& format == e.format
|
||||||
|
&& params == e.params;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return String.format("[level: %s, bundle: %s, format: %s, throwable: %s, object: %s]",
|
||||||
|
level, bundle, format, throwable, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Level level;
|
||||||
|
private ResourceBundle bundle;
|
||||||
|
private String format;
|
||||||
|
private Throwable throwable;
|
||||||
|
private Object[] params;
|
||||||
|
}
|
||||||
|
}
|
35
jdk/test/java/lang/System/LoggerFinder/modules/named_logger/m.l.a/pkg/a/p/LoggerFinderA.java
Normal file
35
jdk/test/java/lang/System/LoggerFinder/modules/named_logger/m.l.a/pkg/a/p/LoggerFinderA.java
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, 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. Oracle designates this
|
||||||
|
* particular file as subject to the "Classpath" exception as provided
|
||||||
|
* by Oracle in the LICENSE file that accompanied this code.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package pkg.a.p;
|
||||||
|
|
||||||
|
import pkg.a.l.LoggerA;
|
||||||
|
|
||||||
|
public class LoggerFinderA extends System.LoggerFinder {
|
||||||
|
@Override
|
||||||
|
public System.Logger getLogger(String name, Module module) {
|
||||||
|
return LoggerA.getLogger(name);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,161 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, 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. Oracle designates this
|
||||||
|
* particular file as subject to the "Classpath" exception as provided
|
||||||
|
* by Oracle in the LICENSE file that accompanied this code.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.lang.System.Logger;
|
||||||
|
import java.util.ResourceBundle;
|
||||||
|
import java.util.ListResourceBundle;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Tests when logger client is in patched module
|
||||||
|
*/
|
||||||
|
public class PatchedClient {
|
||||||
|
|
||||||
|
public static void main(String[] args) throws Exception {
|
||||||
|
assertTrue(args.length >= 2);
|
||||||
|
String loggerMode = args[0];
|
||||||
|
String loggerClassName = args[1];
|
||||||
|
String underlyingLoggerClassName = args.length >= 3 ? args[2] : null;
|
||||||
|
|
||||||
|
testLogger(loggerMode, loggerClassName, underlyingLoggerClassName);
|
||||||
|
testLog(underlyingLoggerClassName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Tests System.getLogger(String) get expected logger.
|
||||||
|
*/
|
||||||
|
private static void testLogger(String loggerMode, String loggerClassName,
|
||||||
|
String underlyingLoggerClassName) {
|
||||||
|
String name = "test.patched";
|
||||||
|
Logger logger = getLogger(name);
|
||||||
|
printLogger(logger);
|
||||||
|
|
||||||
|
final Module lm = logger.getClass().getModule();
|
||||||
|
final ClassLoader loggerCL = lm.getClassLoader();
|
||||||
|
if (loggerMode.equals("system")) {
|
||||||
|
assertTrue(lm.isNamed());
|
||||||
|
assertTrue(loggerCL == null);
|
||||||
|
} else if(loggerMode.equals("unnamed")) {
|
||||||
|
assertTrue(!lm.isNamed());
|
||||||
|
assertTrue(loggerCL != null);
|
||||||
|
} else {
|
||||||
|
throw new RuntimeException("wrong parameter");
|
||||||
|
}
|
||||||
|
|
||||||
|
assertTrue(loggerClassName.equals(logger.getClass().getName()));
|
||||||
|
if (underlyingLoggerClassName != null) {
|
||||||
|
String loggerName = logger.getName();
|
||||||
|
if (underlyingLoggerClassName.equals(
|
||||||
|
"sun.util.logging.internal.LoggingProviderImpl$JULWrapper")) {
|
||||||
|
assertTrue(loggerName.equals(name));
|
||||||
|
} else {
|
||||||
|
assertTrue(loggerName.equals(underlyingLoggerClassName));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Tests Logger retrieved by System.getLogger(String, ResourceBundle) and
|
||||||
|
* System.getLogger(String) works well.
|
||||||
|
*/
|
||||||
|
private static void testLog(String underlyingLoggerClassName) throws Exception {
|
||||||
|
if (underlyingLoggerClassName == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (underlyingLoggerClassName.equals("pkg.a.l.LoggerA")
|
||||||
|
|| underlyingLoggerClassName.equals("pkg.b.l.LoggerB")) {
|
||||||
|
|
||||||
|
String name = "test.patched.logger";
|
||||||
|
String plainMsg = "this is test log message #1";
|
||||||
|
ResourceBundle rb = new MyResourcesPatched();
|
||||||
|
Throwable ex = new Throwable("this is an expected exception to be logged");
|
||||||
|
Class<?> clazz = Class.forName(underlyingLoggerClassName);
|
||||||
|
Method method = clazz.getMethod("checkLog", String.class,
|
||||||
|
System.Logger.Level.class,
|
||||||
|
ResourceBundle.class, String.class,
|
||||||
|
Throwable.class, Object[].class);
|
||||||
|
|
||||||
|
Logger logger = getLogger(name);
|
||||||
|
printLogger(logger);
|
||||||
|
assertTrue(logger.getClass().getName()
|
||||||
|
.equals("jdk.internal.logger.LazyLoggers$JdkLazyLogger"));
|
||||||
|
assertTrue(logger.getName().equals(underlyingLoggerClassName));
|
||||||
|
logger.log(Logger.Level.WARNING, plainMsg);
|
||||||
|
boolean pass = (boolean)method.invoke(null, name, Logger.Level.WARNING,
|
||||||
|
null, plainMsg, ex, (Object)null);
|
||||||
|
assertTrue(pass);
|
||||||
|
pass = (boolean)method.invoke(null, name, Logger.Level.INFO,
|
||||||
|
rb, MyResourcesPatched.VALUE, (Throwable)null,
|
||||||
|
(Object)null);
|
||||||
|
assertTrue(!pass);
|
||||||
|
|
||||||
|
logger = getLogger(name, rb);
|
||||||
|
printLogger(logger);
|
||||||
|
assertTrue(logger.getClass().getName()
|
||||||
|
.equals("jdk.internal.logger.LocalizedLoggerWrapper"));
|
||||||
|
assertTrue(logger.getName().equals(underlyingLoggerClassName));
|
||||||
|
logger.log(Logger.Level.INFO, MyResourcesPatched.KEY);
|
||||||
|
pass = (boolean)method.invoke(null, name, Logger.Level.INFO,
|
||||||
|
rb, MyResourcesPatched.VALUE, (Throwable)null,
|
||||||
|
(Object)null);
|
||||||
|
assertTrue(pass);
|
||||||
|
pass = (boolean)method.invoke(null, name, Logger.Level.WARNING,
|
||||||
|
null, plainMsg, ex, (Object)null);
|
||||||
|
assertTrue(pass);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class MyResourcesPatched extends ListResourceBundle {
|
||||||
|
static final String KEY = "this is the key in MyResourcesPatched";
|
||||||
|
static final String VALUE = "THIS IS THE VALUE IN MyResourcesPatched";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Object[][] getContents() {
|
||||||
|
return new Object[][] {
|
||||||
|
{KEY, VALUE}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Logger getLogger(String name) {
|
||||||
|
return PatchedUsage.getLogger(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Logger getLogger(String name, ResourceBundle rb) {
|
||||||
|
return PatchedUsage.getLogger(name, rb);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void printLogger(Logger logger) {
|
||||||
|
System.err.println("logger name: " + logger.getName()
|
||||||
|
+ ", logger class: " + logger.getClass());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void assertTrue(boolean b) {
|
||||||
|
if (!b) {
|
||||||
|
throw new RuntimeException("expected true, but get false.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
59
jdk/test/java/lang/System/LoggerFinder/modules/patched_usage/java.base/java/lang/PatchedUsage.java
Normal file
59
jdk/test/java/lang/System/LoggerFinder/modules/patched_usage/java.base/java/lang/PatchedUsage.java
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, 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. Oracle designates this
|
||||||
|
* particular file as subject to the "Classpath" exception as provided
|
||||||
|
* by Oracle in the LICENSE file that accompanied this code.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package java.lang;
|
||||||
|
|
||||||
|
import java.lang.System.Logger;
|
||||||
|
import java.util.ResourceBundle;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* PatchedUsage is patched into java.base, it will be used by
|
||||||
|
* PatchedClient to test when logger client is in patched module
|
||||||
|
*/
|
||||||
|
public class PatchedUsage {
|
||||||
|
|
||||||
|
public static Logger getLogger(String name) {
|
||||||
|
check();
|
||||||
|
return System.getLogger(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Logger getLogger(String name, ResourceBundle rb) {
|
||||||
|
check();
|
||||||
|
return System.getLogger(name, rb);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void check() {
|
||||||
|
final Module m = PatchedUsage.class.getModule();
|
||||||
|
final ClassLoader moduleCL = m.getClassLoader();
|
||||||
|
assertTrue(m.isNamed());
|
||||||
|
assertTrue(moduleCL == null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void assertTrue(boolean b) {
|
||||||
|
if (!b) {
|
||||||
|
throw new RuntimeException("expected true, but get false.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,156 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, 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. Oracle designates this
|
||||||
|
* particular file as subject to the "Classpath" exception as provided
|
||||||
|
* by Oracle in the LICENSE file that accompanied this code.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package pkg.b.t;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.lang.System.Logger;
|
||||||
|
import java.util.ResourceBundle;
|
||||||
|
import java.util.ListResourceBundle;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Tests when logger client is in unnamed module
|
||||||
|
*/
|
||||||
|
public class TestB {
|
||||||
|
|
||||||
|
public static void main(String[] args) throws Exception {
|
||||||
|
assertTrue(args.length == 2);
|
||||||
|
String loggerMode = args[0];
|
||||||
|
String loggerClassName = args[1];
|
||||||
|
|
||||||
|
testLogger(loggerMode, loggerClassName);
|
||||||
|
testLog(loggerClassName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Tests System.getLogger(String) get expected logger.
|
||||||
|
*/
|
||||||
|
private static void testLogger(String loggerMode, String loggerClassName) {
|
||||||
|
final Module m = TestB.class.getModule();
|
||||||
|
final ClassLoader moduleCL = m.getClassLoader();
|
||||||
|
assertTrue(!m.isNamed());
|
||||||
|
assertTrue(moduleCL != null);
|
||||||
|
|
||||||
|
String name = "test.b";
|
||||||
|
Logger logger = getLogger(name);
|
||||||
|
printLogger(logger);
|
||||||
|
|
||||||
|
final Module lm = logger.getClass().getModule();
|
||||||
|
final ClassLoader loggerCL = lm.getClassLoader();
|
||||||
|
if (loggerMode.equals("system")) {
|
||||||
|
assertTrue(lm.isNamed());
|
||||||
|
assertTrue(loggerCL == null);
|
||||||
|
} else if(loggerMode.equals("named")) {
|
||||||
|
assertTrue(lm.isNamed());
|
||||||
|
assertTrue(loggerCL != null);
|
||||||
|
} else if(loggerMode.equals("unnamed")) {
|
||||||
|
assertTrue(!lm.isNamed());
|
||||||
|
assertTrue(loggerCL != null);
|
||||||
|
} else {
|
||||||
|
throw new RuntimeException("wrong parameter");
|
||||||
|
}
|
||||||
|
|
||||||
|
assertTrue(loggerClassName.equals(logger.getClass().getName()));
|
||||||
|
assertTrue(!loggerClassName.equals("jdk.internal.logger.LazyLoggers$JdkLazyLogger"));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Tests Logger retrieved by System.getLogger(String, ResourceBundle) and
|
||||||
|
* System.getLogger(String) works well.
|
||||||
|
*/
|
||||||
|
private static void testLog(String loggerClassName) throws Exception {
|
||||||
|
if (loggerClassName.equals("pkg.a.l.LoggerA")
|
||||||
|
|| loggerClassName.equals("pkg.b.l.LoggerB")) {
|
||||||
|
|
||||||
|
String name = "test.b.B";
|
||||||
|
String plainMsg = "this is test log message #1";
|
||||||
|
ResourceBundle rb = new MyResourcesB();
|
||||||
|
Throwable ex = new Throwable("this is an expected exception to be logged");
|
||||||
|
Class<?> clazz = Class.forName(loggerClassName);
|
||||||
|
Method method = clazz.getMethod("checkLog", String.class,
|
||||||
|
System.Logger.Level.class,
|
||||||
|
ResourceBundle.class, String.class,
|
||||||
|
Throwable.class, Object[].class);
|
||||||
|
|
||||||
|
Logger logger = getLogger(name);
|
||||||
|
printLogger(logger);
|
||||||
|
assertTrue(logger.getClass().getName().equals(loggerClassName));
|
||||||
|
assertTrue(logger.getName().equals(loggerClassName));
|
||||||
|
logger.log(Logger.Level.WARNING, plainMsg);
|
||||||
|
boolean pass = (boolean)method.invoke(null, name, Logger.Level.WARNING,
|
||||||
|
null, plainMsg, ex, (Object)null);
|
||||||
|
assertTrue(pass);
|
||||||
|
pass = (boolean)method.invoke(null, name, Logger.Level.INFO,
|
||||||
|
rb, MyResourcesB.VALUE, (Throwable)null,
|
||||||
|
(Object)null);
|
||||||
|
assertTrue(!pass);
|
||||||
|
|
||||||
|
logger = getLogger(name, rb);
|
||||||
|
printLogger(logger);
|
||||||
|
assertTrue(logger.getClass().getName()
|
||||||
|
.equals("jdk.internal.logger.LocalizedLoggerWrapper"));
|
||||||
|
assertTrue(logger.getName().equals(loggerClassName));
|
||||||
|
logger.log(Logger.Level.INFO, MyResourcesB.KEY);
|
||||||
|
pass = (boolean)method.invoke(null, name, Logger.Level.INFO,
|
||||||
|
rb, MyResourcesB.VALUE, (Throwable)null,
|
||||||
|
(Object)null);
|
||||||
|
assertTrue(pass);
|
||||||
|
pass = (boolean)method.invoke(null, name, Logger.Level.WARNING,
|
||||||
|
null, plainMsg, ex, (Object)null);
|
||||||
|
assertTrue(pass);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class MyResourcesB extends ListResourceBundle {
|
||||||
|
static final String KEY = "this is the key in MyResourcesB";
|
||||||
|
static final String VALUE = "THIS IS THE VALUE IN MyResourcesB";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Object[][] getContents() {
|
||||||
|
return new Object[][] {
|
||||||
|
{KEY, VALUE}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Logger getLogger(String name) {
|
||||||
|
return System.getLogger(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Logger getLogger(String name, ResourceBundle rb) {
|
||||||
|
return System.getLogger(name, rb);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void printLogger(Logger logger) {
|
||||||
|
System.err.println("logger name: " + logger.getName()
|
||||||
|
+ ", logger class: " + logger.getClass());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void assertTrue(boolean b) {
|
||||||
|
if (!b) {
|
||||||
|
throw new RuntimeException("expected true, but get false.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
1
jdk/test/java/lang/System/LoggerFinder/modules/unnamed_logger/META-INF/services/java.lang.System$LoggerFinder
Normal file
1
jdk/test/java/lang/System/LoggerFinder/modules/unnamed_logger/META-INF/services/java.lang.System$LoggerFinder
Normal file
@ -0,0 +1 @@
|
|||||||
|
pkg.b.p.LoggerFinderB
|
@ -0,0 +1,123 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, 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. Oracle designates this
|
||||||
|
* particular file as subject to the "Classpath" exception as provided
|
||||||
|
* by Oracle in the LICENSE file that accompanied this code.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package pkg.b.l;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Queue;
|
||||||
|
import java.util.ResourceBundle;
|
||||||
|
|
||||||
|
public class LoggerB implements System.Logger {
|
||||||
|
|
||||||
|
// ---- test utility fields and methods ----
|
||||||
|
|
||||||
|
private static Map<String, LoggerB> map = new HashMap<>();
|
||||||
|
|
||||||
|
public static LoggerB getLogger(String name) {
|
||||||
|
return map.computeIfAbsent(name, (n) -> new LoggerB());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean checkLog(String name, Level level, ResourceBundle bundle,
|
||||||
|
String format, Throwable throwable, Object... params) {
|
||||||
|
LoggerB logger = map.get(name);
|
||||||
|
LogEvent event = new LogEvent(level, bundle, format, null, params);
|
||||||
|
for (LogEvent l : logger.queue) {
|
||||||
|
if (l.equals(event)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---- logger implementation ----
|
||||||
|
|
||||||
|
private Queue<LogEvent> queue = new LinkedList<>();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return this.getClass().getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isLoggable(Level level) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void log(Level level, ResourceBundle bundle, String format, Object... params) {
|
||||||
|
String msg = bundle != null ? bundle.getString(format) : format;
|
||||||
|
log(new LogEvent(level, bundle, msg, null, params));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void log(Level level, ResourceBundle bundle, String format, Throwable throwable) {
|
||||||
|
String msg = bundle != null ? bundle.getString(format) : format;
|
||||||
|
log(new LogEvent(level, bundle, msg, throwable, (Object)null));
|
||||||
|
}
|
||||||
|
|
||||||
|
void log(LogEvent l) {
|
||||||
|
print(l);
|
||||||
|
queue.add(l);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void print(LogEvent l) {
|
||||||
|
System.err.println("LoggerB Message"+ l);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Queue<LogEvent> getLogEvent() {
|
||||||
|
return queue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class LogEvent {
|
||||||
|
public LogEvent(Level level, ResourceBundle bundle, String format,
|
||||||
|
Throwable throwable, Object... params) {
|
||||||
|
this.level = level;
|
||||||
|
this.bundle = bundle;
|
||||||
|
this.format = format;
|
||||||
|
this.throwable = throwable;
|
||||||
|
this.params = params;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (o instanceof LogEvent) {
|
||||||
|
LogEvent e = (LogEvent)o;
|
||||||
|
return level == e.level
|
||||||
|
&& bundle == e.bundle
|
||||||
|
&& format == e.format
|
||||||
|
&& params == e.params;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Level level;
|
||||||
|
private ResourceBundle bundle;
|
||||||
|
private String format;
|
||||||
|
private Throwable throwable;
|
||||||
|
private Object[] params;
|
||||||
|
}
|
||||||
|
}
|
35
jdk/test/java/lang/System/LoggerFinder/modules/unnamed_logger/pkg/b/p/LoggerFinderB.java
Normal file
35
jdk/test/java/lang/System/LoggerFinder/modules/unnamed_logger/pkg/b/p/LoggerFinderB.java
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, 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. Oracle designates this
|
||||||
|
* particular file as subject to the "Classpath" exception as provided
|
||||||
|
* by Oracle in the LICENSE file that accompanied this code.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package pkg.b.p;
|
||||||
|
|
||||||
|
import pkg.b.l.LoggerB;
|
||||||
|
|
||||||
|
public class LoggerFinderB extends System.LoggerFinder {
|
||||||
|
@Override
|
||||||
|
public System.Logger getLogger(String name, Module module) {
|
||||||
|
return LoggerB.getLogger(name);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user