Skip to content

Commit

Permalink
[MJAVADOC-821] Align toolchain discovery code with Maven Compiler Plugin
Browse files Browse the repository at this point in the history
This closes #334
  • Loading branch information
michael-o committed Oct 30, 2024
1 parent 62a6861 commit e314da0
Showing 1 changed file with 3 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.Writer;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
Expand Down Expand Up @@ -2615,27 +2614,13 @@ public Artifact resolveDependency(Dependency dependency) throws MavenReportExcep
}
}

// TODO remove the part with ToolchainManager lookup once we depend on
// 3.0.9 (have it as prerequisite). Define as regular component field then.
protected final Toolchain getToolchain() {
Toolchain tc = null;

if (jdkToolchain != null) {
// Maven 3.3.1 has plugin execution scoped Toolchain Support
try {
Method getToolchainsMethod = toolchainManager
.getClass()
.getMethod("getToolchains", MavenSession.class, String.class, Map.class);

@SuppressWarnings("unchecked")
List<Toolchain> tcs =
(List<Toolchain>) getToolchainsMethod.invoke(toolchainManager, session, "jdk", jdkToolchain);

if (tcs != null && tcs.size() > 0) {
tc = tcs.get(0);
}
} catch (SecurityException | ReflectiveOperationException e) {
// ignore
List<Toolchain> tcs = toolchainManager.getToolchains(session, "jdk", jdkToolchain);
if (tcs != null && !tcs.isEmpty()) {
tc = tcs.get(0);
}
}

Expand Down

0 comments on commit e314da0

Please sign in to comment.