Class DefaultVersionsHelper

java.lang.Object
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
  • Method Details

    • getLog

      public org.apache.maven.plugin.logging.Log getLog()
      Description copied from interface: VersionsHelper
      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, org.apache.maven.artifact.versioning.VersionRange versionRange, boolean usePluginRepositories) throws VersionRetrievalException
      Description copied from interface: VersionsHelper
      Looks up the versions of the specified artifact that are available in either the local repository, or the appropriate remote repositories. The resulting ArtifactVersions instance will contain all versions, including snapshots.
      Specified by:
      lookupArtifactVersions in interface VersionsHelper
      Parameters:
      artifact - The artifact to look for versions of.
      versionRange - versionRange to restrict the search, may be null
      usePluginRepositories - true will consult the pluginRepositories, while false will consult the repositories for normal dependencies.
      Returns:
      The details of the available artifact versions.
      Throws:
      VersionRetrievalException - thrown if version resolution fails
    • lookupArtifactVersions

      public ArtifactVersions lookupArtifactVersions(org.apache.maven.artifact.Artifact artifact, org.apache.maven.artifact.versioning.VersionRange versionRange, boolean usePluginRepositories, boolean useProjectRepositories) throws VersionRetrievalException
      Description copied from interface: VersionsHelper
      Looks up the versions of the specified artifact that are available in either the local repository, or the appropriate remote repositories. The resulting ArtifactVersions instance will contain all versions, including snapshots.
      Specified by:
      lookupArtifactVersions in interface VersionsHelper
      Parameters:
      artifact - The artifact to look for versions of.
      versionRange - versionRange to restrict the search, may be null
      usePluginRepositories - true will consult the pluginRepositories
      useProjectRepositories - true will consult regular project repositories
      Returns:
      The details of the available artifact versions.
      Throws:
      VersionRetrievalException - thrown if version resolution fails
    • lookupArtifactVersions

      public ArtifactVersions lookupArtifactVersions(org.apache.maven.artifact.Artifact artifact, boolean usePluginRepositories) throws VersionRetrievalException
      Description copied from interface: VersionsHelper
      Looks up the versions of the specified artifact that are available in either the local repository, or the appropriate remote repositories. The resulting ArtifactVersions instance will contain all versions, including snapshots.
      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:
      VersionRetrievalException - thrown if version resolution fails
    • resolveArtifact

      public void resolveArtifact(org.apache.maven.artifact.Artifact artifact, boolean usePluginRepositories) throws org.apache.maven.artifact.resolver.ArtifactResolutionException
      Description copied from interface: VersionsHelper
      Attempts to resolve the artifact.
      Specified by:
      resolveArtifact in interface VersionsHelper
      Parameters:
      artifact - The artifact to resolve.
      usePluginRepositories - whether to resolve from the plugin repositories or the regular repositories.
      Throws:
      org.apache.maven.artifact.resolver.ArtifactResolutionException - if resolution is unsuccessful
    • getVersionComparator

      public VersionComparator getVersionComparator(org.apache.maven.artifact.Artifact artifact)
      Description copied from interface: VersionsHelper
      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)
      Description copied from interface: VersionsHelper
      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.
    • getBestFitRule

      protected Rule getBestFitRule(String groupId, String artifactId)
      Find the rule, if any, which best fits the artifact details given.
      Parameters:
      groupId - Group id of the artifact
      artifactId - Artifact id of the artifact
      Returns:
      Rule which best describes the given artifact
    • createPluginArtifact

      public org.apache.maven.artifact.Artifact createPluginArtifact(String groupId, String artifactId, String version)
      Description copied from interface: VersionsHelper
      Shorthand method for repositorySystem.createPluginArtifact(...).
      Specified by:
      createPluginArtifact in interface VersionsHelper
      Parameters:
      groupId - The group Id.
      artifactId - The artifact Id.
      version - The version range.
      Returns:
      the corresponding plugin artifact.
    • createDependencyArtifact

      public org.apache.maven.artifact.Artifact createDependencyArtifact(String groupId, String artifactId, String version, String type, String classifier, String scope, boolean optional)
      Description copied from interface: VersionsHelper
      Shorthand method for repositorySystem.createDependencyArtifact(...).
      Specified by:
      createDependencyArtifact in interface VersionsHelper
      Parameters:
      groupId - The group id.
      artifactId - The artifact id.
      version - 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(org.apache.maven.model.Dependency dependency)
      Description copied from interface: VersionsHelper
      Shorthand method for repositorySystem.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.
    • extractArtifacts

      public Set<org.apache.maven.artifact.Artifact> extractArtifacts(Collection<org.apache.maven.project.MavenProject> mavenProjects)
      Description copied from interface: VersionsHelper
      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)
      Description copied from interface: VersionsHelper
      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.
    • lookupDependenciesUpdates

      public Map<org.apache.maven.model.Dependency,ArtifactVersions> lookupDependenciesUpdates(Stream<org.apache.maven.model.Dependency> dependencies, boolean usePluginRepositories, boolean useProjectRepositories, boolean allowSnapshots) throws VersionRetrievalException
      Description copied from interface: VersionsHelper
      Returns a map of all possible updates per dependency. The lookup is done in parallel using LOOKUP_PARALLEL_THREADS threads.
      Specified by:
      lookupDependenciesUpdates in interface VersionsHelper
      Parameters:
      dependencies - stream of Dependency instances to look up.
      usePluginRepositories - Search the plugin repositories.
      useProjectRepositories - whether to use regular project repositories
      allowSnapshots - whether snapshots should be included
      Returns:
      map containing the ArtifactVersions object per dependency
      Throws:
      VersionRetrievalException - thrown if a version cannot be retrieved
    • lookupDependenciesUpdates

      public Map<org.apache.maven.model.Dependency,ArtifactVersions> lookupDependenciesUpdates(Stream<org.apache.maven.model.Dependency> dependencies, boolean usePluginRepositories, boolean allowSnapshots) throws VersionRetrievalException
      Description copied from interface: VersionsHelper
      Returns a map of all possible updates per dependency. The lookup is done in parallel using LOOKUP_PARALLEL_THREADS threads.
      Specified by:
      lookupDependenciesUpdates in interface VersionsHelper
      Parameters:
      dependencies - a stream of Dependency instances to look up.
      usePluginRepositories - Search the plugin repositories.
      allowSnapshots - whether snapshots should be included
      Returns:
      map containing the ArtifactVersions object per dependency
      Throws:
      VersionRetrievalException - thrown if a version cannot be retrieved
    • lookupDependencyUpdates

      public ArtifactVersions lookupDependencyUpdates(org.apache.maven.model.Dependency dependency, boolean usePluginRepositories, boolean useProjectRepositories, boolean allowSnapshots) throws VersionRetrievalException
      Description copied from interface: VersionsHelper
      Creates an ArtifactVersions instance from a dependency.
      Specified by:
      lookupDependencyUpdates in interface VersionsHelper
      Parameters:
      dependency - The dependency.
      usePluginRepositories - Search the plugin repositories.
      useProjectRepositories - whether to use regular project repositories
      allowSnapshots - whether snapshots should be included
      Returns:
      The details of updates to the dependency.
      Throws:
      VersionRetrievalException - thrown if version resolution fails
    • lookupPluginsUpdates

      public Map<org.apache.maven.model.Plugin,PluginUpdatesDetails> lookupPluginsUpdates(Stream<org.apache.maven.model.Plugin> plugins, boolean allowSnapshots) throws VersionRetrievalException
      Description copied from interface: VersionsHelper
      Looks up the updates for a set of plugins.
      Specified by:
      lookupPluginsUpdates in interface VersionsHelper
      Parameters:
      plugins - A stream 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:
      VersionRetrievalException - thrown if version resolution fails
    • lookupPluginUpdates

      public PluginUpdatesDetails lookupPluginUpdates(org.apache.maven.model.Plugin plugin, boolean allowSnapshots) throws VersionRetrievalException
      Description copied from interface: VersionsHelper
      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:
      VersionRetrievalException - thrown if version resolution fails
    • getExpressionEvaluator

      public org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator getExpressionEvaluator(org.apache.maven.project.MavenProject project)
      Description copied from interface: VersionsHelper
      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<Property,PropertyVersions> getVersionPropertiesMap(VersionsHelper.VersionPropertiesMapRequest request) throws org.apache.maven.plugin.MojoExecutionException
      Description copied from interface: VersionsHelper
      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:
      request - VersionsHelper.VersionPropertiesMapRequest instance containing the arguments
      Returns:
      a map of PropertyVersions values keyed by Property instances.
      Throws:
      org.apache.maven.plugin.MojoExecutionException - if something goes wrong.