Search in sources :

Example 1 with RemoteRepository

use of org.eclipse.aether.repository.RemoteRepository in project buck by facebook.

the class Resolver method resolve.

public void resolve(Collection<String> artifacts) throws RepositoryException, ExecutionException, InterruptedException, IOException {
    ImmutableList.Builder<RemoteRepository> repoBuilder = ImmutableList.builder();
    ImmutableMap.Builder<String, Dependency> dependencyBuilder = ImmutableMap.builder();
    repoBuilder.addAll(repos);
    for (String artifact : artifacts) {
        if (artifact.endsWith(".pom")) {
            Model model = loadPomModel(Paths.get(artifact));
            repoBuilder.addAll(getReposFromPom(model));
            for (Dependency dep : getDependenciesFromPom(model)) {
                dependencyBuilder.put(buildKey(dep.getArtifact()), dep);
            }
        } else {
            Dependency dep = getDependencyFromString(artifact);
            dependencyBuilder.put(buildKey(dep.getArtifact()), dep);
        }
    }
    repos = repoBuilder.build();
    ImmutableMap<String, Dependency> specifiedDependencies = dependencyBuilder.build();
    ImmutableMap<String, Artifact> knownDeps = getRunTimeTransitiveDeps(specifiedDependencies.values());
    // We now have the complete set of dependencies. Build the graph of dependencies. We'd like
    // aether to do this for us, but it doesn't preserve the complete dependency information we need
    // to accurately construct build files.
    final MutableDirectedGraph<Artifact> graph = buildDependencyGraph(knownDeps);
    // Now we have the graph, grab the sources and jars for each dependency, as well as the relevant
    // checksums (which are download by default. Yay!)
    ImmutableSetMultimap<Path, Prebuilt> downloadedArtifacts = downloadArtifacts(graph, specifiedDependencies);
    createBuckFiles(downloadedArtifacts);
}
Also used : Path(java.nio.file.Path) ImmutableList(com.google.common.collect.ImmutableList) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) STGroupString(org.stringtemplate.v4.STGroupString) Dependency(org.eclipse.aether.graph.Dependency) ImmutableMap(com.google.common.collect.ImmutableMap) SubArtifact(org.eclipse.aether.util.artifact.SubArtifact) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Model(org.apache.maven.model.Model)

Example 2 with RemoteRepository

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

the class AetherGrapeEngine method addResolver.

@Override
public void addResolver(Map<String, Object> args) {
    String name = (String) args.get("name");
    String root = (String) args.get("root");
    RemoteRepository.Builder builder = new RemoteRepository.Builder(name, "default", root);
    RemoteRepository repository = builder.build();
    addRepository(repository);
}
Also used : RemoteRepository(org.eclipse.aether.repository.RemoteRepository)

Example 3 with RemoteRepository

use of org.eclipse.aether.repository.RemoteRepository in project bazel by bazelbuild.

the class MavenDownloader method download.

/**
   * Download the Maven artifact to the output directory. Returns the path to the jar.
   */
