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:
ContextEnabled, Mojo
Direct Known Subclasses:
DisplayDependencyUpdatesMojo, DisplayPluginUpdatesMojo, UpdateChildModulesMojo, UpdateParentMojo, UpdatePropertiesMojo

public abstract class AbstractVersionsUpdaterMojo
extends 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  ArtifactFactory artifactFactory
           
protected  ArtifactMetadataSource artifactMetadataSource
          The artifact metadata source to use.
protected  String comparisonMethod
          The versioning rule to use when comparing versions.
protected  ArtifactRepository localRepository
           
protected  MavenProjectBuilder projectBuilder
           
protected  List reactorProjects
           
protected  List remoteRepositories
           
protected  ArtifactResolver resolver
           
 
Fields inherited from interface org.apache.maven.plugin.Mojo
ROLE
 
Constructor Summary
AbstractVersionsUpdaterMojo()
           
 
Method Summary
 void execute()
          
protected  ArtifactVersion findLatestVersion(Artifact artifact, VersionRange versionRange, Boolean allowingSnapshots)
          Finds the latest version of the specified artifact that matches the version range.
 MavenProject getProject()
          Getter for property 'project'.
protected  String getPropertyValue(StringBuffer pom, String property)
          Gets the property value that is defined in the pom.
protected  Comparator getVersionComparator()
          Returns the version comparator to use.
protected  ModifiedPomXMLEventReader newModifiedPomXER(StringBuffer input)
          Creates a ModifiedPomXMLEventReader from a StringBuffer.
protected  void process(File outFile)
          Processes the specified file.
protected  StringBuffer readFile(File outFile)
          Reads a file into a StringBuffer.
 void setProject(MavenProject project)
          Setter for property 'project'.
protected  boolean shouldApplyUpdate(Artifact artifact, String currentVersion, 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 ArtifactFactory artifactFactory
Since:
1.0-alpha-1

resolver

protected ArtifactResolver resolver
Since:
1.0-alpha-1

projectBuilder

protected MavenProjectBuilder projectBuilder
Since:
1.0-alpha-1

localRepository

protected ArtifactRepository localRepository
Since:
1.0-alpha-1

remoteRepositories

protected List remoteRepositories
Since:
1.0-alpha-1

artifactMetadataSource

protected ArtifactMetadataSource artifactMetadataSource
The artifact metadata source to use.

Since:
1.0-alpha-1

comparisonMethod

protected String comparisonMethod
The versioning rule to use when comparing versions. Valid values are maven or numeric which will handle long version numbers provided all components are numeric.

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

reactorProjects

protected List reactorProjects
Since:
1.0-alpha-1
Constructor Detail

AbstractVersionsUpdaterMojo

public AbstractVersionsUpdaterMojo()
Method Detail

getProject

public MavenProject getProject()
Getter for property 'project'.

Returns:
Value for property 'project'.
Since:
1.0-alpha-1

setProject

public void setProject(MavenProject project)
Setter for property 'project'.

Parameters:
project - Value to set for property 'project'.
Since:
1.0-alpha-1

execute

public void execute()
             throws MojoExecutionException,
                    MojoFailureException

Throws:
MojoExecutionException
MojoFailureException
Since:
1.0-alpha-1

findLatestVersion

protected ArtifactVersion findLatestVersion(Artifact artifact,
                                            VersionRange versionRange,
                                            Boolean allowingSnapshots)
                                     throws 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.
Returns:
The latest version of the specified artifact that matches the specified version range or null if no matching version could be found.
Throws:
MojoExecutionException - If the artifact metadata could not be found.
Since:
1.0-alpha-1

getVersionComparator

protected Comparator getVersionComparator()
Returns the version comparator to use.

Returns:
the version comparator to use.
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 MojoExecutionException,
                       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:
MojoExecutionException - If things go wrong.
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.

readFile

protected final StringBuffer readFile(File outFile)
                               throws IOException
Reads a file into a StringBuffer.

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

update

protected abstract void update(ModifiedPomXMLEventReader pom)
                        throws MojoExecutionException,
                               MojoFailureException,
                               javax.xml.stream.XMLStreamException
Updates the pom.

Parameters:
pom - The pom to update.
Throws:
MojoExecutionException - If things go wrong.
MojoFailureException - If things go wrong.
javax.xml.stream.XMLStreamException - If things go wrong.
Since:
1.0-alpha-1

shouldApplyUpdate

protected boolean shouldApplyUpdate(Artifact artifact,
                                    String currentVersion,
                                    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


Copyright © 2008 Codehaus. All Rights Reserved.