Search in sources :

Example 1 with LocalArtifactResult

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

the class DefaultArtifactResolverTest method testFindInLocalRepositoryWhenVersionWasFoundInLocalRepository.

@Test
public void testFindInLocalRepositoryWhenVersionWasFoundInLocalRepository() 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(false);
            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);
            return result;
        }

        public void add(RepositorySystemSession session, LocalMetadataRegistration request) {
        }
    });
    ArtifactRequest request = new ArtifactRequest(artifact, null, "");
    request.addRepository(new RemoteRepository("id", "default", "file:///"));
    resolver.setVersionResolver(new VersionResolver() {

        public VersionResult resolveVersion(RepositorySystemSession session, VersionRequest request) throws VersionResolutionException {
            return new VersionResult(request).setRepository(new LocalRepository("id")).setVersion(request.getArtifact().getVersion());
        }
    });
    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) VersionRequest(org.sonatype.aether.resolution.VersionRequest) 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) VersionResolver(org.sonatype.aether.impl.VersionResolver) VersionResult(org.sonatype.aether.resolution.VersionResult) LocalRepositoryManager(org.sonatype.aether.repository.LocalRepositoryManager) TestLocalRepositoryManager(org.sonatype.aether.test.impl.TestLocalRepositoryManager) LocalMetadataResult(org.sonatype.aether.repository.LocalMetadataResult) VersionResolutionException(org.sonatype.aether.resolution.VersionResolutionException) LocalArtifactRequest(org.sonatype.aether.repository.LocalArtifactRequest) Test(org.junit.Test)

Example 2 with LocalArtifactResult

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

the class DefaultArtifactResolverTest method testFindInLocalRepositoryWhenVersionRangeWasResolvedFromLocalRepository.

@Test
public void testFindInLocalRepositoryWhenVersionRangeWasResolvedFromLocalRepository() 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(false);
            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);
            return result;
        }

        public void add(RepositorySystemSession session, LocalMetadataRegistration request) {
        }
    });
    ArtifactRequest request = new ArtifactRequest(artifact, null, "");
    resolver.setVersionResolver(new VersionResolver() {

        public VersionResult resolveVersion(RepositorySystemSession session, VersionRequest request) throws VersionResolutionException {
            return new VersionResult(request).setVersion(request.getArtifact().getVersion());
        }
    });
    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) VersionRequest(org.sonatype.aether.resolution.VersionRequest) 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) VersionResolver(org.sonatype.aether.impl.VersionResolver) VersionResult(org.sonatype.aether.resolution.VersionResult) LocalRepositoryManager(org.sonatype.aether.repository.LocalRepositoryManager) TestLocalRepositoryManager(org.sonatype.aether.test.impl.TestLocalRepositoryManager) LocalMetadataResult(org.sonatype.aether.repository.LocalMetadataResult) VersionResolutionException(org.sonatype.aether.resolution.VersionResolutionException) LocalArtifactRequest(org.sonatype.aether.repository.LocalArtifactRequest) Test(org.junit.Test)

Example 3 with LocalArtifactResult

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

the class EnhancedLocalRepositoryManagerTest method testFindLocalArtifact.

@Test
public void testFindLocalArtifact() throws Exception {
    addLocalArtifact(artifact);
    LocalArtifactRequest request = new LocalArtifactRequest(artifact, null, null);
    LocalArtifactResult result = manager.find(session, request);
    assertTrue(result.isAvailable());
}
Also used : LocalArtifactResult(org.sonatype.aether.repository.LocalArtifactResult) LocalArtifactRequest(org.sonatype.aether.repository.LocalArtifactRequest) Test(org.junit.Test)

Example 4 with LocalArtifactResult

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

the class EnhancedLocalRepositoryManagerTest method testFindUntrackedFile.

@Test
public void testFindUntrackedFile() throws Exception {
    copy(artifact, manager.getPathForLocalArtifact(artifact));
    LocalArtifactRequest request = new LocalArtifactRequest(artifact, Arrays.asList(repository), testContext);
    LocalArtifactResult result = manager.find(session, request);
    assertTrue(result.isAvailable());
}
Also used : LocalArtifactResult(org.sonatype.aether.repository.LocalArtifactResult) LocalArtifactRequest(org.sonatype.aether.repository.LocalArtifactRequest) Test(org.junit.Test)

Example 5 with LocalArtifactResult

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

the class EnhancedLocalRepositoryManager method find.

@Override
public LocalArtifactResult find(RepositorySystemSession session, LocalArtifactRequest request) {
    String path = getPathForArtifact(request.getArtifact(), false);
    File file = new File(getRepository().getBasedir(), path);
    LocalArtifactResult result = new LocalArtifactResult(request);
    if (file.isFile()) {
        result.setFile(file);
        Properties props = readRepos(file);
        if (props.get(getKey(file, LOCAL_REPO_ID)) != null) {
            result.setAvailable(true);
        } else {
            String context = request.getContext();
            for (RemoteRepository repository : request.getRepositories()) {
                if (props.get(getKey(file, getRepositoryKey(repository, context))) != null) {
                    result.setAvailable(true);
                    result.setRepository(repository);
                    break;
                }
            }
            if (!result.isAvailable() && !isTracked(props, file)) {
                /*
                     * NOTE: The artifact is present but not tracked at all, for inter-op with Maven 2.x, assume the
                     * artifact was locally installed.
                     */
                result.setAvailable(true);
            }
        }
    }
    return result;
}
Also used : LocalArtifactResult(org.sonatype.aether.repository.LocalArtifactResult) RemoteRepository(org.sonatype.aether.repository.RemoteRepository) Properties(java.util.Properties) File(java.io.File)

Aggregations

LocalArtifactResult (org.sonatype.aether.repository.LocalArtifactResult)15 LocalArtifactRequest (org.sonatype.aether.repository.LocalArtifactRequest)12 Test (org.junit.Test)11 Artifact (org.sonatype.aether.artifact.Artifact)7 File (java.io.File)6 RemoteRepository (org.sonatype.aether.repository.RemoteRepository)5 IOException (java.io.IOException)4 LocalArtifactRegistration (org.sonatype.aether.repository.LocalArtifactRegistration)4 LocalRepositoryManager (org.sonatype.aether.repository.LocalRepositoryManager)4 ArtifactRequest (org.sonatype.aether.resolution.ArtifactRequest)4 ArtifactResult (org.sonatype.aether.resolution.ArtifactResult)4 RepositorySystemSession (org.sonatype.aether.RepositorySystemSession)3 Metadata (org.sonatype.aether.metadata.Metadata)3 LocalMetadataRegistration (org.sonatype.aether.repository.LocalMetadataRegistration)3 LocalMetadataRequest (org.sonatype.aether.repository.LocalMetadataRequest)3 LocalMetadataResult (org.sonatype.aether.repository.LocalMetadataResult)3 LocalRepository (org.sonatype.aether.repository.LocalRepository)3 VersionRequest (org.sonatype.aether.resolution.VersionRequest)3 VersionResolutionException (org.sonatype.aether.resolution.VersionResolutionException)3 VersionResult (org.sonatype.aether.resolution.VersionResult)3