private Toolchain getToolchain()

in src/main/java/org/apache/maven/plugins/jdeps/AbstractJDepsMojo.java [592:643]


    private Toolchain getToolchain()
    {
        Toolchain tc = null;
        if ( toolchainManager != null )
        {
            tc = toolchainManager.getToolchainFromBuildContext( "jdk", session );

            if ( tc == null )
            {
                // Maven 3.2.6 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",
                                                                      Collections.singletonMap( "version", "[1.8,)" ) );

                    if ( tcs != null && tcs.size() > 0 )
                    {
                        // pick up latest, jdeps of JDK9 has more options compared to JDK8
                        tc = tcs.get( tcs.size() - 1 );
                    }
                }
                catch ( NoSuchMethodException e )
                {
                    // ignore
                }
                catch ( SecurityException e )
                {
                    // ignore
                }
                catch ( IllegalAccessException e )
                {
                    // ignore
                }
                catch ( IllegalArgumentException e )
                {
                    // ignore
                }
                catch ( InvocationTargetException e )
                {
                    // ignore
                }
            }
        }

        return tc;
    }