Class AbstractVersionsUpdaterMojo

java.lang.Object
org.apache.maven.plugin.AbstractMojo
org.codehaus.mojo.versions.AbstractVersionsUpdaterMojo
All Implemented Interfaces:
org.apache.maven.plugin.ContextEnabled, org.apache.maven.plugin.Mojo
Direct Known Subclasses:
AbstractVersionsDependencyUpdaterMojo, AbstractVersionsDisplayMojo, SetMojo, SetPropertyMojo, SetScmTagMojo, UpdateChildModulesMojo, UpdateParentMojo

public abstract class AbstractVersionsUpdaterMojo extends org.apache.maven.plugin.AbstractMojo
Abstract base class for Versions Mojos.
Author:
Stephen Connolly
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected boolean
    Whether to allow snapshots when searching for the latest version of an artifact.
    protected final org.apache.maven.artifact.handler.manager.ArtifactHandlerManager
    The (injected) ArtifactHandlerManager instance.
    protected boolean
    Controls whether a backup pom should be created.
    protected Set<String>
    Allows specifying ignored versions directly as an alternative to providing the ruleSet parameter; mainly created for -D property usage.
    protected org.apache.maven.project.MavenProject
    The Maven Project.
    protected List<org.apache.maven.project.MavenProject>
     
    protected org.eclipse.aether.RepositorySystem
    The (injected) RepositorySystem instance.
    protected RuleSet
    Allows specifying the RuleSet object describing rules on artifact versions to ignore when considering updates.
    protected org.apache.maven.execution.MavenSession
    The Maven Session.
    protected final Map<String,org.apache.maven.wagon.Wagon>
    (injected) map of Wagon instances

    Fields inherited from interface org.apache.maven.plugin.Mojo

    ROLE
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    AbstractVersionsUpdaterMojo(org.apache.maven.artifact.handler.manager.ArtifactHandlerManager artifactHandlerManager, org.eclipse.aether.RepositorySystem repositorySystem, Map<String,org.apache.maven.wagon.Wagon> wagonMap, Map<String,ChangeRecorder> changeRecorders)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    protected org.apache.maven.artifact.versioning.ArtifactVersion
    findLatestVersion(org.apache.maven.artifact.Artifact artifact, org.apache.maven.artifact.versioning.VersionRange versionRange, Boolean allowingSnapshots, boolean usePluginRepositories)
    Finds the latest version of the specified artifact that matches the version range.
    protected ChangeRecorder
    Configure and return the change recorder.
     
    org.apache.maven.project.MavenProject
    Getter for property 'project'.
     
    protected void
    process(File outFile)
    Processes the specified file.
    protected void
    Save all of the changes recorded by the change recorder.
    void
    setProject(org.apache.maven.project.MavenProject project)
    Setter for property 'project'.
    protected boolean
    shouldApplyUpdate(org.apache.maven.artifact.Artifact artifact, String currentVersion, org.apache.maven.artifact.versioning.ArtifactVersion updateVersion)
    Deprecated.
    This method no longer supported.
    protected boolean
    shouldApplyUpdate(org.apache.maven.artifact.Artifact artifact, String currentVersion, org.apache.maven.artifact.versioning.ArtifactVersion updateVersion, boolean forceUpdate)
    Returns true if the update should be applied.
    protected abstract void
    Updates the pom.
    protected org.apache.maven.artifact.versioning.ArtifactVersion
    updatePropertyToNewestVersion(MutableXMLStreamReader pom, Property property, PropertyVersions version, String currentVersion, boolean allowDowngrade, Optional<Segment> unchangedSegment)
    Attempts to update the property to a newer version, if that exists
    protected void
    Validates input parameters

    Methods inherited from class org.apache.maven.plugin.AbstractMojo

    getLog, getPluginContext, setLog, setPluginContext

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • project

      @Parameter(defaultValue="${project}", required=true, readonly=true) protected org.apache.maven.project.MavenProject project
      The Maven Project.
      Since:
      1.0-alpha-1
    • artifactHandlerManager

      protected final org.apache.maven.artifact.handler.manager.ArtifactHandlerManager artifactHandlerManager
      The (injected) ArtifactHandlerManager instance.
    • repositorySystem

      protected org.eclipse.aether.RepositorySystem repositorySystem
      The (injected) RepositorySystem instance.
    • reactorProjects

      @Parameter(defaultValue="${reactorProjects}", required=true, readonly=true) protected List<org.apache.maven.project.MavenProject> reactorProjects
      Since:
      1.0-alpha-1
    • generateBackupPoms

      @Parameter(property="generateBackupPoms", defaultValue="true") protected boolean generateBackupPoms
      Controls whether a backup pom should be created.
      Since:
      1.0-alpha-3
    • allowSnapshots

      @Parameter(property="allowSnapshots", defaultValue="false") protected boolean allowSnapshots
      Whether to allow snapshots when searching for the latest version of an artifact.
      Since:
      1.0-alpha-1
    • session

      @Parameter(defaultValue="${session}", required=true, readonly=true) protected org.apache.maven.execution.MavenSession session
      The Maven Session.
      Since:
      1.0-alpha-1
    • ruleSet

      @Parameter protected RuleSet ruleSet

      Allows specifying the RuleSet object describing rules on artifact versions to ignore when considering updates.

      Since:
      2.13.0
      See Also:
    • ignoredVersions

      @Parameter(property="maven.version.ignore") protected Set<String> ignoredVersions

      Allows specifying ignored versions directly as an alternative to providing the ruleSet parameter; mainly created for -D property usage.

      Example: "1\.0\.1,.+-M.,.*-SNAPSHOT"

      Currently, this parameter will override the defined ruleSet

      Since:
      2.13.0
    • wagonMap

      protected final Map<String,org.apache.maven.wagon.Wagon> wagonMap
      (injected) map of Wagon instances
      Since:
      2.14.0
  • Constructor Details

    • AbstractVersionsUpdaterMojo

      @Inject protected AbstractVersionsUpdaterMojo(org.apache.maven.artifact.handler.manager.ArtifactHandlerManager artifactHandlerManager, org.eclipse.aether.RepositorySystem repositorySystem, Map<String,org.apache.maven.wagon.Wagon> wagonMap, Map<String,ChangeRecorder> changeRecorders)
  • Method Details

    • getHelper

      public VersionsHelper getHelper() throws org.apache.maven.plugin.MojoExecutionException
      Throws:
      org.apache.maven.plugin.MojoExecutionException
    • getProject

      public org.apache.maven.project.MavenProject getProject()
      Getter for property 'project'.
      Returns:
      Value for property 'project'.
      Since:
      1.0-alpha-1
    • setProject

      public void setProject(org.apache.maven.project.MavenProject project)
      Setter for property 'project'.
      Parameters:
      project - Value to set for property 'project'.
      Since:
      1.0-alpha-1
    • getVersion

      public String getVersion()
    • execute

      public void execute() throws org.apache.maven.plugin.MojoExecutionException, org.apache.maven.plugin.MojoFailureException
      Throws:
      org.apache.maven.plugin.MojoExecutionException
      org.apache.maven.plugin.MojoFailureException
      Since:
      1.0-alpha-1
    • validateInput

      protected void validateInput() throws org.apache.maven.plugin.MojoExecutionException
      Validates input parameters
      Throws:
      org.apache.maven.plugin.MojoExecutionException - thrown if any of input parameters is invalid
    • findLatestVersion

      protected org.apache.maven.artifact.versioning.ArtifactVersion findLatestVersion(org.apache.maven.artifact.Artifact artifact, org.apache.maven.artifact.versioning.VersionRange versionRange, Boolean allowingSnapshots, boolean usePluginRepositories) throws org.apache.maven.plugin.MojoExecutionException, VersionRetrievalException
      Finds the latest version of the specified artifact that matches the version range.
      Parameters:
      artifact - The artifact.
      versionRange - The version range.
      allowingSnapshots - null for no override, otherwise the local override to apply.
      usePluginRepositories - Use plugin repositories
      Returns:
      The latest version of the specified artifact that matches the specified version range or null if no matching version could be found.
      Throws:
      VersionRetrievalException - If the artifact metadata could not be found.
      org.apache.maven.plugin.MojoExecutionException - if something goes wrong.
      Since:
      1.0-alpha-1
    • process

      protected void process(File outFile) throws org.apache.maven.plugin.MojoExecutionException, org.apache.maven.plugin.MojoFailureException
      Processes the specified file. This is an extension point to allow updating a file external to the reactor.
      Parameters:
      outFile - The file to process.
      Throws:
      org.apache.maven.plugin.MojoExecutionException - If things go wrong.
      org.apache.maven.plugin.MojoFailureException - If things go wrong.
      Since:
      1.0-alpha-1
    • update

      protected abstract void update(MutableXMLStreamReader pom) throws org.apache.maven.plugin.MojoExecutionException, org.apache.maven.plugin.MojoFailureException, XMLStreamException, VersionRetrievalException
      Updates the pom.
      Parameters:
      pom - The pom to update.
      Throws:
      org.apache.maven.plugin.MojoExecutionException - If things go wrong.
      org.apache.maven.plugin.MojoFailureException - If things go wrong.
      XMLStreamException - If things go wrong.
      VersionRetrievalException - if version retrieval goes wrong
      Since:
      1.0-alpha-1
    • shouldApplyUpdate

      @Deprecated protected boolean shouldApplyUpdate(org.apache.maven.artifact.Artifact artifact, String currentVersion, org.apache.maven.artifact.versioning.ArtifactVersion updateVersion)
      Deprecated.
      This method no longer supported. use shouldApplyUpdate( Artifact artifact, String currentVersion, ArtifactVersion updateVersion, Boolean forceUpdate )

      Returns true if the update should be applied.

      Parameters:
      artifact - The artifact.
      currentVersion - The current version of the artifact.
      updateVersion - The proposed new version of the artifact.
      Returns:
      true if the update should be applied.
      Since:
      1.0-alpha-1
    • shouldApplyUpdate

      protected boolean shouldApplyUpdate(org.apache.maven.artifact.Artifact artifact, String currentVersion, org.apache.maven.artifact.versioning.ArtifactVersion updateVersion, boolean forceUpdate)
      Returns true if the update should be applied.
      Parameters:
      artifact - The artifact.
      currentVersion - The current version of the artifact.
      updateVersion - The proposed new version of the artifact.
      forceUpdate - if true, LATEST and RELEASE versions will be overwritten with the real version
      Returns:
      true if the update should be applied to the pom.
      Since:
      2.9
    • updatePropertyToNewestVersion

      protected org.apache.maven.artifact.versioning.ArtifactVersion updatePropertyToNewestVersion(MutableXMLStreamReader pom, Property property, PropertyVersions version, String currentVersion, boolean allowDowngrade, Optional<Segment> unchangedSegment) throws XMLStreamException, org.apache.maven.artifact.versioning.InvalidVersionSpecificationException, InvalidSegmentException, org.apache.maven.plugin.MojoExecutionException
      Attempts to update the property to a newer version, if that exists
      Parameters:
      pom - pom to update
      property - property to update
      version - PropertyVersions object
      currentVersion - current version
      allowDowngrade - if downgrades should be allowed if snapshots are not allowed
      unchangedSegment - most major segment not to be changed
      Returns:
      new version of the artifact, if the property was updated; null if there was no update
      Throws:
      XMLStreamException - thrown from MutableXMLStreamReader if the update doesn't succeed
      org.apache.maven.artifact.versioning.InvalidVersionSpecificationException - thrown if unchangedSegment doesn't match the version
      InvalidSegmentException - thrown if unchangedSegment is invalid
      org.apache.maven.plugin.MojoExecutionException - thrown if any other error occurs
    • getChangeRecorder

      protected ChangeRecorder getChangeRecorder() throws org.apache.maven.plugin.MojoExecutionException
      Configure and return the change recorder.
      Returns:
      The change recorder
      Throws:
      org.apache.maven.plugin.MojoExecutionException - if something goes wrong.
    • saveChangeRecorderResults

      protected void saveChangeRecorderResults() throws IOException, org.apache.maven.plugin.MojoExecutionException
      Save all of the changes recorded by the change recorder.
      Throws:
      IOException - On I/O errors
      org.apache.maven.plugin.MojoExecutionException - if something goes wrong.