Skip to content

Commit

Permalink
extract Maven 3.3.1 specific method call
Browse files Browse the repository at this point in the history
  • Loading branch information
hboutemy committed Mar 1, 2024
1 parent 87ff9f7 commit d59ef49
Showing 1 changed file with 24 additions and 19 deletions.
Expand Up @@ -1500,26 +1500,11 @@ protected final Toolchain getToolchain() {
Toolchain tc = null;

if (jdkToolchain != null) {
// require Maven 3.3.1, that has plugin execution scoped Toolchain support MNG-5755
try {
// TODO use direct method invocation when prerequisite upgraded to Maven 3.3.1
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);
// require Maven 3.3.1, that has plugin execution scoped Toolchain support: MNG-5755
List<Toolchain> tcs = getToolchains();

if (tcs != null && !tcs.isEmpty()) {
tc = tcs.get(0);
}
} catch (NoSuchMethodException
| SecurityException
| IllegalAccessException
| IllegalArgumentException
| InvocationTargetException e) {
// ignore
if (tcs != null && !tcs.isEmpty()) {
tc = tcs.get(0);
}
}

Expand All @@ -1530,6 +1515,26 @@ protected final Toolchain getToolchain() {
return tc;
}

// TODO use direct method invocation when prerequisite upgraded to Maven 3.3.1
private List<Toolchain> getToolchains() {
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);
return tcs;
} catch (NoSuchMethodException
| SecurityException
| IllegalAccessException
| IllegalArgumentException
| InvocationTargetException e) {
// ignore
}
return null;
}

private boolean isDigits(String string) {
for (int i = 0; i < string.length(); i++) {
if (!Character.isDigit(string.charAt(i))) {
Expand Down

0 comments on commit d59ef49

Please sign in to comment.