Search in sources :

Example 6 with RemoteRepository

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

the class SettingsXmlRepositorySystemSessionAutoConfigurationTests method assertMirrorSelectorConfiguration.

private void assertMirrorSelectorConfiguration(DefaultRepositorySystemSession session, RemoteRepository repository) {
    RemoteRepository mirror = session.getMirrorSelector().getMirror(repository);
    assertThat(mirror).as("Mirror configured for repository " + repository.getId()).isNotNull();
    assertThat(mirror.getHost()).isEqualTo("maven.example.com");
}
Also used : RemoteRepository(org.eclipse.aether.repository.RemoteRepository)

Example 7 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 8 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)

Example 9 with RemoteRepository

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

the class BaselineMojo method execute.

public void execute() throws MojoExecutionException, MojoFailureException {
    if (skip) {
        logger.debug("skip project as configured");
        return;
    }
    Artifact artifact = RepositoryUtils.toArtifact(project.getArtifact());
    List<RemoteRepository> aetherRepos = getRepositories(artifact);
    setupBase(artifact);
    try {
        if (base.getVersion() == null || base.getVersion().isEmpty()) {
            searchForBaseVersion(artifact, aetherRepos);
        }
        if (base.getVersion() != null && !base.getVersion().isEmpty()) {
            ArtifactResult artifactResult = locateBaseJar(aetherRepos);
            Reporter reporter;
            if (fullReport) {
                reporter = new ReporterAdapter(System.out);
                ((ReporterAdapter) reporter).setTrace(true);
            } else {
                reporter = new ReporterAdapter();
            }
            Baseline baseline = new Baseline(reporter, new DiffPluginImpl());
            if (checkFailures(artifact, artifactResult, baseline)) {
                if (continueOnError) {
                    logger.warn("The baselining check failed when checking {} against {} but the bnd-baseline-maven-plugin is configured not to fail the build.", artifact, artifactResult.getArtifact());
                } else {
                    throw new MojoExecutionException("The baselining plugin detected versioning errors");
                }
            } else {
                logger.info("Baselining check succeeded checking {} against {}", artifact, artifactResult.getArtifact());
            }
        } else {
            if (failOnMissing) {
                throw new MojoExecutionException("Unable to locate a previous version of the artifact");
            } else {
                logger.warn("No previous version of {} could be found to baseline against", artifact);
            }
        }
    } catch (RepositoryException re) {
        throw new MojoExecutionException("Unable to locate a previous version of the artifact", re);
    } catch (Exception e) {
        throw new MojoExecutionException("An error occurred while calculating the baseline", e);
    }
}
Also used : DiffPluginImpl(aQute.bnd.differ.DiffPluginImpl) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ReporterAdapter(aQute.libg.reporter.ReporterAdapter) Reporter(aQute.service.reporter.Reporter) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) RepositoryException(org.eclipse.aether.RepositoryException) Baseline(aQute.bnd.differ.Baseline) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) VersionRangeResolutionException(org.eclipse.aether.resolution.VersionRangeResolutionException) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) RepositoryException(org.eclipse.aether.RepositoryException) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult)

Example 10 with RemoteRepository

use of org.eclipse.aether.repository.RemoteRepository in project camel by apache.

the class BOMResolver method retrieveUpstreamBOMVersions.

