Home / Class/ TestRunMojo Class — spring-boot Architecture

TestRunMojo Class — spring-boot Architecture

Architecture documentation for the TestRunMojo class in TestRunMojo.java from the spring-boot codebase.

Entity Profile

Source Code

build-plugin/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/TestRunMojo.java lines 49–118

@Mojo(name = "test-run", requiresProject = true, defaultPhase = LifecyclePhase.VALIDATE,
		requiresDependencyResolution = ResolutionScope.TEST)
@Execute(phase = LifecyclePhase.TEST_COMPILE)
public class TestRunMojo extends AbstractRunMojo {

	/**
	 * Whether the JVM's launch should be optimized.
	 */
	@Parameter(property = "spring-boot.test-run.optimizedLaunch", defaultValue = "true")
	private boolean optimizedLaunch;

	/**
	 * Directory containing the test classes and resource files that should be used to run
	 * the application.
	 */
	@Parameter(defaultValue = "${project.build.testOutputDirectory}", required = true)
	@SuppressWarnings("NullAway.Init")
	private File testClassesDirectory;

	@Inject
	public TestRunMojo(ToolchainManager toolchainManager) {
		super(toolchainManager);
	}

	@Override
	protected List<File> getClassesDirectories() {
		ArrayList<File> classesDirectories = new ArrayList<>(super.getClassesDirectories());
		classesDirectories.add(0, this.testClassesDirectory);
		return classesDirectories;
	}

	@Override
	protected boolean isUseTestClasspath() {
		return true;
	}

	@Override
	protected RunArguments resolveJvmArguments() {
		RunArguments jvmArguments = super.resolveJvmArguments();
		if (this.optimizedLaunch) {
			jvmArguments.getArgs().addFirst("-XX:TieredStopAtLevel=1");
		}
		return jvmArguments;
	}

	@Override
	protected void run(JavaProcessExecutor processExecutor, File workingDirectory, List<String> args,
			Map<String, String> environmentVariables) throws MojoExecutionException, MojoFailureException {
		processExecutor
			.withRunProcessCustomizer(
					(runProcess) -> Runtime.getRuntime().addShutdownHook(new Thread(new RunProcessKiller(runProcess))))
			.run(workingDirectory, args, environmentVariables);
	}

	private static final class RunProcessKiller implements Runnable {

		private final RunProcess runProcess;

		private RunProcessKiller(RunProcess runProcess) {
			this.runProcess = runProcess;
		}

		@Override
		public void run() {
			this.runProcess.kill();
		}

	}

}

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free