Search in sources :

Example 16 with ArtifactResult

use of org.sonatype.aether.resolution.ArtifactResult in project sonatype-aether by sonatype.

the class DefaultRepositorySystem method resolveDependencies.

public List<ArtifactResult> resolveDependencies(RepositorySystemSession session, DependencyNode node, DependencyFilter filter) throws ArtifactResolutionException {
    validateSession(session);
    RequestTrace trace = DefaultRequestTrace.newChild(null, node);
    ArtifactRequestBuilder builder = new ArtifactRequestBuilder(trace);
    DependencyVisitor visitor = (filter != null) ? new FilteringDependencyVisitor(builder, filter) : builder;
    visitor = new TreeDependencyVisitor(visitor);
    node.accept(visitor);
    List<ArtifactRequest> requests = builder.getRequests();
    try {
        List<ArtifactResult> results = resolveArtifacts(session, requests);
        updateNodesWithResolvedArtifacts(results);
        return results;
    } catch (ArtifactResolutionException e) {
        updateNodesWithResolvedArtifacts(e.getResults());
        throw e;
    }
}
Also used : ArtifactResolutionException(org.sonatype.aether.resolution.ArtifactResolutionException) FilteringDependencyVisitor(org.sonatype.aether.util.graph.FilteringDependencyVisitor) ArtifactRequest(org.sonatype.aether.resolution.ArtifactRequest) DependencyVisitor(org.sonatype.aether.graph.DependencyVisitor) FilteringDependencyVisitor(org.sonatype.aether.util.graph.FilteringDependencyVisitor) TreeDependencyVisitor(org.sonatype.aether.util.graph.TreeDependencyVisitor) TreeDependencyVisitor(org.sonatype.aether.util.graph.TreeDependencyVisitor) RequestTrace(org.sonatype.aether.RequestTrace) DefaultRequestTrace(org.sonatype.aether.util.DefaultRequestTrace) ArtifactResult(org.sonatype.aether.resolution.ArtifactResult)

Example 17 with ArtifactResult

use of org.sonatype.aether.resolution.ArtifactResult in project sonatype-aether by sonatype.

the class DefaultArtifactResolverTest method testResolveFromWorkspaceFallbackToRepository.

@Test
public void testResolveFromWorkspaceFallbackToRepository() throws IOException, ArtifactResolutionException {
    session = new TestRepositorySystemSession() {

        @Override
        public WorkspaceReader getWorkspaceReader() {
            return new WorkspaceReader() {

                public WorkspaceRepository getRepository() {
                    return new WorkspaceRepository("default");
                }

                public List<String> findVersions(Artifact artifact) {
                    return Arrays.asList(artifact.getVersion());
                }

                public File findArtifact(Artifact artifact) {
                    return null;
                }
            };
        }
    };
    connector.setExpectGet(artifact);
    remoteRepositoryManager.setConnector(connector);
    ArtifactRequest request = new ArtifactRequest(artifact, null, "");
    request.addRepository(new RemoteRepository("id", "default", "file:///"));
    ArtifactResult result = resolver.resolveArtifact(session, request);
    assertTrue("exception on resolveArtifact", result.getExceptions().isEmpty());
    Artifact resolved = result.getArtifact();
    assertNotNull(resolved.getFile());
    resolved = resolved.setFile(null);
    assertEquals(artifact, resolved);
    connector.assertSeenExpected();
}
Also used : TestRepositorySystemSession(org.sonatype.aether.test.impl.TestRepositorySystemSession) ArtifactRequest(org.sonatype.aether.resolution.ArtifactRequest) LocalArtifactRequest(org.sonatype.aether.repository.LocalArtifactRequest) WorkspaceRepository(org.sonatype.aether.repository.WorkspaceRepository) List(java.util.List) RemoteRepository(org.sonatype.aether.repository.RemoteRepository) WorkspaceReader(org.sonatype.aether.repository.WorkspaceReader) File(java.io.File) StubArtifact(org.sonatype.aether.test.util.impl.StubArtifact) Artifact(org.sonatype.aether.artifact.Artifact) LocalArtifactResult(org.sonatype.aether.repository.LocalArtifactResult) ArtifactResult(org.sonatype.aether.resolution.ArtifactResult) Test(org.junit.Test)

Example 18 with ArtifactResult

use of org.sonatype.aether.resolution.ArtifactResult in project sonatype-aether by sonatype.

the class DefaultArtifactResolverTest method testResolveRemoteArtifact.

