Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. Get all toolchains for a given type (eg. jdk)
  2. go through them one by one and try match the requirements in the toolchain-plugin configuration against the provided tokens. Some like 'version' are to be specially handled and allow for range matching etc, the rest is exact match only. The creator of the particular type of toolchain can define the specially handled tokens.
  3. first successful match is pushed into the maven build environment (BuildContextMavenSession) for use by other plugins down the road
  4. if there are no matches, the build fails.

Backward compatibility

Can we achieve backward compatibility with 1. The Toolchain core components need to go to 2.0.x or do we have to go with 2.1 only? It would be nice if at least plugins that start using toolchains would not require 2.1.
The only roadblock for backward compatibility is the build-context that is needed for inter-plugin communication. Build-context seems to be relatively independent of the rest of maven, just requires plexus container that is newer than the one used in 2.0.x. Can we upgrade?9-SNAPSHOT and 2.1-SNAPSHOT codebase.
2. maven-toolchains-plugin gets the maven prerequisite of 2.0.9-SNAPSHOT. That way anyone actively using toolchains needs to be using 2.0.9-SNAPSHOT+
3. Any other plugins using the toolchains components don't need to explicitly set the maven prerequite to 2.0.9-SNAPSHOT. The components will work but will fail to deliver a configured toolchain, thus they will keep behaving the same way as they did before. That's critical for further development of plugins.

What changes are needed in plugin code to start using toolchains?

The changes are rather simple. An additional dependency on the toolchains component artifact is necessary and then a short code snippet added to mojo's execute method.

Code Block
java
java

/**
     * @component
     */
    private ToolchainManager toolchainManager;

    /**
     * The current build session instance. This is used for
     * toolchain manager API calls.
     *
     * @parameter expression="${session}"
     * @required
     * @readonly
     */
    private MavenSession session;

    public void execute() {
        .....

        //get toolchain from context
        Toolchain tc = toolchainManager.getToolchainFromBuildContext( "jdk", //NOI18N
                                session );
        if ( tc != null )
        {
            getLog().info( "Toolchain in javadoc-plugin: " + tc );
            //when the executable to use is explicitly set by user in mojo's parameter, ignore toolchains.
            if ( javadocExecutable  != null)
            {
                getLog().warn( "Toolchains are ignored, 'javadocExecutable' parameter is set to " + javadocExecutable );
            }
            else
            {
                //assign the path to executable from toolchains
                javadocExecutable = tc.findTool( "javadoc" ); //NOI18N
            }
        }

        .....
     }

Implementation

The feature is developed mainly on trunk. toolchains components toolchains plugin
Only the changes to existing plugins are on branch.

...