eu.lindenbaum.maven.util
Class MavenUtils

java.lang.Object
  extended by eu.lindenbaum.maven.util.MavenUtils

public final class MavenUtils
extends Object

Containing utilities related to maven plugins/projects.

Author:
Tobias Schlager , Olle Törnström

Nested Class Summary
static class MavenUtils.LogLevel
          Corresponds to the log levels of Log.
 
Field Summary
static String FAT_SEPARATOR
           
static String SEPARATOR
           
 
Constructor Summary
MavenUtils()
           
 
Method Summary
static org.apache.maven.artifact.versioning.VersionRange createVersionRange(String versionSpec)
          Returns a VersionRange from a given string specification.
static org.apache.maven.artifact.Artifact getArtifact(org.apache.maven.artifact.Artifact from, String version, MavenComponents components)
          Returns an Artifact object of a specific Artifact with a specific version.
static String getArtifactDirectory(org.apache.maven.artifact.Artifact artifact)
          Returns the directory name for the given Artifact.
static File getArtifactFile(org.apache.maven.artifact.Artifact artifact, MavenComponents components)
          Returns an (existing) file pointing to an Artifact of an ArtifactRepository.
static Set<String> getArtifactIds(Collection<org.apache.maven.artifact.Artifact> artifacts)
          Converts a Collection of Artifacts into a Set containing their artifactIds.
static Set<org.apache.maven.artifact.Artifact> getArtifacts(org.apache.maven.project.MavenProject project)
          Returns the transitive dependency artifacts of a project using MavenProject.getArtifacts().
static Set<org.apache.maven.artifact.versioning.ArtifactVersion> getAvailableVersions(org.apache.maven.artifact.Artifact artifact, MavenComponents components)
          Returns a Set of available versions for an artifact in the given repositories.
static Set<org.apache.maven.artifact.Artifact> getDependencies(org.apache.maven.project.MavenProject project)
          Returns the direct dependency artifacts of a project using MavenProject.getDependencyArtifacts().
static Set<org.apache.maven.artifact.Artifact> getErlangArtifacts(org.apache.maven.project.MavenProject project)
          Returns the transitive erlang artifacts of a project using MavenProject.getArtifacts() filtered for PackagingType.ERLANG_OTP and PackagingType.ERLANG_STD packaged projects.
static Set<org.apache.maven.artifact.Artifact> getErlangDependencies(org.apache.maven.project.MavenProject project)
          Returns the direct erlang dependencies of a project using MavenProject.getDependencyArtifacts() filtered for PackagingType.ERLANG_OTP and PackagingType.ERLANG_STD packaged projects.
static Set<org.apache.maven.artifact.Artifact> getErlangDependenciesToPackage(org.apache.maven.project.MavenProject project)
          Returns the direct erlang dependencies of a project using MavenProject.getDependencyArtifacts() filtered for PackagingType.ERLANG_OTP and PackagingType.ERLANG_STD packaged projects.
static Set<org.apache.maven.artifact.Artifact> getErlangReleaseArtifacts(org.apache.maven.project.MavenProject project)
          Returns the transitive erlang artifacts of a project using MavenProject.getArtifacts() filtered for PackagingType.ERLANG_OTP and PackagingType.ERLANG_STD packaged projects.
static Set<org.apache.maven.artifact.Artifact> getForeignDependencies(org.apache.maven.project.MavenProject project)
          Returns the direct non-erlang dependencies of a project using MavenProject.getDependencyArtifacts().
static Set<org.apache.maven.artifact.Artifact> getForeignDependenciesToPackage(org.apache.maven.project.MavenProject project)
          Returns the direct non-erlang dependencies of a project using MavenProject.getDependencyArtifacts().
static Map<String,String> getProjectReplacements(org.apache.maven.project.MavenProject project, String artifactQuote, String commonQuote)
          Returns a mapping of string replacements for project related values: "${ARTIFACT}" -> the projects artifact id "${DESCRIPTION}" -> the projects description string "${ID}" -> the project id "${NAME}" -> the projects name "${VERSION}" -> the projects version
static String getReleaseName(org.apache.maven.project.MavenProject project)
          Returns the release name for the given MavenProject.
static
<T> void
logCollection(org.apache.maven.plugin.logging.Log log, MavenUtils.LogLevel level, Collection<T> collection, String linePrefix)
          Logs the content of the given Collection using a specific logger.
