Search in sources :

Example 51 with RemoteRepository

use of org.eclipse.aether.repository.RemoteRepository in project fabric8-maven-plugin by fabric8io.

the class AbstractArtifactSearchMojo method resolveArtifactFile.

protected File resolveArtifactFile(HelmIndexMojo.ArtifactDTO artifactDTO, String classifier, String extension) {
    File file = null;
    try {
        ArtifactRequest artifactRequest = new ArtifactRequest();
        org.eclipse.aether.artifact.Artifact artifact = new DefaultArtifact(artifactDTO.getG(), artifactDTO.getA(), classifier, extension, artifactDTO.getV());
        artifactRequest.setArtifact(artifact);
        // convert maven remote repositories to Aether repos
        List<RemoteRepository> aetherRepoList = new ArrayList<>();
        for (MavenArtifactRepository remoteRepository : remoteRepositories) {
            RemoteRepository.Builder builder = new RemoteRepository.Builder(remoteRepository.getId(), remoteRepository.getLayout().getId(), remoteRepository.getUrl());
            RemoteRepository aetherRepo = builder.build();
            aetherRepoList.add(aetherRepo);
        }
        artifactRequest.setRepositories(aetherRepoList);
        ArtifactResult artifactResult = artifactResolver.resolveArtifact(repoSession, artifactRequest);
        org.eclipse.aether.artifact.Artifact resolvedArtifact = artifactResult.getArtifact();
        if (resolvedArtifact == null) {
            getLog().warn("Could not resolve artifact " + artifactDTO.description());
            return null;
        }
        file = resolvedArtifact.getFile();
    } catch (Exception e) {
        getLog().warn("Failed to resolve manifest manifest for " + artifactDTO.description() + ". " + e, e);
        return null;
    }
    if (file == null) {
        getLog().warn("Could not resolve artifact file for " + artifactDTO.description());
        return null;
    }
    if (!file.isFile() || !file.exists()) {
        getLog().warn("Resolved artifact file does not exist for " + artifactDTO.description());
        return null;
    }
    return file;
}
Also used : ArrayList(java.util.ArrayList) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) MavenArtifactRepository(org.apache.maven.artifact.repository.MavenArtifactRepository) File(java.io.File) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

Example 52 with RemoteRepository

use of org.eclipse.aether.repository.RemoteRepository in project acceptance-test-harness by jenkinsci.

the class ArtifactResolverUtil method resolve.

/**
 * @param artifact The artifact to be resolved
 *
 * @return artifact resolution result
 */
public ArtifactResult resolve(DefaultArtifact artifact) {
    Builder repoBuilder = new RemoteRepository.Builder("repo.jenkins-ci.org", "default", "http://repo.jenkins-ci.org/public/");
    DefaultSettingsBuildingRequest request = new DefaultSettingsBuildingRequest();
    File userHome = new File(System.getProperty("user.home"));
    File userSettingsFile = new File(new File(userHome, ".m2"), "settings.xml");
    request.setUserSettingsFile(userSettingsFile);
    if (userSettingsFile.exists()) {
        LOGGER.debug("Found maven settings file - " + userSettingsFile.getAbsolutePath());
        SettingsBuilder settingsBuilder = new DefaultSettingsBuilderFactory().newInstance();
        try {
            Settings settings = settingsBuilder.build(request).getEffectiveSettings();
            org.apache.maven.settings.Proxy mavenActiveproxy = settings.getActiveProxy();
            if (mavenActiveproxy != null) {
                LOGGER.debug("Found maven proxy settings. Will use for artifact resolution");
                repoBuilder.setProxy(asProxy(mavenActiveproxy));
            } else {
                LOGGER.debug("Did not find an active proxy in maven settings xml file");
            }
        } catch (SettingsBuildingException e) {
            LOGGER.warn("Could not find or load settings.xml to attempt to user proxy settings.", e);
        }
    }
    RemoteRepository repo = repoBuilder.build();
    ArtifactResult r;
    try {
        r = repoSystem.resolveArtifact(repoSystemSession, new ArtifactRequest(artifact, Arrays.asList(repo), null));
    } catch (ArtifactResolutionException e) {
        throw new RuntimeException("Could not resolve " + artifact + " from Maven repository", e);
    }
    LOGGER.debug("Found " + r);
    return r;
}
Also used : SettingsBuildingException(org.apache.maven.settings.building.SettingsBuildingException) DefaultSettingsBuildingRequest(org.apache.maven.settings.building.DefaultSettingsBuildingRequest) SettingsBuilder(org.apache.maven.settings.building.SettingsBuilder) AuthenticationBuilder(org.eclipse.aether.util.repository.AuthenticationBuilder) Builder(org.eclipse.aether.repository.RemoteRepository.Builder) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) DefaultSettingsBuilderFactory(org.apache.maven.settings.building.DefaultSettingsBuilderFactory) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) SettingsBuilder(org.apache.maven.settings.building.SettingsBuilder) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) File(java.io.File) Settings(org.apache.maven.settings.Settings)

