Search in sources :

Example 1 with ArtifactResolutionException

use of org.eclipse.aether.resolution.ArtifactResolutionException in project buck by facebook.

the class Resolver method downloadSources.

private void downloadSources(Artifact artifact, Path project, Prebuilt library) throws IOException {
    Artifact srcs = new SubArtifact(artifact, "sources", "jar");
    try {
        Path relativePath = resolveArtifact(srcs, project);
        library.setSourceJar(relativePath);
    } catch (ArtifactResolutionException e) {
        System.err.println("Skipping sources for: " + srcs);
    }
}
Also used : Path(java.nio.file.Path) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) SubArtifact(org.eclipse.aether.util.artifact.SubArtifact) SubArtifact(org.eclipse.aether.util.artifact.SubArtifact) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

Example 2 with ArtifactResolutionException

use of org.eclipse.aether.resolution.ArtifactResolutionException in project karaf by apache.

the class Dependency31Helper method resolve.

@Override
public File resolve(Object artifact, Log log) {
    ArtifactRequest request = new ArtifactRequest();
    request.setArtifact((Artifact) artifact);
    request.setRepositories(projectRepositories);
    log.debug("Resolving artifact " + artifact + " from " + projectRepositories);
    ArtifactResult result;
    try {
        result = repositorySystem.resolveArtifact(repositorySystemSession, request);
    } catch (ArtifactResolutionException e) {
        log.warn("Cound not resolve " + artifact, e);
        return null;
    }
    log.debug("Resolved artifact " + artifact + " to " + result.getArtifact().getFile() + " from " + result.getRepository());
    return result.getArtifact().getFile();
}
Also used : ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult)

Example 3 with ArtifactResolutionException

use of org.eclipse.aether.resolution.ArtifactResolutionException in project spring-boot by spring-projects.

the class AetherGrapeEngine method grab.

@Override
public Object grab(Map args, Map... dependencyMaps) {
    List<Exclusion> exclusions = createExclusions(args);
    List<Dependency> dependencies = createDependencies(dependencyMaps, exclusions);
    try {
        List<File> files = resolve(dependencies);
        GroovyClassLoader classLoader = getClassLoader(args);
        for (File file : files) {
            classLoader.addURL(file.toURI().toURL());
        }
    } catch (ArtifactResolutionException ex) {
        throw new DependencyResolutionFailedException(ex);
    } catch (MalformedURLException ex) {
        throw new DependencyResolutionFailedException(ex);
    }
    return null;
}
Also used : GroovyClassLoader(groovy.lang.GroovyClassLoader) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) MalformedURLException(java.net.MalformedURLException) Exclusion(org.eclipse.aether.graph.Exclusion) Dependency(org.eclipse.aether.graph.Dependency) File(java.io.File)

Example 4 with ArtifactResolutionException

use of org.eclipse.aether.resolution.ArtifactResolutionException in project spring-boot by spring-projects.

the class AetherGrapeEngine method resolve.

private List<File> resolve(List<Dependency> dependencies) throws ArtifactResolutionException {
    try {
        CollectRequest collectRequest = getCollectRequest(dependencies);
        DependencyRequest dependencyRequest = getDependencyRequest(collectRequest);
        DependencyResult result = this.repositorySystem.resolveDependencies(this.session, dependencyRequest);
        addManagedDependencies(result);
        return getFiles(result);
    } catch (Exception ex) {
        throw new DependencyResolutionFailedException(ex);
    } finally {
        this.progressReporter.finished();
    }
}
Also used : DependencyRequest(org.eclipse.aether.resolution.DependencyRequest) DependencyResult(org.eclipse.aether.resolution.DependencyResult) CollectRequest(org.eclipse.aether.collection.CollectRequest) MalformedURLException(java.net.MalformedURLException) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException)

Example 5 with ArtifactResolutionException

use of org.eclipse.aether.resolution.ArtifactResolutionException 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)

Aggregations

ArtifactResolutionException (org.eclipse.aether.resolution.ArtifactResolutionException)50 ArtifactResult (org.eclipse.aether.resolution.ArtifactResult)31 ArtifactRequest (org.eclipse.aether.resolution.ArtifactRequest)30 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)25 File (java.io.File)20 Artifact (org.eclipse.aether.artifact.Artifact)19 IOException (java.io.IOException)17 MalformedURLException (java.net.MalformedURLException)9 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)9 DefaultRepositorySystemSession (org.eclipse.aether.DefaultRepositorySystemSession)9 VersionRangeResolutionException (org.eclipse.aether.resolution.VersionRangeResolutionException)9 RepositorySystemSession (org.eclipse.aether.RepositorySystemSession)8 RemoteRepository (org.eclipse.aether.repository.RemoteRepository)7 FileNotFoundException (java.io.FileNotFoundException)6 ArrayList (java.util.ArrayList)6 DependencyResolutionException (org.eclipse.aether.resolution.DependencyResolutionException)6 XmlPullParserException (org.codehaus.plexus.util.xml.pull.XmlPullParserException)5 RepositoryException (org.eclipse.aether.RepositoryException)5 FileReader (java.io.FileReader)4 Path (java.nio.file.Path)4