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