use of org.eclipse.aether.util.graph.transformer.SimpleOptionalitySelector in project sts4 by spring-projects.
the class MavenCore method readDependencyTree.
/**
* Taken from M2E same named method from MavenModelManager
*
* @param repositorySystem
* @param repositorySession
* @param mavenProject
* @param scope
* @return
*/
private DependencyNode readDependencyTree(org.eclipse.aether.RepositorySystem repositorySystem, RepositorySystemSession repositorySession, MavenProject mavenProject, String scope) {
DefaultRepositorySystemSession session = new DefaultRepositorySystemSession(repositorySession);
ConflictResolver transformer = new ConflictResolver(new NearestVersionSelector(), new JavaScopeSelector(), new SimpleOptionalitySelector(), new JavaScopeDeriver());
session.setDependencyGraphTransformer(transformer);
session.setConfigProperty(ConflictResolver.CONFIG_PROP_VERBOSE, Boolean.toString(true));
session.setConfigProperty(DependencyManagerUtils.CONFIG_PROP_VERBOSE, true);
ArtifactTypeRegistry stereotypes = session.getArtifactTypeRegistry();
CollectRequest request = new CollectRequest();
// $NON-NLS-1$
request.setRequestContext("project");
request.setRepositories(mavenProject.getRemoteProjectRepositories());
for (org.apache.maven.model.Dependency dependency : mavenProject.getDependencies()) {
request.addDependency(RepositoryUtils.toDependency(dependency, stereotypes));
}
DependencyManagement depMngt = mavenProject.getDependencyManagement();
if (depMngt != null) {
for (org.apache.maven.model.Dependency dependency : depMngt.getDependencies()) {
request.addManagedDependency(RepositoryUtils.toDependency(dependency, stereotypes));
}
}
DependencyNode node;
try {
node = repositorySystem.collectDependencies(session, request).getRoot();
} catch (DependencyCollectionException ex) {
node = ex.getResult().getRoot();
}
Collection<String> scopes = new HashSet<String>();
Collections.addAll(scopes, Artifact.SCOPE_SYSTEM, Artifact.SCOPE_COMPILE, Artifact.SCOPE_PROVIDED, Artifact.SCOPE_RUNTIME, Artifact.SCOPE_TEST);
if (Artifact.SCOPE_COMPILE.equals(scope)) {
scopes.remove(Artifact.SCOPE_COMPILE);
scopes.remove(Artifact.SCOPE_SYSTEM);
scopes.remove(Artifact.SCOPE_PROVIDED);
} else if (Artifact.SCOPE_RUNTIME.equals(scope)) {
scopes.remove(Artifact.SCOPE_COMPILE);
scopes.remove(Artifact.SCOPE_RUNTIME);
} else if (Artifact.SCOPE_COMPILE_PLUS_RUNTIME.equals(scope)) {
scopes.remove(Artifact.SCOPE_COMPILE);
scopes.remove(Artifact.SCOPE_SYSTEM);
scopes.remove(Artifact.SCOPE_PROVIDED);
scopes.remove(Artifact.SCOPE_RUNTIME);
} else {
scopes.clear();
}
CloningDependencyVisitor cloner = new CloningDependencyVisitor();
node.accept(new FilteringDependencyVisitor(cloner, new ScopeDependencyFilter(null, scopes)));
node = cloner.getRootNode();
return node;
}
use of org.eclipse.aether.util.graph.transformer.SimpleOptionalitySelector in project fabric8 by jboss-fuse.
the class AetherBasedResolver method newRepositorySystemSession.
private static DefaultRepositorySystemSession newRepositorySystemSession() {
DefaultRepositorySystemSession session = new DefaultRepositorySystemSession();
DependencyTraverser depTraverser = new FatArtifactTraverser();
session.setDependencyTraverser(depTraverser);
DependencyManager depManager = new ClassicDependencyManager();
session.setDependencyManager(depManager);
DependencySelector depFilter = new AndDependencySelector(new ScopeDependencySelector("test", "provided"), new OptionalDependencySelector(), new ExclusionDependencySelector());
session.setDependencySelector(depFilter);
DependencyGraphTransformer transformer = new ConflictResolver(new NearestVersionSelector(), new JavaScopeSelector(), new SimpleOptionalitySelector(), new JavaScopeDeriver());
new ChainedDependencyGraphTransformer(transformer, new JavaDependencyContextRefiner());
session.setDependencyGraphTransformer(transformer);
DefaultArtifactTypeRegistry stereotypes = new DefaultArtifactTypeRegistry();
stereotypes.add(new DefaultArtifactType("pom"));
stereotypes.add(new DefaultArtifactType("maven-plugin", "jar", "", "java"));
stereotypes.add(new DefaultArtifactType("jar", "jar", "", "java"));
stereotypes.add(new DefaultArtifactType("ejb", "jar", "", "java"));
stereotypes.add(new DefaultArtifactType("ejb-client", "jar", "client", "java"));
stereotypes.add(new DefaultArtifactType("test-jar", "jar", "tests", "java"));
stereotypes.add(new DefaultArtifactType("javadoc", "jar", "javadoc", "java"));
stereotypes.add(new DefaultArtifactType("java-source", "jar", "sources", "java", false, false));
stereotypes.add(new DefaultArtifactType("war", "war", "", "java", false, true));
stereotypes.add(new DefaultArtifactType("ear", "ear", "", "java", false, true));
stereotypes.add(new DefaultArtifactType("rar", "rar", "", "java", false, true));
stereotypes.add(new DefaultArtifactType("par", "par", "", "java", false, true));
session.setArtifactTypeRegistry(stereotypes);
session.setArtifactDescriptorPolicy(new SimpleArtifactDescriptorPolicy(true, true));
Properties sysProps = (Properties) System.getProperties().clone();
session.setSystemProperties(sysProps);
session.setConfigProperties(sysProps);
// set timeout smaller than 30 minutes by default
session.setConfigProperty(ConfigurationProperties.REQUEST_TIMEOUT, TimeUnit.MINUTES.toMillis(5));
return session;
}
use of org.eclipse.aether.util.graph.transformer.SimpleOptionalitySelector in project wildfly-swarm by wildfly-swarm.
the class MavenArtifactResolvingHelper method resolveAll.
@Override
public Set<ArtifactSpec> resolveAll(Collection<ArtifactSpec> specs, boolean transitive, boolean defaultExcludes) throws Exception {
if (specs.isEmpty()) {
return Collections.emptySet();
}
List<DependencyNode> nodes;
if (transitive) {
final CollectRequest request = new CollectRequest();
request.setRepositories(this.remoteRepositories);
// SWARM-1031
if (this.dependencyManagement != null) {
List<Dependency> managedDependencies = this.dependencyManagement.getDependencies().stream().map(mavenDep -> {
DefaultArtifact artifact = new DefaultArtifact(mavenDep.getGroupId(), mavenDep.getArtifactId(), mavenDep.getType(), mavenDep.getVersion());
return new Dependency(artifact, mavenDep.getScope());
}).collect(Collectors.toList());
request.setManagedDependencies(managedDependencies);
}
specs.forEach(spec -> request.addDependency(new Dependency(new DefaultArtifact(spec.groupId(), spec.artifactId(), spec.classifier(), spec.type(), spec.version()), "compile")));
RepositorySystemSession tempSession = new RepositorySystemSessionWrapper(this.session, new ConflictResolver(new NearestVersionSelector(), new JavaScopeSelector(), new SimpleOptionalitySelector(), new JavaScopeDeriver()), defaultExcludes);
CollectResult result = this.system.collectDependencies(tempSession, request);
PreorderNodeListGenerator gen = new PreorderNodeListGenerator();
result.getRoot().accept(gen);
nodes = gen.getNodes();
} else {
nodes = new ArrayList<>();
for (ArtifactSpec spec : specs) {
Dependency dependency = new Dependency(new DefaultArtifact(spec.groupId(), spec.artifactId(), spec.classifier(), spec.type(), spec.version()), "compile");
DefaultDependencyNode node = new DefaultDependencyNode(dependency);
nodes.add(node);
}
}
List<DependencyNode> extraDependencies = ExtraArtifactsHandler.getExtraDependencies(nodes);
nodes.addAll(extraDependencies);
resolveDependenciesInParallel(nodes);
return nodes.stream().filter(node -> !"system".equals(node.getDependency().getScope())).map(node -> {
final Artifact artifact = node.getArtifact();
return new ArtifactSpec(node.getDependency().getScope(), artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact.getExtension(), artifact.getClassifier(), null);
}).map(this::resolve).filter(Objects::nonNull).collect(Collectors.toSet());
}
Aggregations