Package org.jboss.modules.maven

# Class MavenArtifactUtil

java.lang.Object
org.jboss.modules.maven.MavenArtifactUtil

public final class MavenArtifactUtil extends Object
Helper class to resolve a maven artifact.

Author:
  Bill Burke, Tomaz Cerar, David M. Lloyd

## Constructor Summary

Constructors
Constructor
Description
`MavenArtifactUtil()`

## Method Summary

Modifier and Type
Method
Description
`static ResourceLoader`
`createMavenArtifactLoader(String name)`
A utility method to create a Maven artifact resource loader for the given artifact name.
`static ResourceLoader`
`createMavenArtifactLoader(MavenResolver mavenResolver, String name)`
A utility method to create a Maven artifact resource loader for the given artifact name.
`static ResourceLoader`
`createMavenArtifactLoader(MavenResolver mavenResolver, ArtifactCoordinates coordinates, String rootName)`
A utility method to create a Maven artifact resource loader for the given artifact coordinates.
`static File`
`resolveArtifact(ArtifactCoordinates coordinates, String packaging)`
Tries to find a maven jar artifact from the system property `"maven.repo.local"` This property is a list of platform separated directory names.
`static File`
`resolveJarArtifact(ArtifactCoordinates coordinates)`
Try to resolve a Maven JAR artifact.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### MavenArtifactUtil

public MavenArtifactUtil()

## Method Details

### resolveJarArtifact

public static File resolveJarArtifact(ArtifactCoordinates coordinates) throws IOException
Try to resolve a Maven JAR artifact. Calling this method is identical to calling `resolveJarArtifact(qualifier, "jar")`.

Parameters:
  `coordinates` - the non-`null` Maven coordinates object
Returns:
  the absolute path to the artifact, or `null` if none exists
Throws:
  `IOException` - if acquiring the artifact path failed for some reason

### resolveArtifact

public static File resolveArtifact(ArtifactCoordinates coordinates, String packaging) throws IOException
Tries to find a maven jar artifact from the system property `"maven.repo.local"` This property is a list of platform separated directory names. If not specified, then it looks in `${user.home}/.m2/repository` by default.

If it can't find it in local paths, then will try to download from a remote repository from the system property `"remote.maven.repo"`. There is no default remote repository. It will download both the pom and jar and put it into the first directory listed in `"maven.repo.local"` (or the default directory). This directory will be created if it doesn't exist.

Finally, if you do not want a message to console, then set the system property `"maven.download.message"` to `"false"`.

Parameters:
  `coordinates` - the non-`null` Maven coordinates object
  `packaging` - a non-`null` string with the exact packaging type desired (e.g. `pom`, `jar`, etc.)
Returns:
  the absolute path to the artifact, or `null` if none exists
Throws:
  `IOException` - if acquiring the artifact path failed for some reason

### createMavenArtifactLoader

public static ResourceLoader createMavenArtifactLoader(String name) throws IOException
A utility method to create a Maven artifact resource loader for the given artifact name.

Parameters:
  `name` - the artifact name
Returns:
  the resource loader
Throws:
  `IOException` - if the artifact could not be resolved

### createMavenArtifactLoader

public static ResourceLoader createMavenArtifactLoader(MavenResolver mavenResolver, String name) throws IOException
A utility method to create a Maven artifact resource loader for the given artifact name.

Parameters:
  `mavenResolver` - the Maven resolver to use (must not be `null`)
  `name` - the artifact name
Returns:
  the resource loader
Throws:
  `IOException` - if the artifact could not be resolved

### createMavenArtifactLoader

public static ResourceLoader createMavenArtifactLoader(MavenResolver mavenResolver, ArtifactCoordinates coordinates, String rootName) throws IOException
A utility method to create a Maven artifact resource loader for the given artifact coordinates.

Parameters:
  `mavenResolver` - the Maven resolver to use (must not be `null`)
  `coordinates` - the artifact coordinates to use (must not be `null`)
  `rootName` - the resource root name to use (must not be `null`)
Returns:
  the resource loader
Throws:
  `IOException` - if the artifact could not be resolved