Debian Codegraph @

junit-platform-console/src/main/java/org/junit/platform/console/ConsoleLauncher.java

raw symbols SCIP
1 /*
2 * Copyright 2015-2024 the original author or authors.
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v2.0 which
6 * accompanies this distribution and is available at
7 *
8 * https://www.eclipse.org/legal/epl-v20.html
9 */
10
11 package org.junit.platform.console;
12
13 import static org.apiguardian.api.API.Status.INTERNAL;
14 import static org.apiguardian.api.API.Status.MAINTAINED;
15
16 import java.io.PrintWriter;
17
18 import org.apiguardian.api.API;
19 import org.junit.platform.console.options.CommandFacade;
20 import org.junit.platform.console.options.CommandResult;
21 import org.junit.platform.console.tasks.ConsoleTestExecutor;
22
23 /**
24 * The {@code ConsoleLauncher} is a stand-alone application for launching the
25 * JUnit Platform from the console.
26 *
27 * @since 1.0
28 */
29 @API(status = MAINTAINED, since = "1.0")
30 public class ConsoleLauncher {
31
32 public static void main(String... args) {
33 PrintWriter out = new PrintWriter(System.out);
34 PrintWriter err = new PrintWriter(System.err);
35 CommandResult<?> result = run(out, err, args);
36 System.exit(result.getExitCode());
37 }
38
39 @API(status = INTERNAL, since = "1.0")
40 public static CommandResult<?> run(PrintWriter out, PrintWriter err, String... args) {
41 ConsoleLauncher consoleLauncher = new ConsoleLauncher(ConsoleTestExecutor::new, out, err);
42 return consoleLauncher.run(args);
43 }
44
45 private final ConsoleTestExecutor.Factory consoleTestExecutorFactory;
46 private final PrintWriter out;
47 private final PrintWriter err;
48
49 ConsoleLauncher(ConsoleTestExecutor.Factory consoleTestExecutorFactory, PrintWriter out, PrintWriter err) {
50 this.consoleTestExecutorFactory = consoleTestExecutorFactory;
51 this.out = out;
52 this.err = err;
53 }
54
55 CommandResult<?> run(String... args) {
56 try {
57 return new CommandFacade(consoleTestExecutorFactory).run(out, err, args);
58 }
59 finally {
60 out.flush();
61 err.flush();
62 }
63 }
64
65 }