* @throws MojoExecutionException if any
*/
private void updatePluginVersionInRegistry( String aGroupId, String anArtifactId, String aVersion )
throws MojoExecutionException
{
PluginRegistry pluginRegistry;
try
{
pluginRegistry = getPluginRegistry( aGroupId, anArtifactId );
}
catch ( IOException e )
{
throw new MojoExecutionException( "Failed to read plugin registry.", e );
}
catch ( XmlPullParserException e )
{
throw new MojoExecutionException( "Failed to parse plugin registry.", e );
}
String pluginKey = ArtifactUtils.versionlessKey( aGroupId, anArtifactId );
Plugin plugin = (Plugin) pluginRegistry.getPluginsByKey().get( pluginKey );
// if we can find the plugin, but we've gotten here, the useVersion must be missing; fill it in.
if ( plugin != null )
{
if ( TrackableBase.GLOBAL_LEVEL.equals( plugin.getSourceLevel() ) )
{
// do nothing. We don't rewrite the globals, under any circumstances.
getLog().warn( "Cannot update registered version for plugin {" + aGroupId + ":" + anArtifactId
+ "}; it is specified in the global registry." );
}
else
{
plugin.setUseVersion( aVersion );
SimpleDateFormat format =
new SimpleDateFormat( org.apache.maven.plugin.registry.Plugin.LAST_CHECKED_DATE_FORMAT );
plugin.setLastChecked( format.format( new Date() ) );
}
}
else
{
plugin = new org.apache.maven.plugin.registry.Plugin();
plugin.setGroupId( aGroupId );
plugin.setArtifactId( anArtifactId );
plugin.setUseVersion( aVersion );
pluginRegistry.addPlugin( plugin );
pluginRegistry.flushPluginsByKey();
}
writeUserRegistry( aGroupId, anArtifactId, pluginRegistry );
}