org.codehaus.mojo.versions
Class AbstractVersionsUpdaterMojo

java.lang.Object
  extended by org.apache.maven.plugin.AbstractMojo
      extended by org.codehaus.mojo.versions.AbstractVersionsUpdaterMojo
All Implemented Interfaces:
org.apache.maven.plugin.ContextEnabled, org.apache.maven.plugin.Mojo
Direct Known Subclasses:
AbstractVersionsDependencyUpdaterMojo, DisplayDependencyUpdatesMojo, DisplayPluginUpdatesMojo, DisplayPropertyUpdatesMojo, SetMojo, UpdateChildModulesMojo, UpdateParentMojo, UpdatePropertiesMojo

public abstract class AbstractVersionsUpdaterMojo
extends org.apache.maven.plugin.AbstractMojo

Abstract base class for Versions Mojos.

Author:
Stephen Connolly

Field Summary
protected  Boolean allowSnapshots
          Whether to allow snapshots when searching for the latest version of an artifact.
protected  org.apache.maven.artifact.factory.ArtifactFactory artifactFactory
           
protected  org.apache.maven.artifact.metadata.ArtifactMetadataSource artifactMetadataSource
          The artifact metadata source to use.
protected  org.apache.maven.artifact.repository.ArtifactRepository localRepository
           
protected  org.apache.maven.project.path.PathTranslator pathTranslator
           
protected  org.apache.maven.project.MavenProjectBuilder projectBuilder
           
protected  List reactorProjects
           
protected  List remoteArtifactRepositories
           
protected  List remotePluginRepositories
           
protected  org.apache.maven.artifact.resolver.ArtifactResolver resolver
           
protected  org.apache.maven.execution.MavenSession session
          The Maven Sessopm.
 
Fields inherited from interface org.apache.maven.plugin.Mojo
ROLE
 
Constructor Summary
AbstractVersionsUpdaterMojo()
           
 
Method Summary
protected  int determineUnchangedSegment(Boolean allowMajorUpdates, Boolean allowMinorUpdates, Boolean allowIncrementalUpdates)
          Based on the passed flags, determines which segment is unchangable.
 void execute()
          
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.
 VersionsHelper getHelper()
           
 org.apache.maven.project.MavenProject getProject()
          Getter for property 'project'.
protected  String getPropertyValue(StringBuffer pom, String property)
          Gets the property value that is defined in the pom.
protected  ModifiedPomXMLEventReader newModifiedPomXER(StringBuffer input)
          Creates a ModifiedPomXMLEventReader from a StringBuffer.
protected  void process(File outFile)
          Processes the specified file.
 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)
          Returns true if the update should be applied.
protected abstract  void update(ModifiedPomXMLEventReader pom)
          Updates the pom.
protected  void writeFile(File outFile, StringBuffer input)
          Writes a StringBuffer into a file.
 
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 Detail

artifactFactory

protected org.apache.maven.artifact.factory.ArtifactFactory artifactFactory
Since:
1.0-alpha-1

resolver

protected org.apache.maven.artifact.resolver.ArtifactResolver resolver
Since:
1.0-alpha-1

projectBuilder

protected org.apache.maven.project.MavenProjectBuilder projectBuilder
Since:
1.0-alpha-1

reactorProjects

protected List reactorProjects
Since:
1.0-alpha-1

artifactMetadataSource

protected org.apache.maven.artifact.metadata.ArtifactMetadataSource artifactMetadataSource
The artifact metadata source to use.

Since:
1.0-alpha-1

remoteArtifactRepositories

protected List remoteArtifactRepositories
Since:
1.0-alpha-3

remotePluginRepositories

protected List remotePluginRepositories
Since:
1.0-alpha-3

localRepository

protected org.apache.maven.artifact.repository.ArtifactRepository localRepository
Since:
1.0-alpha-1

allowSnapshots

protected Boolean allowSnapshots
Whether to allow snapshots when searching for the latest version of an artifact.

Since:
1.0-alpha-1

session

protected org.apache.maven.execution.MavenSession session
The Maven Sessopm.

Since:
1.0-alpha-1

pathTranslator

protected org.apache.maven.project.path.PathTranslator pathTranslator
Constructor Detail

AbstractVersionsUpdaterMojo

public AbstractVersionsUpdaterMojo()
Method Detail

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

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

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.artifact.metadata.ArtifactMetadataRetrievalException,
                                                                                 org.apache.maven.plugin.MojoExecutionException
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 -
Returns:
The latest version of the specified artifact that matches the specified version range or null if no matching version could be found.
Throws:
org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException - If the artifact metadata could not be found.
org.apache.maven.plugin.MojoExecutionException
Since:
1.0-alpha-1

getPropertyValue

protected String getPropertyValue(StringBuffer pom,
                                  String property)
Gets the property value that is defined in the pom. This is an extension point to allow updating a file external to the reactor.

Parameters:
pom - The pom.
property - The property.
Returns:
The value as defined in the pom or null if not defined.
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

newModifiedPomXER

protected final ModifiedPomXMLEventReader newModifiedPomXER(StringBuffer input)
Creates a ModifiedPomXMLEventReader from a StringBuffer.

Parameters:
input - The XML to read and modify.
Returns:
The ModifiedPomXMLEventReader.

writeFile

protected final void writeFile(File outFile,
                               StringBuffer input)
                        throws IOException
Writes a StringBuffer into a file.

Parameters:
outFile - The file to read.
input - The contents of the file.
Throws:
IOException - when things go wrong.

update

protected abstract void update(ModifiedPomXMLEventReader pom)
                        throws org.apache.maven.plugin.MojoExecutionException,
                               org.apache.maven.plugin.MojoFailureException,
                               javax.xml.stream.XMLStreamException,
                               org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException
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.
javax.xml.stream.XMLStreamException - If things go wrong.
org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException
Since:
1.0-alpha-1

shouldApplyUpdate

protected boolean shouldApplyUpdate(org.apache.maven.artifact.Artifact artifact,
                                    String currentVersion,
                                    org.apache.maven.artifact.versioning.ArtifactVersion updateVersion)
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

determineUnchangedSegment

protected int determineUnchangedSegment(Boolean allowMajorUpdates,
                                        Boolean allowMinorUpdates,
                                        Boolean allowIncrementalUpdates)
Based on the passed flags, determines which segment is unchangable. This can be used when determining an upper bound for the "latest" version.

Parameters:
allowMajorUpdates -
allowMinorUpdates -
allowIncrementalUpdates -
Returns:
Returns the segment that is unchangable. If any segment can change, returns -1.


Copyright © 2008-2011 Codehaus. All Rights Reserved.