Cleaned up plugin-version resolution.

o Added four command-line options:

  --check-plugin-updates is a synonym for --update-plugins
  
  --no-plugin-registry turns off usage of plugin-registry.xml for plugin version resolution for the current build.
  
  --check-plugin-latest turns on usage of LATEST metadata for plugin version resolution for the current build.

  --no-plugin-latest turns off usage of LATEST metadata for plugin version resolution for the current build.

o Added settings.xml configuration <usePluginRegistry>true|false</usePluginRegistry> to en/disable the use of plugin-registry.xml for plugin version resolution. The default value is true, to use the plugin-registry.xml.

o Added plugin-registry.xml configuration <checkLatest>true|false</checkLatest> to en/disable the use of LATEST metadata when resolving plugin versions. The default value is false, or do not use LATEST.



git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@219089 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
John Dennis Casey 2005-07-14 20:35:23 +00:00
parent 06597924cf
commit 3f47c60752
8 changed files with 171 additions and 91 deletions

View File

@ -122,7 +122,7 @@ echo Rebuilding maven2 plugins
echo -----------------------------------------------------------------------
cd maven-plugins
@REM update the release info to ensure these versions get used in the integration tests
call m2 --no-plugin-updates --batch-mode -DupdateReleaseInfo=true -e %MAVEN_CMD_LINE_ARGS% clean:clean install
call m2 --no-plugin-registry --check-plugin-latest --batch-mode -DupdateReleaseInfo=true -e %MAVEN_CMD_LINE_ARGS% clean:clean install
cd ..
echo
@ -131,7 +131,7 @@ echo Rebuilding maven2 reports
echo -----------------------------------------------------------------------
cd maven-reports
@REM update the release info to ensure these versions get used in the integration tests
call m2 --no-plugin-updates --batch-mode -DupdateReleaseInfo=true -e %MAVEN_CMD_LINE_ARGS% clean:clean install
call m2 --no-plugin-registry --check-plugin-latest --batch-mode -DupdateReleaseInfo=true -e %MAVEN_CMD_LINE_ARGS% clean:clean install
cd ..
echo

View File

@ -57,7 +57,7 @@ ret=$?; if [ $ret != 0 ]; then exit $ret; fi
cd maven-plugins
# update the release info to ensure these versions get used in the integration tests
m2 --no-plugin-updates --batch-mode -DupdateReleaseInfo=true -e $ARGS clean:clean install
m2 --no-plugin-registry --check-plugin-latest --batch-mode -DupdateReleaseInfo=true -e $ARGS clean:clean install
ret=$?; if [ $ret != 0 ]; then exit $ret; fi
)
ret=$?; if [ $ret != 0 ]; then exit $ret; fi
@ -69,7 +69,7 @@ ret=$?; if [ $ret != 0 ]; then exit $ret; fi
cd maven-reports
# update the release info to ensure these versions get used in the integration tests
m2 --no-plugin-updates --batch-mode -DupdateReleaseInfo=true -e $ARGS clean:clean install
m2 --no-plugin-registry --check-plugin-latest --batch-mode -DupdateReleaseInfo=true -e $ARGS clean:clean install
ret=$?; if [ $ret != 0 ]; then exit $ret; fi
)
ret=$?; if [ $ret != 0 ]; then exit $ret; fi
@ -79,7 +79,7 @@ ret=$?; if [ $ret != 0 ]; then exit $ret; fi
echo
echo "Running maven-core integration tests ..."
echo
./maven-core-it.sh --batch-mode "$HOME_ARGS" $ARGS
./maven-core-it.sh "$HOME_ARGS" $ARGS
ret=$?; if [ $ret != 0 ]; then exit $ret; fi
)
ret=$?; if [ $ret != 0 ]; then exit $ret; fi

View File

@ -493,9 +493,12 @@ public class Verifier
cli.setExecutable( executable );
cli.createArgument().setValue( "-e" );
// cli.createArgument().setValue( "-e" );
cli.createArgument().setValue( "-X" );
cli.createArgument().setValue( "--no-plugin-updates" );
cli.createArgument().setValue( "--no-plugin-registry" );
cli.createArgument().setValue( "--check-plugin-latest" );
cli.createArgument().setValue( "--batch-mode" );

View File

