use of org.eclipse.aether.graph.Dependency in project fabric8 by jboss-fuse.
the class DependencyFilters method parse.
/**
* Creates a filter from the given String
*/
public static Filter<Dependency> parse(String dependencyFilterText) {
List<Filter<Dependency>> filters = new ArrayList<Filter<Dependency>>();
StringTokenizer iter = new StringTokenizer(dependencyFilterText);
while (iter.hasMoreElements()) {
String text = iter.nextToken();
Filter<Dependency> filter = parseSingleFilter(text);
if (filter != null) {
filters.add(filter);
}
}
return Filters.compositeFilter(filters);
}
use of org.eclipse.aether.graph.Dependency in project drools by kiegroup.
the class MavenRepository method getArtifactDependecies.
public List<DependencyDescriptor> getArtifactDependecies(String artifactName) {
Artifact artifact = new DefaultArtifact(artifactName);
CollectRequest collectRequest = new CollectRequest();
Dependency root = new Dependency(artifact, "");
collectRequest.setRoot(root);
for (RemoteRepository repo : remoteRepositoriesForRequest) {
collectRequest.addRepository(repo);
}
CollectResult collectResult;
try {
collectResult = aether.getSystem().collectDependencies(aether.getSession(), collectRequest);
} catch (DependencyCollectionException e) {
throw new RuntimeException(e);
}
CollectDependencyVisitor visitor = new CollectDependencyVisitor();
collectResult.getRoot().accept(visitor);
List<DependencyDescriptor> descriptors = new ArrayList<DependencyDescriptor>();
for (DependencyNode node : visitor.getDependencies()) {
// skip root to not add artifact as dependency
if (node.getDependency().equals(root)) {
continue;
}
descriptors.add(new DependencyDescriptor(node.getDependency().getArtifact()));
}
return descriptors;
}
use of org.eclipse.aether.graph.Dependency in project spring-boot by spring-projects.
the class MavenResolverGrapeEngine method resolve.
@Override
public URI[] resolve(Map args, List depsInfo, Map... dependencyMaps) {
List<Exclusion> exclusions = createExclusions(args);
List<Dependency> dependencies = createDependencies(dependencyMaps, exclusions);
try {
List<File> files = resolve(dependencies);
List<URI> uris = new ArrayList<>(files.size());
for (File file : files) {
uris.add(file.toURI());
}
return uris.toArray(new URI[0]);
} catch (Exception ex) {
throw new DependencyResolutionFailedException(ex);
}
}
use of org.eclipse.aether.graph.Dependency in project atlasmap by atlasmap.
the class AbstractAtlasMapMojo method resolveClasspath.
/**
* Resolves the classpath.
* @param artifacts artifacts
* @return resolved
* @throws MojoFailureException unexpected error
*/
protected List<URL> resolveClasspath(List<String> artifacts) throws MojoFailureException {
final List<URL> urls = new ArrayList<>();
try {
for (String gav : artifacts) {
Artifact artifact = new DefaultArtifact(gav);
getLog().debug("Resolving dependencies for artifact: " + artifact);
CollectRequest collectRequest = new CollectRequest();
collectRequest.setRoot(new Dependency(artifact, ""));
collectRequest.setRepositories(getRemoteRepos());
DependencyRequest dependencyRequest = new DependencyRequest();
dependencyRequest.setCollectRequest(collectRequest);
DependencyResult dependencyResult = getSystem().resolveDependencies(getRepoSession(), dependencyRequest);
PreorderNodeListGenerator nlg = new PreorderNodeListGenerator();
dependencyResult.getRoot().accept(nlg);
Iterator<DependencyNode> it = nlg.getNodes().iterator();
while (it.hasNext()) {
DependencyNode node = it.next();
if (node.getDependency() != null) {
Artifact x = node.getDependency().getArtifact();
if (x.getFile() != null) {
getLog().debug("Found dependency: " + x + " for artifact: " + artifact);
urls.add(x.getFile().toURI().toURL());
}
}
}
}
} catch (IllegalArgumentException e) {
throw new MojoFailureException(e.getMessage(), e);
} catch (DependencyResolutionException e) {
throw new MojoFailureException(e.getMessage(), e);
} catch (MalformedURLException e) {
throw new MojoFailureException(e.getMessage(), e);
}
return urls;
}
use of org.eclipse.aether.graph.Dependency in project BIMserver by opensourceBIM.
the class PluginBundleManager method loadDependencies.
private PublicFindClassClassLoader loadDependencies(Set<org.bimserver.plugins.Dependency> bimServerDependencies, Model model, PublicFindClassClassLoader previous, boolean resolveRemoteDependencies) 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") || depend.getArtifactId().equals("ifcplugins"))) {
// 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(resolveRemoteDependencies ? mavenPluginRepository.getRepositoriesAsList() : 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 (ArtifactResolutionException e) {
LOGGER.error(model.getGroupId() + "." + model.getArtifactId(), e);
}
}
} 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.getRepositoriesAsList());
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.getRepositoriesAsList());
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.getRepositoriesAsList());
// 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;
}
Aggregations