ToolProviderTest.java revision 3779:7d2f8aa366e2
1101313Stjr/* 2101313Stjr * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. 3101313Stjr * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4101313Stjr * 5101313Stjr * This code is free software; you can redistribute it and/or modify it 6101313Stjr * under the terms of the GNU General Public License version 2 only, as 7101313Stjr * published by the Free Software Foundation. 8101313Stjr * 9101313Stjr * This code is distributed in the hope that it will be useful, but WITHOUT 10101313Stjr * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11101313Stjr * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12101313Stjr * version 2 for more details (a copy is included in the LICENSE file that 13101313Stjr * accompanied this code). 14101313Stjr * 15101313Stjr * You should have received a copy of the GNU General Public License version 16101313Stjr * 2 along with this work; if not, write to the Free Software Foundation, 17101313Stjr * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18101313Stjr * 19101313Stjr * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20101313Stjr * or visit www.oracle.com if you need additional information or have any 21101313Stjr * questions. 22101313Stjr */ 23101313Stjr 24101313Stjrimport java.nio.file.Files; 25101313Stjrimport java.nio.file.Path; 26101313Stjrimport java.nio.file.Paths; 27104402Stjrimport java.util.Objects; 28101313Stjrimport javax.tools.ToolProvider; 29101313Stjr 30101313Stjr/** 31107392Sru * @test 32101313Stjr * @bug 8154190 33101313Stjr * @summary Test javax.tools.ToolProvider running with security manager 34101313Stjr * @modules java.compiler 35101313Stjr * jdk.compiler 36101313Stjr * @run main/othervm ToolProviderTest 37101313Stjr */ 38101313Stjr 39101313Stjr// run in other vm to ensure the initialization code path is exercised. 40101313Stjrpublic class ToolProviderTest { 41101313Stjr public static void main(String... args) { 42101313Stjr // The following code allows the test to be skipped when run on 43101313Stjr // an exploded image. 44101313Stjr // See https://bugs.openjdk.java.net/browse/JDK-8155858 45101313Stjr Path javaHome = Paths.get(System.getProperty("java.home")); 46101313Stjr Path image = javaHome.resolve("lib").resolve("modules"); 47101313Stjr Path modules = javaHome.resolve("modules"); 48101313Stjr if (!Files.exists(image) && Files.exists(modules)) { 49101313Stjr System.err.println("Test running on exploded image"); 50101313Stjr System.err.println("Test skipped!"); 51101313Stjr return; 52107392Sru } 53101313Stjr 54101313Stjr System.setSecurityManager(new SecurityManager()); 55101313Stjr 56101313Stjr Objects.requireNonNull(ToolProvider.getSystemDocumentationTool()); 57101313Stjr Objects.requireNonNull(ToolProvider.getSystemJavaCompiler()); 58101313Stjr if (ToolProvider.getSystemToolClassLoader() != null) { 59101313Stjr throw new AssertionError("unexpected value for getSystemToolClassLoader"); 60101313Stjr } 61101313Stjr } 62101313Stjr} 63101313Stjr