ShrinkWrap Resolver Aggregator 1.1.0-alpha-2

org.jboss.shrinkwrap.resolver.impl.maven
Class MavenBuilderImpl

java.lang.Object
  extended by org.jboss.shrinkwrap.resolver.impl.maven.MavenBuilderImpl

public class MavenBuilderImpl
extends Object

A default implementation of dependency builder based on Maven. Apart from contract, it allows to load Maven settings from an XML file, configure remote repositories from an POM file and retrieve dependencies defined in a POM file, including ones in POM parents. Maven can be configured externally, using following properties:

Author:
Karel Piwko, Jose Rodolfo freitas
See Also:
MavenSettingsBuilder

Constructor Summary
MavenBuilderImpl()
          Constructs new instance of MavenDependencies
MavenBuilderImpl(MavenRepositorySystem system, org.sonatype.aether.RepositorySystemSession session, org.jboss.shrinkwrap.resolver.impl.maven.MavenDependencyResolverSettings settings, Stack<MavenDependency> dependencies, Set<MavenDependency> dependencyManagement)
           
 
Method Summary
 MavenDependencyResolver artifact(String coordinates)
          Creates an artifact builder.
 MavenDependencyResolver artifacts(String... coordinates)
          Creates an artifact builder.
 MavenDependencyResolver configureFrom(String path)
          Configures Maven from a settings.xml file
 MavenDependencyResolver exclusion(String coordinates)
          Adds an exclusion for current dependency.
 MavenDependencyResolver exclusions(Collection<String> coordinates)
          Adds multiple exclusions for current dependency
 MavenDependencyResolver exclusions(String... coordinates)
          Adds multiple exclusions for current dependency
 Stack<MavenDependency> getDependencies()
          Gets all the dependencies marked by Resolver to be resolved
 Set<MavenDependency> getVersionManagement()
          Gets all the dependencies retrieved from metadata parsing.
 MavenDependencyResolver goOffline()
          Disables touching remote repositories at all, rely on local repository only
 MavenDependencyResolver includeDependenciesFromPom(String path)
          Loads dependencies from the specified path and applies the specified MavenResolutionFilter.
 MavenDependencyResolver loadDependenciesFromPom(String path)
          Deprecated. please use includeDependenciesFromPom(String) instead
 MavenDependencyResolver loadDependenciesFromPom(String path, MavenResolutionFilter filter)
          Deprecated. please use includeDependenciesFromPom(String) instead
 MavenDependencyResolver loadMetadataFromPom(String path)
          Loads remote repositories for a POM file.
 MavenDependencyResolver loadReposFromPom(String path)
          Deprecated. please use loadMetadataFromPom(String) instead
 MavenDependencyResolver optional(boolean optional)
          Sets dependency as optional.
<ARCHIVEVIEW extends org.jboss.shrinkwrap.api.Assignable>
Collection<ARCHIVEVIEW>
resolveAs(Class<ARCHIVEVIEW> archiveView)
          Resolves dependencies for dependency builder
<ARCHIVEVIEW extends org.jboss.shrinkwrap.api.Assignable>
Collection<ARCHIVEVIEW>
resolveAs(Class<ARCHIVEVIEW> archiveView, MavenResolutionFilter filter)
          Resolves dependencies for dependency builder.
 File[] resolveAsFiles()
          Resolves dependencies for dependency builder
 File[] resolveAsFiles(MavenResolutionFilter filter)
          Resolves dependencies for dependency builder.
 MavenDependencyResolver scope(String scope)
          Sets a scope of dependency
 MavenDependencyResolver useCentralRepo(boolean useCentral)
          Sets the resolver to either consider (or not) Maven Central in resolution
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MavenBuilderImpl

public MavenBuilderImpl()
Constructs new instance of MavenDependencies


MavenBuilderImpl

public MavenBuilderImpl(MavenRepositorySystem system,
                        org.sonatype.aether.RepositorySystemSession session,
                        org.jboss.shrinkwrap.resolver.impl.maven.MavenDependencyResolverSettings settings,
                        Stack<MavenDependency> dependencies,
                        Set<MavenDependency> dependencyManagement)
Method Detail

getDependencies

