Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.modeshape.maven
Class MavenRepository

    java.lang.Object
      org.modeshape.maven.MavenRepository

All Implemented Interfaces:
  ClassLoaderFactory

    public class MavenRepository

extends Object
implements ClassLoaderFactory

A Maven 2 repository that can be used to store and access artifacts like JARs and source archives within a running application. This class understands Maven 2 Project Object Model (POM) files, and thus is able to analyze dependencies and provide a `class loader` that accesses libraries using these transitive dependencies.

Instances are initialized with an authenticated `Maven URL provider`, which is typically a `JcrMavenUrlProvider` instance configured with a `JCR Repository` and path to the root of the repository subtree in that workspace. The repository can either already exist and contain the required artifacts, or it will be created as artifacts are loaded. Then to use libraries that are in the repository, simply obtain the `class loader` by specifying the `artifact identifiers` for the libraries used directly by your code. This class loader will add any libraries that are required by those you supply.

Constructor Summary
`MavenRepository(MavenUrlProvider urlProvider)`

Method Summary
`boolean` | `exists(MavenId mavenId)` Determine whether the identified library exists in this Maven repository.
`Set<MavenId>` | `exists(MavenId firstId, MavenId... mavenIds)` Determine which of the identified libraries exist in this Maven repository.
`ClassLoader` | `getClassLoader(ClassLoader parent, MavenId... mavenIds)` Get a class loader that has as its classpath the JARs for the libraries identified by the supplied IDs.
`ClassLoader` | `getClassLoader(ClassLoader parent, String... coordinates)` Get a class loader that has as its classpath the JARs for the libraries identified by the supplied IDs.
`ClassLoader` | `getClassLoader(String... coordinates)` Get a class loader that has as its classpath the JARs for the libraries identified by the supplied IDs.
`List<MavenDependency>` | `getDependencies(MavenId mavenId)` Get the dependencies for the Maven project with the specified ID.
`protected List<MavenDependency>` | `getDependencies(MavenId mavenId, InputStream pomStream, MavenDependency.Scope... allowedScopes)` Get the dependencies for the Maven project with the specified ID.
`URL` | `getUrl(MavenId mavenId, ArtifactType artifactType, SignatureType signatureType)` Get the URL for the artifact with the specified type in the given Maven project.
`URL` | `getUrl(MavenId mavenId, ArtifactType artifactType, SignatureType signatureType, boolean createIfRequired)` Get the URL for the artifact with the specified type in the given Maven project.
`protected void` | `notifyUpdatedPom(MavenId mavenId)` This method is called to signal this repository that the POM file for a project has been updated.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### MavenRepository

    public MavenRepository(MavenUrlProvider urlProvider)

Method Detail

### getClassLoader

    public ClassLoader getClassLoader(ClassLoader parent,
                                      MavenId... mavenIds)

  Get a class loader that has as its classpath the JARs for the libraries identified by the supplied IDs. This method always returns a class loader, even when none of the specified libraries `exist` in this repository.

  Parameters:
    `parent` - the parent class loader that will be consulted before any project class loaders; may be null if the `current thread's context class loader` or the class loader that loaded this class should be used
    `mavenIds` - the IDs of the libraries in this Maven repository
  Returns:
    the class loader
  Throws:
    `IllegalArgumentException` - if no Maven IDs are passed in or if any of the IDs are null
  See Also:
    `exists(MavenId)`, `exists(MavenId,MavenId...)`

### getClassLoader

    public ClassLoader getClassLoader(String... coordinates)

  Get a class loader that has as its classpath the JARs for the libraries identified by the supplied IDs. This method always returns a class loader, even when none of the specified libraries `exist` in this repository.

  Specified by:
    `getClassLoader` in interface `ClassLoaderFactory`
  Parameters:
    `coordinates` - the IDs of the libraries in this Maven repository
  Returns:
    the class loader
  Throws:
    `IllegalArgumentException` - if no coordinates are passed in or if any of the coordinate references is null

### getClassLoader

    public ClassLoader getClassLoader(ClassLoader parent,
                                      String... coordinates)

  Get a class loader that has as its classpath the JARs for the libraries identified by the supplied IDs. This method always returns a class loader, even when none of the specified libraries `exist` in this repository.

  Parameters:
    `parent` - the parent class loader that will be consulted before any project class loaders; may be null if the `current thread's context class loader` or the class loader that loaded this class should be used
    `coordinates` - the IDs of the libraries in this Maven repository
  Returns:
    the class loader
  Throws:
    `IllegalArgumentException` - if no coordinates are passed in or if any of the coordinate references is null

