org.codehaus.mojo.versions.api
Class DefaultVersionsHelper

java.lang.Object
  extended by org.codehaus.mojo.versions.api.DefaultVersionsHelper
All Implemented Interfaces:
VersionsHelper

public class DefaultVersionsHelper
extends Object
implements VersionsHelper

Helper class that provides common functionality required by both the mojos and the reports.

Since:
1.0-alpha-3
Author:
Stephen Connolly

Constructor Summary
DefaultVersionsHelper(org.apache.maven.artifact.factory.ArtifactFactory artifactFactory, org.apache.maven.artifact.metadata.ArtifactMetadataSource artifactMetadataSource, List remoteArtifactRepositories, List remotePluginRepositories, org.apache.maven.artifact.repository.ArtifactRepository localRepository, org.apache.maven.artifact.manager.WagonManager wagonManager, org.apache.maven.settings.Settings settings, String serverId, String rulesUri, org.apache.maven.plugin.logging.Log log, org.apache.maven.execution.MavenSession mavenSession, org.apache.maven.project.path.PathTranslator pathTranslator)
          Constructs a new DefaultVersionsHelper.
 
Method Summary
 org.apache.maven.artifact.versioning.ArtifactVersion createArtifactVersion(String version)
          Creates an ArtifactVersion instance from a string.
 org.apache.maven.artifact.Artifact createDependencyArtifact(org.apache.maven.model.Dependency dependency)
          Shorthand method for getArtifactFactory().createDependencyArtifact(...) which extracts the parameters from the Dependency instance.
 org.apache.maven.artifact.Artifact createDependencyArtifact(String groupId, String artifactId, org.apache.maven.artifact.versioning.VersionRange versionRange, String type, String classifier, String scope)
          Shorthand method for getArtifactFactory().createDependencyArtifact(...).
 org.apache.maven.artifact.Artifact createDependencyArtifact(String groupId, String artifactId, org.apache.maven.artifact.versioning.VersionRange versionRange, String type, String classifier, String scope, boolean optional)
          Shorthand method for getArtifactFactory().createDependencyArtifact(...).
 org.apache.maven.artifact.Artifact createPluginArtifact(String groupId, String artifactId, org.apache.maven.artifact.versioning.VersionRange versionRange)
          Shorthand method for getArtifactFactory().createPluginArtifact(...).
 Set extractArtifacts(Collection mavenProjects)
          Takes a List of MavenProject instances and converts it into a Set of Artifact instances.
 org.apache.maven.artifact.factory.ArtifactFactory getArtifactFactory()
          Returns the artifact factory to use.
 org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator getExpressionEvaluator(org.apache.maven.project.MavenProject project)
          Returns an ExpressionEvaluator for the specified project.
 org.apache.maven.plugin.logging.Log getLog()
          Gets the logger used by this helper.
 VersionComparator getVersionComparator(org.apache.maven.artifact.Artifact artifact)
          Returns the version comparator to use for the specified artifact.
 VersionComparator getVersionComparator(String groupId, String artifactId)
          Returns the version comparator to use for the specified groupId and artifactId.
 Map getVersionPropertiesMap(org.apache.maven.project.MavenProject project, Property[] propertyDefinitions, String includeProperties, String excludeProperties, boolean autoLinkItems)
          Returns a map of PropertyVersions values keyed by Property instances consisting of the properties defined in the project which are associated with version information.
 ArtifactVersions lookupArtifactUpdates(org.apache.maven.artifact.Artifact artifact, Boolean allowSnapshots, boolean usePluginRepositories)
          Looks up the updates of an artifact.
 ArtifactVersions lookupArtifactVersions(org.apache.maven.artifact.Artifact artifact, boolean usePluginRepositories)
          Looks up the versions of the specified artifact that are available in either the local repository, or the appropriate remote repositories.
 Map lookupDependenciesUpdates(Set dependencies, boolean usePluginRepositories)
          Looks up the updates for a set of dependencies.
 ArtifactVersions lookupDependencyUpdates(org.apache.maven.model.Dependency dependency, boolean usePluginRepositories)
          Creates an ArtifactVersions instance from a dependency.
 Map lookupPluginsUpdates(Set plugins, Boolean allowSnapshots)
          Looks up the updates for a set of plugins.
 PluginUpdatesDetails lookupPluginUpdates(org.apache.maven.model.Plugin plugin, Boolean allowSnapshots)
          Looks up the updates for a plugin.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultVersionsHelper

public DefaultVersionsHelper(org.apache.maven.artifact.factory.ArtifactFactory artifactFactory,
                             org.apache.maven.artifact.metadata.ArtifactMetadataSource artifactMetadataSource,
                             List remoteArtifactRepositories,
                             List remotePluginRepositories,
                             org.apache.maven.artifact.repository.ArtifactRepository localRepository,
                             org.apache.maven.artifact.manager.WagonManager wagonManager,
                             org.apache.maven.settings.Settings settings,
                             String serverId,
                             String rulesUri,
                             org.apache.maven.plugin.logging.Log log,
                             org.apache.maven.execution.MavenSession mavenSession,
                             org.apache.maven.project.path.PathTranslator pathTranslator)
                      throws org.apache.maven.plugin.MojoExecutionException
