Search in sources :

Example 6 with LocalRepositoryManager

use of org.eclipse.aether.repository.LocalRepositoryManager in project spring-boot by spring-projects.

the class GrapeRootRepositorySystemSessionAutoConfiguration method configureLocalRepository.

private void configureLocalRepository(DefaultRepositorySystemSession session, RepositorySystem repositorySystem, String grapeRoot) {
    File repositoryDir = new File(grapeRoot, "repository");
    LocalRepository localRepository = new LocalRepository(repositoryDir);
    LocalRepositoryManager localRepositoryManager = repositorySystem.newLocalRepositoryManager(session, localRepository);
    session.setLocalRepositoryManager(localRepositoryManager);
}
Also used : LocalRepositoryManager(org.eclipse.aether.repository.LocalRepositoryManager) LocalRepository(org.eclipse.aether.repository.LocalRepository) File(java.io.File)

Example 7 with LocalRepositoryManager

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

the class Maven3ServerEmbedderImpl method resolveDependencies.

/**
   * copied from {@link DefaultProjectBuilder#resolveDependencies(MavenProject, org.sonatype.aether.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.eclipse.aether.repository.LocalRepositoryManager) ProjectDependenciesResolver(org.apache.maven.project.ProjectDependenciesResolver) File(java.io.File) Artifact(org.apache.maven.artifact.Artifact)

Example 8 with LocalRepositoryManager

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

the class CustomMaven3ArtifactResolver method resolveOld.

private void resolveOld(Artifact artifact, List<ArtifactRepository> remoteRepositories, RepositorySystemSession session) throws ArtifactResolutionException, ArtifactNotFoundException {
    if (artifact == null) {
        return;
    }
    if (Artifact.SCOPE_SYSTEM.equals(artifact.getScope())) {
        File systemFile = artifact.getFile();
        if (systemFile == null) {
            throw new ArtifactNotFoundException("System artifact: " + artifact + " has no file attached", artifact);
        }
        if (!systemFile.exists()) {
            throw new ArtifactNotFoundException("System artifact: " + artifact + " not found in path: " + systemFile, artifact);
        }
        if (!systemFile.isFile()) {
            throw new ArtifactNotFoundException("System artifact: " + artifact + " is not a file: " + systemFile, artifact);
        }
        artifact.setResolved(true);
        return;
    }
    if (!artifact.isResolved()) {
        ArtifactResult result;
        try {
            ArtifactRequest artifactRequest = new ArtifactRequest();
            artifactRequest.setArtifact(RepositoryUtils.toArtifact(artifact));
            artifactRequest.setRepositories(RepositoryUtils.toRepos(remoteRepositories));
            // Maven 2.x quirk: an artifact always points at the local repo, regardless whether resolved or not
            LocalRepositoryManager lrm = session.getLocalRepositoryManager();
            String path = lrm.getPathForLocalArtifact(artifactRequest.getArtifact());
            artifact.setFile(new File(lrm.getRepository().getBasedir(), path));
            result = repoSystem.resolveArtifact(session, artifactRequest);
        } catch (org.eclipse.aether.resolution.ArtifactResolutionException e) {
            if (e.getCause() instanceof org.eclipse.aether.transfer.ArtifactNotFoundException) {
                throw new ArtifactNotFoundException(e.getMessage(), artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact.getType(), artifact.getClassifier(), remoteRepositories, artifact.getDownloadUrl(), artifact.getDependencyTrail(), e);
            } else {
                throw new ArtifactResolutionException(e.getMessage(), artifact, remoteRepositories, e);
            }
        }
        artifact.selectVersion(result.getArtifact().getVersion());
        artifact.setFile(result.getArtifact().getFile());
        artifact.setResolved(true);
        if (artifact.isSnapshot()) {
            Matcher matcher = Artifact.VERSION_FILE_PATTERN.matcher(artifact.getVersion());
            if (matcher.matches()) {
                Snapshot snapshot = new Snapshot();
                snapshot.setTimestamp(matcher.group(2));
                try {
                    snapshot.setBuildNumber(Integer.parseInt(matcher.group(3)));
                    artifact.addMetadata(new SnapshotArtifactRepositoryMetadata(artifact, snapshot));
                } catch (NumberFormatException e) {
                    logger.warn("Invalid artifact version " + artifact.getVersion() + ": " + e.getMessage());
                }
            }
        }
    }
}
Also used : Matcher(java.util.regex.Matcher) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult) Snapshot(org.apache.maven.artifact.repository.metadata.Snapshot) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) LocalRepositoryManager(org.eclipse.aether.repository.LocalRepositoryManager) LegacyLocalRepositoryManager(org.apache.maven.artifact.repository.LegacyLocalRepositoryManager) SnapshotArtifactRepositoryMetadata(org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata) File(java.io.File)

Aggregations

LocalRepositoryManager (org.eclipse.aether.repository.LocalRepositoryManager)8 File (java.io.File)6 LocalRepository (org.eclipse.aether.repository.LocalRepository)3 ArtifactRequest (org.eclipse.aether.resolution.ArtifactRequest)3 ArtifactResult (org.eclipse.aether.resolution.ArtifactResult)3 Matcher (java.util.regex.Matcher)2 LegacyLocalRepositoryManager (org.apache.maven.artifact.repository.LegacyLocalRepositoryManager)2 Snapshot (org.apache.maven.artifact.repository.metadata.Snapshot)2 SnapshotArtifactRepositoryMetadata (org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata)2 Artifact (org.apache.maven.artifact.Artifact)1 AbstractArtifactResolutionException (org.apache.maven.artifact.resolver.AbstractArtifactResolutionException)1 ArtifactNotFoundException (org.apache.maven.artifact.resolver.ArtifactNotFoundException)1 ArtifactResolutionException (org.apache.maven.artifact.resolver.ArtifactResolutionException)1 ProjectDependenciesResolver (org.apache.maven.project.ProjectDependenciesResolver)1 DefaultRepositorySystemSession (org.eclipse.aether.DefaultRepositorySystemSession)1 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)1 SimpleLocalRepositoryManagerFactory (org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory)1 ProxySelector (org.eclipse.aether.repository.ProxySelector)1 ArtifactResolutionException (org.eclipse.aether.resolution.ArtifactResolutionException)1 JreProxySelector (org.eclipse.aether.util.repository.JreProxySelector)1