Add toolchains support for Spring Boot Maven Plugin
See gh-18732
This commit is contained in:
committed by
Stephane Nicoll
parent
08ac72f5f0
commit
eede16ff0a
@@ -30,15 +30,20 @@ import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
import org.apache.maven.execution.MavenSession;
|
||||
import org.apache.maven.model.Resource;
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.apache.maven.plugin.MojoFailureException;
|
||||
import org.apache.maven.plugins.annotations.Component;
|
||||
import org.apache.maven.plugins.annotations.Parameter;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.apache.maven.shared.artifact.filter.collection.AbstractArtifactFeatureFilter;
|
||||
import org.apache.maven.shared.artifact.filter.collection.FilterArtifacts;
|
||||
import org.apache.maven.toolchain.Toolchain;
|
||||
import org.apache.maven.toolchain.ToolchainManager;
|
||||
|
||||
import org.springframework.boot.loader.tools.FileUtils;
|
||||
import org.springframework.boot.loader.tools.JavaExecutable;
|
||||
import org.springframework.boot.loader.tools.MainClassFinder;
|
||||
|
||||
/**
|
||||
@@ -204,6 +209,20 @@ public abstract class AbstractRunMojo extends AbstractDependencyFilterMojo {
|
||||
@Parameter(property = "spring-boot.run.skip", defaultValue = "false")
|
||||
private boolean skip;
|
||||
|
||||
/**
|
||||
* The Maven Session Object.
|
||||
* @since 2.2.1
|
||||
*/
|
||||
@Parameter(defaultValue = "${session}", readonly = true)
|
||||
private MavenSession session;
|
||||
|
||||
/**
|
||||
* The toolchain manager to use.
|
||||
* @since 2.2.1
|
||||
*/
|
||||
@Component
|
||||
private ToolchainManager toolchainManager;
|
||||
|
||||
@Override
|
||||
public void execute() throws MojoExecutionException, MojoFailureException {
|
||||
if (this.skip) {
|
||||
@@ -325,6 +344,16 @@ public abstract class AbstractRunMojo extends AbstractDependencyFilterMojo {
|
||||
return runArguments;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides access to the java binary executable, regardless of OS.
|
||||
* @return the java executable
|
||||
**/
|
||||
protected String getJavaExecutable() {
|
||||
Toolchain toolchain = this.toolchainManager.getToolchainFromBuildContext("jdk", this.session);
|
||||
String javaExecutable = (toolchain != null) ? toolchain.findTool("java") : null;
|
||||
return (javaExecutable != null) ? javaExecutable : new JavaExecutable().toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the environment variables to use.
|
||||
* @return an {@link EnvVariables} defining the environment variables
|
||||
|
||||
@@ -30,7 +30,6 @@ import org.apache.maven.plugins.annotations.Mojo;
|
||||
import org.apache.maven.plugins.annotations.Parameter;
|
||||
import org.apache.maven.plugins.annotations.ResolutionScope;
|
||||
|
||||
import org.springframework.boot.loader.tools.JavaExecutable;
|
||||
import org.springframework.boot.loader.tools.RunProcess;
|
||||
|
||||
/**
|
||||
@@ -111,7 +110,7 @@ public class RunMojo extends AbstractRunMojo {
|
||||
private int forkJvm(File workingDirectory, List<String> args, Map<String, String> environmentVariables)
|
||||
throws MojoExecutionException {
|
||||
try {
|
||||
RunProcess runProcess = new RunProcess(workingDirectory, new JavaExecutable().toString());
|
||||
RunProcess runProcess = new RunProcess(workingDirectory, getJavaExecutable());
|
||||
Runtime.getRuntime().addShutdownHook(new Thread(new RunProcessKiller(runProcess)));
|
||||
return runProcess.run(true, args, environmentVariables);
|
||||
}
|
||||
|
||||
@@ -37,7 +37,6 @@ import org.apache.maven.plugins.annotations.Mojo;
|
||||
import org.apache.maven.plugins.annotations.Parameter;
|
||||
import org.apache.maven.plugins.annotations.ResolutionScope;
|
||||
|
||||
import org.springframework.boot.loader.tools.JavaExecutable;
|
||||
import org.springframework.boot.loader.tools.RunProcess;
|
||||
|
||||
/**
|
||||
@@ -104,7 +103,7 @@ public class StartMojo extends AbstractRunMojo {
|
||||
private RunProcess runProcess(File workingDirectory, List<String> args, Map<String, String> environmentVariables)
|
||||
throws MojoExecutionException {
|
||||
try {
|
||||
RunProcess runProcess = new RunProcess(workingDirectory, new JavaExecutable().toString());
|
||||
RunProcess runProcess = new RunProcess(workingDirectory, getJavaExecutable());
|
||||
runProcess.run(false, args, environmentVariables);
|
||||
return runProcess;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user