org.codehaus.mojo.versions.api
Class PomHelper

java.lang.Object
  extended by org.codehaus.mojo.versions.api.PomHelper

public class PomHelper
extends Object

Helper class for modifying pom files.

Since:
1.0-alpha-3
Author:
Stephen Connolly

Field Summary
static String APACHE_MAVEN_PLUGINS_GROUPID
           
 
Constructor Summary
PomHelper()
           
 
Method Summary
static void debugModules(org.apache.maven.plugin.logging.Log logger, String message, Collection modules)
          Outputs a debug message with a list of modules.
static Set getAllChildModules(org.apache.maven.project.MavenProject project, org.apache.maven.plugin.logging.Log logger)
          Returns a set of all child modules for a project, including any defined in profiles (ignoring profile activation).
static Set getAllChildModules(org.apache.maven.model.Model model, org.apache.maven.plugin.logging.Log logger)
          Returns a set of all child modules for a project, including any defined in profiles (ignoring profile activation).
static String getArtifactId(org.apache.maven.model.Model model)
          Extracts the artifactId from a raw model, interpolating from the parent if necessary.
static Map getChildModels(Map reactor, String groupId, String artifactId)
          Returns all the models that have a specified groupId and artifactId as parent.
static String getGroupId(org.apache.maven.model.Model model)
          Extracts the groupId from a raw model, interpolating from the parent if necessary.
static org.apache.maven.project.MavenProject getLocalRoot(org.apache.maven.project.MavenProjectBuilder builder, org.apache.maven.project.MavenProject project, org.apache.maven.artifact.repository.ArtifactRepository localRepository, org.apache.maven.profiles.ProfileManager globalProfileManager, org.apache.maven.plugin.logging.Log logger)
          Finds the local root of the specified project.
static org.apache.maven.model.Model getModel(Map reactor, String groupId, String artifactId)
          Returns the model that has the specified groupId and artifactId or null if no such model exists.
static org.apache.maven.artifact.Artifact getProjectParent(ModifiedPomXMLEventReader pom, VersionsHelper helper)
          Gets the parent artifact from the pom.
static String getProjectVersion(ModifiedPomXMLEventReader pom)
          Retrieves the project version from the pom.
static org.codehaus.mojo.versions.api.PropertyVersionsBuilder[] getPropertyVersionsBuilders(VersionsHelper helper, org.apache.maven.project.MavenProject project)
          Examines the project to find any properties which are associated with versions of artifacts in the project.
static org.apache.maven.model.Model getRawModel(File moduleProjectFile)
          Gets the raw model before any interpolation what-so-ever.
static org.apache.maven.model.Model getRawModel(org.apache.maven.project.MavenProject project)
          Gets the raw model before any interpolation what-so-ever.
static org.apache.maven.model.Model getRawModel(ModifiedPomXMLEventReader modifiedPomXMLEventReader)
          Gets the current raw model before any interpolation what-so-ever.
static Map getReactorModels(org.apache.maven.project.MavenProject project, org.apache.maven.plugin.logging.Log logger)
          Builds a map of raw models keyed by module path.
static int getReactorParentCount(Map reactor, org.apache.maven.model.Model model)
          Returns a count of how many parents a model has in the reactor.
static String getVersion(org.apache.maven.model.Model model)
          Extracts the version from a raw model, interpolating from the parent if necessary.
static StringBuffer readXmlFile(File outFile)
          Reads a file into a String.
static void removeMissingChildModules(org.apache.maven.plugin.logging.Log logger, File basedir, Collection childModules)
          Modifies the collection of child modules removing those which cannot be found relative to the parent.
static void removeMissingChildModules(org.apache.maven.plugin.logging.Log logger, org.apache.maven.project.MavenProject project, Collection childModules)
          Modifies the collection of child modules removing those which cannot be found relative to the parent.
static boolean setDependencyVersion(ModifiedPomXMLEventReader pom, String groupId, String artifactId, String oldVersion, String newVersion)
          Searches the pom re-defining the specified dependency to the specified version.
static boolean setPluginVersion(ModifiedPomXMLEventReader pom, String groupId, String artifactId, String oldVersion, String newVersion)
          Searches the pom re-defining the specified plugin to the specified version.
static boolean setProjectParentVersion(ModifiedPomXMLEventReader pom, String value)
          Searches the pom re-defining the project version to the specified version.
static boolean setProjectVersion(ModifiedPomXMLEventReader pom, String value)
          Searches the pom re-defining the project version to the specified version.
static boolean setPropertyVersion(ModifiedPomXMLEventReader pom, String profileId, String property, String value)
          Searches the pom re-defining the specified property to the specified version.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

APACHE_MAVEN_PLUGINS_GROUPID

public static final String APACHE_MAVEN_PLUGINS_GROUPID
See Also:
Constant Field Values
Constructor Detail

