Search in sources :

Example 1 with MetadataRequest

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

the class DefaultMetadataResolverTest method testOfflineSessionResolveMetadata.

@Test
public void testOfflineSessionResolveMetadata() throws IOException {
    session.setOffline(true);
    String path = session.getLocalRepositoryManager().getPathForRemoteMetadata(metadata, repository, "");
    File file = new File(session.getLocalRepository().getBasedir(), path);
    TestFileUtils.write(file.getAbsolutePath(), file);
    // set file to use in TestLRM find()
    metadata = metadata.setFile(file);
    MetadataRequest request = new MetadataRequest(metadata, repository, "");
    List<MetadataResult> results = resolver.resolveMetadata(session, Arrays.asList(request));
    assertEquals(1, results.size());
    MetadataResult result = results.get(0);
    assertSame(request, result.getRequest());
    assertNull(String.valueOf(result.getException()), result.getException());
    assertNotNull(result.getMetadata());
    assertNotNull(result.getMetadata().getFile());
    assertEquals(file, result.getMetadata().getFile());
    assertEquals(metadata.setFile(null), result.getMetadata().setFile(null));
    connector.assertSeenExpected();
}
Also used : MetadataRequest(org.sonatype.aether.resolution.MetadataRequest) File(java.io.File) MetadataResult(org.sonatype.aether.resolution.MetadataResult) Test(org.junit.Test)

Example 2 with MetadataRequest

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

the class DefaultMetadataResolverTest method testResolve.

@Test
public void testResolve() throws IOException {
    connector.setExpectGet(metadata);
    // prepare "download"
    File file = new File(session.getLocalRepository().getBasedir(), session.getLocalRepositoryManager().getPathForRemoteMetadata(metadata, repository, ""));
    TestFileUtils.write(file.getAbsolutePath(), file);
    MetadataRequest request = new MetadataRequest(metadata, repository, "");
    List<MetadataResult> results = resolver.resolveMetadata(session, Arrays.asList(request));
    assertEquals(1, results.size());
    MetadataResult result = results.get(0);
    assertSame(request, result.getRequest());
    assertNull(result.getException());
    assertNotNull(result.getMetadata());
    assertNotNull(result.getMetadata().getFile());
    assertEquals(file, result.getMetadata().getFile());
    assertEquals(metadata, result.getMetadata().setFile(null));
    connector.assertSeenExpected();
    Set<Metadata> metadataRegistration = ((TestLocalRepositoryManager) session.getLocalRepositoryManager()).getMetadataRegistration();
    assertTrue(metadataRegistration.contains(metadata));
    assertEquals(1, metadataRegistration.size());
}
Also used : TestLocalRepositoryManager(org.sonatype.aether.test.impl.TestLocalRepositoryManager) MetadataRequest(org.sonatype.aether.resolution.MetadataRequest) StubMetadata(org.sonatype.aether.test.util.impl.StubMetadata) Metadata(org.sonatype.aether.metadata.Metadata) File(java.io.File) MetadataResult(org.sonatype.aether.resolution.MetadataResult) Test(org.junit.Test)

Example 3 with MetadataRequest

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

the class DefaultMetadataResolverTest method testRemoveMetadataIfMissing.

