@Test public void testLookup() throws ArtifactDescriptorException { StubArtifact art = new StubArtifact("gid:aid:ext:ver"); ArtifactDescriptorRequest request = new ArtifactDescriptorRequest(art, null, ""); ArtifactDescriptorResult description = reader.readArtifactDescriptor(session, request); assertEquals(request, description.getRequest()); assertEquals(art, description.getArtifact()); assertEquals(1, description.getRelocations().size()); Artifact artifact = description.getRelocations().get(0); assertEquals("gid", artifact.getGroupId()); assertEquals("aid", artifact.getArtifactId()); assertEquals("ver", artifact.getVersion()); assertEquals("ext", artifact.getExtension()); assertEquals(1, description.getRepositories().size()); RemoteRepository repo = description.getRepositories().get(0); assertEquals("id", repo.getId()); assertEquals("type", repo.getContentType()); assertEquals("protocol://some/url?for=testing", repo.getUrl()); assertDependencies(description.getDependencies()); assertDependencies(description.getManagedDependencies()); }
public void execute() throws MojoExecutionException, MojoFailureException { try { ArtifactDescriptorResult artifactDescriptor = repoSystem.readArtifactDescriptor( repoSession, new ArtifactDescriptorRequest(new DefaultArtifact(artifact), projectRepos, null)); CollectRequest collectRequest = new CollectRequest(); collectRequest.setDependencies(artifactDescriptor.getDependencies()); collectRequest.setManagedDependencies(artifactDescriptor.getManagedDependencies()); collectRequest.setRepositories(projectRepos); CollectResult dependencies = repoSystem.collectDependencies(repoSession, collectRequest); StringWriter writer = new StringWriter(); NodeFormatter nodeFormatter = new DefaultNodeFormatter(artifactDescriptor.getArtifact().toString()); dependencies .getRoot() .accept( new SerializingDependencyVisitor( writer, SerializingDependencyVisitor.STANDARD_TOKENS, nodeFormatter)); try { if (outputFile == null) { log(writer.toString(), getLog()); } else { write(writer.toString(), outputFile); getLog().info("Wrote dependency tree to: " + outputFile); } } catch (IOException e) { throw new MojoExecutionException("Failed to write dependencies to file", e); } } catch (ArtifactDescriptorException e) { throw new MojoExecutionException("Failed to read artifact descriptor", e); } catch (DependencyCollectionException e) { throw new MojoExecutionException("Failed to collect dependencies", e); } }