public Path download(String name, WorkspaceAttributeMapper mapper, Path outputDirectory, MavenServerValue serverValue) throws IOException, EvalException {
    this.name = name;
    this.outputDirectory = outputDirectory;
    String url = serverValue.getUrl();
    Server server = serverValue.getServer();
    Artifact artifact;
    String artifactId = mapper.get("artifact", Type.STRING);
    String sha1 = mapper.isAttributeValueExplicitlySpecified("sha1") ? mapper.get("sha1", Type.STRING) : null;
    if (sha1 != null && !KeyType.SHA1.isValid(sha1)) {
        throw new IOException("Invalid SHA-1 for maven_jar " + name + ": '" + sha1 + "'");
    }
    try {
        artifact = new DefaultArtifact(artifactId);
    } catch (IllegalArgumentException e) {
        throw new IOException(e.getMessage());
    }
    boolean isCaching = repositoryCache.isEnabled() && KeyType.SHA1.isValid(sha1);
    if (isCaching) {
        Path downloadPath = getDownloadDestination(artifact);
        Path cachedDestination = repositoryCache.get(sha1, downloadPath, KeyType.SHA1);
        if (cachedDestination != null) {
            return cachedDestination;
        }
    }
    MavenConnector connector = new MavenConnector(outputDirectory.getPathString());
    RepositorySystem system = connector.newRepositorySystem();
    RepositorySystemSession session = connector.newRepositorySystemSession(system);
    RemoteRepository repository = new RemoteRepository.Builder(name, MavenServerValue.DEFAULT_ID, url).setAuthentication(new MavenAuthentication(server)).build();
    ArtifactRequest artifactRequest = new ArtifactRequest();
    artifactRequest.setArtifact(artifact);
    artifactRequest.setRepositories(ImmutableList.of(repository));
    try {
        ArtifactResult artifactResult = system.resolveArtifact(session, artifactRequest);
        artifact = artifactResult.getArtifact();
    } catch (ArtifactResolutionException e) {
        throw new IOException("Failed to fetch Maven dependency: " + e.getMessage());
    }
    Path downloadPath = outputDirectory.getRelative(artifact.getFile().getAbsolutePath());
    // Verify checksum.
    if (!Strings.isNullOrEmpty(sha1)) {
        RepositoryCache.assertFileChecksum(sha1, downloadPath, KeyType.SHA1);
    }
    if (isCaching) {
        repositoryCache.put(sha1, downloadPath, KeyType.SHA1);
    }
    return downloadPath;
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) RepositorySystemSession(org.eclipse.aether.RepositorySystemSession) Server(org.apache.maven.settings.Server) Builder(com.google.common.collect.ImmutableMap.Builder) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) IOException(java.io.IOException) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult) RepositorySystem(org.eclipse.aether.RepositorySystem) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

Example 4 with RemoteRepository

use of org.eclipse.aether.repository.RemoteRepository in project byte-buddy by raphw.

the class ClassLoaderResolverTest method setUp.

@Before
public void setUp() throws Exception {
    classLoaderResolver = new ClassLoaderResolver(log, repositorySystem, repositorySystemSession, Collections.<RemoteRepository>emptyList());
    when(repositorySystem.collectDependencies(eq(repositorySystemSession), any(CollectRequest.class))).thenReturn(new CollectResult(new CollectRequest()).setRoot(root));
    when(child.getDependency()).thenReturn(new Dependency(new DefaultArtifact(FOO, BAR, QUX, BAZ, FOO + BAR, Collections.<String, String>emptyMap(), new File(FOO + "/" + BAR)), QUX + BAZ));
    when(root.accept(any(DependencyVisitor.class))).then(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
            DependencyVisitor dependencyVisitor = invocationOnMock.getArgumentAt(0, DependencyVisitor.class);
            dependencyVisitor.visitEnter(child);
            dependencyVisitor.visitLeave(child);
            return null;
        }
    });
}
Also used : CollectResult(org.eclipse.aether.collection.CollectResult) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) Dependency(org.eclipse.aether.graph.Dependency) CollectRequest(org.eclipse.aether.collection.CollectRequest) InvocationOnMock(org.mockito.invocation.InvocationOnMock) DependencyVisitor(org.eclipse.aether.graph.DependencyVisitor) File(java.io.File) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Before(org.junit.Before)

Example 5 with RemoteRepository

use of org.eclipse.aether.repository.RemoteRepository in project bnd by bndtools.

the class RemotePostProcessor method postProcessSnapshot.

