Search in sources :

Example 11 with RepositoryPolicy

use of org.eclipse.aether.repository.RepositoryPolicy 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 12 with RepositoryPolicy

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

the class ArtifactoryEclipseRepositoryListener method setRepositoryPolicy.

/**
 * Enables both snapshot and release polocies for a repository
 */
private void setRepositoryPolicy(RemoteRepository repo) throws NoSuchFieldException, IllegalAccessException {
    RepositoryPolicy policy = new RepositoryPolicy(true, RepositoryPolicy.UPDATE_POLICY_DAILY, RepositoryPolicy.CHECKSUM_POLICY_WARN);
    Field releasePolicyField = RemoteRepository.class.getDeclaredField("releasePolicy");
    Field snapshotPolicyField = RemoteRepository.class.getDeclaredField("snapshotPolicy");
    releasePolicyField.setAccessible(true);
    snapshotPolicyField.setAccessible(true);
    releasePolicyField.set(repo, policy);
    snapshotPolicyField.set(repo, policy);
}
Also used : Field(java.lang.reflect.Field) RepositoryPolicy(org.eclipse.aether.repository.RepositoryPolicy)

Aggregations

RepositoryPolicy (org.eclipse.aether.repository.RepositoryPolicy)12 RemoteRepository (org.eclipse.aether.repository.RemoteRepository)11 AuthenticationBuilder (org.eclipse.aether.util.repository.AuthenticationBuilder)6 Authentication (org.eclipse.aether.repository.Authentication)4 Field (java.lang.reflect.Field)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ArtifactRepositoryPolicy (org.apache.maven.artifact.repository.ArtifactRepositoryPolicy)2 Proxy (org.eclipse.aether.repository.Proxy)2 Test (org.junit.Test)2 HashMap (java.util.HashMap)1 Properties (java.util.Properties)1 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)1 MavenArtifactRepository (org.apache.maven.artifact.repository.MavenArtifactRepository)1 DefaultRepositoryLayout (org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout)1 DeploymentRepository (org.apache.maven.model.DeploymentRepository)1 DistributionManagement (org.apache.maven.model.DistributionManagement)1 MavenProject (org.apache.maven.project.MavenProject)1 Server (org.apache.maven.settings.Server)1 RepositorySystemSession (org.eclipse.aether.RepositorySystemSession)1