Top Description Fields Constructors Methods
org.jboss.modules.maven

public final Class MavenArtifactUtil

extends Object
Class Inheritance
Imports
java.io.File, .IOException, .InputStream, java.lang.reflect.UndeclaredThrowableException, java.net.HttpURLConnection, .URL, java.nio.file.Files, .Path, .StandardCopyOption, java.security.AccessControlContext, .AccessController, .PrivilegedActionException, .PrivilegedExceptionAction, java.util.List, java.util.jar.JarFile, org.jboss.modules.Module, .ResourceLoader, .ResourceLoaders

Helper class to resolve a maven artifact.
Authors
Bill Burke, Tomaz Cerar, David M. Lloyd

Field Summary

Modifier and TypeField and Description
pack-priv static final Object

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static ResourceLoader

Returns:

the resource loader
createMavenArtifactLoader
(final String
the artifact name
name
)

A utility method to create a Maven artifact resource loader for the given artifact name.

public static ResourceLoader

Returns:

the resource loader
createMavenArtifactLoader
(final MavenResolver
the Maven resolver to use (must not be null)
mavenResolver
,
final String
the artifact name
name
)

A utility method to create a Maven artifact resource loader for the given artifact name.

public static ResourceLoader

Returns:

the resource loader
createMavenArtifactLoader
(final MavenResolver
the Maven resolver to use (must not be null)
mavenResolver
,
final ArtifactCoordinates
the artifact coordinates to use (must not be null)
coordinates
,
final String
the resource root name to use (must not be null)
rootName
)

A utility method to create a Maven artifact resource loader for the given artifact coordinates.

pack-priv static <T> T
pack-priv static <T> T
doIo(PrivilegedExceptionAction<T> action, AccessControlContext context)

Deprecated as a consequence of AccessControlContext being deprecated.
pack-priv static void
downloadFile(String artifact, String src, File dest)

public static File

Returns:

the absolute path to the artifact, or null if none exists
resolveArtifact
(final ArtifactCoordinates
the non-null Maven coordinates object
coordinates
,
final String
a non-null string with the exact packaging type desired (e.g. pom, jar, etc.)
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.

public static File

Returns:

the absolute path to the artifact, or null if none exists
resolveJarArtifact
(final ArtifactCoordinates
the non-null Maven coordinates object
coordinates
)

Try to resolve a Maven JAR artifact.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

artifactLockback to summary
pack-priv static final Object artifactLock

Constructor Detail

MavenArtifactUtilback to summary
public MavenArtifactUtil()

Method Detail

createMavenArtifactLoaderback to summary
public static ResourceLoader createMavenArtifactLoader(final String name) throws IOException

A utility method to create a Maven artifact resource loader for the given artifact name.

Parameters
name:String

the artifact name

Returns:ResourceLoader

the resource loader

Exceptions
IOException:
if the artifact could not be resolved
createMavenArtifactLoaderback to summary
public static ResourceLoader createMavenArtifactLoader(final MavenResolver mavenResolver, final String name) throws IOException

A utility method to create a Maven artifact resource loader for the given artifact name.

Parameters
mavenResolver:MavenResolver

the Maven resolver to use (must not be null)

name:String

the artifact name

Returns:ResourceLoader

the resource loader

Exceptions
IOException:
if the artifact could not be resolved
createMavenArtifactLoaderback to summary
public static ResourceLoader createMavenArtifactLoader(final MavenResolver mavenResolver, final ArtifactCoordinates coordinates, final String rootName) throws IOException

A utility method to create a Maven artifact resource loader for the given artifact coordinates.

Parameters
mavenResolver:MavenResolver

the Maven resolver to use (must not be null)

coordinates:ArtifactCoordinates

the artifact coordinates to use (must not be null)

rootName:String

the resource root name to use (must not be null)

Returns:ResourceLoader

the resource loader

Exceptions
IOException:
if the artifact could not be resolved
doIoback to summary
pack-priv static <T> T doIo(PrivilegedExceptionAction<T> action) throws IOException
doIoback to summary
pack-priv static <T> T doIo(PrivilegedExceptionAction<T> action, AccessControlContext context) throws IOException

Deprecated

as a consequence of AccessControlContext being deprecated. See corresponding docs for further information.

downloadFileback to summary
pack-priv static void downloadFile(String artifact, String src, File dest) throws IOException
resolveArtifactback to summary
public static File resolveArtifact(final ArtifactCoordinates coordinates, final 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:ArtifactCoordinates

the non-null Maven coordinates object

packaging:String

a non-null string with the exact packaging type desired (e.g. pom, jar, etc.)

Returns:File

the absolute path to the artifact, or null if none exists

Exceptions
IOException:
if acquiring the artifact path failed for some reason
resolveJarArtifactback to summary
public static File resolveJarArtifact(final ArtifactCoordinates coordinates) throws IOException

Try to resolve a Maven JAR artifact. Calling this method is identical to calling resolveJarArtifact(qualifier, "jar").

Parameters
coordinates:ArtifactCoordinates

the non-null Maven coordinates object

Returns:File

the absolute path to the artifact, or null if none exists

Exceptions
IOException:
if acquiring the artifact path failed for some reason