Search in sources :

Example 1 with WorkspaceRepository

use of org.sonatype.aether.repository.WorkspaceRepository in project sonatype-aether by sonatype.

the class DefaultArtifactResolverTest method testResolveFromWorkspace.

@Test
public void testResolveFromWorkspace() 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) {
                    try {
                        return TestFileUtils.createTempFile(artifact.toString());
                    } catch (IOException e) {
                        throw new RuntimeException(e.getMessage(), e);
                    }
                }
            };
        }
    };
    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());
    byte[] expected = resolved.toString().getBytes("UTF-8");
    TestFileUtils.assertContent(expected, resolved.getFile());
    resolved = resolved.setFile(null);
    assertEquals(artifact, resolved);
    connector.assertSeenExpected();
}
Also used : RemoteRepository(org.sonatype.aether.repository.RemoteRepository) IOException(java.io.IOException) WorkspaceReader(org.sonatype.aether.repository.WorkspaceReader) 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) 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) File(java.io.File) Test(org.junit.Test)

Example 2 with WorkspaceRepository

use of org.sonatype.aether.repository.WorkspaceRepository 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)

Aggregations

File (java.io.File)2 List (java.util.List)2 Test (org.junit.Test)2 Artifact (org.sonatype.aether.artifact.Artifact)2 LocalArtifactRequest (org.sonatype.aether.repository.LocalArtifactRequest)2 LocalArtifactResult (org.sonatype.aether.repository.LocalArtifactResult)2 RemoteRepository (org.sonatype.aether.repository.RemoteRepository)2 WorkspaceReader (org.sonatype.aether.repository.WorkspaceReader)2 WorkspaceRepository (org.sonatype.aether.repository.WorkspaceRepository)2 ArtifactRequest (org.sonatype.aether.resolution.ArtifactRequest)2 ArtifactResult (org.sonatype.aether.resolution.ArtifactResult)2 TestRepositorySystemSession (org.sonatype.aether.test.impl.TestRepositorySystemSession)2 StubArtifact (org.sonatype.aether.test.util.impl.StubArtifact)2 IOException (java.io.IOException)1