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
           
static String POM_ENCODING
          The encoding used for the pom file.
 
Constructor Summary
PomHelper()
           
 
Method Summary
static void debugModules(Log logger, String message, Collection modules)
          Outputs a debug message with a list of modules.
static Set getAllChildModules(MavenProject project, Log logger)
          Returns a set of all child modules for a project, including any defined in profiles (ignoring profile activation).
static 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 PropertyVersions[] getPropertyVersions(VersionsHelper helper, MavenProject project, org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator expressionEvaluator)
          Examines the project to find any properties which are associated with versions of artifacts in the project.
static Model getRawModel(MavenProject project)
          Gets the raw model before any interpolation what-so-ever.
static void removeMissingChildModules(Log logger, 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

POM_ENCODING

public static final String POM_ENCODING
The encoding used for the pom file.

Since:
1.0-alpha-3
See Also:
Constant Field Values

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 Model getRawModel(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.

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 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.

getPropertyVersions

public static PropertyVersions[] getPropertyVersions(VersionsHelper helper,
                                                     MavenProject project,
                                                     org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator expressionEvaluator)
                                              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.
expressionEvaluator - The expression evaluator to use when examining properties.
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(MavenProject project,
                                     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 -
Returns:
the set of all child modules of the project.

debugModules

public static void debugModules(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(Log logger,
                                             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.


Copyright © 2008-2009 Codehaus. All Rights Reserved.