Constructs a new DefaultVersionsHelper.

Parameters:
artifactFactory - The artifact factory.
artifactMetadataSource - The artifact metadata source to use.
remoteArtifactRepositories - The remote artifact repositories to consult.
remotePluginRepositories - The remote plugin repositories to consult.
localRepository - The local repository to consult.
wagonManager - The wagon manager (used if rules need to be retrieved).
settings - The settings (used to provide proxy information to the wagon manager).
serverId - The serverId hint for the wagon manager.
rulesUri - The URL to retrieve the versioning rules from.
log - The Log to send log messages to.
mavenSession - The maven session information.
pathTranslator - The path translator component.
Throws:
org.apache.maven.plugin.MojoExecutionException - If things go wrong.
Since:
1.0-alpha-3
Method Detail

getArtifactFactory

public org.apache.maven.artifact.factory.ArtifactFactory getArtifactFactory()
Returns the artifact factory to use.

Specified by:
getArtifactFactory in interface VersionsHelper
Returns:
the artifact factory to use.

getLog

public org.apache.maven.plugin.logging.Log getLog()
Gets the logger used by this helper.

Specified by:
getLog in interface VersionsHelper
Returns:
the logger used by this helper.

lookupArtifactVersions

public ArtifactVersions lookupArtifactVersions(org.apache.maven.artifact.Artifact artifact,
                                               boolean usePluginRepositories)
                                        throws org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException
Looks up the versions of the specified artifact that are available in either the local repository, or the appropriate remote repositories.

Specified by:
lookupArtifactVersions in interface VersionsHelper
Parameters:
artifact - The artifact to look for versions of.
usePluginRepositories - true will consult the pluginRepositories, while false will consult the repositories for normal dependencies.
Returns:
The details of the available artifact versions.
Throws:
org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException - When things go wrong.

getVersionComparator

public VersionComparator getVersionComparator(org.apache.maven.artifact.Artifact artifact)
Returns the version comparator to use for the specified artifact.

Specified by:
getVersionComparator in interface VersionsHelper
Parameters:
artifact - the artifact.
Returns:
the version comparator to use.

getVersionComparator

public VersionComparator getVersionComparator(String groupId,
                                              String artifactId)
Returns the version comparator to use for the specified groupId and artifactId.

Specified by:
getVersionComparator in interface VersionsHelper
Parameters:
groupId - the groupId.
artifactId - the artifactId.
Returns:
the version comparator to use.

createPluginArtifact

public org.apache.maven.artifact.Artifact createPluginArtifact(String groupId,
                                                               String artifactId,
                                                               org.apache.maven.artifact.versioning.VersionRange versionRange)
Shorthand method for getArtifactFactory().createPluginArtifact(...).

Specified by:
createPluginArtifact in interface VersionsHelper
Parameters:
groupId - The group Id.
artifactId - The artifact Id.
versionRange - The version range.
Returns:
the corresponding plugin artifact.

createDependencyArtifact

public org.apache.maven.artifact.Artifact createDependencyArtifact(String groupId,
                                                                   String artifactId,
                                                                   org.apache.maven.artifact.versioning.VersionRange versionRange,
                                                                   String type,
                                                                   String classifier,
                                                                   String scope,
                                                                   boolean optional)
Shorthand method for getArtifactFactory().createDependencyArtifact(...).

Specified by:
createDependencyArtifact in interface VersionsHelper
Parameters:
groupId - The group id.
artifactId - The artifact id.
versionRange - The version (possibly a range)
type - The type.
classifier - The classifier.
scope - The scope.
optional - If optional or not.
Returns:
The corresponding dependency artifact.

createDependencyArtifact

public org.apache.maven.artifact.Artifact createDependencyArtifact(String groupId,
                                                                   String artifactId,
                                                                   org.apache.maven.artifact.versioning.VersionRange versionRange,
                                                                   String type,
                                                                   String classifier,
                                                                   String scope)
Shorthand method for getArtifactFactory().createDependencyArtifact(...).

Specified by:
createDependencyArtifact in interface VersionsHelper
Parameters:
groupId - The group id.
artifactId - The artifact id.
versionRange - The version range.
type - The type.
classifier - The classifier.
scope - The scope.
Returns:
The corresponding dependency artifact.

createDependencyArtifact

public org.apache.maven.artifact.Artifact createDependencyArtifact(org.apache.maven.model.Dependency dependency)
                                                            throws org.apache.maven.artifact.versioning.InvalidVersionSpecificationException
Shorthand method for getArtifactFactory().createDependencyArtifact(...) which extracts the parameters from the Dependency instance.

Specified by:
createDependencyArtifact in interface VersionsHelper
Parameters:
dependency - The dependency to create the artifact for.
Returns:
The corresponding dependency artifact.
Throws:
org.apache.maven.artifact.versioning.InvalidVersionSpecificationException - if the version specified in the dependency is invalid.

extractArtifacts

