本文整理汇总了Java中org.apache.maven.RepositoryUtils.toArtifacts方法的典型用法代码示例。如果您正苦于以下问题:Java RepositoryUtils.toArtifacts方法的具体用法?Java RepositoryUtils.toArtifacts怎么用?Java RepositoryUtils.toArtifacts使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.maven.RepositoryUtils
的用法示例。
在下文中一共展示了RepositoryUtils.toArtifacts方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: resolveDependencies
import org.apache.maven.RepositoryUtils; //导入方法依赖的package包/类
private DependencyResolutionResult resolveDependencies( MavenProject project, RepositorySystemSession session )
{
DependencyResolutionResult resolutionResult = null;
try
{
DefaultDependencyResolutionRequest resolution = new DefaultDependencyResolutionRequest( project, session );
resolutionResult = dependencyResolver.resolve( resolution );
}
catch ( DependencyResolutionException e )
{
resolutionResult = e.getResult();
}
Set<Artifact> artifacts = new LinkedHashSet<Artifact>();
if ( resolutionResult.getDependencyGraph() != null )
{
RepositoryUtils.toArtifacts( artifacts, resolutionResult.getDependencyGraph().getChildren(),
Collections.singletonList( project.getArtifact().getId() ), null );
// Maven 2.x quirk: an artifact always points at the local repo, regardless whether resolved or not
LocalRepositoryManager lrm = session.getLocalRepositoryManager();
for ( Artifact artifact : artifacts )
{
if ( !artifact.isResolved() )
{
String path = lrm.getPathForLocalArtifact( RepositoryUtils.toArtifact( artifact ) );
artifact.setFile( new File( lrm.getRepository().getBasedir(), path ) );
}
}
}
project.setResolvedArtifacts( artifacts );
project.setArtifacts( artifacts );
return resolutionResult;
}
示例2: getDependencies
import org.apache.maven.RepositoryUtils; //导入方法依赖的package包/类
private Set<Artifact> getDependencies( MavenProject project, Collection<String> scopesToCollect,
Collection<String> scopesToResolve, MavenSession session,
boolean aggregating, Set<Artifact> projectArtifacts )
throws LifecycleExecutionException
{
if ( scopesToCollect == null )
{
scopesToCollect = Collections.emptySet();
}
if ( scopesToResolve == null )
{
scopesToResolve = Collections.emptySet();
}
if ( scopesToCollect.isEmpty() && scopesToResolve.isEmpty() )
{
return new LinkedHashSet<Artifact>();
}
scopesToCollect = new HashSet<String>( scopesToCollect );
scopesToCollect.addAll( scopesToResolve );
DependencyFilter collectionFilter = new ScopeDependencyFilter( null, negate( scopesToCollect ) );
DependencyFilter resolutionFilter = new ScopeDependencyFilter( null, negate( scopesToResolve ) );
resolutionFilter = AndDependencyFilter.newInstance( collectionFilter, resolutionFilter );
resolutionFilter =
AndDependencyFilter.newInstance( resolutionFilter, new ReactorDependencyFilter( projectArtifacts ) );
DependencyResolutionResult result;
try
{
DefaultDependencyResolutionRequest request =
new DefaultDependencyResolutionRequest( project, session.getRepositorySession() );
request.setResolutionFilter( resolutionFilter );
eventSpyDispatcher.onEvent( request );
result = dependenciesResolver.resolve( request );
}
catch ( DependencyResolutionException e )
{
result = e.getResult();
/*
* MNG-2277, the check below compensates for our bad plugin support where we ended up with aggregator
* plugins that require dependency resolution although they usually run in phases of the build where project
* artifacts haven't been assembled yet. The prime example of this is "mvn release:prepare".
*/
if ( aggregating && areAllDependenciesInReactor( session.getProjects(), result.getUnresolvedDependencies() ) )
{
logger.warn( "The following dependencies could not be resolved at this point of the build"
+ " but seem to be part of the reactor:" );
for ( Dependency dependency : result.getUnresolvedDependencies() )
{
logger.warn( "o " + dependency );
}
logger.warn( "Try running the build up to the lifecycle phase \"package\"" );
}
else
{
throw new LifecycleExecutionException( null, project, e );
}
}
eventSpyDispatcher.onEvent( result );
Set<Artifact> artifacts = new LinkedHashSet<Artifact>();
if ( result.getDependencyGraph() != null && !result.getDependencyGraph().getChildren().isEmpty() )
{
RepositoryUtils.toArtifacts( artifacts, result.getDependencyGraph().getChildren(),
Collections.singletonList( project.getArtifact().getId() ), collectionFilter );
}
return artifacts;
}