public Stack<MavenDependency> getDependencies()
Gets all the dependencies marked by Resolver to be resolved

Returns:
the stack which represents content of MavenDependencyResolver

getVersionManagement

public Set<MavenDependency> getVersionManagement()
Gets all the dependencies retrieved from metadata parsing.

Returns:
the set which represents content of MavenDependencyResolver version metadata

configureFrom

public MavenDependencyResolver configureFrom(String path)
Configures Maven from a settings.xml file

Parameters:
path - A path to a settings.xml configuration file
Returns:
A dependency builder with a configuration from given file

loadMetadataFromPom

public MavenDependencyResolver loadMetadataFromPom(String path)
                                            throws ResolutionException
Loads remote repositories for a POM file. If repositories are defined in the parent of the POM file and there are accessible via local file system, they are set as well. These remote repositories are used to resolve the artifacts during dependency resolution. Additionally, it loads dependencies defined in the POM file model in an internal cache, which can be later used to resolve an artifact without explicitly specifying its version.

Parameters:
path - A path to the POM file, must not be null or empty
Returns:
A dependency builder with remote repositories set according to the content of POM file.
Throws:
Exception
ResolutionException

loadReposFromPom

@Deprecated
public MavenDependencyResolver loadReposFromPom(String path)
                                         throws ResolutionException
Deprecated. please use loadMetadataFromPom(String) instead

Description copied from interface: MavenDependencyResolver
Loads remote repositories for a POM file. If repositories are defined in the parent of the POM file and there are accessible via local file system, they are set as well. These remote repositories are used to resolve the artifacts during dependency resolution. Additionally, it loads dependencies defined in the POM file model in an internal cache, which can be later used to resolve an artifact without explicitly specifying its version.

Parameters:
path - A path to the POM file, must not be null or empty
Returns:
A dependency builder with remote repositories set according to the content of POM file.
Throws:
ResolutionException

includeDependenciesFromPom

public MavenDependencyResolver includeDependenciesFromPom(String path)
                                                   throws ResolutionException
Loads dependencies from the specified path and applies the specified MavenResolutionFilter. Adds the Maven central repository by default.

Parameters:
path - path to file which contains the desired dependencies
filter - the filter to apply
Returns:
a corresponding MavenDependencyResolver
Throws:
ResolutionException - if any resolution related exceptions occur

loadDependenciesFromPom

@Deprecated
public MavenDependencyResolver loadDependenciesFromPom(String path)
                                                throws ResolutionException
Deprecated. please use includeDependenciesFromPom(String) instead

Description copied from interface: MavenDependencyResolver
Resolves based upon dependencies declared in the POM at the specified path

Returns:
Throws:
ResolutionException

loadDependenciesFromPom

@Deprecated
public MavenDependencyResolver loadDependenciesFromPom(String path,
                                                                  MavenResolutionFilter filter)
                                                throws ResolutionException
Deprecated. please use includeDependenciesFromPom(String) instead

Description copied from interface: MavenDependencyResolver
Resolves based upon dependencies declared in the POM at the specified path

Returns:
Throws:
ResolutionException

artifact

public MavenDependencyResolver artifact(String coordinates)
                                 throws ResolutionException
Description copied from interface: DependencyBuilder
Creates an artifact builder. You can define additional parameters for the artifact later. Additional parameters will be changed for all artifacts defined by this call.

Parameters:
coordinates - Coordinates specified to a created artifact, specified in an implementation-specific format.
Returns:
This DependencyBuilder
Throws:
ResolutionException - If artifact coordinates are wrong or if version cannot be determined.

artifacts

public MavenDependencyResolver artifacts(String... coordinates)
                                  throws ResolutionException
Description copied from interface: DependencyBuilder
Creates an artifact builder. You can define additional parameters for the artifacts later. Additional parameters will be changed for all artifacts defined by this call.

Parameters:
coordinates - A list of coordinates specified to the created artifacts, specified in an implementation-specific format.
Returns:
This DependencyBuilder
Throws:
ResolutionException - If artifact coordinates are wrong or if version cannot be determined.

exclusion

public MavenDependencyResolver exclusion(String coordinates)
Description copied from interface: MavenDependencyResolver
Adds an exclusion for current dependency.