@Test
public void testResolveRemoteArtifact() throws IOException, ArtifactResolutionException {
    connector.setExpectGet(artifact);
    ArtifactRequest request = new ArtifactRequest(artifact, null, "");
    request.addRepository(new RemoteRepository("id", "default", "file:///"));
    ArtifactResult result = resolver.resolveArtifact(session, request);
    assertTrue(result.getExceptions().isEmpty());
    Artifact resolved = result.getArtifact();
    assertNotNull(resolved.getFile());
    resolved = resolved.setFile(null);
    assertEquals(artifact, resolved);
    connector.assertSeenExpected();
}
Also used : ArtifactRequest(org.sonatype.aether.resolution.ArtifactRequest) LocalArtifactRequest(org.sonatype.aether.repository.LocalArtifactRequest) RemoteRepository(org.sonatype.aether.repository.RemoteRepository) StubArtifact(org.sonatype.aether.test.util.impl.StubArtifact) Artifact(org.sonatype.aether.artifact.Artifact) LocalArtifactResult(org.sonatype.aether.repository.LocalArtifactResult) ArtifactResult(org.sonatype.aether.resolution.ArtifactResult) Test(org.junit.Test)

Example 19 with ArtifactResult

use of org.sonatype.aether.resolution.ArtifactResult in project sonatype-aether by sonatype.

the class DefaultArtifactResolverTest method testLocalArtifactAvailable.

@Test
public void testLocalArtifactAvailable() throws ArtifactResolutionException {
    session.setLocalRepositoryManager(new LocalRepositoryManager() {

        public LocalRepository getRepository() {
            return null;
        }

        public String getPathForRemoteMetadata(Metadata metadata, RemoteRepository repository, String context) {
            return null;
        }

        public String getPathForRemoteArtifact(Artifact artifact, RemoteRepository repository, String context) {
            return null;
        }

        public String getPathForLocalMetadata(Metadata metadata) {
            return null;
        }

        public String getPathForLocalArtifact(Artifact artifact) {
            return null;
        }

        public LocalArtifactResult find(RepositorySystemSession session, LocalArtifactRequest request) {
            LocalArtifactResult result = new LocalArtifactResult(request);
            result.setAvailable(true);
            try {
                result.setFile(TestFileUtils.createTempFile(""));
            } catch (IOException e) {
                e.printStackTrace();
            }
            return result;
        }

        public void add(RepositorySystemSession session, LocalArtifactRegistration request) {
        }

        public LocalMetadataResult find(RepositorySystemSession session, LocalMetadataRequest request) {
            LocalMetadataResult result = new LocalMetadataResult(request);
            try {
                result.setFile(TestFileUtils.createTempFile(""));
            } catch (IOException e) {
                e.printStackTrace();
            }
            return result;
        }

        public void add(RepositorySystemSession session, LocalMetadataRegistration request) {
        }
    });
    ArtifactRequest request = new ArtifactRequest(artifact, null, "");
    request.addRepository(new RemoteRepository("id", "default", "file:///"));
    ArtifactResult result = resolver.resolveArtifact(session, request);
    assertTrue(result.getExceptions().isEmpty());
    Artifact resolved = result.getArtifact();
    assertNotNull(resolved.getFile());
    resolved = resolved.setFile(null);
    assertEquals(artifact, resolved);
}
Also used : RepositorySystemSession(org.sonatype.aether.RepositorySystemSession) TestRepositorySystemSession(org.sonatype.aether.test.impl.TestRepositorySystemSession) LocalArtifactRegistration(org.sonatype.aether.repository.LocalArtifactRegistration) LocalMetadataRequest(org.sonatype.aether.repository.LocalMetadataRequest) LocalArtifactResult(org.sonatype.aether.repository.LocalArtifactResult) LocalMetadataRegistration(org.sonatype.aether.repository.LocalMetadataRegistration) LocalRepository(org.sonatype.aether.repository.LocalRepository) Metadata(org.sonatype.aether.metadata.Metadata) RemoteRepository(org.sonatype.aether.repository.RemoteRepository) IOException(java.io.IOException) StubArtifact(org.sonatype.aether.test.util.impl.StubArtifact) Artifact(org.sonatype.aether.artifact.Artifact) LocalArtifactResult(org.sonatype.aether.repository.LocalArtifactResult) ArtifactResult(org.sonatype.aether.resolution.ArtifactResult) ArtifactRequest(org.sonatype.aether.resolution.ArtifactRequest) LocalArtifactRequest(org.sonatype.aether.repository.LocalArtifactRequest) LocalRepositoryManager(org.sonatype.aether.repository.LocalRepositoryManager) TestLocalRepositoryManager(org.sonatype.aether.test.impl.TestLocalRepositoryManager) LocalMetadataResult(org.sonatype.aether.repository.LocalMetadataResult) LocalArtifactRequest(org.sonatype.aether.repository.LocalArtifactRequest) Test(org.junit.Test)

Example 20 with ArtifactResult

use of org.sonatype.aether.resolution.ArtifactResult in project sonatype-aether by sonatype.

the class DefaultArtifactResolverTest method testArtifactNotFoundCache.

