Search in sources :

Example 1 with LocalRepositoryManager

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

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

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

the class DefaultInstaller method install.

private void install(RepositorySystemSession session, RequestTrace trace, Artifact artifact) throws InstallationException {
    LocalRepositoryManager lrm = session.getLocalRepositoryManager();
    File srcFile = artifact.getFile();
    File dstFile = new File(lrm.getRepository().getBasedir(), lrm.getPathForLocalArtifact(artifact));
    artifactInstalling(session, trace, artifact, dstFile);
    Exception exception = null;
    try {
        boolean copy = "pom".equals(artifact.getExtension()) || srcFile.lastModified() != dstFile.lastModified() || srcFile.length() != dstFile.length();
        if (copy) {
            fileProcessor.copy(srcFile, dstFile, null);
            dstFile.setLastModified(srcFile.lastModified());
        } else {
            logger.debug("Skipped re-installing " + srcFile + " to " + dstFile + ", seems unchanged");
        }
        lrm.add(session, new LocalArtifactRegistration(artifact));
    } catch (Exception e) {
        exception = e;
        throw new InstallationException("Failed to install artifact " + artifact + ": " + e.getMessage(), e);
    } finally {
        artifactInstalled(session, trace, artifact, dstFile, exception);
    }
}
Also used : LocalArtifactRegistration(org.sonatype.aether.repository.LocalArtifactRegistration) InstallationException(org.sonatype.aether.installation.InstallationException) LocalRepositoryManager(org.sonatype.aether.repository.LocalRepositoryManager) File(java.io.File) InstallationException(org.sonatype.aether.installation.InstallationException)

Example 4 with LocalRepositoryManager

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

the class DefaultMetadataResolver method getLocalFile.

private File getLocalFile(RepositorySystemSession session, Metadata metadata) {
    LocalRepositoryManager lrm = session.getLocalRepositoryManager();
    LocalMetadataResult localResult = lrm.find(session, new LocalMetadataRequest(metadata, null, null));
    File localFile = localResult.getFile();
    return localFile;
}
Also used : LocalMetadataRequest(org.sonatype.aether.repository.LocalMetadataRequest) LocalRepositoryManager(org.sonatype.aether.repository.LocalRepositoryManager) LocalMetadataResult(org.sonatype.aether.repository.LocalMetadataResult) File(java.io.File)

Example 5 with LocalRepositoryManager

use of org.sonatype.aether.repository.LocalRepositoryManager in project intellij-community by JetBrains.

the class Maven30ServerEmbedderImpl method resolveDependencies.

/**
   * copied from {@link DefaultProjectBuilder#resolveDependencies(MavenProject, RepositorySystemSession)}
   */
private DependencyResolutionResult resolveDependencies(MavenProject project, RepositorySystemSession session) {
    DependencyResolutionResult resolutionResult;
    try {
        ProjectDependenciesResolver dependencyResolver = getComponent(ProjectDependenciesResolver.class);
        DefaultDependencyResolutionRequest resolution = new DefaultDependencyResolutionRequest(project, session);
        resolutionResult = dependencyResolver.resolve(resolution);
    } catch (DependencyResolutionException e) {
        resolutionResult = e.getResult();
    }
    Set<Artifact> artifacts = new LinkedHashSet<Artifact>();
    if (resolutionResult.getDependencyGraph() != null) {
        RepositoryUtils.toArtifacts(artifacts, resolutionResult.getDependencyGraph().getChildren(), Collections.singletonList(project.getArtifact().getId()), null);
        // Maven 2.x quirk: an artifact always points at the local repo, regardless whether resolved or not
        LocalRepositoryManager lrm = session.getLocalRepositoryManager();
        for (Artifact artifact : artifacts) {
            if (!artifact.isResolved()) {
                String path = lrm.getPathForLocalArtifact(RepositoryUtils.toArtifact(artifact));
                artifact.setFile(new File(lrm.getRepository().getBasedir(), path));
            }
        }
    }
    project.setResolvedArtifacts(artifacts);
    project.setArtifacts(artifacts);
    return resolutionResult;
}
Also used : LocalRepositoryManager(org.sonatype.aether.repository.LocalRepositoryManager) ProjectDependenciesResolver(org.apache.maven.project.ProjectDependenciesResolver) File(java.io.File) Artifact(org.apache.maven.artifact.Artifact)

Aggregations

LocalRepositoryManager (org.sonatype.aether.repository.LocalRepositoryManager)12 File (java.io.File)8 IOException (java.io.IOException)5 Metadata (org.sonatype.aether.metadata.Metadata)5 LocalArtifactRegistration (org.sonatype.aether.repository.LocalArtifactRegistration)5 LocalMetadataRequest (org.sonatype.aether.repository.LocalMetadataRequest)5 LocalMetadataResult (org.sonatype.aether.repository.LocalMetadataResult)5 RemoteRepository (org.sonatype.aether.repository.RemoteRepository)5 ArtifactRequest (org.sonatype.aether.resolution.ArtifactRequest)5 ArtifactResult (org.sonatype.aether.resolution.ArtifactResult)5 Artifact (org.sonatype.aether.artifact.Artifact)4 LocalArtifactRequest (org.sonatype.aether.repository.LocalArtifactRequest)4 LocalArtifactResult (org.sonatype.aether.repository.LocalArtifactResult)4 LocalMetadataRegistration (org.sonatype.aether.repository.LocalMetadataRegistration)4 LocalRepository (org.sonatype.aether.repository.LocalRepository)4 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 RepositorySystemSession (org.sonatype.aether.RepositorySystemSession)3 UpdateCheck (org.sonatype.aether.impl.UpdateCheck)3 RepositoryPolicy (org.sonatype.aether.repository.RepositoryPolicy)3