static void logContent(org.apache.maven.plugin.logging.Log log, MavenUtils.LogLevel level, File file, String linePrefix)
          Logs the absolute path of a file along with its content using a specific logger.
static void logMultiLineString(org.apache.maven.plugin.logging.Log log, MavenUtils.LogLevel level, String multiLineString)
          Logs a multi line string containing either unix or windows style line breaks using a specific logger.
static void logMultiLineString(org.apache.maven.plugin.logging.Log log, MavenUtils.LogLevel level, String multiLineString, String linePrefix)
          Logs a multi line string containing either unix or windows style line breaks using a specific logger.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SEPARATOR

public static String SEPARATOR

FAT_SEPARATOR

public static String FAT_SEPARATOR
Constructor Detail

MavenUtils

public MavenUtils()
Method Detail

getAvailableVersions

public static Set<org.apache.maven.artifact.versioning.ArtifactVersion> getAvailableVersions(org.apache.maven.artifact.Artifact artifact,
                                                                                             MavenComponents components)
                                                                                      throws org.apache.maven.plugin.MojoExecutionException
Returns a Set of available versions for an artifact in the given repositories.

Parameters:
artifact - to lookup in the repository
components - a bean holding maven specific components
Returns:
a non-null Set of ArtifactVersions
Throws:
org.apache.maven.plugin.MojoExecutionException

getArtifactFile

public static File getArtifactFile(org.apache.maven.artifact.Artifact artifact,
                                   MavenComponents components)
                            throws org.apache.maven.plugin.MojoExecutionException
Returns an (existing) file pointing to an Artifact of an ArtifactRepository. The artifact will first be resolved.

Parameters:
artifact - to lookup in the repository
components - a bean holding maven specific components
Returns:
an existing file pointing to an artifact
Throws:
org.apache.maven.plugin.MojoExecutionException

getArtifact

public static org.apache.maven.artifact.Artifact getArtifact(org.apache.maven.artifact.Artifact from,
                                                             String version,
                                                             MavenComponents components)
Returns an Artifact object of a specific Artifact with a specific version.

Parameters:
from - to clone
version - of the returned artifact
components - a bean holding maven specific components
Returns:
a new Artifact with the requested version

createVersionRange

public static org.apache.maven.artifact.versioning.VersionRange createVersionRange(String versionSpec)
                                                                            throws org.apache.maven.plugin.MojoExecutionException
Returns a VersionRange from a given string specification.

Parameters:
versionSpec - to create a VersionRange from
Returns:
a version range object
Throws:
org.apache.maven.plugin.MojoExecutionException - if specification is invalid

getArtifactIds

public static Set<String> getArtifactIds(Collection<org.apache.maven.artifact.Artifact> artifacts)
Converts a Collection of Artifacts into a Set containing their artifactIds.

Parameters:
artifacts - to get the artifactIds from
Returns:
a non-null Set object containing artifactIds.

getArtifactDirectory

public static String getArtifactDirectory(org.apache.maven.artifact.Artifact artifact)
Returns the directory name for the given Artifact. This is used by the DependencyExtractor to construct dependency directory names.


getReleaseName

public static String getReleaseName(org.apache.maven.project.MavenProject project)
Returns the release name for the given MavenProject. The release name consists of the project artifacts id and its version.

Parameters:
project - to retrieve the release name from
Returns:
a string containing the release name

getErlangReleaseArtifacts

public static Set<org.apache.maven.artifact.Artifact> getErlangReleaseArtifacts(org.apache.maven.project.MavenProject project)
Returns the transitive erlang artifacts of a project using MavenProject.getArtifacts() filtered for PackagingType.ERLANG_OTP and PackagingType.ERLANG_STD packaged projects. This will return all Artifact with scopes other than test and provided.

Parameters:
project - to get the dependencies for
Returns:
a non-null Set of dependency artifacts

getErlangDependenciesToPackage

public static Set<org.apache.maven.artifact.Artifact> getErlangDependenciesToPackage(org.apache.maven.project.MavenProject project)
Returns the direct erlang dependencies of a project using MavenProject.getDependencyArtifacts() filtered for PackagingType.ERLANG_OTP and PackagingType.ERLANG_STD packaged projects. This will return all Artifact with scopes other than test and provided.