### exists

    public boolean exists(MavenId mavenId)
                   throws MavenRepositoryException

  Determine whether the identified library exists in this Maven repository.

  Parameters:
    `mavenId` - the ID of the library
  Returns:
    true if this repository contains the library, or false if it does not exist (or the ID is null)
  Throws:
    `MavenRepositoryException` - if there is a problem connecting to or using the Maven repository, as configured
  See Also:
    `exists(MavenId,MavenId...)`

### exists

    public Set<MavenId> exists(MavenId firstId,
                               MavenId... mavenIds)
                        throws MavenRepositoryException

  Determine which of the identified libraries exist in this Maven repository.

  Parameters:
    `firstId` - the first ID of the library to check
    `mavenIds` - the IDs of the libraries; any null IDs will be ignored
  Returns:
    the set of IDs for libraries that do exist in this repository; never null
  Throws:
    `MavenRepositoryException` - if there is a problem connecting to or using the Maven repository, as configured
  See Also:
    `exists(MavenId)`

### getDependencies

    public List<MavenDependency> getDependencies(MavenId mavenId)

  Get the dependencies for the Maven project with the specified ID.

  This implementation downloads the POM file for the specified project to extract the dependencies and exclusions.

  Parameters:
    `mavenId` - the ID of the project; may not be null
  Returns:
    the list of dependencies
  Throws:
    `IllegalArgumentException` - if the MavenId reference is null
    `MavenRepositoryException` - if there is a problem finding or reading the POM file given the MavenId

### getDependencies

    protected List<MavenDependency> getDependencies(MavenId mavenId,
                                                    InputStream pomStream,
                                                    MavenDependency.Scope... allowedScopes)
                                             throws IOException

  Get the dependencies for the Maven project with the specified ID.

  This implementation downloads the POM file for the specified project to extract the dependencies and exclusions.

  Parameters:
    `mavenId` - the ID of the Maven project for which the dependencies are to be obtained
    `pomStream` - the stream to the POM file
    `allowedScopes` - the set of scopes that are to be allowed in the dependency list; if null, the default scopes of `MavenDependency.Scope.getRuntimeScopes()` are used
  Returns:
    the list of dependencies; never null
  Throws:
    `IllegalArgumentException` - if the MavenId or InputStream references are null
    `IOException` - if an error occurs reading the stream
    `MavenRepositoryException` - if there is a problem reading the POM file given the supplied stream and MavenId

### getUrl

    public URL getUrl(MavenId mavenId,
                      ArtifactType artifactType,
                      SignatureType signatureType)
               throws MalformedURLException

  Get the URL for the artifact with the specified type in the given Maven project. The resulting URL can be used to `connect` to the repository to `read` or `write` the artifact's content.

  Parameters:
    `mavenId` - the ID of the Maven project; may not be null
    `artifactType` - the type of artifact; may be null, but the URL will not be able to be read or written to
    `signatureType` - the type of signature; may be null if the signature file is not desired
  Returns:
    the URL to this artifact; never null
  Throws:
    `MalformedURLException` - if the supplied information cannot be turned into a valid URL

### getUrl

    public URL getUrl(MavenId mavenId,
                      ArtifactType artifactType,
                      SignatureType signatureType,
                      boolean createIfRequired)
               throws MalformedURLException

  Get the URL for the artifact with the specified type in the given Maven project. The resulting URL can be used to `connect` to the repository to `read` or `write` the artifact's content.

  Parameters:
    `mavenId` - the ID of the Maven project; may not be null
    `artifactType` - the type of artifact; may be null, but the URL will not be able to be read or written to
    `signatureType` - the type of signature; may be null if the signature file is not desired
    `createIfRequired` - true if the node structure should be created if any part of it does not exist; this always expects that the path to the top of the repository tree exists.
  Returns:
    the URL to this artifact; never null
  Throws:
    `MalformedURLException` - if the supplied information cannot be turned into a valid URL

### notifyUpdatedPom

    protected void notifyUpdatedPom(MavenId mavenId)

  This method is called to signal this repository that the POM file for a project has been updated. This method notifies the associated class loader of the change, which will adapt appropriately.

  Parameters:
    `mavenId` -

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2008-2012 JBoss, a division of Red Hat. All Rights Reserved.