public Set extractArtifacts(Collection mavenProjects)
Takes a List of MavenProject instances and converts it into a Set of Artifact instances.

Specified by:
extractArtifacts in interface VersionsHelper
Parameters:
mavenProjects - the List of MavenProject instances.
Returns:
a Set of Artifact instances.

createArtifactVersion

public org.apache.maven.artifact.versioning.ArtifactVersion createArtifactVersion(String version)
Creates an ArtifactVersion instance from a string.

Specified by:
createArtifactVersion in interface VersionsHelper
Parameters:
version - the string representation of the version.
Returns:
The artifact version.

lookupArtifactUpdates

public ArtifactVersions lookupArtifactUpdates(org.apache.maven.artifact.Artifact artifact,
                                              Boolean allowSnapshots,
                                              boolean usePluginRepositories)
                                       throws org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException
Looks up the updates of an artifact.

Specified by:
lookupArtifactUpdates in interface VersionsHelper
Parameters:
artifact - The artifact to look up
allowSnapshots - Include snapshots in the list of updates.
usePluginRepositories - Search the plugin repositories.
Returns:
The artifact update details.
Throws:
org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException - When things go wrong.

lookupDependenciesUpdates

public Map lookupDependenciesUpdates(Set dependencies,
                                     boolean usePluginRepositories)
                              throws org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException,
                                     org.apache.maven.artifact.versioning.InvalidVersionSpecificationException
Looks up the updates for a set of dependencies.

Specified by:
lookupDependenciesUpdates in interface VersionsHelper
Parameters:
dependencies - The set of Dependency instances to look up.
usePluginRepositories - Search the plugin repositories.
Returns:
A map, keyed by dependency, with values of type ArtifactVersions.
Throws:
org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException - When things go wrong.
org.apache.maven.artifact.versioning.InvalidVersionSpecificationException

lookupDependencyUpdates

public ArtifactVersions lookupDependencyUpdates(org.apache.maven.model.Dependency dependency,
                                                boolean usePluginRepositories)
                                         throws org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException,
                                                org.apache.maven.artifact.versioning.InvalidVersionSpecificationException
Creates an ArtifactVersions instance from a dependency.

Specified by:
lookupDependencyUpdates in interface VersionsHelper
Parameters:
dependency - The dependency.
usePluginRepositories - Search the plugin repositories.
Returns:
The details of updates to the dependency.
Throws:
org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException - When things go wrong.
org.apache.maven.artifact.versioning.InvalidVersionSpecificationException

lookupPluginsUpdates

public Map lookupPluginsUpdates(Set plugins,
                                Boolean allowSnapshots)
                         throws org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException,
                                org.apache.maven.artifact.versioning.InvalidVersionSpecificationException
Looks up the updates for a set of plugins.

Specified by:
lookupPluginsUpdates in interface VersionsHelper
Parameters:
plugins - The set of Plugin instances to look up.
allowSnapshots - Include snapshots in the list of updates.
Returns:
A map, keyed by plugin, with values of type PluginUpdatesDetails.
Throws:
org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException - When things go wrong.
org.apache.maven.artifact.versioning.InvalidVersionSpecificationException

lookupPluginUpdates

public PluginUpdatesDetails lookupPluginUpdates(org.apache.maven.model.Plugin plugin,
                                                Boolean allowSnapshots)
                                         throws org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException,
                                                org.apache.maven.artifact.versioning.InvalidVersionSpecificationException
Looks up the updates for a plugin.

Specified by:
lookupPluginUpdates in interface VersionsHelper
Parameters:
plugin - The Plugin instance to look up.
allowSnapshots - Include snapshots in the list of updates.
Returns:
The plugin update details.
Throws:
org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException - When things go wrong.
org.apache.maven.artifact.versioning.InvalidVersionSpecificationException

getExpressionEvaluator

public org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator getExpressionEvaluator(org.apache.maven.project.MavenProject project)
Returns an ExpressionEvaluator for the specified project.

Specified by:
getExpressionEvaluator in interface VersionsHelper
Parameters:
project - The project.
Returns:
an ExpressionEvaluator for the specified project.

getVersionPropertiesMap

public Map getVersionPropertiesMap(org.apache.maven.project.MavenProject project,
                                   Property[] propertyDefinitions,
                                   String includeProperties,
                                   String excludeProperties,
                                   boolean autoLinkItems)
                            throws org.apache.maven.plugin.MojoExecutionException
Returns a map of PropertyVersions values keyed by Property instances consisting of the properties defined in the project which are associated with version information.

Specified by:
getVersionPropertiesMap in interface VersionsHelper
Parameters:
project - The project.
propertyDefinitions - Any extra hints about properties.
includeProperties - A comma separated list of properties to include.
excludeProperties - A comma separated list of properties to exclude.
autoLinkItems - whether to automatically infer associations
Returns:
a map of PropertyVersions values keyed by Property instances.
Throws:
org.apache.maven.plugin.MojoExecutionException - if something goes wrong.


Copyright © 2008-2011 Codehaus. All Rights Reserved.