Parameters:
project - to get the dependencies for
Returns:
a non-null Set of dependency artifacts

getErlangArtifacts

public static Set<org.apache.maven.artifact.Artifact> getErlangArtifacts(org.apache.maven.project.MavenProject project)
Returns the transitive erlang artifacts of a project using MavenProject.getArtifacts() filtered for PackagingType.ERLANG_OTP and PackagingType.ERLANG_STD packaged projects.

Parameters:
project - to get the dependencies for
Returns:
a non-null Set of dependency artifacts

getErlangDependencies

public static Set<org.apache.maven.artifact.Artifact> getErlangDependencies(org.apache.maven.project.MavenProject project)
Returns the direct erlang dependencies of a project using MavenProject.getDependencyArtifacts() filtered for PackagingType.ERLANG_OTP and PackagingType.ERLANG_STD packaged projects.

Parameters:
project - to get the dependencies for
Returns:
a non-null Set of dependency artifacts

getForeignDependenciesToPackage

public static Set<org.apache.maven.artifact.Artifact> getForeignDependenciesToPackage(org.apache.maven.project.MavenProject project)
Returns the direct non-erlang dependencies of a project using MavenProject.getDependencyArtifacts(). All erlang artifacts will be filtered out. This will return all Artifacts with scopes other than test and provided.

Parameters:
project - to get the dependencies for
Returns:
a non-null Set of dependency artifacts

getForeignDependencies

public static Set<org.apache.maven.artifact.Artifact> getForeignDependencies(org.apache.maven.project.MavenProject project)
Returns the direct non-erlang dependencies of a project using MavenProject.getDependencyArtifacts(). All erlang artifacts will be filtered out.

Parameters:
project - to get the dependencies for
Returns:
a non-null Set of dependency artifacts

getDependencies

public static Set<org.apache.maven.artifact.Artifact> getDependencies(org.apache.maven.project.MavenProject project)
Returns the direct dependency artifacts of a project using MavenProject.getDependencyArtifacts().

Parameters:
project - to get the dependencies for
Returns:
a non-null Set of dependency artifacts

getArtifacts

public static Set<org.apache.maven.artifact.Artifact> getArtifacts(org.apache.maven.project.MavenProject project)
Returns the transitive dependency artifacts of a project using MavenProject.getArtifacts().

Parameters:
project - to get the dependencies for
Returns:
a non-null Set of dependency artifacts

getProjectReplacements

public static Map<String,String> getProjectReplacements(org.apache.maven.project.MavenProject project,
                                                        String artifactQuote,
                                                        String commonQuote)
Returns a mapping of string replacements for project related values:

Parameters:
project - the project object to retrieve values from
artifactQuote - the quote character used for the ${ARTIFACT} mapping
commonQuote - the quote character used all other mappings
Returns:
a non-null Map of string mappings

logContent

public static void logContent(org.apache.maven.plugin.logging.Log log,
                              MavenUtils.LogLevel level,
                              File file,
                              String linePrefix)
Logs the absolute path of a file along with its content using a specific logger.

Parameters:
log - logger to use
level - priority to log the file
file - to read the content from
linePrefix - prefix prepended to each line

logMultiLineString

public static void logMultiLineString(org.apache.maven.plugin.logging.Log log,
                                      MavenUtils.LogLevel level,
                                      String multiLineString)
Logs a multi line string containing either unix or windows style line breaks using a specific logger.

Parameters:
log - logger to use.
level - priority to log the message
multiLineString - to log

logMultiLineString

public static void logMultiLineString(org.apache.maven.plugin.logging.Log log,
                                      MavenUtils.LogLevel level,
                                      String multiLineString,
                                      String linePrefix)
Logs a multi line string containing either unix or windows style line breaks using a specific logger.

Parameters:
log - logger to use.
level - priority to log the message
multiLineString - to log
linePrefix - prefix prepended to each line

logCollection

public static <T> void logCollection(org.apache.maven.plugin.logging.Log log,
                                     MavenUtils.LogLevel level,
                                     Collection<T> collection,
                                     String linePrefix)
Logs the content of the given Collection using a specific logger. Each entry is placed in its own line.

Parameters:
log - logger to use
level - priority to log the file
collection - to print
linePrefix - prefix prepended to each line


Copyright © 2012 Lindenbaum GmbH. All Rights Reserved.