Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

integrate maven-toolchain support #701

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.util.logging.Logger;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.versioning.OverConstrainedVersionException;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Plugin;
import org.apache.maven.plugin.AbstractMojo;
Expand All @@ -42,6 +43,8 @@
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.apache.maven.toolchain.Toolchain;
import org.apache.maven.toolchain.ToolchainManager;
import org.codehaus.plexus.util.Os;
import org.codehaus.plexus.util.cli.CommandLineException;
import org.codehaus.plexus.util.cli.CommandLineUtils;
Expand Down Expand Up @@ -131,6 +134,15 @@ abstract class AbstractJaxwsMojo extends AbstractMojo {
@Parameter
private File executable;

@Component
private ToolchainManager toolchainManager;

@Parameter(defaultValue = "false")
private boolean useJdkToolchainExecutable;

@Parameter(defaultValue = "${session}", readonly = true, required = true)
protected MavenSession session;

/**
* The entry point to Aether, i.e. the component doing all the work.
*
Expand Down Expand Up @@ -340,7 +352,7 @@ protected void exec(List<String> args) throws MojoExecutionException {
throw new MojoExecutionException("Cannot execute: " + executable.getAbsolutePath());
}
} else {
cmd.setExecutable(new File(new File(System.getProperty("java.home"), "bin"), getJavaExec()).getAbsolutePath());
cmd.setExecutable(new File(new File(getJavaHome(), "bin"), getJavaExec()).getAbsolutePath());
// add additional JVM options
if (vmArgs != null) {
for (String arg : vmArgs) {
Expand Down Expand Up @@ -441,10 +453,12 @@ private String[] getCP() throws DependencyResolutionException {
throw new RuntimeException(ex);
}
sb.append(File.pathSeparator);

String javaHome = getJavaHome();
//don't forget tools.jar
File toolsJar = new File(System.getProperty("java.home"), "../lib/tools.jar");
File toolsJar = new File(javaHome, "../lib/tools.jar");
if (!toolsJar.exists()) {
toolsJar = new File(System.getProperty("java.home"), "lib/tools.jar");
toolsJar = new File(javaHome, "lib/tools.jar");
}
if (toolsJar.exists()) {
sb.append(toolsJar.getAbsolutePath());
Expand All @@ -458,6 +472,27 @@ private String[] getCP() throws DependencyResolutionException {
private String getJavaExec() {
return isWindows() ? "java.exe" : "java";
}

private String getJavaHome() {
String javaHome = System.getProperty("java.home");
if (getJdkToolchain() != null) {
File javaExecutable = new File(getJdkToolchain().findTool("java"));
javaHome = javaExecutable.getParentFile().getParent();
getLog().info("got java home from maven toolchain: " + javaHome);
}
else {
getLog().info("couldnt get a javahome from maven toolchain, defaulting to the java.home System property : " + javaHome);
}
return javaHome;
}

private Toolchain getJdkToolchain() {
Toolchain tc = null;
if (this.toolchainManager != null) {
tc = this.toolchainManager.getToolchainFromBuildContext("jdk", this.session);
}
return tc;
}

private File createPathFile(String cp) throws IOException {
File f = File.createTempFile("jax-ws-mvn-plugin-cp", ".txt");
Expand Down