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