Mon, 03 Oct 2016 11:21:14 -0700
Added tag jdk8u122-b02 for changeset 2baeb96fa198
jjg@500 | 1 | /* |
ohair@554 | 2 | * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. |
jjg@500 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
jjg@500 | 4 | * |
jjg@500 | 5 | * This code is free software; you can redistribute it and/or modify it |
jjg@500 | 6 | * under the terms of the GNU General Public License version 2 only, as |
jjg@500 | 7 | * published by the Free Software Foundation. |
jjg@500 | 8 | * |
jjg@500 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
jjg@500 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
jjg@500 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
jjg@500 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
jjg@500 | 13 | * accompanied this code). |
jjg@500 | 14 | * |
jjg@500 | 15 | * You should have received a copy of the GNU General Public License version |
jjg@500 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
jjg@500 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
jjg@500 | 18 | * |
ohair@554 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ohair@554 | 20 | * or visit www.oracle.com if you need additional information or have any |
ohair@554 | 21 | * questions. |
jjg@500 | 22 | */ |
jjg@500 | 23 | |
jjg@500 | 24 | import java.io.*; |
jjg@500 | 25 | import java.util.*; |
jjg@500 | 26 | |
jjg@500 | 27 | /* |
jjg@500 | 28 | * Wrapper for the EarlyAssert test to run the test in a JVM without assertions |
jjg@500 | 29 | * enabled. |
jjg@500 | 30 | */ |
jjg@500 | 31 | public class EarlyAssertWrapper { |
jjg@500 | 32 | public static void main(String... args) throws Exception { |
jjg@500 | 33 | EarlyAssertWrapper w = new EarlyAssertWrapper(); |
jjg@500 | 34 | w.run(); |
jjg@500 | 35 | } |
jjg@500 | 36 | |
jjg@500 | 37 | void run() throws Exception { |
jjg@500 | 38 | List<String> cmd = new ArrayList<String>(); |
jjg@500 | 39 | File java_home = new File(System.getProperty("java.home")); |
jjg@500 | 40 | if (java_home.getName().equals("jre")) |
jjg@500 | 41 | java_home = java_home.getParentFile(); |
jjg@500 | 42 | cmd.add(new File(new File(java_home, "bin"), "java").getPath()); |
jjg@500 | 43 | |
jjg@500 | 44 | // ensure we run with the same bootclasspath as this test, |
jjg@500 | 45 | // in case this test is being run with -Xbootclasspath |
jjg@500 | 46 | cmd.add("-Xbootclasspath:" + System.getProperty("sun.boot.class.path")); |
jjg@500 | 47 | |
jjg@500 | 48 | // propogate classpath |
jjg@500 | 49 | cmd.add("-classpath"); |
jjg@500 | 50 | cmd.add(System.getProperty("java.class.path")); |
jjg@500 | 51 | |
jjg@500 | 52 | // ensure all assertions disabled in target VM |
jjg@500 | 53 | cmd.add("-da"); |
jjg@500 | 54 | cmd.add("-dsa"); |
jjg@500 | 55 | |
jjg@500 | 56 | cmd.add("EarlyAssert"); |
jjg@500 | 57 | |
jjg@500 | 58 | System.err.println("Running command: " + cmd); |
jjg@500 | 59 | |
jjg@500 | 60 | ProcessBuilder pb = new ProcessBuilder(cmd); |
jjg@500 | 61 | pb.redirectErrorStream(true); |
jjg@500 | 62 | Process p = pb.start(); |
jjg@500 | 63 | p.getOutputStream().close(); |
jjg@500 | 64 | |
jjg@500 | 65 | StringWriter sw = new StringWriter(); |
jjg@500 | 66 | PrintWriter pw = new PrintWriter(sw); |
jjg@500 | 67 | |
jjg@500 | 68 | String line; |
jjg@500 | 69 | DataInputStream in = new DataInputStream(p.getInputStream()); |
jjg@500 | 70 | try { |
jjg@500 | 71 | while ((line = in.readLine()) != null) |
jjg@500 | 72 | pw.println(line); |
jjg@500 | 73 | } finally { |
jjg@500 | 74 | in.close(); |
jjg@500 | 75 | } |
jjg@500 | 76 | pw.close(); |
jjg@500 | 77 | |
jjg@500 | 78 | String out = sw.toString(); |
jjg@500 | 79 | int rc = p.waitFor(); |
jjg@500 | 80 | if (rc != 0 || out.length() > 0) |
jjg@500 | 81 | throw new Error("failed: rc=" + rc + (out.length() > 0 ? ": " + out : "")); |
jjg@500 | 82 | } |
jjg@500 | 83 | } |