1 /*
2 * Copyright (c) 2017, 2018, 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 */
547 public static File getOutputFile(String name) {
548 File dir = new File(System.getProperty("test.classes", "."));
549 return new File(dir, getTestName() + "-" + name);
550 }
551
552
553 public static File getOutputSourceFile(String name) {
554 File dir = new File(System.getProperty("test.classes", "."));
555 return new File(dir, name);
556 }
557
558
559 public static File getSourceFile(String name) {
560 File dir = new File(System.getProperty("test.src", "."));
561 return new File(dir, name);
562 }
563
564
565 // ============================= Logging
566 public static OutputAnalyzer executeAndLog(ProcessBuilder pb, String logName) throws Exception {
567 long started = System.currentTimeMillis();
568 OutputAnalyzer output = new OutputAnalyzer(pb.start());
569 String outputFileNamePrefix =
570 getTestName() + "-" + String.format("%04d", getNextLogCounter()) + "-" + logName;
571
572 writeFile(getOutputFile(outputFileNamePrefix + ".stdout"), output.getStdout());
573 writeFile(getOutputFile(outputFileNamePrefix + ".stderr"), output.getStderr());
574 System.out.println("[ELAPSED: " + (System.currentTimeMillis() - started) + " ms]");
575 System.out.println("[logging stdout to " + outputFileNamePrefix + ".stdout]");
576 System.out.println("[logging stderr to " + outputFileNamePrefix + ".stderr]");
577 System.out.println("[STDERR]\n" + output.getStderr());
578
579 if (copyChildStdoutToMainStdout)
580 System.out.println("[STDOUT]\n" + output.getStdout());
581
582 return output;
583 }
584
585
586 private static void writeFile(File file, String content) throws Exception {
587 FileOutputStream fos = new FileOutputStream(file);
588 PrintStream ps = new PrintStream(fos);
|
1 /*
2 * Copyright (c) 2017, 2019, 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 */
547 public static File getOutputFile(String name) {
548 File dir = new File(System.getProperty("test.classes", "."));
549 return new File(dir, getTestName() + "-" + name);
550 }
551
552
553 public static File getOutputSourceFile(String name) {
554 File dir = new File(System.getProperty("test.classes", "."));
555 return new File(dir, name);
556 }
557
558
559 public static File getSourceFile(String name) {
560 File dir = new File(System.getProperty("test.src", "."));
561 return new File(dir, name);
562 }
563
564
565 // ============================= Logging
566 public static OutputAnalyzer executeAndLog(ProcessBuilder pb, String logName) throws Exception {
567 return executeAndLog(pb.start(), logName);
568 }
569
570 public static OutputAnalyzer executeAndLog(Process process, String logName) throws Exception {
571 long started = System.currentTimeMillis();
572 OutputAnalyzer output = new OutputAnalyzer(process);
573 String outputFileNamePrefix =
574 getTestName() + "-" + String.format("%04d", getNextLogCounter()) + "-" + logName;
575
576 writeFile(getOutputFile(outputFileNamePrefix + ".stdout"), output.getStdout());
577 writeFile(getOutputFile(outputFileNamePrefix + ".stderr"), output.getStderr());
578 System.out.println("[ELAPSED: " + (System.currentTimeMillis() - started) + " ms]");
579 System.out.println("[logging stdout to " + outputFileNamePrefix + ".stdout]");
580 System.out.println("[logging stderr to " + outputFileNamePrefix + ".stderr]");
581 System.out.println("[STDERR]\n" + output.getStderr());
582
583 if (copyChildStdoutToMainStdout)
584 System.out.println("[STDOUT]\n" + output.getStdout());
585
586 return output;
587 }
588
589
590 private static void writeFile(File file, String content) throws Exception {
591 FileOutputStream fos = new FileOutputStream(file);
592 PrintStream ps = new PrintStream(fos);
|