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

Added support for maven toolchains #24

Merged
merged 1 commit into from
Jul 19, 2014
Merged
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 @@ -7,14 +7,34 @@
import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableMap;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.*;
import org.apache.maven.plugins.annotations.*;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.BuildPluginManager;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;

import java.io.*;
import java.util.*;

import static org.twdata.maven.mojoexecutor.MojoExecutor.*;
import org.apache.maven.toolchain.Toolchain;
import org.apache.maven.toolchain.ToolchainManager;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Map;
import java.util.Properties;
import java.util.TreeSet;

import static org.twdata.maven.mojoexecutor.MojoExecutor.artifactId;
import static org.twdata.maven.mojoexecutor.MojoExecutor.attribute;
import static org.twdata.maven.mojoexecutor.MojoExecutor.attributes;
import static org.twdata.maven.mojoexecutor.MojoExecutor.configuration;
import static org.twdata.maven.mojoexecutor.MojoExecutor.element;
import static org.twdata.maven.mojoexecutor.MojoExecutor.executeMojo;
import static org.twdata.maven.mojoexecutor.MojoExecutor.executionEnvironment;
import static org.twdata.maven.mojoexecutor.MojoExecutor.goal;
import static org.twdata.maven.mojoexecutor.MojoExecutor.groupId;
import static org.twdata.maven.mojoexecutor.MojoExecutor.name;
import static org.twdata.maven.mojoexecutor.MojoExecutor.plugin;
import static org.twdata.maven.mojoexecutor.MojoExecutor.version;

abstract class ProcessClassesMojo extends AbstractMojo {

Expand All @@ -25,6 +45,9 @@ abstract class ProcessClassesMojo extends AbstractMojo {
"1.8", 52
);

@Component
private ToolchainManager toolchainManager;

@Component
private MavenSession session;

Expand Down Expand Up @@ -73,6 +96,17 @@ public void execute() throws MojoExecutionException {
processClasses();
}

private String getJavaCommandViaToolChain() {
Toolchain tc = toolchainManager.getToolchainFromBuildContext( "jdk", session);
if (tc != null) {
getLog().info("Using JDK Toolchain: " + tc );
String javaCommand = tc.findTool("java");
return javaCommand;
} else {
return java8home + "/bin/java";
}
}

private void validateTarget() throws MojoExecutionException {
if (!targetBytecodeVersions.containsKey(target)) {
String possibleValues = Joiner.on(", ").join(new TreeSet<String>(targetBytecodeVersions.keySet()));
Expand Down Expand Up @@ -120,7 +154,7 @@ private void processClasses() throws MojoExecutionException {
attribute("refid", getClasspathId()))),
element("exec",
attributes(
attribute("executable", java8home + "/bin/java"),
attribute("executable", getJavaCommandViaToolChain()),
attribute("failonerror", "true")),
element("arg", attribute("value", "-Dretrolambda.bytecodeVersion=" + targetBytecodeVersions.get(target))),
element("arg", attribute("value", "-Dretrolambda.inputDir=" + getInputDir().getAbsolutePath())),
Expand Down