Example 53 with RemoteRepository

use of org.eclipse.aether.repository.RemoteRepository in project wildfly-swarm by wildfly-swarm.

the class MavenArtifactResolvingHelper method buildRemoteRepository.

private RemoteRepository buildRemoteRepository(final String id, final String url, final Authentication auth, final ArtifactRepositoryPolicy releasesPolicy, final ArtifactRepositoryPolicy snapshotsPolicy) {
    RemoteRepository.Builder builder = new RemoteRepository.Builder(id, "default", url);
    if (auth != null && auth.getUsername() != null && auth.getPassword() != null) {
        builder.setAuthentication(new AuthenticationBuilder().addUsername(auth.getUsername()).addPassword(auth.getPassword()).build());
    }
    builder.setSnapshotPolicy(new RepositoryPolicy(snapshotsPolicy.isEnabled(), snapshotsPolicy.getUpdatePolicy(), snapshotsPolicy.getChecksumPolicy()));
    builder.setReleasePolicy(new RepositoryPolicy(releasesPolicy.isEnabled(), releasesPolicy.getUpdatePolicy(), releasesPolicy.getChecksumPolicy()));
    RemoteRepository repository = builder.build();
    final RemoteRepository mirror = session.getMirrorSelector().getMirror(repository);
    if (mirror != null) {
        final org.eclipse.aether.repository.Authentication mirrorAuth = session.getAuthenticationSelector().getAuthentication(mirror);
        RemoteRepository.Builder mirrorBuilder = new RemoteRepository.Builder(mirror).setId(repository.getId()).setSnapshotPolicy(new RepositoryPolicy(snapshotsPolicy.isEnabled(), snapshotsPolicy.getUpdatePolicy(), snapshotsPolicy.getChecksumPolicy())).setReleasePolicy(new RepositoryPolicy(releasesPolicy.isEnabled(), releasesPolicy.getUpdatePolicy(), releasesPolicy.getChecksumPolicy()));
        if (mirrorAuth != null) {
            mirrorBuilder.setAuthentication(mirrorAuth);
        }
        repository = mirrorBuilder.build();
    }
    Proxy proxy = session.getProxySelector().getProxy(repository);
    if (proxy != null) {
        repository = new RemoteRepository.Builder(repository).setProxy(proxy).build();
    }
    return repository;
}
Also used : Proxy(org.eclipse.aether.repository.Proxy) AuthenticationBuilder(org.eclipse.aether.util.repository.AuthenticationBuilder) ArtifactRepositoryPolicy(org.apache.maven.artifact.repository.ArtifactRepositoryPolicy) RepositoryPolicy(org.eclipse.aether.repository.RepositoryPolicy) AuthenticationBuilder(org.eclipse.aether.util.repository.AuthenticationBuilder) RemoteRepository(org.eclipse.aether.repository.RemoteRepository)

Example 54 with RemoteRepository

