use of org.eclipse.aether.resolution.ArtifactDescriptorRequest in project buck by facebook.
the class Resolver method getDependenciesOf.
private List<Dependency> getDependenciesOf(Artifact dep) throws ArtifactDescriptorException {
ArtifactDescriptorRequest descriptorRequest = new ArtifactDescriptorRequest();
descriptorRequest.setArtifact(dep);
descriptorRequest.setRepositories(repos);
descriptorRequest.setRequestContext(JavaScopes.RUNTIME);
ArtifactDescriptorResult result = repoSys.readArtifactDescriptor(session, descriptorRequest);
return result.getDependencies();
}
use of org.eclipse.aether.resolution.ArtifactDescriptorRequest in project BIMserver by opensourceBIM.
the class PluginManager method loadDependencies.
private PublicFindClassClassLoader loadDependencies(Set<org.bimserver.plugins.Dependency> bimServerDependencies, Model model, PublicFindClassClassLoader previous) throws FileNotFoundException, IOException {
List<org.apache.maven.model.Dependency> dependencies = model.getDependencies();
Iterator<org.apache.maven.model.Dependency> it = dependencies.iterator();
Path workspaceDir = Paths.get("..");
bimServerDependencies.add(new org.bimserver.plugins.Dependency(workspaceDir.resolve("PluginBase/target/classes")));
bimServerDependencies.add(new org.bimserver.plugins.Dependency(workspaceDir.resolve("Shared/target/classes")));
while (it.hasNext()) {
org.apache.maven.model.Dependency depend = it.next();
try {
if (depend.getGroupId().equals("org.opensourcebim") && (depend.getArtifactId().equals("shared") || depend.getArtifactId().equals("pluginbase"))) {
// TODO we might want to check the version though
continue;
}
if (depend.isOptional() || "test".equals(depend.getScope())) {
continue;
}
Dependency dependency2 = new Dependency(new DefaultArtifact(depend.getGroupId() + ":" + depend.getArtifactId() + ":jar:" + depend.getVersion()), "compile");
DelegatingClassLoader depDelLoader = new DelegatingClassLoader(previous);
if (!dependency2.getArtifact().isSnapshot()) {
if (dependency2.getArtifact().getFile() != null) {
bimServerDependencies.add(new org.bimserver.plugins.Dependency(dependency2.getArtifact().getFile().toPath()));
loadDependencies(dependency2.getArtifact().getFile().toPath(), depDelLoader);
} else {
ArtifactRequest request = new ArtifactRequest();
request.setArtifact(dependency2.getArtifact());
request.setRepositories(mavenPluginRepository.getRepositories());
try {
ArtifactResult resolveArtifact = mavenPluginRepository.getSystem().resolveArtifact(mavenPluginRepository.getSession(), request);
if (resolveArtifact.getArtifact().getFile() != null) {
bimServerDependencies.add(new org.bimserver.plugins.Dependency(resolveArtifact.getArtifact().getFile().toPath()));
loadDependencies(resolveArtifact.getArtifact().getFile().toPath(), depDelLoader);
} else {
// TODO error?
}
} catch (ArtifactResolutionException e) {
e.printStackTrace();
}
}
} else {
// Snapshot projects linked in Eclipse
ArtifactRequest request = new ArtifactRequest();
if ((!"test".equals(dependency2.getScope()) && !dependency2.getArtifact().isSnapshot())) {
request.setArtifact(dependency2.getArtifact());
request.setRepositories(mavenPluginRepository.getLocalRepositories());
try {
ArtifactResult resolveArtifact = mavenPluginRepository.getSystem().resolveArtifact(mavenPluginRepository.getSession(), request);
if (resolveArtifact.getArtifact().getFile() != null) {
bimServerDependencies.add(new org.bimserver.plugins.Dependency(resolveArtifact.getArtifact().getFile().toPath()));
loadDependencies(resolveArtifact.getArtifact().getFile().toPath(), depDelLoader);
} else {
// TODO error?
}
} catch (Exception e) {
LOGGER.info(dependency2.getArtifact().toString());
e.printStackTrace();
}
// bimServerDependencies.add(new
// org.bimserver.plugins.Dependency(resolveArtifact.getArtifact().getFile().toPath()));
}
}
ArtifactDescriptorRequest descriptorRequest = new ArtifactDescriptorRequest();
descriptorRequest.setArtifact(dependency2.getArtifact());
descriptorRequest.setRepositories(mavenPluginRepository.getRepositories());
ArtifactDescriptorResult descriptorResult = mavenPluginRepository.getSystem().readArtifactDescriptor(mavenPluginRepository.getSession(), descriptorRequest);
CollectRequest collectRequest = new CollectRequest();
collectRequest.setRootArtifact(descriptorResult.getArtifact());
collectRequest.setDependencies(descriptorResult.getDependencies());
collectRequest.setManagedDependencies(descriptorResult.getManagedDependencies());
collectRequest.setRepositories(descriptorResult.getRepositories());
DependencyNode node = mavenPluginRepository.getSystem().collectDependencies(mavenPluginRepository.getSession(), collectRequest).getRoot();
DependencyRequest dependencyRequest = new DependencyRequest();
dependencyRequest.setRoot(node);
CollectResult collectResult = mavenPluginRepository.getSystem().collectDependencies(mavenPluginRepository.getSession(), collectRequest);
PreorderNodeListGenerator nlg = new PreorderNodeListGenerator();
// collectResult.getRoot().accept(new
// ConsoleDependencyGraphDumper());
collectResult.getRoot().accept(nlg);
try {
mavenPluginRepository.getSystem().resolveDependencies(mavenPluginRepository.getSession(), dependencyRequest);
} catch (DependencyResolutionException e) {
// Ignore
}
for (DependencyNode dependencyNode : nlg.getNodes()) {
ArtifactRequest newRequest = new ArtifactRequest(dependencyNode);
newRequest.setRepositories(mavenPluginRepository.getRepositories());
ArtifactResult resolveArtifact = mavenPluginRepository.getSystem().resolveArtifact(mavenPluginRepository.getSession(), newRequest);
Artifact artifact = resolveArtifact.getArtifact();
Path jarFile = Paths.get(artifact.getFile().getAbsolutePath());
loadDependencies(jarFile, depDelLoader);
Artifact versionArtifact = new DefaultArtifact(artifact.getGroupId(), artifact.getArtifactId(), "pom", artifact.getVersion());
ArtifactRequest request = new ArtifactRequest();
request.setArtifact(versionArtifact);
request.setRepositories(mavenPluginRepository.getRepositories());
// try {
// ArtifactResult resolveArtifact =
// mavenPluginRepository.getSystem().resolveArtifact(mavenPluginRepository.getSession(),
// request);
// File depPomFile =
// resolveArtifact.getArtifact().getFile();
// if (depPomFile != null) {
// MavenXpp3Reader mavenreader = new MavenXpp3Reader();
// Model depModel = null;
// try (FileReader reader = new FileReader(depPomFile)) {
// try {
// depModel = mavenreader.read(reader);
// } catch (XmlPullParserException e) {
// e.printStackTrace();
// }
// }
// previous = loadDependencies(bimServerDependencies,
// depModel, previous);
// } else {
// LOGGER.info("Artifact not found " + versionArtifact);
// }
// } catch (ArtifactResolutionException e1) {
// LOGGER.error(e1.getMessage());
// }
// EclipsePluginClassloader depLoader = new
// EclipsePluginClassloader(depDelLoader, projectRoot);
bimServerDependencies.add(new org.bimserver.plugins.Dependency(jarFile));
}
previous = depDelLoader;
} catch (DependencyCollectionException e) {
e.printStackTrace();
} catch (ArtifactDescriptorException e2) {
e2.printStackTrace();
} catch (ArtifactResolutionException e) {
e.printStackTrace();
}
}
return previous;
}
use of org.eclipse.aether.resolution.ArtifactDescriptorRequest 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.resolution.ArtifactDescriptorRequest in project BIMserver by opensourceBIM.
the class MavenPluginLocation method createMavenVersion.
private MavenPluginVersion createMavenVersion(Version version) throws ArtifactDescriptorException, FileNotFoundException, IOException, ArtifactResolutionException, XmlPullParserException {
ArtifactDescriptorRequest descriptorRequest = new ArtifactDescriptorRequest();
Artifact versionArtifact = new DefaultArtifact(groupId, artifactId, "pom", version.toString());
descriptorRequest.setArtifact(versionArtifact);
descriptorRequest.setRepositories(mavenPluginRepository.getRepositoriesAsList());
MavenPluginVersion mavenPluginVersion = new MavenPluginVersion(versionArtifact, version);
ArtifactDescriptorResult descriptorResult;
descriptorResult = mavenPluginRepository.getSystem().readArtifactDescriptor(mavenPluginRepository.getSession(), descriptorRequest);
try {
ArtifactRequest request = new ArtifactRequest();
request.setArtifact(descriptorResult.getArtifact());
request.setRepositories(mavenPluginRepository.getRepositoriesAsList());
ArtifactResult resolveArtifact = mavenPluginRepository.getSystem().resolveArtifact(mavenPluginRepository.getSession(), request);
File pomFile = resolveArtifact.getArtifact().getFile();
MavenXpp3Reader mavenreader = new MavenXpp3Reader();
try (FileReader fileReader = new FileReader(pomFile)) {
Model model = mavenreader.read(fileReader);
mavenPluginVersion.setModel(model);
}
} catch (Exception e) {
LOGGER.error(e.getMessage());
}
for (org.eclipse.aether.graph.Dependency dependency : descriptorResult.getDependencies()) {
DefaultArtifactVersion artifactVersion = new DefaultArtifactVersion(dependency.getArtifact().getVersion());
mavenPluginVersion.addDependency(new MavenDependency(dependency.getArtifact(), artifactVersion));
}
return mavenPluginVersion;
}
use of org.eclipse.aether.resolution.ArtifactDescriptorRequest in project mule by mulesoft.
the class DependencyResolver method readArtifactDescriptor.
/**
* Gets information about an artifact like its direct dependencies and potential relocations.
*
* @param artifact the {@link Artifact} requested, must not be {@code null}
* @return {@link ArtifactDescriptorResult} descriptor result, never {@code null}
* @throws {@link ArtifactDescriptorException} if the artifact descriptor could not be read
*/
public ArtifactDescriptorResult readArtifactDescriptor(Artifact artifact) throws ArtifactDescriptorException {
checkNotNull(artifact, "artifact cannot be null");
final ArtifactDescriptorRequest request = new ArtifactDescriptorRequest(artifact, resolutionContext.getRemoteRepositories(), null);
return repositoryState.getSystem().readArtifactDescriptor(repositoryState.getSession(), request);
}
Aggregations