org.apache.maven
Class MavenUtils

java.lang.Object
  extended byorg.apache.maven.MavenUtils

public class MavenUtils
extends java.lang.Object

Utilities for reading maven project descriptors, profile descriptors and workspace descriptors.

Author:
Jason van Zyl, Brett Porter
To Do:
Remove all the context creation code and make a ContextBuilder class., [RC2] split getProject (project.properties + defaults) != getPluginProject (plugin.properties only)

Field Summary
static java.lang.String MAVEN_UNKNOWN_ERROR
          Maven unknown error message.
 
Constructor Summary
MavenUtils()
           
 
Method Summary
static MavenJellyContext createContext(java.io.File descriptorDirectory)
          Create a jelly context given a descriptor directory.
static MavenJellyContext createContext(java.io.File descriptorDirectory, MavenJellyContext parentContext)
          Create a jelly context given a descriptor directory and parent jelly context.
static void displayClassLoaderContents(com.werken.forehead.ForeheadClassLoader classLoader)
          Debugging function.
static java.lang.String[] getFiles(java.io.File directory, java.lang.String includes)
          Get a set of files from a specifed directory with a set of includes.
static java.lang.String[] getFiles(java.io.File directory, java.lang.String includes, java.lang.String excludes)
          Get a set of files from a specifed directory with a set of includes.
static java.util.List getGoalListFromCsv(java.lang.String goalCsv)
          Get a list of goals from a CSV list.
static Project getJellyProject(Project project)
          Take the POM and interpolate the value of the project's context to create a new version of the POM with expanded context values.
static java.lang.String getMessage(java.lang.String messageId)
          Retrieve a user message.
static java.lang.String getMessage(java.lang.String messageId, java.lang.Object variable)
          Retrieve a user message.
static Project getNonJellyProject(java.io.File projectDescriptor, MavenJellyContext parentContext, boolean useParentPom)
          Get a project, but not a Jelly-ised project.
static Project getProject(java.io.File projectDescriptor)
          Create a Project object given a file descriptor.
static Project getProject(java.io.File projectDescriptor, MavenJellyContext parentContext)
          Create a Project object given a file descriptor, and a parent context
static Project getProject(java.io.File projectDescriptor, MavenJellyContext parentContext, boolean useParentPom)
          Create a Project object given a file descriptor and optionally a parent Jelly context.
static java.util.List getProjects(java.io.File directory, java.lang.String includes, java.lang.String excludes)
          This is currently used for the reactor but may be generally useful.
static java.util.List getProjects(java.io.File directory, java.lang.String includes, java.lang.String excludes, MavenJellyContext context)
          This is currently used for the reactor but may be generally useful.
static void integrateMapInContext(java.util.Map map, MavenJellyContext context)
          Integrate a Map of key:value pairs into a MavenJellyContext.
static java.lang.String makeAbsolutePath(java.io.File basedir, java.lang.String dir)
          Resolve directory against a base directory if it is not already absolute.
static java.lang.String makeRelativePath(java.io.File basedir, java.lang.String path)
          Convert an absolute path to a relative path if it is under a given base directory.
static java.util.Map mergeMaps(java.util.Map[] maps)
          Take a series of Maps and merge them where the ordering of the array from 0..n is the dominant order.
static java.util.Map mergeMaps(java.util.Map dominantMap, java.util.Map recessiveMap)
          Take a dominant and recessive Map and merge the key:value pairs where the recessive Map may add key:value pairs to the dominant Map but may not override any existing key:value pairs.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAVEN_UNKNOWN_ERROR

public static final java.lang.String MAVEN_UNKNOWN_ERROR
Maven unknown error message.

See Also:
Constant Field Values
Constructor Detail

MavenUtils

public MavenUtils()
Method Detail

getProject

public static Project getProject(java.io.File projectDescriptor)
                          throws MavenException
Create a Project object given a file descriptor.

Parameters:
projectDescriptor - a maven project.xml
Returns:
the Maven project object for the given project descriptor
Throws:
MavenException - when any errors occur

getProject

public static Project getProject(java.io.File projectDescriptor,
                                 MavenJellyContext parentContext)
                          throws MavenException
Create a Project object given a file descriptor, and a parent context

Parameters:
projectDescriptor - The file to create the project from
parentContext - the parent Maven Jelly Context
Returns:
a new Project
Throws:
MavenException - when any error happens.

getProject

public static Project getProject(java.io.File projectDescriptor,
                                 MavenJellyContext parentContext,
                                 boolean useParentPom)
                          throws MavenException
Create a Project object given a file descriptor and optionally a parent Jelly context.

Parameters:
projectDescriptor - a maven project.xml File
parentContext - the parent context for the new project
useParentPom - whether a parent project should be respected
Returns:
the MavenSession project object for the given project descriptor
Throws:
MavenException - when any errors occur

getNonJellyProject

public static Project getNonJellyProject(java.io.File projectDescriptor,
                                         MavenJellyContext parentContext,
                                         boolean useParentPom)
                                  throws MavenException,
                                         java.io.IOException
Get a project, but not a Jelly-ised project. ie Don't evaluate the variables. We are doing several things when creating a POM object, the phases are outlined here: 1) The project.xml file is read in using betwixt which creates for us a Project object that, at this point, has not been run through Jelly i.e. no interpolation has occured yet. 2) The context for the project is created and set. So each project manages its own context. See the createContext() method for the details context creation process. 3) We check to see if the <extend> tag is being employed. If so, the parent project.xml file is read in. At this point we have a child and parent POM and the values are merged where the child's values override those of the parent.