use of org.eclipse.aether.repository.RemoteRepository in project build-info by JFrogDev.

the class ArtifactoryEclipseResolversHelper method getResolutionRepositories.

/**
 * Create a list containing one release and one snapshot resolution repositories, according to the configuration in the Artifactory plugin.
 * The list is used to override Maven's default or configured repositories, so that the build dependencies are resolved from Artifactory.
 * The list is saved and reused for further invokations to this method.
 * @param session
 * @return
 */
public List<RemoteRepository> getResolutionRepositories(RepositorySystemSession session) {
    if (resolutionRepositories == null) {
        Properties allMavenProps = new Properties();
        allMavenProps.putAll(session.getSystemProperties());
        allMavenProps.putAll(session.getUserProperties());
        resolutionHelper.init(allMavenProps);
        String releaseRepoUrl = resolutionHelper.getRepoReleaseUrl();
        String snapshotRepoUrl = resolutionHelper.getRepoSnapshotUrl();
        Authentication authentication = null;
        if (StringUtils.isNotBlank(resolutionHelper.getRepoUsername())) {
            authentication = new AuthenticationBuilder().addString("username", resolutionHelper.getRepoUsername()).addSecret("password", resolutionHelper.getRepoPassword()).build();
        }
        Proxy proxy = null;
        if (StringUtils.isNotBlank(resolutionHelper.getProxyHost())) {
            Authentication auth = new AuthenticationBuilder().addString("username", resolutionHelper.getProxyUsername()).addSecret("password", resolutionHelper.getProxyPassword()).build();
            proxy = new Proxy(null, resolutionHelper.getProxyHost(), resolutionHelper.getProxyPort(), auth);
        }
        if (StringUtils.isNotBlank(snapshotRepoUrl)) {
            logger.debug("[buildinfo] Enforcing snapshot repository for resolution: " + snapshotRepoUrl);
            RepositoryPolicy releasePolicy = new RepositoryPolicy(false, RepositoryPolicy.UPDATE_POLICY_DAILY, RepositoryPolicy.CHECKSUM_POLICY_WARN);
            RepositoryPolicy snapshotPolicy = new RepositoryPolicy(true, RepositoryPolicy.UPDATE_POLICY_DAILY, RepositoryPolicy.CHECKSUM_POLICY_WARN);
            RemoteRepository.Builder builder = new RemoteRepository.Builder("artifactory-snapshot", "default", snapshotRepoUrl);
            builder.setReleasePolicy(releasePolicy);
            builder.setSnapshotPolicy(snapshotPolicy);
            if (authentication != null) {
                logger.debug("[buildinfo] Enforcing repository authentication: " + authentication + " for snapshot resolution repository");
                builder.setAuthentication(authentication);
            }
            if (proxy != null) {
                logger.debug("[buildinfo] Enforcing proxy: " + proxy + " for snapshot resolution repository");
                builder.setProxy(proxy);
            }
            snapshotRepository = builder.build();
        }
        if (StringUtils.isNotBlank(releaseRepoUrl)) {
            logger.debug("[buildinfo] Enforcing release repository for resolution: " + releaseRepoUrl);
            boolean snapshotPolicyEnabled = snapshotRepository == null;
            String repositoryId = snapshotPolicyEnabled ? "artifactory-release-snapshot" : "artifactory-release";
            RepositoryPolicy releasePolicy = new RepositoryPolicy(true, RepositoryPolicy.UPDATE_POLICY_DAILY, RepositoryPolicy.CHECKSUM_POLICY_WARN);
            RepositoryPolicy snapshotPolicy = new RepositoryPolicy(snapshotPolicyEnabled, RepositoryPolicy.UPDATE_POLICY_DAILY, RepositoryPolicy.CHECKSUM_POLICY_WARN);
            RemoteRepository.Builder builder = new RemoteRepository.Builder(repositoryId, "default", releaseRepoUrl);
            builder.setReleasePolicy(releasePolicy);
            builder.setSnapshotPolicy(snapshotPolicy);
            if (authentication != null) {
                logger.debug("[buildinfo] Enforcing repository authentication: " + authentication + " for release resolution repository");
                builder.setAuthentication(authentication);
            }
            if (proxy != null) {
                logger.debug("[buildinfo] Enforcing proxy: " + proxy + " for release resolution repository");
                builder.setProxy(proxy);
            }
            releaseRepository = builder.build();
        }
        List<RemoteRepository> tempRepositories = Lists.newArrayList();
        if (releaseRepository != null) {
            tempRepositories.add(releaseRepository);
        }
        if (snapshotRepository != null) {
            tempRepositories.add(snapshotRepository);
        }
        resolutionRepositories = tempRepositories;
    }
    return resolutionRepositories;
}
Also used : Proxy(org.eclipse.aether.repository.Proxy) AuthenticationBuilder(org.eclipse.aether.util.repository.AuthenticationBuilder) Authentication(org.eclipse.aether.repository.Authentication) RepositoryPolicy(org.eclipse.aether.repository.RepositoryPolicy) AuthenticationBuilder(org.eclipse.aether.util.repository.AuthenticationBuilder) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) Properties(java.util.Properties)