private ArtifactResult postProcessSnapshot(ArtifactRequest request, Artifact artifact) throws MojoExecutionException {
    for (RemoteRepository repository : request.getRepositories()) {
        if (!repository.getPolicy(true).isEnabled()) {
            // Skip the repo if it isn't enabled for snapshots
            continue;
        }
        // Remove the workspace from the session so that we don't use it
        DefaultRepositorySystemSession newSession = new DefaultRepositorySystemSession(session);
        newSession.setWorkspaceReader(null);
        // Find the snapshot metadata for the module
        MetadataRequest mr = new MetadataRequest().setRepository(repository).setMetadata(new DefaultMetadata(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), "maven-metadata.xml", SNAPSHOT));
        for (MetadataResult metadataResult : system.resolveMetadata(newSession, singletonList(mr))) {
            if (metadataResult.isResolved()) {
                String version;
                try {
                    Metadata read = metadataReader.read(metadataResult.getMetadata().getFile(), null);
                    Versioning versioning = read.getVersioning();
                    if (versioning == null || versioning.getSnapshotVersions() == null || versioning.getSnapshotVersions().isEmpty()) {
                        continue;
                    } else {
                        version = versioning.getSnapshotVersions().get(0).getVersion();
                    }
                } catch (Exception e) {
                    throw new MojoExecutionException("Unable to read project metadata for " + artifact, e);
                }
                Artifact fullVersionArtifact = new org.eclipse.aether.artifact.DefaultArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getClassifier(), artifact.getExtension(), version);
                try {
                    ArtifactResult result = system.resolveArtifact(newSession, new ArtifactRequest().setArtifact(fullVersionArtifact).addRepository(repository));
                    if (result.isResolved()) {
                        File toUse = new File(session.getLocalRepository().getBasedir(), session.getLocalRepositoryManager().getPathForRemoteArtifact(fullVersionArtifact, repository, artifact.toString()));
                        if (!toUse.exists()) {
                            logger.warn("The resolved artifact {} does not exist at {}", fullVersionArtifact, toUse);
                            continue;
                        } else {
                            logger.debug("Located snapshot file {} for artifact {}", toUse, artifact);
                        }
                        result.getArtifact().setFile(toUse);
                        return result;
                    }
                } catch (ArtifactResolutionException e) {
                    logger.debug("Unable to locate the artifact {}", fullVersionArtifact, e);
                }
            }
        }
    }
    logger.debug("Unable to resolve a remote repository containing {}", artifact);
    return null;
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) DefaultMetadata(org.eclipse.aether.metadata.DefaultMetadata) DefaultMetadata(org.eclipse.aether.metadata.DefaultMetadata) Metadata(org.apache.maven.artifact.repository.metadata.Metadata) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) Artifact(org.eclipse.aether.artifact.Artifact) MetadataResult(org.eclipse.aether.resolution.MetadataResult) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult) Versioning(org.apache.maven.artifact.repository.metadata.Versioning) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) MetadataRequest(org.eclipse.aether.resolution.MetadataRequest) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) File(java.io.File)

Aggregations

RemoteRepository (org.eclipse.aether.repository.RemoteRepository)66 File (java.io.File)24 ArrayList (java.util.ArrayList)17 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)16 Artifact (org.eclipse.aether.artifact.Artifact)15 DefaultRepositorySystemSession (org.eclipse.aether.DefaultRepositorySystemSession)13 ArtifactResult (org.eclipse.aether.resolution.ArtifactResult)13 Dependency (org.eclipse.aether.graph.Dependency)12 ArtifactResolutionException (org.eclipse.aether.resolution.ArtifactResolutionException)12 IOException (java.io.IOException)11 List (java.util.List)9 RepositorySystemSession (org.eclipse.aether.RepositorySystemSession)9 MalformedURLException (java.net.MalformedURLException)8 RepositorySystem (org.eclipse.aether.RepositorySystem)8 LocalRepository (org.eclipse.aether.repository.LocalRepository)8 RepositoryPolicy (org.eclipse.aether.repository.RepositoryPolicy)8 CollectRequest (org.eclipse.aether.collection.CollectRequest)7 DependencyFilter (org.eclipse.aether.graph.DependencyFilter)7 ArtifactRequest (org.eclipse.aether.resolution.ArtifactRequest)7 URL (java.net.URL)6