PomHelper

public PomHelper()
Method Detail

getRawModel

public static org.apache.maven.model.Model getRawModel(org.apache.maven.project.MavenProject project)
                                                throws IOException
Gets the raw model before any interpolation what-so-ever.

Parameters:
project - The project to get the raw model for.
Returns:
The raw model.
Throws:
IOException - if the file is not found or if the file does not parse.

getRawModel

public static org.apache.maven.model.Model getRawModel(File moduleProjectFile)
                                                throws IOException
Gets the raw model before any interpolation what-so-ever.

Parameters:
moduleProjectFile - The project file to get the raw model for.
Returns:
The raw model.
Throws:
IOException - if the file is not found or if the file does not parse.

getRawModel

public static org.apache.maven.model.Model getRawModel(ModifiedPomXMLEventReader modifiedPomXMLEventReader)
                                                throws IOException
Gets the current raw model before any interpolation what-so-ever.

Parameters:
modifiedPomXMLEventReader - The ModifiedPomXMLEventReader to get the raw model for.
Returns:
The raw model.
Throws:
IOException - if the file is not found or if the file does not parse.

setPropertyVersion

public static boolean setPropertyVersion(ModifiedPomXMLEventReader pom,
                                         String profileId,
                                         String property,
                                         String value)
                                  throws javax.xml.stream.XMLStreamException
Searches the pom re-defining the specified property to the specified version.

Parameters:
pom - The pom to modify.
profileId - The profile in which to modify the property.
property - The property to modify.
value - The new value of the property.
Returns:
true if a replacement was made.
Throws:
javax.xml.stream.XMLStreamException - if somethinh went wrong.

setProjectVersion

public static boolean setProjectVersion(ModifiedPomXMLEventReader pom,
                                        String value)
                                 throws javax.xml.stream.XMLStreamException
Searches the pom re-defining the project version to the specified version.

Parameters:
pom - The pom to modify.
value - The new value of the property.
Returns:
true if a replacement was made.
Throws:
javax.xml.stream.XMLStreamException - if somethinh went wrong.

getProjectVersion

public static String getProjectVersion(ModifiedPomXMLEventReader pom)
                                throws javax.xml.stream.XMLStreamException
Retrieves the project version from the pom.

Parameters:
pom - The pom.
Returns:
the project version or null if the project version is not defined (i.e. inherited from parent version).
Throws:
javax.xml.stream.XMLStreamException - if something went wrong.

setProjectParentVersion

public static boolean setProjectParentVersion(ModifiedPomXMLEventReader pom,
                                              String value)
                                       throws javax.xml.stream.XMLStreamException
Searches the pom re-defining the project version to the specified version.

Parameters:
pom - The pom to modify.
value - The new value of the property.
Returns:
true if a replacement was made.
Throws:
javax.xml.stream.XMLStreamException - if somethinh went wrong.

getProjectParent

public static org.apache.maven.artifact.Artifact getProjectParent(ModifiedPomXMLEventReader pom,
                                                                  VersionsHelper helper)
                                                           throws javax.xml.stream.XMLStreamException
Gets the parent artifact from the pom.

Parameters:
pom - The pom.
helper - The helper (used to create the artifact).
Returns:
The parent artifact or null if no parent is specified.
Throws:
javax.xml.stream.XMLStreamException - if something went wrong.

setDependencyVersion

public static boolean setDependencyVersion(ModifiedPomXMLEventReader pom,
                                           String groupId,
                                           String artifactId,
                                           String oldVersion,
                                           String newVersion)
                                    throws javax.xml.stream.XMLStreamException
Searches the pom re-defining the specified dependency to the specified version.

Parameters:
pom - The pom to modify.
groupId - The groupId of the dependency.
artifactId - The artifactId of the dependency.
oldVersion - The old version of the dependency.
newVersion - The new version of the dependency.
Returns:
true if a replacement was made.
Throws:
javax.xml.stream.XMLStreamException - if somethinh went wrong.

setPluginVersion

public static boolean setPluginVersion(ModifiedPomXMLEventReader pom,
                                       String groupId,
                                       String artifactId,
                                       String oldVersion,
                                       String newVersion)
                                throws javax.xml.stream.XMLStreamException
Searches the pom re-defining the specified plugin to the specified version.

Parameters:
pom - The pom to modify.
groupId - The groupId of the dependency.
artifactId - The artifactId of the dependency.
oldVersion - The old version of the dependency.
newVersion - The new version of the dependency.
Returns:
true if a replacement was made.
Throws:
javax.xml.stream.XMLStreamException - if somethinh went wrong.

getPropertyVersionsBuilders

public static org.codehaus.mojo.versions.api.PropertyVersionsBuilder[] getPropertyVersionsBuilders(VersionsHelper helper,
                                                                                                   org.apache.maven.project.MavenProject project)
                                                                                            throws org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException,
                                                                                                   IOException
