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.

Version:
$Id: MavenUtils.java,v 1.107.4.23 2004/07/19 13:48:58 vmassol Exp $
Author:
Jason van Zyl, Brett Porter

Constructor Summary
MavenUtils()
           
 
Method Summary
static org.apache.commons.betwixt.io.BeanReader createBeanReader(java.lang.Class clazz)
          Creates a new instance of BeanReader
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 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 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.io.InputStream getProjectInputStream(Project project)
           
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 org.apache.commons.betwixt.XMLIntrospector getXMLIntrospector()
          If caching is enabled then this method will return a pooled introspector
static org.xml.sax.XMLReader getXMLReader()
          Get the XMLReader to use for processing XML related resources.
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
 

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

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. FIXME this is bad

getProjectInputStream

public static java.io.InputStream getProjectInputStream(Project project)
                                                 throws MavenException
Parameters:
project - a maven project
Returns:
an InputStream for the given project
Throws:
MavenException - when reading the project

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

createBeanReader

public static org.apache.commons.betwixt.io.BeanReader createBeanReader(java.lang.Class clazz)
                                                                 throws java.beans.IntrospectionException,
                                                                        org.xml.sax.SAXException,
                                                                        javax.xml.parsers.ParserConfigurationException
Creates a new instance of BeanReader

Parameters:
clazz - the class to register with the reader
Returns:
a bean reader
Throws:
java.beans.IntrospectionException - when there are errors registering the provided class
org.xml.sax.SAXException - when there are errors getting an XML reader
javax.xml.parsers.ParserConfigurationException - when there are errors getting an XML reader

getXMLIntrospector

public static org.apache.commons.betwixt.XMLIntrospector getXMLIntrospector()
If caching is enabled then this method will return a pooled introspector

Returns:
XMLIntrospector used for processing the MavenSession xml-based POM.

getXMLReader

public static org.xml.sax.XMLReader getXMLReader()
                                          throws org.xml.sax.SAXException,
                                                 javax.xml.parsers.ParserConfigurationException
Get the XMLReader to use for processing XML related resources.

Returns:
an XMLReader which is pooled per thread
Throws:
org.xml.sax.SAXException - when the reader can't be created
javax.xml.parsers.ParserConfigurationException - when the reader can't be created

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.

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-2005 Apache Software Foundation. All Rights Reserved.