test/runtime/CheckEndorsedAndExtDirs/EndorsedExtDirs.java

Tue, 02 Dec 2014 08:42:50 -0800

author
mchung
date
Tue, 02 Dec 2014 08:42:50 -0800
changeset 7398
c03d85ef5e6a
parent 7368
fa6adc194d48
child 7423
28f116adb50c
permissions
-rw-r--r--

8065765: Missing space in output message from -XX:+CheckEndorsedAndExtDirs
Reviewed-by: hseigel, ccheung

     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  * @run main/othervm EndorsedExtDirs
    30  */
    32 import com.oracle.java.testlibrary.*;
    33 import java.io.File;
    34 import java.io.IOException;
    35 import java.nio.file.attribute.BasicFileAttributes;
    36 import java.nio.file.Files;
    37 import java.nio.file.Path;
    38 import java.nio.file.Paths;
    39 import java.util.ArrayList;
    40 import java.util.List;
    42 public class EndorsedExtDirs {
    43     static final String cpath = System.getProperty("test.classes", ".");
    44     public static void main(String arg[]) throws Exception {
    45         fatalError("-XX:+CheckEndorsedAndExtDirs", "-Djava.endorsed.dirs=foo");
    46         fatalError("-XX:+CheckEndorsedAndExtDirs", "-Djava.ext.dirs=bar");
    47         testNonEmptySystemExtDirs();
    48     }
    50     static void testNonEmptySystemExtDirs() throws Exception {
    51         String home = System.getProperty("java.home");
    52         Path ext = Paths.get(home, "lib", "ext");
    53         String extDirs = System.getProperty("java.ext.dirs");
    54         String[] dirs = extDirs.split(File.pathSeparator);
    55         long count = 0;
    56         for (String d : dirs) {
    57             Path path = Paths.get(d);
    58             if (Files.notExists(path) || path.equals(ext)) continue;
    59             count += Files.find(path, 1, (Path p, BasicFileAttributes attr)
    60                                        -> p.getFileName().toString().endsWith(".jar"))
    61                           .count();
    62         }
    63         if (count > 0) {
    64             fatalError("-XX:+CheckEndorsedAndExtDirs");
    65         }
    66     }
    68     static ProcessBuilder newProcessBuilder(String... args) {
    69         List<String> commands = new ArrayList<>();
    70         String java = System.getProperty("java.home") + "/bin/java";
    71         commands.add(java);
    72         for (String s : args) {
    73             commands.add(s);
    74         }
    75         commands.add("-cp");
    76         commands.add(cpath);
    77         commands.add("EndorsedExtDirs");
    79         System.out.println("Process " + commands);
    80         return new ProcessBuilder(commands);
    81     }
    83     static void fatalError(String... args) throws Exception {
    84         fatalError(newProcessBuilder(args));
    85     }
    87     static void fatalError(ProcessBuilder pb) throws Exception {
    88         OutputAnalyzer output = new OutputAnalyzer(pb.start());
    89         output.shouldContain("Could not create the Java Virtual Machine");
    90         output.shouldHaveExitValue(1);
    91     }
    92 }

mercurial