use of org.eclipse.aether.collection.CollectResult in project byte-buddy by raphw.
the class ClassLoaderResolverTest method setUp.
@Before
public void setUp() throws Exception {
classLoaderResolver = new ClassLoaderResolver(log, repositorySystem, repositorySystemSession, Collections.<RemoteRepository>emptyList());
when(repositorySystem.collectDependencies(eq(repositorySystemSession), any(CollectRequest.class))).thenReturn(new CollectResult(new CollectRequest()).setRoot(root));
when(child.getDependency()).thenReturn(new Dependency(new DefaultArtifact(FOO, BAR, QUX, BAZ, FOO + BAR, Collections.<String, String>emptyMap(), new File(FOO + "/" + BAR)), QUX + BAZ));
when(root.accept(any(DependencyVisitor.class))).then(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
DependencyVisitor dependencyVisitor = invocationOnMock.getArgumentAt(0, DependencyVisitor.class);
dependencyVisitor.visitEnter(child);
dependencyVisitor.visitLeave(child);
return null;
}
});
}
use of org.eclipse.aether.collection.CollectResult in project byte-buddy by raphw.
the class ClassLoaderResolverTest method testCollectionFailure.
@Test(expected = MojoExecutionException.class)
public void testCollectionFailure() throws Exception {
when(repositorySystem.collectDependencies(eq(repositorySystemSession), any(CollectRequest.class))).thenThrow(new DependencyCollectionException(new CollectResult(new CollectRequest())));
classLoaderResolver.resolve(new MavenCoordinate(FOO, BAR, QUX));
}
use of org.eclipse.aether.collection.CollectResult 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.collection.CollectResult in project activemq-artemis by apache.
the class ArtemisAbstractPlugin method explodeDependencies.
protected List<Artifact> explodeDependencies(Artifact artifact) throws DependencyCollectionException {
final List<Artifact> dependencies = new LinkedList<>();
CollectRequest exploreDependenciesRequest = new CollectRequest(new Dependency(artifact, "compile"), remoteRepos);
CollectResult result = repositorySystem.collectDependencies(repoSession, exploreDependenciesRequest);
final AtomicInteger level = new AtomicInteger(0);
DependencyNode node = result.getRoot();
StringWriter writer = new StringWriter();
final PrintWriter strPrint = new PrintWriter(writer);
strPrint.println("Dependencies explored for " + artifact + ":");
if (node != null) {
node.accept(new DependencyVisitor() {
@Override
public boolean visitEnter(DependencyNode node) {
for (int i = 0; i < level.get(); i++) {
strPrint.print("!...");
}
level.incrementAndGet();
strPrint.println("Dependency:: " + node.getDependency() + " node = " + node.getArtifact());
dependencies.add(node.getArtifact());
return true;
}
@Override
public boolean visitLeave(DependencyNode node) {
level.decrementAndGet();
return true;
}
});
}
getLog().info(writer.toString());
return dependencies;
}
use of org.eclipse.aether.collection.CollectResult in project byte-buddy by raphw.
the class ByteBuddyMojoTest method setUp.
@Before
public void setUp() throws Exception {
when(repositorySystem.collectDependencies(any(RepositorySystemSession.class), any(CollectRequest.class))).thenReturn(new CollectResult(new CollectRequest()).setRoot(root));
project = File.createTempFile(FOO, TEMP);
assertThat(project.delete(), is(true));
assertThat(project.mkdir(), is(true));
}
Aggregations