Skip to content

Commit d59ef49

Browse files
committed
extract Maven 3.3.1 specific method call
1 parent 87ff9f7 commit d59ef49

File tree

1 file changed

+24
-19
lines changed

1 file changed

+24
-19
lines changed

src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java

+24-19
Original file line numberDiff line numberDiff line change
@@ -1500,26 +1500,11 @@ protected final Toolchain getToolchain() {
15001500
Toolchain tc = null;
15011501

15021502
if (jdkToolchain != null) {
1503-
// require Maven 3.3.1, that has plugin execution scoped Toolchain support MNG-5755
1504-
try {
1505-
// TODO use direct method invocation when prerequisite upgraded to Maven 3.3.1
1506-
Method getToolchainsMethod = toolchainManager
1507-
.getClass()
1508-
.getMethod("getToolchains", MavenSession.class, String.class, Map.class);
1509-
1510-
@SuppressWarnings("unchecked")
1511-
List<Toolchain> tcs =
1512-
(List<Toolchain>) getToolchainsMethod.invoke(toolchainManager, session, "jdk", jdkToolchain);
1503+
// require Maven 3.3.1, that has plugin execution scoped Toolchain support: MNG-5755
1504+
List<Toolchain> tcs = getToolchains();
15131505

1514-
if (tcs != null && !tcs.isEmpty()) {
1515-
tc = tcs.get(0);
1516-
}
1517-
} catch (NoSuchMethodException
1518-
| SecurityException
1519-
| IllegalAccessException
1520-
| IllegalArgumentException
1521-
| InvocationTargetException e) {
1522-
// ignore
1506+
if (tcs != null && !tcs.isEmpty()) {
1507+
tc = tcs.get(0);
15231508
}
15241509
}
15251510

@@ -1530,6 +1515,26 @@ protected final Toolchain getToolchain() {
15301515
return tc;
15311516
}
15321517

1518+
// TODO use direct method invocation when prerequisite upgraded to Maven 3.3.1
1519+
private List<Toolchain> getToolchains() {
1520+
try {
1521+
Method getToolchainsMethod =
1522+
toolchainManager.getClass().getMethod("getToolchains", MavenSession.class, String.class, Map.class);
1523+
1524+
@SuppressWarnings("unchecked")
1525+
List<Toolchain> tcs =
1526+
(List<Toolchain>) getToolchainsMethod.invoke(toolchainManager, session, "jdk", jdkToolchain);
1527+
return tcs;
1528+
} catch (NoSuchMethodException
1529+
| SecurityException
1530+
| IllegalAccessException
1531+
| IllegalArgumentException
1532+
| InvocationTargetException e) {
1533+
// ignore
1534+
}
1535+
return null;
1536+
}
1537+
15331538
private boolean isDigits(String string) {
15341539
for (int i = 0; i < string.length(); i++) {
15351540
if (!Character.isDigit(string.charAt(i))) {

0 commit comments

Comments
 (0)