@ -192,7 +192,8 @@ public class MavenCli
settings.setInteractiveMode( false );
}
if ( commandLine.hasOption( CLIManager.FORCE_PLUGIN_UPDATES ) )
if ( commandLine.hasOption( CLIManager.FORCE_PLUGIN_UPDATES )
|| commandLine.hasOption( CLIManager.FORCE_PLUGIN_UPDATES2 ) )
{
settings.getRuntimeInfo().setPluginUpdateOverride( Boolean.TRUE );
}
@ -200,6 +201,20 @@ public class MavenCli
{
settings.getRuntimeInfo().setPluginUpdateOverride( Boolean.FALSE );
}
if ( commandLine.hasOption( CLIManager.FORCE_PLUGIN_LATEST_CHECK ) )
{
settings.getRuntimeInfo().setCheckLatestPluginVersion( Boolean.TRUE );
}
else if ( commandLine.hasOption( CLIManager.SUPPRESS_PLUGIN_LATEST_CHECK ) )
{
settings.getRuntimeInfo().setCheckLatestPluginVersion( Boolean.FALSE );
}
if ( commandLine.hasOption( CLIManager.SUPPRESS_PLUGIN_REGISTRY ) )
{
settings.setUsePluginRegistry( false );
}
List projectFiles = null;
try
@ -508,9 +523,17 @@ public class MavenCli
public static final char ACTIVATE_PROFILES = 'P';
public static final String FORCE_PLUGIN_UPDATES = "update-plugins";
public static final String FORCE_PLUGIN_UPDATES = "check-plugin-updates";
public static final String FORCE_PLUGIN_UPDATES2 = "update-plugins";
public static final String SUPPRESS_PLUGIN_UPDATES = "no-plugin-updates";
public static final String SUPPRESS_PLUGIN_REGISTRY = "no-plugin-registry";
public static final String FORCE_PLUGIN_LATEST_CHECK = "check-plugin-latest";
public static final String SUPPRESS_PLUGIN_LATEST_CHECK = "no-plugin-latest";
public static final char CHECKSUM_FAILURE_POLICY = 'C';
@ -541,9 +564,17 @@ public class MavenCli
"Update all snapshots regardless of repository policies" ).create( UPDATE_SNAPSHOTS ) );
options.addOption( OptionBuilder.withLongOpt( "activate-profiles" ).withDescription(
"Comma-delimited list of profiles to activate").hasArg().create( ACTIVATE_PROFILES ) );
options.addOption( OptionBuilder.withLongOpt( "batch-mode" ).withDescription( "Run in non-interactive (batch) mode" ).create( BATCH_MODE ) );
options.addOption( OptionBuilder.withLongOpt( FORCE_PLUGIN_UPDATES ).withDescription( "Force upToDate check for any relevant registered plugins" ).create() );
options.addOption( OptionBuilder.withLongOpt( FORCE_PLUGIN_UPDATES2 ).withDescription( "Synonym for " + FORCE_PLUGIN_UPDATES ).create() );
options.addOption( OptionBuilder.withLongOpt( SUPPRESS_PLUGIN_UPDATES ).withDescription( "Suppress upToDate check for any relevant registered plugins" ).create() );
options.addOption( OptionBuilder.withLongOpt( FORCE_PLUGIN_LATEST_CHECK ).withDescription( "Force checking of LATEST metadata for plugin versions" ).create() );
options.addOption( OptionBuilder.withLongOpt( SUPPRESS_PLUGIN_LATEST_CHECK ).withDescription( "Suppress checking of LATEST metadata for plugin versions" ).create() );
options.addOption( OptionBuilder.withLongOpt( SUPPRESS_PLUGIN_REGISTRY ).withDescription( "Don't use ~/.m2/plugin-registry.xml for plugin versions" ).create() );
options.addOption( OptionBuilder.withLongOpt( "strict-checksums" ).withDescription( "Fail the build if checksums don't match" ).create( CHECKSUM_FAILURE_POLICY ) );
options.addOption( OptionBuilder.withLongOpt( "lax-checksums" ).withDescription( "Warn if checksums don't match" ).create( CHECKSUM_WARNING_POLICY ) );
}

View File

