jjg@500: /* ohair@554: * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. jjg@500: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. jjg@500: * jjg@500: * This code is free software; you can redistribute it and/or modify it jjg@500: * under the terms of the GNU General Public License version 2 only, as jjg@500: * published by the Free Software Foundation. jjg@500: * jjg@500: * This code is distributed in the hope that it will be useful, but WITHOUT jjg@500: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or jjg@500: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License jjg@500: * version 2 for more details (a copy is included in the LICENSE file that jjg@500: * accompanied this code). jjg@500: * jjg@500: * You should have received a copy of the GNU General Public License version jjg@500: * 2 along with this work; if not, write to the Free Software Foundation, jjg@500: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. jjg@500: * ohair@554: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA ohair@554: * or visit www.oracle.com if you need additional information or have any ohair@554: * questions. jjg@500: */ jjg@500: jjg@500: import java.io.*; jjg@500: import java.util.*; jjg@500: jjg@500: /* jjg@500: * Wrapper for the EarlyAssert test to run the test in a JVM without assertions jjg@500: * enabled. jjg@500: */ jjg@500: public class EarlyAssertWrapper { jjg@500: public static void main(String... args) throws Exception { jjg@500: EarlyAssertWrapper w = new EarlyAssertWrapper(); jjg@500: w.run(); jjg@500: } jjg@500: jjg@500: void run() throws Exception { jjg@500: List cmd = new ArrayList(); jjg@500: File java_home = new File(System.getProperty("java.home")); jjg@500: if (java_home.getName().equals("jre")) jjg@500: java_home = java_home.getParentFile(); jjg@500: cmd.add(new File(new File(java_home, "bin"), "java").getPath()); jjg@500: jjg@500: // ensure we run with the same bootclasspath as this test, jjg@500: // in case this test is being run with -Xbootclasspath jjg@500: cmd.add("-Xbootclasspath:" + System.getProperty("sun.boot.class.path")); jjg@500: jjg@500: // propogate classpath jjg@500: cmd.add("-classpath"); jjg@500: cmd.add(System.getProperty("java.class.path")); jjg@500: jjg@500: // ensure all assertions disabled in target VM jjg@500: cmd.add("-da"); jjg@500: cmd.add("-dsa"); jjg@500: jjg@500: cmd.add("EarlyAssert"); jjg@500: jjg@500: System.err.println("Running command: " + cmd); jjg@500: jjg@500: ProcessBuilder pb = new ProcessBuilder(cmd); jjg@500: pb.redirectErrorStream(true); jjg@500: Process p = pb.start(); jjg@500: p.getOutputStream().close(); jjg@500: jjg@500: StringWriter sw = new StringWriter(); jjg@500: PrintWriter pw = new PrintWriter(sw); jjg@500: jjg@500: String line; jjg@500: DataInputStream in = new DataInputStream(p.getInputStream()); jjg@500: try { jjg@500: while ((line = in.readLine()) != null) jjg@500: pw.println(line); jjg@500: } finally { jjg@500: in.close(); jjg@500: } jjg@500: pw.close(); jjg@500: jjg@500: String out = sw.toString(); jjg@500: int rc = p.waitFor(); jjg@500: if (rc != 0 || out.length() > 0) jjg@500: throw new Error("failed: rc=" + rc + (out.length() > 0 ? ": " + out : "")); jjg@500: } jjg@500: }