Search in sources :

Example 1 with CollectResult

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;
        }
    });
}
Also used : CollectResult(org.eclipse.aether.collection.CollectResult) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) Dependency(org.eclipse.aether.graph.Dependency) CollectRequest(org.eclipse.aether.collection.CollectRequest) InvocationOnMock(org.mockito.invocation.InvocationOnMock) DependencyVisitor(org.eclipse.aether.graph.DependencyVisitor) File(java.io.File) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Before(org.junit.Before)

Example 2 with CollectResult

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));
}
Also used : DependencyCollectionException(org.eclipse.aether.collection.DependencyCollectionException) CollectResult(org.eclipse.aether.collection.CollectResult) CollectRequest(org.eclipse.aether.collection.CollectRequest) Test(org.junit.Test)

Example 3 with CollectResult

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;
}
Also used : ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) DependencyNode(org.eclipse.aether.graph.DependencyNode) DependencyResolutionException(org.eclipse.aether.resolution.DependencyResolutionException) ArtifactDescriptorRequest(org.eclipse.aether.resolution.ArtifactDescriptorRequest) Path(java.nio.file.Path) DependencyCollectionException(org.eclipse.aether.collection.DependencyCollectionException) CollectResult(org.eclipse.aether.collection.CollectResult) Dependency(org.eclipse.aether.graph.Dependency) CollectRequest(org.eclipse.aether.collection.CollectRequest) DelegatingClassLoader(org.bimserver.plugins.classloaders.DelegatingClassLoader) PreorderNodeListGenerator(org.eclipse.aether.util.graph.visitor.PreorderNodeListGenerator) ObjectIDMException(org.bimserver.plugins.objectidms.ObjectIDMException) ArtifactDescriptorException(org.eclipse.aether.resolution.ArtifactDescriptorException) DependencyCollectionException(org.eclipse.aether.collection.DependencyCollectionException) ServiceException(org.bimserver.shared.exceptions.ServiceException) IOException(java.io.IOException) PluginException(org.bimserver.shared.exceptions.PluginException) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) JAXBException(javax.xml.bind.JAXBException) FileNotFoundException(java.io.FileNotFoundException) UserException(org.bimserver.shared.exceptions.UserException) ChannelConnectionException(org.bimserver.shared.ChannelConnectionException) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) DependencyResolutionException(org.eclipse.aether.resolution.DependencyResolutionException) FileSystemNotFoundException(java.nio.file.FileSystemNotFoundException) DeserializeException(org.bimserver.plugins.deserializers.DeserializeException) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult) DependencyRequest(org.eclipse.aether.resolution.DependencyRequest) ArtifactDescriptorResult(org.eclipse.aether.resolution.ArtifactDescriptorResult) ArtifactDescriptorException(org.eclipse.aether.resolution.ArtifactDescriptorException) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

Example 4 with CollectResult

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;
}
Also used : StringWriter(java.io.StringWriter) CollectResult(org.eclipse.aether.collection.CollectResult) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DependencyNode(org.eclipse.aether.graph.DependencyNode) DependencyVisitor(org.eclipse.aether.graph.DependencyVisitor) Dependency(org.eclipse.aether.graph.Dependency) CollectRequest(org.eclipse.aether.collection.CollectRequest) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) LinkedList(java.util.LinkedList) PrintWriter(java.io.PrintWriter)

Example 5 with CollectResult

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));
}
Also used : RepositorySystemSession(org.eclipse.aether.RepositorySystemSession) CollectResult(org.eclipse.aether.collection.CollectResult) CollectRequest(org.eclipse.aether.collection.CollectRequest) Before(org.junit.Before)

Aggregations

CollectRequest (org.eclipse.aether.collection.CollectRequest)7 CollectResult (org.eclipse.aether.collection.CollectResult)7 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)5 Dependency (org.eclipse.aether.graph.Dependency)5 Artifact (org.eclipse.aether.artifact.Artifact)4 DependencyNode (org.eclipse.aether.graph.DependencyNode)4 DependencyCollectionException (org.eclipse.aether.collection.DependencyCollectionException)3 RemoteRepository (org.eclipse.aether.repository.RemoteRepository)3 ArrayList (java.util.ArrayList)2 RepositorySystemSession (org.eclipse.aether.RepositorySystemSession)2 DependencyVisitor (org.eclipse.aether.graph.DependencyVisitor)2 ArtifactRequest (org.eclipse.aether.resolution.ArtifactRequest)2 ArtifactResolutionException (org.eclipse.aether.resolution.ArtifactResolutionException)2 ArtifactResult (org.eclipse.aether.resolution.ArtifactResult)2 PreorderNodeListGenerator (org.eclipse.aether.util.graph.visitor.PreorderNodeListGenerator)2 Before (org.junit.Before)2 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1