@ -17,6 +17,7 @@ import org.apache.maven.plugin.registry.io.xpp3.PluginRegistryXpp3Writer;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectBuilder;
import org.apache.maven.project.artifact.MavenMetadataSource;
import org.apache.maven.settings.RuntimeInfo;
import org.apache.maven.settings.Settings;
import org.codehaus.plexus.components.inputhandler.InputHandler;
import org.codehaus.plexus.logging.AbstractLogEnabled;
@ -82,11 +83,14 @@ public class DefaultPluginVersionManager
// we're not going to prompt the user to accept a plugin update until we find one.
boolean promptToPersist = false;
// determine the behavior WRT prompting the user and installing plugin updates.
Boolean pluginUpdateOverride = settings.getRuntimeInfo().getPluginUpdateOverride();
RuntimeInfo settingsRTInfo = settings.getRuntimeInfo();
// second pass...if the plugin is listed in the settings.xml, use the version from <useVersion/>.
if ( StringUtils.isEmpty( version ) )
// determine the behavior WRT prompting the user and installing plugin updates.
Boolean pluginUpdateOverride = settingsRTInfo.getPluginUpdateOverride();
// second pass...if we're using the plugin registry, and the plugin is listed in the plugin-registry.xml, use
// the version from <useVersion/>.
if ( StringUtils.isEmpty( version ) && settings.isUsePluginRegistry() )
{
// resolve existing useVersion.
version = resolveExistingFromPluginRegistry( groupId, artifactId );
@ -102,8 +106,8 @@ public class DefaultPluginVersionManager
if ( Boolean.TRUE.equals( pluginUpdateOverride )
|| ( !Boolean.FALSE.equals( pluginUpdateOverride ) && shouldCheckForUpdates( groupId, artifactId ) ) )
{
updatedVersion = resolveMetaVersion( groupId, artifactId, project
.getPluginArtifactRepositories(), localRepository, ReleaseArtifactTransformation.RELEASE_VERSION );
updatedVersion = resolveMetaVersion( groupId, artifactId, project.getPluginArtifactRepositories(),
localRepository, ReleaseArtifactTransformation.RELEASE_VERSION );
if ( StringUtils.isNotEmpty( updatedVersion ) && !updatedVersion.equals( version ) )
{
@ -120,23 +124,31 @@ public class DefaultPluginVersionManager
}
else
{
getLogger()
.info( "Plugin \'" + constructPluginKey( groupId, artifactId ) + "\' has updates." );
getLogger().info(
"Plugin \'" + constructPluginKey( groupId, artifactId )
+ "\' has updates." );
}
}
}
}
}
boolean forcePersist = false;
// third pass...retrieve the version for RELEASE and also set that resolved version as the <useVersion/>
// in settings.xml.
if ( StringUtils.isEmpty( version ) )
// are we using the LATEST metadata to resolve plugin version?
Boolean rtCheckLatest = settingsRTInfo.getCheckLatestPluginVersion();
boolean checkLatestMetadata = Boolean.TRUE.equals( rtCheckLatest )
|| ( !Boolean.FALSE.equals( rtCheckLatest ) && Boolean.valueOf( pluginRegistry.getCheckLatest() )
.booleanValue() );
// third pass...if we're checking for latest install/deploy, retrieve the version for LATEST metadata and also
// set that resolved version as the <useVersion/> in settings.xml.
if ( StringUtils.isEmpty( version ) && checkLatestMetadata )
{
// 1. resolve the version to be used
version = resolveMetaVersion( groupId, artifactId, project.getPluginArtifactRepositories(),
localRepository, ReleaseArtifactTransformation.RELEASE_VERSION );
localRepository, LatestArtifactTransformation.LATEST_VERSION );
// 2. Set the updatedVersion so the user will be prompted whether to make this version permanent.
updatedVersion = version;
@ -146,13 +158,13 @@ public class DefaultPluginVersionManager
promptToPersist = false;
}
// final pass...retrieve the version for LATEST and also set that resolved version as the <useVersion/>
// final pass...retrieve the version for RELEASE and also set that resolved version as the <useVersion/>
// in settings.xml.
if ( StringUtils.isEmpty( version ) )
{
// 1. resolve the version to be used
version = resolveMetaVersion( groupId, artifactId, project.getPluginArtifactRepositories(),
localRepository, LatestArtifactTransformation.LATEST_VERSION );
localRepository, ReleaseArtifactTransformation.RELEASE_VERSION );
// 2. Set the updatedVersion so the user will be prompted whether to make this version permanent.
updatedVersion = version;
@ -169,73 +181,78 @@ public class DefaultPluginVersionManager
"Failed to resolve a valid version for this plugin" );
}
// determine whether this build is running in interactive mode
// If it's not, then we'll defer to the autoUpdate setting from the registry
// for a decision on updating the plugin in the registry...rather than prompting
// the user.
boolean inInteractiveMode = settings.isInteractiveMode();
// determines what should be done if we're in non-interactive mode.
// if true, then just update the registry with the new versions.
String s = getPluginRegistry( groupId, artifactId ).getAutoUpdate();
boolean autoUpdate = true;
if ( s != null )
// if the plugin registry is inactive, then the rest of this goop is useless...
if ( settings.isUsePluginRegistry() )
{
autoUpdate = Boolean.valueOf( s ).booleanValue();
}
// determine whether this build is running in interactive mode
// If it's not, then we'll defer to the autoUpdate setting from the registry
// for a decision on updating the plugin in the registry...rather than prompting
// the user.
boolean inInteractiveMode = settings.isInteractiveMode();
// We should persist by default if:
//
// 0. RELEASE or LATEST was used to resolve the plugin version (it's not in the registry)
//
// -OR-
//
// 1. we detected a change in the plugin version from what was in the registry, or
// a. the plugin is not registered
// 2. the pluginUpdateOverride flag has NOT been set to Boolean.FALSE (suppression mode)
// 3. we're in interactive mode, or
// a. the registry is declared to be in autoUpdate mode
//
// NOTE: This is only the default value; it may be changed as the result of prompting the user.
boolean persistUpdate = forcePersist || ( promptToPersist && !Boolean.FALSE.equals( pluginUpdateOverride )
&& ( inInteractiveMode || autoUpdate ) );
// determines what should be done if we're in non-interactive mode.
// if true, then just update the registry with the new versions.
String s = getPluginRegistry( groupId, artifactId ).getAutoUpdate();
boolean autoUpdate = true;
if ( s != null )
{
autoUpdate = Boolean.valueOf( s ).booleanValue();
}
// retrieve the apply-to-all flag, if it's been set previously.
Boolean applyToAll = settings.getRuntimeInfo().getApplyToAllPluginUpdates();
// We should persist by default if:
//
// 0. RELEASE or LATEST was used to resolve the plugin version (it's not in the registry)
//
// -OR-
//
// 1. we detected a change in the plugin version from what was in the registry, or
// a. the plugin is not registered
// 2. the pluginUpdateOverride flag has NOT been set to Boolean.FALSE (suppression mode)
// 3. we're in interactive mode, or
// a. the registry is declared to be in autoUpdate mode
//
// NOTE: This is only the default value; it may be changed as the result of prompting the user.
boolean persistUpdate = forcePersist
|| ( promptToPersist && !Boolean.FALSE.equals( pluginUpdateOverride ) && ( inInteractiveMode || autoUpdate ) );
// Incorporate interactive-mode CLI overrides, and previous decisions on apply-to-all, if appropriate.
//
// don't prompt if RELEASE or LATEST was used to resolve the plugin version
// don't prompt if not in interactive mode.
// don't prompt if the CLI pluginUpdateOverride is set (either suppression or force mode will stop prompting)
// don't prompt if the user has selected ALL/NONE previously in this session
//
// NOTE: We're incorporating here, to make the usages of this check more consistent and
// resistant to change.
promptToPersist = promptToPersist && pluginUpdateOverride == null && applyToAll == null && inInteractiveMode;
// retrieve the apply-to-all flag, if it's been set previously.
Boolean applyToAll = settings.getRuntimeInfo().getApplyToAllPluginUpdates();
if ( promptToPersist )
{
persistUpdate = promptToPersistPluginUpdate( version, updatedVersion, groupId, artifactId, settings );
}
// Incorporate interactive-mode CLI overrides, and previous decisions on apply-to-all, if appropriate.
//
// don't prompt if RELEASE or LATEST was used to resolve the plugin version
// don't prompt if not in interactive mode.
// don't prompt if the CLI pluginUpdateOverride is set (either suppression or force mode will stop prompting)
// don't prompt if the user has selected ALL/NONE previously in this session
//
// NOTE: We're incorporating here, to make the usages of this check more consistent and
// resistant to change.
promptToPersist = promptToPersist && pluginUpdateOverride == null && applyToAll == null
&& inInteractiveMode;
// if it is determined that we should use this version, persist it as useVersion.
// cases where this version will be persisted:
// 1. the user is prompted and answers yes or all
// 2. the user has previously answered all in this session
// 3. the build is running in non-interactive mode, and the registry setting is for auto-update
if ( !Boolean.FALSE.equals( applyToAll ) && persistUpdate )
{
updatePluginVersionInRegistry( groupId, artifactId, updatedVersion );
if ( promptToPersist )
{
persistUpdate = promptToPersistPluginUpdate( version, updatedVersion, groupId, artifactId, settings );
}
// we're using the updated version of the plugin in this session as well.
version = updatedVersion;
}
// otherwise, if we prompted the user to update, we should treat this as a rejectedVersion, and
// persist it iff the plugin pre-exists and is in the user-level registry.
else if ( promptToPersist )
{
addNewVersionToRejectedListInExisting( groupId, artifactId, updatedVersion );
// if it is determined that we should use this version, persist it as useVersion.
// cases where this version will be persisted:
// 1. the user is prompted and answers yes or all
// 2. the user has previously answered all in this session
// 3. the build is running in non-interactive mode, and the registry setting is for auto-update
if ( !Boolean.FALSE.equals( applyToAll ) && persistUpdate )
{
updatePluginVersionInRegistry( groupId, artifactId, updatedVersion );
// we're using the updated version of the plugin in this session as well.
version = updatedVersion;
}
// otherwise, if we prompted the user to update, we should treat this as a rejectedVersion, and
// persist it iff the plugin pre-exists and is in the user-level registry.
else if ( promptToPersist )
{
addNewVersionToRejectedListInExisting( groupId, artifactId, updatedVersion );
}
}
return version;
@ -587,26 +604,26 @@ public class DefaultPluginVersionManager
}
private String resolveMetaVersion( String groupId, String artifactId, List remoteRepositories,
ArtifactRepository localRepository, String metaVersionId )
ArtifactRepository localRepository, String metaVersionId )
throws PluginVersionResolutionException
{
Artifact artifact = artifactFactory.createArtifact( groupId, artifactId, metaVersionId,
Artifact.SCOPE_RUNTIME, "pom" );
Artifact artifact = artifactFactory.createArtifact( groupId, artifactId, metaVersionId, Artifact.SCOPE_RUNTIME,
"pom" );
MavenMetadataSource metadataSource = new MavenMetadataSource( artifactResolver, projectBuilder, artifactFactory );
String version = null;
try
{
metadataSource.retrieve( artifact, localRepository, remoteRepositories );
version = artifact.getBaseVersion();
version = artifact.getVersion();
}
catch ( ArtifactMetadataRetrievalException e )
{
getLogger().debug( "Failed to resolve " + metaVersionId + " version", e );
}
return version;
}