@Test
public void testRemoveMetadataIfMissing() throws IOException {
    connector = new RecordingRepositoryConnector() {

        @Override
        public void get(Collection<? extends ArtifactDownload> artifactDownloads, Collection<? extends MetadataDownload> metadataDownloads) {
            super.get(artifactDownloads, metadataDownloads);
            for (MetadataDownload d : metadataDownloads) {
                d.setException(new MetadataNotFoundException(metadata, repository));
            }
        }
    };
    manager.setConnector(connector);
    File file = new File(session.getLocalRepository().getBasedir(), session.getLocalRepositoryManager().getPathForRemoteMetadata(metadata, repository, ""));
    TestFileUtils.write(file.getAbsolutePath(), file);
    metadata.setFile(file);
    MetadataRequest request = new MetadataRequest(metadata, repository, "");
    request.setDeleteLocalCopyIfMissing(true);
    List<MetadataResult> results = resolver.resolveMetadata(session, Arrays.asList(request));
    assertEquals(1, results.size());
    MetadataResult result = results.get(0);
    assertNotNull(result.getException());
    assertEquals(false, file.exists());
}
Also used : MetadataNotFoundException(org.sonatype.aether.transfer.MetadataNotFoundException) MetadataRequest(org.sonatype.aether.resolution.MetadataRequest) MetadataDownload(org.sonatype.aether.spi.connector.MetadataDownload) File(java.io.File) MetadataResult(org.sonatype.aether.resolution.MetadataResult) Test(org.junit.Test)

Example 4 with MetadataRequest

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

the class DefaultMetadataResolverTest method testNoRepositoryFailing.

@Test
public void testNoRepositoryFailing() {
    MetadataRequest request = new MetadataRequest(metadata, null, "");
    List<MetadataResult> results = resolver.resolveMetadata(session, Arrays.asList(request));
    assertEquals(1, results.size());
    MetadataResult result = results.get(0);
    assertSame(request, result.getRequest());
    assertNotNull("" + (result.getMetadata() != null ? result.getMetadata().getFile() : result.getMetadata()), result.getException());
    assertEquals(MetadataNotFoundException.class, result.getException().getClass());
    assertNull(result.getMetadata());
}
Also used : MetadataRequest(org.sonatype.aether.resolution.MetadataRequest) MetadataResult(org.sonatype.aether.resolution.MetadataResult) Test(org.junit.Test)

Example 5 with MetadataRequest

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

the class DefaultMetadataResolver method resolveMetadata.

public List<MetadataResult> resolveMetadata(RepositorySystemSession session, Collection<? extends MetadataRequest> requests) {
    SyncContext syncContext = syncContextFactory.newInstance(session, false);
    try {
        Collection<Metadata> metadata = new ArrayList<Metadata>(requests.size());
        for (MetadataRequest request : requests) {
            metadata.add(request.getMetadata());
        }
        syncContext.acquire(null, metadata);
        return resolve(session, requests);
    } finally {
        syncContext.release();
    }
}
Also used : MetadataRequest(org.sonatype.aether.resolution.MetadataRequest) LocalMetadataRequest(org.sonatype.aether.repository.LocalMetadataRequest) Metadata(org.sonatype.aether.metadata.Metadata) ArrayList(java.util.ArrayList) SyncContext(org.sonatype.aether.SyncContext)

Aggregations

MetadataRequest (org.sonatype.aether.resolution.MetadataRequest)8 MetadataResult (org.sonatype.aether.resolution.MetadataResult)7 Test (org.junit.Test)6 File (java.io.File)5 Metadata (org.sonatype.aether.metadata.Metadata)3 ArrayList (java.util.ArrayList)2 LocalMetadataRequest (org.sonatype.aether.repository.LocalMetadataRequest)2 MetadataNotFoundException (org.sonatype.aether.transfer.MetadataNotFoundException)2 HashMap (java.util.HashMap)1 Executor (java.util.concurrent.Executor)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1 RepositorySystemSession (org.sonatype.aether.RepositorySystemSession)1 RequestTrace (org.sonatype.aether.RequestTrace)1 SyncContext (org.sonatype.aether.SyncContext)1 UpdateCheck (org.sonatype.aether.impl.UpdateCheck)1 LocalMetadataRegistration (org.sonatype.aether.repository.LocalMetadataRegistration)1 LocalMetadataResult (org.sonatype.aether.repository.LocalMetadataResult)1 LocalRepository (org.sonatype.aether.repository.LocalRepository)1 LocalRepositoryManager (org.sonatype.aether.repository.LocalRepositoryManager)1 RemoteRepository (org.sonatype.aether.repository.RemoteRepository)1