private void retrieveUpstreamBOMVersions() throws Exception {
    RepositorySystem system = newRepositorySystem();
    DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
    LocalRepository localRepo = new LocalRepository(LOCAL_REPO);
    session.setLocalRepositoryManager(system.newLocalRepositoryManager(session, localRepo));
    String camelVersion = DependencyResolver.resolveCamelParentProperty("${project.version}");
    List<Artifact> neededArtifacts = new LinkedList<>();
    neededArtifacts.add(new DefaultArtifact("org.apache.camel:camel:pom:" + camelVersion).setFile(camelRoot("pom.xml")));
    neededArtifacts.add(new DefaultArtifact("org.apache.camel:camel-parent:pom:" + camelVersion).setFile(camelRoot("parent/pom.xml")));
    neededArtifacts.add(new DefaultArtifact("org.apache.camel:spring-boot:pom:" + camelVersion).setFile(camelRoot("platforms/spring-boot/pom.xml")));
    neededArtifacts.add(new DefaultArtifact("org.apache.camel:camel-spring-boot-dm:pom:" + camelVersion).setFile(camelRoot("platforms/spring-boot/spring-boot-dm/pom.xml")));
    neededArtifacts.add(new DefaultArtifact("org.apache.camel:camel-spring-boot-dependencies:pom:" + camelVersion).setFile(camelRoot("platforms/spring-boot/spring-boot-dm/camel-spring-boot-dependencies/pom.xml")));
    Artifact camelSpringBootParent = new DefaultArtifact("org.apache.camel:camel-starter-parent:pom:" + camelVersion).setFile(camelRoot("platforms/spring-boot/spring-boot-dm/camel-starter-parent/pom.xml"));
    neededArtifacts.add(camelSpringBootParent);
    RemoteRepository localRepoDist = new RemoteRepository.Builder("org.apache.camel.itest.springboot", "default", new File(LOCAL_REPO).toURI().toString()).build();
    for (Artifact artifact : neededArtifacts) {
        DeployRequest deployRequest = new DeployRequest();
        deployRequest.addArtifact(artifact);
        deployRequest.setRepository(localRepoDist);
        system.deploy(session, deployRequest);
    }
    RemoteRepository mavenCentral = new RemoteRepository.Builder("central", "default", "http://repo1.maven.org/maven2/").build();
    ArtifactDescriptorRequest dReq = new ArtifactDescriptorRequest(camelSpringBootParent, Arrays.asList(localRepoDist, mavenCentral), null);
    ArtifactDescriptorResult dRes = system.readArtifactDescriptor(session, dReq);
    this.versions = new TreeMap<>();
    for (Dependency dependency : dRes.getManagedDependencies()) {
        Artifact a = dependency.getArtifact();
        String key = a.getGroupId() + ":" + a.getArtifactId();
        versions.put(key, dependency.getArtifact().getVersion());
    }
}
Also used : DeployRequest(org.eclipse.aether.deployment.DeployRequest) LocalRepository(org.eclipse.aether.repository.LocalRepository) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) Dependency(org.eclipse.aether.graph.Dependency) LinkedList(java.util.LinkedList) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) RepositorySystem(org.eclipse.aether.RepositorySystem) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) File(java.io.File) ArtifactDescriptorResult(org.eclipse.aether.resolution.ArtifactDescriptorResult) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) ArtifactDescriptorRequest(org.eclipse.aether.resolution.ArtifactDescriptorRequest)

Aggregations

RemoteRepository (org.eclipse.aether.repository.RemoteRepository)19 DefaultRepositorySystemSession (org.eclipse.aether.DefaultRepositorySystemSession)7 ArtifactResult (org.eclipse.aether.resolution.ArtifactResult)7 File (java.io.File)5 Artifact (org.eclipse.aether.artifact.Artifact)5 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)5 ArtifactRequest (org.eclipse.aether.resolution.ArtifactRequest)5 ArtifactResolutionException (org.eclipse.aether.resolution.ArtifactResolutionException)5 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)4 RepositorySystemSession (org.eclipse.aether.RepositorySystemSession)4 ArrayList (java.util.ArrayList)3 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)3 RepositorySystem (org.eclipse.aether.RepositorySystem)3 Dependency (org.eclipse.aether.graph.Dependency)3 IOException (java.io.IOException)2 Metadata (org.apache.maven.artifact.repository.metadata.Metadata)2 Versioning (org.apache.maven.artifact.repository.metadata.Versioning)2 DefaultArtifactResolver (org.eclipse.aether.internal.impl.DefaultArtifactResolver)2 DefaultRepositorySystem (org.eclipse.aether.internal.impl.DefaultRepositorySystem)2 DefaultMetadata (org.eclipse.aether.metadata.DefaultMetadata)2