Example 55 with RemoteRepository

use of org.eclipse.aether.repository.RemoteRepository in project gate-core by GateNLP.

the class SimpleMavenCache method cacheArtifact.

public void cacheArtifact(Artifact artifact) throws IOException, SettingsBuildingException, DependencyCollectionException, DependencyResolutionException, ArtifactResolutionException, ModelBuildingException {
    List<RemoteRepository> repos = getRepositoryList();
    Dependency dependency = new Dependency(artifact, "runtime");
    RepositorySystem repoSystem = getRepositorySystem();
    RepositorySystemSession repoSession = getRepositorySession(repoSystem, null);
    CollectRequest collectRequest = new CollectRequest(dependency, repos);
    DependencyNode node = repoSystem.collectDependencies(repoSession, collectRequest).getRoot();
    DependencyRequest dependencyRequest = new DependencyRequest();
    dependencyRequest.setRoot(node);
    DependencyResult result = repoSystem.resolveDependencies(repoSession, dependencyRequest);
    for (ArtifactResult ar : result.getArtifactResults()) {
        // generate output file name from the *requested* artifact rather
        // than the resolved one (e.g. if we requested a -SNAPSHOT version
        // but got a timestamped one)
        File file = getArtifactFile(ar.getRequest().getArtifact());
        FileUtils.copyFile(ar.getArtifact().getFile(), file);
        // get the POM corresponding to the specific resolved JAR
        Artifact pomArtifact = new SubArtifact(ar.getArtifact(), "", "pom");
        ArtifactRequest artifactRequest = new ArtifactRequest(pomArtifact, repos, null);
        ArtifactResult artifactResult = repoSystem.resolveArtifact(repoSession, artifactRequest);
        // but copy it to a file named for the original requested version number
        file = getArtifactFile(new SubArtifact(ar.getRequest().getArtifact(), "", "pom"));
        FileUtils.copyFile(artifactResult.getArtifact().getFile(), file);
        cacheParents(artifactResult.getArtifact().getFile(), repoSystem, repoSession, repos);
    }
}
Also used : RepositorySystemSession(org.eclipse.aether.RepositorySystemSession) DependencyResult(org.eclipse.aether.resolution.DependencyResult) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) Dependency(org.eclipse.aether.graph.Dependency) CollectRequest(org.eclipse.aether.collection.CollectRequest) SubArtifact(org.eclipse.aether.util.artifact.SubArtifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult) Utils.getRepositorySystem(gate.util.maven.Utils.getRepositorySystem) RepositorySystem(org.eclipse.aether.RepositorySystem) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) DependencyRequest(org.eclipse.aether.resolution.DependencyRequest) DependencyNode(org.eclipse.aether.graph.DependencyNode) SubArtifact(org.eclipse.aether.util.artifact.SubArtifact) 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