Examines the project to find any properties which are associated with versions of artifacts in the project.

Parameters:
helper - Our versions helper.
project - The project to examine.
Returns:
An array of properties that are associated within the project.
Throws:
org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException - if an expression cannot be evaluated.
IOException - if the project's pom file cannot be parsed.
Since:
1.0-alpha-3

getAllChildModules

public static Set getAllChildModules(org.apache.maven.project.MavenProject project,
                                     org.apache.maven.plugin.logging.Log logger)
Returns a set of all child modules for a project, including any defined in profiles (ignoring profile activation).

Parameters:
project - The project.
logger - The logger to use.
Returns:
the set of all child modules of the project.

getAllChildModules

public static Set getAllChildModules(org.apache.maven.model.Model model,
                                     org.apache.maven.plugin.logging.Log logger)
Returns a set of all child modules for a project, including any defined in profiles (ignoring profile activation).

Parameters:
model - The project model.
logger - The logger to use.
Returns:
the set of all child modules of the project.

debugModules

public static void debugModules(org.apache.maven.plugin.logging.Log logger,
                                String message,
                                Collection modules)
Outputs a debug message with a list of modules.

Parameters:
logger - The logger to log to.
message - The message to display.
modules - The modules to append to the message.

removeMissingChildModules

public static void removeMissingChildModules(org.apache.maven.plugin.logging.Log logger,
                                             org.apache.maven.project.MavenProject project,
                                             Collection childModules)
Modifies the collection of child modules removing those which cannot be found relative to the parent.

Parameters:
logger - The logger to log to.
project - the project.
childModules - the child modules.

removeMissingChildModules

public static void removeMissingChildModules(org.apache.maven.plugin.logging.Log logger,
                                             File basedir,
                                             Collection childModules)
Modifies the collection of child modules removing those which cannot be found relative to the parent.

Parameters:
logger - The logger to log to.
basedir - the project basedir.
childModules - the child modules.

getVersion

public static String getVersion(org.apache.maven.model.Model model)
Extracts the version from a raw model, interpolating from the parent if necessary.

Parameters:
model - The model.
Returns:
The version.

getArtifactId

public static String getArtifactId(org.apache.maven.model.Model model)
Extracts the artifactId from a raw model, interpolating from the parent if necessary.

Parameters:
model - The model.
Returns:
The artifactId.

getGroupId

public static String getGroupId(org.apache.maven.model.Model model)
Extracts the groupId from a raw model, interpolating from the parent if necessary.

Parameters:
model - The model.
Returns:
The groupId.

getLocalRoot

public static org.apache.maven.project.MavenProject getLocalRoot(org.apache.maven.project.MavenProjectBuilder builder,
                                                                 org.apache.maven.project.MavenProject project,
                                                                 org.apache.maven.artifact.repository.ArtifactRepository localRepository,
                                                                 org.apache.maven.profiles.ProfileManager globalProfileManager,
                                                                 org.apache.maven.plugin.logging.Log logger)
Finds the local root of the specified project.

Parameters:
project - The project to find the local root for.
localRepository - the local repo.
globalProfileManager - the global profile manager.
logger -
Returns:
The local root (note this may be the project passed as an argument).

getReactorModels

public static Map getReactorModels(org.apache.maven.project.MavenProject project,
                                   org.apache.maven.plugin.logging.Log logger)
                            throws IOException
Builds a map of raw models keyed by module path.

Parameters:
project - The project to build from.
logger - The logger for logging.
Returns:
A map of raw models keyed by path relative to the project's basedir.
Throws:
IOException - if things go wrong.

getChildModels

public static Map getChildModels(Map reactor,
                                 String groupId,
                                 String artifactId)
Returns all the models that have a specified groupId and artifactId as parent.

Parameters:
reactor - The map of models keyed by path.
groupId - The groupId of the parent.
artifactId - The artifactId of the parent.
Returns:
a map of models that have a specified groupId and artifactId as parent keyed by path.

getModel

public static org.apache.maven.model.Model getModel(Map reactor,
                                                    String groupId,
                                                    String artifactId)
Returns the model that has the specified groupId and artifactId or null if no such model exists.

Parameters:
reactor - The map of models keyed by path.
groupId - The groupId to match.
artifactId - The artifactId to match.
Returns:
The model or null if the model was not in the reactor.

getReactorParentCount

public static int getReactorParentCount(Map reactor,
                                        org.apache.maven.model.Model model)
Returns a count of how many parents a model has in the reactor.

Parameters:
reactor - The map of models keyed by path.
model - The model.
Returns:
The number of parents of this model in the reactor.

readXmlFile

public static StringBuffer readXmlFile(File outFile)
                                throws IOException
Reads a file into a String.

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


Copyright © 2008-2011 Codehaus. All Rights Reserved.