test/tools/javac/EarlyAssertWrapper.java

Wed, 14 Nov 2018 10:18:25 -0800

author
diazhou
date
Wed, 14 Nov 2018 10:18:25 -0800
changeset 3762
7909abb85562
parent 554
9d9f26857129
child 2525
2eb010b6cb22
permissions
-rw-r--r--

Added tag jdk8u201-b04 for changeset a7f48b9dfb82

     1 /*
     2  * Copyright (c) 2010, 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 import java.io.*;
    25 import java.util.*;
    27 /*
    28  * Wrapper for the EarlyAssert test to run the test in a JVM without assertions
    29  * enabled.
    30  */
    31 public class EarlyAssertWrapper {
    32     public static void main(String... args) throws Exception {
    33         EarlyAssertWrapper w = new EarlyAssertWrapper();
    34         w.run();
    35     }
    37     void run() throws Exception {
    38         List<String> cmd = new ArrayList<String>();
    39         File java_home = new File(System.getProperty("java.home"));
    40         if (java_home.getName().equals("jre"))
    41             java_home = java_home.getParentFile();
    42         cmd.add(new File(new File(java_home, "bin"), "java").getPath());
    44         // ensure we run with the same bootclasspath as this test,
    45         // in case this test is being run with -Xbootclasspath
    46         cmd.add("-Xbootclasspath:" + System.getProperty("sun.boot.class.path"));
    48         // propogate classpath
    49         cmd.add("-classpath");
    50         cmd.add(System.getProperty("java.class.path"));
    52         // ensure all assertions disabled in target VM
    53         cmd.add("-da");
    54         cmd.add("-dsa");
    56         cmd.add("EarlyAssert");
    58         System.err.println("Running command: " + cmd);
    60         ProcessBuilder pb = new ProcessBuilder(cmd);
    61         pb.redirectErrorStream(true);
    62         Process p = pb.start();
    63         p.getOutputStream().close();
    65         StringWriter sw = new StringWriter();
    66         PrintWriter pw = new PrintWriter(sw);
    68         String line;
    69         DataInputStream in = new DataInputStream(p.getInputStream());
    70         try {
    71         while ((line = in.readLine()) != null)
    72             pw.println(line);
    73         } finally {
    74             in.close();
    75         }
    76         pw.close();
    78         String out = sw.toString();
    79         int rc = p.waitFor();
    80         if (rc != 0 || out.length() > 0)
    81             throw new Error("failed: rc=" + rc + (out.length() > 0 ? ": " + out : ""));
    82     }
    83 }

mercurial