Path: blob/master/test/jdk/java/lang/System/LoggerFinder/BaseLoggerFinderTest/AccessSystemLogger.java
41154 views
/*1* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/22import java.io.IOException;23import java.lang.System.Logger;24import java.nio.file.Files;25import java.nio.file.Path;26import java.nio.file.Paths;27import java.nio.file.StandardCopyOption;28import java.util.ResourceBundle;2930/**31*32* @author danielfuchs33*/34public final class AccessSystemLogger {3536public AccessSystemLogger() {37this(check());38}3940private AccessSystemLogger(Void unused) {41}4243private static Void check() {44if (AccessSystemLogger.class.getClassLoader() != null) {45throw new RuntimeException("AccessSystemLogger should be loaded by the null classloader");46}47return null;48}4950public Logger getLogger(String name) {51Logger logger = System.getLogger(name);52System.out.println("System.getLogger(\"" + name + "\"): " + logger);53return logger;54}5556public Logger getLogger(String name, ResourceBundle bundle) {57Logger logger = System.getLogger(name, bundle);58System.out.println("System.getLogger(\"" + name + "\", bundle): " + logger);59return logger;60}6162// copy AccessSystemLogger.class to ./boot63public static void main(String[] args) throws IOException {64Path testDir = Paths.get(System.getProperty("user.dir", "."));65Path bootDir = Paths.get(testDir.toString(), "boot");66Path classes = Paths.get(System.getProperty("test.classes", "build/classes"));67Path thisClass = Paths.get(classes.toString(),68AccessSystemLogger.class.getSimpleName()+".class");69if (Files.notExists(bootDir)) {70Files.createDirectory(bootDir);71}72Path dest = Paths.get(bootDir.toString(),73AccessSystemLogger.class.getSimpleName()+".class");74Files.copy(thisClass, dest, StandardCopyOption.REPLACE_EXISTING);75}7677}787980