List of usage examples for org.apache.maven.project DefaultDependencyResolutionRequest setResolutionFilter
public DependencyResolutionRequest setResolutionFilter(DependencyFilter filter)
From source file:net.sf.taverna.t2.maven.plugins.MavenOsgiUtils.java
License:Apache License
public Set<BundleArtifact> getBundleDependencies(String... scopes) throws MojoExecutionException { ScopeDependencyFilter scopeFilter = new ScopeDependencyFilter(Arrays.asList(scopes), null); DefaultDependencyResolutionRequest dependencyResolutionRequest = new DefaultDependencyResolutionRequest( project, repositorySystemSession); dependencyResolutionRequest.setResolutionFilter(scopeFilter); DependencyResolutionResult dependencyResolutionResult; try {//from ww w . j a va 2s .com dependencyResolutionResult = projectDependenciesResolver.resolve(dependencyResolutionRequest); } catch (DependencyResolutionException ex) { throw new MojoExecutionException(ex.getMessage(), ex); } DependencyNode dependencyGraph = dependencyResolutionResult.getDependencyGraph(); if (dependencyGraph != null) { checkBundleDependencies(dependencyGraph.getChildren()); return getBundleArtifacts(dependencyGraph.getChildren()); } else { return new HashSet<BundleArtifact>(); } }
From source file:org.sourcepit.b2.internal.maven.DefaultModuleArtifactResolver.java
License:Apache License
private SetMultimap<Artifact, String> resolveModuleDependencies(final MavenSession session, MavenProject project, final String scope) { final Map<DependencyNode, String> moduleNodeToClassifiers = new LinkedHashMap<DependencyNode, String>(); final DependencyFilter resolutionFilter = new DependencyFilter() { public boolean accept(DependencyNode node, List<DependencyNode> parents) { Artifact moduleArtifact = getModuleArtifact(node); if (moduleArtifact != null) { final String classifier = moduleArtifact.getClassifier(); final Artifact newArtifact; newArtifact = new DefaultArtifact(moduleArtifact.getGroupId(), moduleArtifact.getArtifactId(), "", moduleArtifact.getExtension(), moduleArtifact.getVersion(), moduleArtifact.getProperties(), moduleArtifact.getFile()); node.setArtifact(newArtifact); moduleNodeToClassifiers.put(node, classifier); }//from ww w. j a v a2 s.c o m return true; } private Artifact getModuleArtifact(DependencyNode node) { if (node.getDependency() != null) { final Dependency dependency = node.getDependency(); if (dependency.getArtifact() != null) { final Artifact artifact = dependency.getArtifact(); if ("module".equals(artifact.getExtension())) { return artifact; } } } return null; } }; final DependencySelector dependencySelector = createDependencySelector(scope); final AbstractForwardingRepositorySystemSession systemSession = new AbstractForwardingRepositorySystemSession() { @Override public DependencySelector getDependencySelector() { return dependencySelector; } @Override protected RepositorySystemSession getSession() { return session.getRepositorySession(); } }; final DefaultDependencyResolutionRequest request; request = new DefaultDependencyResolutionRequest(project, systemSession); request.setResolutionFilter(resolutionFilter); try { dependenciesResolver.resolve(request); } catch (DependencyResolutionException e) { throw Exceptions.pipe(e); } final SetMultimap<Artifact, String> artifactToClassifiers = LinkedHashMultimap.create(); for (Entry<DependencyNode, String> entry : moduleNodeToClassifiers.entrySet()) { DependencyNode dependencyNode = entry.getKey(); artifactToClassifiers.get(dependencyNode.getDependency().getArtifact()).add(entry.getValue()); } return artifactToClassifiers; }
From source file:org.sourcepit.maven.dependency.model.aether.AetherDependencyModelResolver.java
License:Apache License
private DependencyModel resolve(@NotNull MavenProject project, boolean resolveRoot, ArtifactAttachmentFactory attachmentFactory) throws DependencyResolutionException { project = filterUnconnectableRepos(project); final DependencyModelBuilder modelBuilder = new DependencyModelBuilder(attachmentFactory); final RepositorySystemSession repositorySession = newRepositorySystemSession(project, resolveRoot, modelBuilder);//from www. j a va 2s . c o m final DefaultDependencyResolutionRequest resolutionRequest = new DefaultDependencyResolutionRequest(); resolutionRequest.setMavenProject(project); resolutionRequest.setRepositorySession(repositorySession); resolutionRequest.setResolutionFilter(new ScopeDependencyFilter("test")); DependencyResolutionResult resolutionResult; try { resolutionResult = dependenciesResolver.resolve(resolutionRequest); } catch (DependencyResolutionException e) { resolutionResult = e.getResult(); } final Collection<org.eclipse.aether.artifact.Artifact> resolvedAttachments; try { resolvedAttachments = attachmentResolver.resolveAttachments(repositorySession, resolutionResult.getDependencyGraph()); } catch (ArtifactResolutionException e) { throw pipe(e); } final DependencyModel model = modelBuilder.getDependencyModel(); applyResolvedArtifacts(project, resolutionResult, resolvedAttachments, model); final DependencyNode dependencyGraph = resolutionResult.getDependencyGraph(); if (resolveRoot) { addNodeArtifact(model.getRootArtifacts(), model, dependencyGraph); } else { for (DependencyNode dependencyNode : dependencyGraph.getChildren()) { addNodeArtifact(model.getRootArtifacts(), model, dependencyNode); } } return model; }
From source file:org.sourcepit.maven.dependency.model.DependencyTreeBuilder.java
License:Apache License
private DefaultDependencyResolutionRequest buildDependencyResolutionRequest( DependencyTreeBuilderRequest request) throws ProjectBuildingException { final MavenProject project = buildProject(request.getArtifact()); final DependencySelector selector = buildDependencySelector(request); final DependencyGraphTransformer transformer = new ChainedDependencyGraphTransformer( new DependencyNode2AdapterTransformer(false), new VersionConflictResolver(new NearestDependencyNodeChooser(false)), new JavaDependencyContextRefiner()); final RepositorySystemSession repositorySession = new AbstractForwardingRepositorySystemSession() { @Override/*from ww w . j ava 2 s . c o m*/ public DependencySelector getDependencySelector() { return selector; } @Override public DependencyGraphTransformer getDependencyGraphTransformer() { return transformer; } @Override protected RepositorySystemSession getSession() { return buildContext.getRepositorySession(); } }; final DefaultDependencyResolutionRequest resolutionRequest = new DefaultDependencyResolutionRequest(); resolutionRequest.setMavenProject(project); resolutionRequest.setRepositorySession(repositorySession); resolutionRequest.setResolutionFilter(new ReplacedDependencyFilter()); resolutionRequest.setResolutionFilter(new ScopeDependencyFilter("test")); return resolutionRequest; }