Parameters:
projectDescriptor - the project file
parentContext - the parent context for the new project
useParentPom - whether a parent project should be respected
Returns:
the project
Throws:
MavenException - when there are errors reading the descriptor
java.io.IOException - when resolving file names and paths

getProjects

public static java.util.List getProjects(java.io.File directory,
                                         java.lang.String includes,
                                         java.lang.String excludes)
                                  throws MavenException
This is currently used for the reactor but may be generally useful.

Parameters:
directory - the directory to scan for maven projects
includes - the pattern that matches a project that you want included
excludes - the pattern that matches a project that you don't want included
Returns:
a {link List} of Projects
Throws:
MavenException - when anything goes wrong.

getProjects

public static java.util.List getProjects(java.io.File directory,
                                         java.lang.String includes,
                                         java.lang.String excludes,
                                         MavenJellyContext context)
                                  throws MavenException
This is currently used for the reactor but may be generally useful.

Parameters:
directory - the directory to scan for maven projects
includes - Patterns to include.
excludes - Patterns to exclude.
context - the parent context
Returns:
a {link List} of Projects
Throws:
MavenException - when anything goes wrong.

getJellyProject

public static Project getJellyProject(Project project)
                               throws java.lang.Exception
Take the POM and interpolate the value of the project's context to create a new version of the POM with expanded context values.

Parameters:
project - the maven POM
Returns:
Jelly interpolated project.
Throws:
java.lang.Exception - when there are errors reading FIXME

getFiles

public static java.lang.String[] getFiles(java.io.File directory,
                                          java.lang.String includes)
Get a set of files from a specifed directory with a set of includes.

Parameters:
directory - Directory to scan.
includes - Comma separated list of includes.
Returns:
files

getFiles

public static java.lang.String[] getFiles(java.io.File directory,
                                          java.lang.String includes,
                                          java.lang.String excludes)
Get a set of files from a specifed directory with a set of includes.

Parameters:
directory - Directory to scan.
includes - Comma separated list of includes.
excludes - Comma separated list of excludes.
Returns:
files

mergeMaps

public static java.util.Map mergeMaps(java.util.Map dominantMap,
                                      java.util.Map recessiveMap)
Take a dominant and recessive Map and merge the key:value pairs where the recessive Map may add key:value pairs to the dominant Map but may not override any existing key:value pairs. If we have two Maps, a dominant and recessive, and their respective keys are as follows: dominantMapKeys = { a, b, c, d, e, f } recessiveMapKeys = { a, b, c, x, y, z } Then the result should be the following: resultantKeys = { a, b, c, d, e, f, x, y, z }

Parameters:
dominantMap - Dominant Map.
recessiveMap - Recessive Map.
Returns:
The result map with combined dominant and recessive values.

mergeMaps

public static java.util.Map mergeMaps(java.util.Map[] maps)
Take a series of Maps and merge them where the ordering of the array from 0..n is the dominant order.

Parameters:
maps - An array of Maps to merge.
Returns:
Map The result Map produced after the merging process.

createContext

public static MavenJellyContext createContext(java.io.File descriptorDirectory)
Create a jelly context given a descriptor directory.

Parameters:
descriptorDirectory - The directory from which to pull the standard maven properties files from.
Returns:
The generated maven based on the contents of the standard maven properties files.

createContext

public static MavenJellyContext createContext(java.io.File descriptorDirectory,
                                              MavenJellyContext parentContext)
Create a jelly context given a descriptor directory and parent jelly context.

Parameters:
descriptorDirectory - The directory from which to pull the standard maven properties files from.
parentContext - The parent jelly context.
Returns:
The generated maven based on the contents of the standard maven properties files.
To Do:
should premerge driver, etc if they are being kept

integrateMapInContext

public static void integrateMapInContext(java.util.Map map,
                                         MavenJellyContext context)
Integrate a Map of key:value pairs into a MavenJellyContext. The values in the Map may be CompositeExpressions that need to be evaluated before being placed into the context.

Parameters:
map - Map to integrate into the provided jelly context.
context - Jelly context to integrate the map into.

getMessage

public static java.lang.String getMessage(java.lang.String messageId)
Retrieve a user message.

Parameters:
messageId - Id of message type to use.
Returns:
Message for the user's locale.

getMessage

public static java.lang.String getMessage(java.lang.String messageId,
                                          java.lang.Object variable)
Retrieve a user message.

Parameters:
messageId - Id of message type to use.
variable - Value to substitute for ${1} in the given message.
Returns:
Message for the user's locale.

makeAbsolutePath

public static java.lang.String makeAbsolutePath(java.io.File basedir,
                                                java.lang.String dir)
                                         throws java.io.IOException
Resolve directory against a base directory if it is not already absolute.

Parameters:
basedir - the base directory for relative paths
dir - the directory to resolve
Returns:
the canonical path of the directory if not absolute
Throws:
java.io.IOException - if canonical path fails

makeRelativePath

public static java.lang.String makeRelativePath(java.io.File basedir,
                                                java.lang.String path)
                                         throws java.io.IOException
Convert an absolute path to a relative path if it is under a given base directory.

Parameters:
basedir - the base directory for relative paths
path - the directory to resolve
Returns:
the relative path
Throws:
java.io.IOException - if canonical path fails

getGoalListFromCsv

public static java.util.List getGoalListFromCsv(java.lang.String goalCsv)
Get a list of goals from a CSV list.

Parameters:
goalCsv - the goals
Returns:
the list of goal names

displayClassLoaderContents

public static void displayClassLoaderContents(com.werken.forehead.ForeheadClassLoader classLoader)
Debugging function.

Parameters:
classLoader - the class loader


Copyright © 2001-2008 Apache Software Foundation. All Rights Reserved.