use of org.eclipse.aether.collection.DependencyGraphTransformer in project fabric8 by jboss-fuse.
the class AetherBasedResolver method collectDependencies.
protected DependencyNode collectDependencies(Artifact root, String pomVersion, final Filter<Dependency> excludeDependencyFilter) throws RepositoryException, IOException {
final DefaultRepositorySystemSession session = newSession();
try {
List<RemoteRepository> repos = selectRepositories();
assignProxyAndMirrors(repos);
ArtifactDescriptorResult artifactDescriptorResult = m_repoSystem.readArtifactDescriptor(session, new ArtifactDescriptorRequest(root, repos, null));
repos.addAll(artifactDescriptorResult.getRepositories());
Dependency rootDependency = new Dependency(root, null);
List<Dependency> dependencies = artifactDescriptorResult.getDependencies();
final DefaultDependencyNode rootNode = new DefaultDependencyNode(rootDependency);
GenericVersionScheme versionScheme = new GenericVersionScheme();
rootNode.setVersion(versionScheme.parseVersion(pomVersion));
rootNode.setVersionConstraint(versionScheme.parseVersionConstraint(pomVersion));
DependencyNode pomNode = rootNode;
// final Filter<Dependency> shouldExclude = Filters.or(DependencyFilters.testScopeFilter, excludeDependencyFilter, new NewerVersionExistsFilter(rootNode));
final Filter<Dependency> shouldExclude = Filters.or(Arrays.asList(DependencyFilters.testScopeFilter, excludeDependencyFilter));
DependencySelector dependencySelector = new AndDependencySelector(new ScopeDependencySelector("test"), new ExclusionDependencySelector(), new DependencySelector() {
@Override
public DependencySelector deriveChildSelector(DependencyCollectionContext context) {
return this;
}
@Override
public boolean selectDependency(Dependency dependency) {
try {
return !DependencyFilters.matches(dependency, shouldExclude);
} catch (Exception e) {
failedToMakeDependencyTree(dependency, e);
return false;
}
}
});
session.setDependencySelector(dependencySelector);
// work on the root dependency directly?
if (true) {
for (Dependency dependency : dependencies) {
DependencyNode node = resolveDependencies(session, repos, pomNode, dependency, shouldExclude);
if (node != null) {
pomNode.getChildren().add(node);
}
}
} else {
DependencyNode node = resolveDependencies(session, repos, pomNode, rootDependency, shouldExclude);
if (node != null) {
pomNode = node;
}
}
// now lets transform the dependency tree to remove different versions for the same artifact
final DependencyGraphTransformationContext tranformContext = new DependencyGraphTransformationContext() {
Map<Object, Object> map = new HashMap<>();
public RepositorySystemSession getSession() {
return session;
}
public Object get(Object key) {
return map.get(key);
}
public Object put(Object key, Object value) {
return map.put(key, value);
}
};
DependencyGraphTransformer transformer = new ReplaceConflictingVersionResolver();
pomNode = transformer.transformGraph(pomNode, tranformContext);
transformer = new DuplicateTransformer();
pomNode = transformer.transformGraph(pomNode, tranformContext);
return pomNode;
} finally {
releaseSession(session);
}
}
use of org.eclipse.aether.collection.DependencyGraphTransformer 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;
}
Aggregations