test/runtime/CheckEndorsedAndExtDirs/EndorsedExtDirs.java

Mon, 06 Nov 2017 16:51:47 +0800

author
aoqi
date
Mon, 06 Nov 2017 16:51:47 +0800
changeset 7997
6cbff0651f1a
parent 7423
28f116adb50c
permissions
-rw-r--r--

[Code Reorganization] remove trailing whitespace to pass jcheck test

mchung@7368 1 /*
mchung@7368 2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
mchung@7368 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
mchung@7368 4 *
mchung@7368 5 * This code is free software; you can redistribute it and/or modify it
mchung@7368 6 * under the terms of the GNU General Public License version 2 only, as
mchung@7368 7 * published by the Free Software Foundation.
mchung@7368 8 *
mchung@7368 9 * This code is distributed in the hope that it will be useful, but WITHOUT
mchung@7368 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
mchung@7368 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
mchung@7368 12 * version 2 for more details (a copy is included in the LICENSE file that
mchung@7368 13 * accompanied this code).
mchung@7368 14 *
mchung@7368 15 * You should have received a copy of the GNU General Public License version
mchung@7368 16 * 2 along with this work; if not, write to the Free Software Foundation,
mchung@7368 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
mchung@7368 18 *
mchung@7368 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
mchung@7368 20 * or visit www.oracle.com if you need additional information or have any
mchung@7368 21 * questions.
mchung@7368 22 */
mchung@7368 23
mchung@7368 24 /*
mchung@7368 25 * @test
mchung@7368 26 * @bug 8064667
mchung@7368 27 * @summary Sanity test for -XX:+CheckEndorsedAndExtDirs
mchung@7368 28 * @library /testlibrary
mseledtsov@7423 29 * @build com.oracle.java.testlibrary.*
mchung@7398 30 * @run main/othervm EndorsedExtDirs
mchung@7368 31 */
mchung@7368 32
mchung@7368 33 import com.oracle.java.testlibrary.*;
mchung@7398 34 import java.io.File;
mchung@7398 35 import java.io.IOException;
mchung@7398 36 import java.nio.file.attribute.BasicFileAttributes;
mchung@7398 37 import java.nio.file.Files;
mchung@7398 38 import java.nio.file.Path;
mchung@7398 39 import java.nio.file.Paths;
mchung@7368 40 import java.util.ArrayList;
mchung@7368 41 import java.util.List;
mchung@7368 42
mchung@7368 43 public class EndorsedExtDirs {
mchung@7368 44 static final String cpath = System.getProperty("test.classes", ".");
mchung@7368 45 public static void main(String arg[]) throws Exception {
mchung@7368 46 fatalError("-XX:+CheckEndorsedAndExtDirs", "-Djava.endorsed.dirs=foo");
mchung@7368 47 fatalError("-XX:+CheckEndorsedAndExtDirs", "-Djava.ext.dirs=bar");
mchung@7398 48 testNonEmptySystemExtDirs();
mchung@7368 49 }
mchung@7368 50
mchung@7398 51 static void testNonEmptySystemExtDirs() throws Exception {
mchung@7398 52 String home = System.getProperty("java.home");
mchung@7398 53 Path ext = Paths.get(home, "lib", "ext");
mchung@7398 54 String extDirs = System.getProperty("java.ext.dirs");
mchung@7398 55 String[] dirs = extDirs.split(File.pathSeparator);
mchung@7398 56 long count = 0;
mchung@7398 57 for (String d : dirs) {
mchung@7398 58 Path path = Paths.get(d);
mchung@7398 59 if (Files.notExists(path) || path.equals(ext)) continue;
mchung@7398 60 count += Files.find(path, 1, (Path p, BasicFileAttributes attr)
mchung@7398 61 -> p.getFileName().toString().endsWith(".jar"))
mchung@7398 62 .count();
mchung@7398 63 }
mchung@7398 64 if (count > 0) {
mchung@7398 65 fatalError("-XX:+CheckEndorsedAndExtDirs");
mchung@7398 66 }
mchung@7398 67 }
mchung@7398 68
mchung@7398 69 static ProcessBuilder newProcessBuilder(String... args) {
mchung@7368 70 List<String> commands = new ArrayList<>();
mchung@7368 71 String java = System.getProperty("java.home") + "/bin/java";
mchung@7368 72 commands.add(java);
mchung@7368 73 for (String s : args) {
mchung@7368 74 commands.add(s);
mchung@7368 75 }
mchung@7368 76 commands.add("-cp");
mchung@7368 77 commands.add(cpath);
mchung@7368 78 commands.add("EndorsedExtDirs");
mchung@7368 79
mchung@7398 80 System.out.println("Process " + commands);
mchung@7398 81 return new ProcessBuilder(commands);
mchung@7398 82 }
mchung@7398 83
mchung@7398 84 static void fatalError(String... args) throws Exception {
mchung@7398 85 fatalError(newProcessBuilder(args));
mchung@7398 86 }
mchung@7398 87
mchung@7398 88 static void fatalError(ProcessBuilder pb) throws Exception {
mchung@7368 89 OutputAnalyzer output = new OutputAnalyzer(pb.start());
mchung@7368 90 output.shouldContain("Could not create the Java Virtual Machine");
mchung@7368 91 output.shouldHaveExitValue(1);
mchung@7368 92 }
mchung@7368 93 }

mercurial