Parameters:
coordinates - the exclusion to be added to list of artifacts to be excluded, specified in the format <groupId>:<artifactId>[:<extension>[:<classifier>]], an empty string or * will match all exclusions, you can pass an * instead of any part of the coordinates to match all possible values
Returns:
Artifact builder with added exclusion

exclusions

public MavenDependencyResolver exclusions(String... coordinates)
Description copied from interface: MavenDependencyResolver
Adds multiple exclusions for current dependency

Parameters:
coordinates - the exclusions to be added to the list of artifacts to be excluded, specified in the format <groupId>:<artifactId>[:<extension>[:<classifier>]], an empty string or * will match all exclusions, you can pass an * instead of any part of the coordinates to match all possible values
Returns:
Artifact builder with added exclusions

exclusions

public MavenDependencyResolver exclusions(Collection<String> coordinates)
Description copied from interface: MavenDependencyResolver
Adds multiple exclusions for current dependency

Parameters:
coordinates - the exclusions to be added to the list of artifacts to be excluded, specified in the format <groupId>:<artifactId>[:<extension>[:<classifier>]], an empty string or * will match all exclusions, you can pass an * instead of any part of the coordinates to match all possible values
Returns:
Artifact builder with added exclusions

optional

public MavenDependencyResolver optional(boolean optional)
Description copied from interface: MavenDependencyResolver
Sets dependency as optional. If dependency is marked as optional, it is always resolved, however, the dependency graph can later be filtered based on optional flag

Parameters:
optional - Optional flag
Returns:
Artifact builder with optional flag set

scope

public MavenDependencyResolver scope(String scope)
Description copied from interface: MavenDependencyResolver
Sets a scope of dependency

Parameters:
scope - A scope, for example @{code compile}, @{code test} and others
Returns:
Artifact builder with scope set

resolveAsFiles

public File[] resolveAsFiles()
                      throws ResolutionException
Description copied from interface: DependencyResolver
Resolves dependencies for dependency builder

Returns:
An array of Files which contains resolved artifacts.
Throws:
ResolutionException - If artifacts could not be resolved

resolveAsFiles

public File[] resolveAsFiles(MavenResolutionFilter filter)
                      throws ResolutionException
Description copied from interface: DependencyResolver
Resolves dependencies for dependency builder. Uses a filter to limit dependency tree

Parameters:
filter - The filter to limit the dependencies during resolution
Returns:
An array of Files which contains resolved artifacts
Throws:
ResolutionException

resolveAs

public <ARCHIVEVIEW extends org.jboss.shrinkwrap.api.Assignable> Collection<ARCHIVEVIEW> resolveAs(Class<ARCHIVEVIEW> archiveView)
                                                                              throws ResolutionException
Description copied from interface: DependencyResolver
Resolves dependencies for dependency builder

Parameters:
archiveView - End-user view of the archive requested (ie. GenericArchive or JavaArchive)
Returns:
An array of archives which contains resolved artifacts.
Throws:
ResolutionException - If artifacts could not be resolved

useCentralRepo

public MavenDependencyResolver useCentralRepo(boolean useCentral)
Sets the resolver to either consider (or not) Maven Central in resolution

Parameters:
useCentral - a flag whether to use Maven central
Returns:
See Also:
MavenDependencyResolver.useCentralRepo(boolean)

resolveAs

public <ARCHIVEVIEW extends org.jboss.shrinkwrap.api.Assignable> Collection<ARCHIVEVIEW> resolveAs(Class<ARCHIVEVIEW> archiveView,
                                                                                                   MavenResolutionFilter filter)
                                                                              throws ResolutionException
Description copied from interface: DependencyResolver
Resolves dependencies for dependency builder. Uses a filter to limit dependency tree

Parameters:
archiveView - End-user view of the archive requested (ie. GenericArchive or JavaArchive)
filter - The filter to limit the dependencies during resolution
Returns:
An array of archive which contains resolved artifacts
Throws:
ResolutionException

goOffline

public MavenDependencyResolver goOffline()
Description copied from interface: MavenDependencyResolver
Disables touching remote repositories at all, rely on local repository only

Returns:
Modified MavenDependencyResolution

ShrinkWrap Resolver Aggregator 1.1.0-alpha-2

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