@Test
public void testArtifactNotFoundCache() throws Exception {
    RecordingRepositoryConnector connector = new RecordingRepositoryConnector() {

        @Override
        public void get(Collection<? extends ArtifactDownload> artifactDownloads, Collection<? extends MetadataDownload> metadataDownloads) {
            super.get(artifactDownloads, metadataDownloads);
            for (ArtifactDownload download : artifactDownloads) {
                download.getFile().delete();
                ArtifactTransferException exception = new ArtifactNotFoundException(download.getArtifact(), null, "not found");
                download.setException(exception);
            }
        }
    };
    remoteRepositoryManager.setConnector(connector);
    resolver.setUpdateCheckManager(new DefaultUpdateCheckManager());
    session.setNotFoundCachingEnabled(true);
    session.setUpdatePolicy(RepositoryPolicy.UPDATE_POLICY_NEVER);
    RemoteRepository remoteRepo = new RemoteRepository("id", "default", "file:///");
    Artifact artifact1 = artifact;
    Artifact artifact2 = artifact.setVersion("ver2");
    ArtifactRequest request1 = new ArtifactRequest(artifact1, Arrays.asList(remoteRepo), "");
    ArtifactRequest request2 = new ArtifactRequest(artifact2, Arrays.asList(remoteRepo), "");
    connector.setExpectGet(new Artifact[] { artifact1, artifact2 });
    try {
        resolver.resolveArtifacts(session, Arrays.asList(request1, request2));
        fail("expected exception");
    } catch (ArtifactResolutionException e) {
        connector.assertSeenExpected();
    }
    TestFileUtils.write("artifact", new File(lrm.getRepository().getBasedir(), lrm.getPathForLocalArtifact(artifact2)));
    lrm.setArtifactAvailability(artifact2, false);
    DefaultUpdateCheckManagerTest.resetSessionData(session);
    connector.resetActual();
    connector.setExpectGet(new Artifact[0]);
    try {
        resolver.resolveArtifacts(session, Arrays.asList(request1, request2));
        fail("expected exception");
    } catch (ArtifactResolutionException e) {
        connector.assertSeenExpected();
        for (ArtifactResult result : e.getResults()) {
            Throwable t = result.getExceptions().get(0);
            assertEquals(t.toString(), true, t instanceof ArtifactNotFoundException);
            assertEquals(t.toString(), true, t.getMessage().contains("cached"));
        }
    }
}
Also used : RemoteRepository(org.sonatype.aether.repository.RemoteRepository) StubArtifact(org.sonatype.aether.test.util.impl.StubArtifact) Artifact(org.sonatype.aether.artifact.Artifact) LocalArtifactResult(org.sonatype.aether.repository.LocalArtifactResult) ArtifactResult(org.sonatype.aether.resolution.ArtifactResult) ArtifactResolutionException(org.sonatype.aether.resolution.ArtifactResolutionException) ArtifactTransferException(org.sonatype.aether.transfer.ArtifactTransferException) ArtifactRequest(org.sonatype.aether.resolution.ArtifactRequest) LocalArtifactRequest(org.sonatype.aether.repository.LocalArtifactRequest) ArtifactDownload(org.sonatype.aether.spi.connector.ArtifactDownload) Collection(java.util.Collection) MetadataDownload(org.sonatype.aether.spi.connector.MetadataDownload) ArtifactNotFoundException(org.sonatype.aether.transfer.ArtifactNotFoundException) File(java.io.File) Test(org.junit.Test)

Aggregations

ArtifactResult (org.sonatype.aether.resolution.ArtifactResult)24 ArtifactRequest (org.sonatype.aether.resolution.ArtifactRequest)18 Artifact (org.sonatype.aether.artifact.Artifact)17 Test (org.junit.Test)12 LocalArtifactRequest (org.sonatype.aether.repository.LocalArtifactRequest)12 LocalArtifactResult (org.sonatype.aether.repository.LocalArtifactResult)12 RemoteRepository (org.sonatype.aether.repository.RemoteRepository)12 StubArtifact (org.sonatype.aether.test.util.impl.StubArtifact)11 File (java.io.File)9 ArtifactResolutionException (org.sonatype.aether.resolution.ArtifactResolutionException)9 RepositorySystemSession (org.sonatype.aether.RepositorySystemSession)6 TestRepositorySystemSession (org.sonatype.aether.test.impl.TestRepositorySystemSession)6 DefaultArtifact (org.sonatype.aether.util.artifact.DefaultArtifact)6 IOException (java.io.IOException)5 LocalRepositoryManager (org.sonatype.aether.repository.LocalRepositoryManager)5 LocalArtifactRegistration (org.sonatype.aether.repository.LocalArtifactRegistration)4 VersionRequest (org.sonatype.aether.resolution.VersionRequest)4 VersionResolutionException (org.sonatype.aether.resolution.VersionResolutionException)4 VersionResult (org.sonatype.aether.resolution.VersionResult)4 ArtifactNotFoundException (org.sonatype.aether.transfer.ArtifactNotFoundException)4