View File

@ -77,6 +77,12 @@
<type>String</type>
<description>Specifies whether the user should be prompted to update plugins.</description>
</field>
<field>
<name>checkLatest</name>
<version>1.0.0</version>
<type>String</type>
<description>Whether to resolve plugin versions using LATEST metadata.</description>
</field>
<field>
<name>plugins</name>
<version>1.0.0</version>

View File

@ -85,6 +85,13 @@
<type>boolean</type>
<defaultValue>true</defaultValue>
</field>
<field>
<name>usePluginRegistry</name>
<version>1.0.0</version>
<description><![CDATA[Whether Maven should use the plugin-registry.xml file to manage plugin versions.]]></description>
<type>boolean</type>
<defaultValue>true</defaultValue>
</field>
<!-- [JC] Not ready to use yet, so I'm making if unavailable for now. -->
<!-- field>
<name>passwordStore</name>

View File

@ -25,11 +25,17 @@ public class RuntimeInfo
private File file;
// using Boolean for 3VL (null for not-set, otherwise override with value)
private Boolean pluginUpdateForced;
// using Boolean for 3VL (null, true-to-all, false-to-all)
private Boolean applyToAllPluginUpdates;
private boolean pluginRegistryActive = true;
// using Boolean for 3VL (null for not-set, otherwise override with value)
private Boolean checkLatest;
private Map activeProfileToSourceLevel = new HashMap();
private String localRepositorySourceLevel = TrackableBase.USER_LEVEL;
@ -120,5 +126,15 @@ public class RuntimeInfo
{
return localRepositorySourceLevel;
}
public void setCheckLatestPluginVersion( Boolean checkLatest )
{
this.checkLatest = checkLatest;
}
public Boolean getCheckLatestPluginVersion()
{
return checkLatest;
}
}