Search in sources :

Example 6 with RepositoryPolicy

use of org.eclipse.aether.repository.RepositoryPolicy in project drools by kiegroup.

the class MavenRepository method getRemoteRepositoryFromDistributionManagement.

protected RemoteRepository getRemoteRepositoryFromDistributionManagement(File pomfile) {
    MavenProject mavenProject = parseMavenPom(pomfile);
    DistributionManagement distMan = mavenProject.getDistributionManagement();
    if (distMan == null) {
        return null;
    }
    DeploymentRepository deployRepo = distMan.getSnapshotRepository() != null && mavenProject.getVersion().endsWith("SNAPSHOT") ? distMan.getSnapshotRepository() : distMan.getRepository();
    if (deployRepo == null) {
        return null;
    }
    RemoteRepository.Builder remoteRepoBuilder = new RemoteRepository.Builder(deployRepo.getId(), deployRepo.getLayout(), deployRepo.getUrl()).setSnapshotPolicy(new RepositoryPolicy(true, RepositoryPolicy.UPDATE_POLICY_DAILY, RepositoryPolicy.CHECKSUM_POLICY_WARN)).setReleasePolicy(new RepositoryPolicy(true, RepositoryPolicy.UPDATE_POLICY_ALWAYS, RepositoryPolicy.CHECKSUM_POLICY_WARN));
    Server server = MavenSettings.getSettings().getServer(deployRepo.getId());
    if (server != null) {
        MavenEmbedder embedder = MavenProjectLoader.newMavenEmbedder(false);
        try {
            Authentication authentication = embedder.getMavenSession().getRepositorySession().getAuthenticationSelector().getAuthentication(remoteRepoBuilder.build());
            remoteRepoBuilder.setAuthentication(authentication);
        } finally {
            embedder.dispose();
        }
    }
    return remoteRepoBuilder.build();
}
Also used : MavenProject(org.apache.maven.project.MavenProject) Server(org.apache.maven.settings.Server) RepositoryPolicy(org.eclipse.aether.repository.RepositoryPolicy) MavenEmbedder(org.kie.maven.integration.embedder.MavenEmbedder) Authentication(org.eclipse.aether.repository.Authentication) DeploymentRepository(org.apache.maven.model.DeploymentRepository) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) DistributionManagement(org.apache.maven.model.DistributionManagement)

Example 7 with RepositoryPolicy

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

the class AetherUtil method toRemoteRepository.

public static RemoteRepository toRemoteRepository(String repoUrl, Optional<String> username, Optional<String> password) {
    RemoteRepository.Builder repo = new RemoteRepository.Builder(null, "default", repoUrl).setPolicy(new RepositoryPolicy(true, null, CHECKSUM_POLICY_FAIL));
    if (username.isPresent() && password.isPresent()) {
        Authentication authentication = new AuthenticationBuilder().addUsername(username.get()).addPassword(password.get()).build();
        repo.setAuthentication(authentication);
    }
    return repo.build();
}
Also used : AuthenticationBuilder(org.eclipse.aether.util.repository.AuthenticationBuilder) RepositoryPolicy(org.eclipse.aether.repository.RepositoryPolicy) Authentication(org.eclipse.aether.repository.Authentication) RemoteRepository(org.eclipse.aether.repository.RemoteRepository)

Example 8 with RepositoryPolicy

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

the class AetherGrapeEngineFactory method createRepositories.

private static List<RemoteRepository> createRepositories(List<RepositoryConfiguration> repositoryConfigurations) {
    List<RemoteRepository> repositories = new ArrayList<>(repositoryConfigurations.size());
    for (RepositoryConfiguration repositoryConfiguration : repositoryConfigurations) {
        RemoteRepository.Builder builder = new RemoteRepository.Builder(repositoryConfiguration.getName(), "default", repositoryConfiguration.getUri().toASCIIString());
        if (!repositoryConfiguration.getSnapshotsEnabled()) {
            builder.setSnapshotPolicy(new RepositoryPolicy(false, RepositoryPolicy.UPDATE_POLICY_NEVER, RepositoryPolicy.CHECKSUM_POLICY_IGNORE));
        }
        repositories.add(builder.build());
    }
    return repositories;
}
Also used : RepositoryPolicy(org.eclipse.aether.repository.RepositoryPolicy) ArrayList(java.util.ArrayList) RemoteRepository(org.eclipse.aether.repository.RemoteRepository)

Example 9 with RepositoryPolicy

use of org.eclipse.aether.repository.RepositoryPolicy in project spring-cloud-deployer by spring-cloud.

the class MavenResourceTests method checkRepositoryPolicies.

@Test
public void checkRepositoryPolicies() {
    MavenProperties mavenProperties = new MavenProperties();
    Map<String, MavenProperties.RemoteRepository> remoteRepositoryMap = new HashMap<>();
    MavenProperties.RemoteRepository remoteRepo1 = new MavenProperties.RemoteRepository("https://repo.spring.io/libs-snapshot-local");
    MavenProperties.RemoteRepository.RepositoryPolicy snapshotPolicy = new MavenProperties.RemoteRepository.RepositoryPolicy();
    snapshotPolicy.setEnabled(true);
    snapshotPolicy.setUpdatePolicy("always");
    snapshotPolicy.setChecksumPolicy("warn");
    remoteRepo1.setSnapshotPolicy(snapshotPolicy);
    MavenProperties.RemoteRepository.RepositoryPolicy releasePolicy = new MavenProperties.RemoteRepository.RepositoryPolicy();
    releasePolicy.setEnabled(true);
    releasePolicy.setUpdatePolicy("interval");
    releasePolicy.setChecksumPolicy("ignore");
    remoteRepo1.setReleasePolicy(releasePolicy);
    remoteRepositoryMap.put("repo1", remoteRepo1);
    MavenProperties.RemoteRepository remoteRepo2 = new MavenProperties.RemoteRepository("https://repo.spring.io/libs-milestone-local");
    MavenProperties.RemoteRepository.RepositoryPolicy policy = new MavenProperties.RemoteRepository.RepositoryPolicy();
    policy.setEnabled(true);
    policy.setUpdatePolicy("daily");
    policy.setChecksumPolicy("fail");
    remoteRepo2.setPolicy(policy);
    remoteRepositoryMap.put("repo2", remoteRepo2);
    mavenProperties.setRemoteRepositories(remoteRepositoryMap);
    MavenArtifactResolver artifactResolver = new MavenArtifactResolver(mavenProperties);
    Field remoteRepositories = ReflectionUtils.findField(MavenArtifactResolver.class, "remoteRepositories");
    ReflectionUtils.makeAccessible(remoteRepositories);
    List<RemoteRepository> remoteRepositoryList = (List<RemoteRepository>) ReflectionUtils.getField(remoteRepositories, artifactResolver);
    for (RemoteRepository remoteRepository : remoteRepositoryList) {
        assertEquals(2, remoteRepositoryList.size());
        assertEquals(true, remoteRepositoryList.get(0).getId().equals("repo1") || remoteRepositoryList.get(0).getId().equals("repo2"));
        assertEquals(true, remoteRepositoryList.get(1).getId().equals("repo2") || remoteRepositoryList.get(1).getId().equals("repo1"));
        if (remoteRepository.getId().equals("repo1")) {
            RepositoryPolicy snapshotPolicy1 = remoteRepository.getPolicy(true);
            assertEquals(true, snapshotPolicy1.isEnabled());
            assertEquals("always", snapshotPolicy1.getUpdatePolicy());
            assertEquals("warn", snapshotPolicy1.getChecksumPolicy());
            RepositoryPolicy releasePolicy1 = remoteRepository.getPolicy(false);
            assertEquals(true, releasePolicy1.isEnabled());
            assertEquals("interval", releasePolicy1.getUpdatePolicy());
            assertEquals("ignore", releasePolicy1.getChecksumPolicy());
        } else if (remoteRepository.getId().equals("repo2")) {
            RepositoryPolicy snapshotPolicy2 = remoteRepository.getPolicy(true);
            assertEquals(true, snapshotPolicy2.isEnabled());
            assertEquals("daily", snapshotPolicy2.getUpdatePolicy());
            assertEquals("fail", snapshotPolicy2.getChecksumPolicy());
            RepositoryPolicy releasePolicy2 = remoteRepository.getPolicy(false);
            assertEquals(true, releasePolicy2.isEnabled());
            assertEquals("daily", releasePolicy2.getUpdatePolicy());
            assertEquals("fail", releasePolicy2.getChecksumPolicy());
        }
    }
    MavenResource resource = MavenResource.parse("org.springframework.cloud.task.app:timestamp-task:jar:1.0.0.BUILD-SNAPSHOT", mavenProperties);
    assertEquals(resource.exists(), true);
}
Also used : HashMap(java.util.HashMap) RepositoryPolicy(org.eclipse.aether.repository.RepositoryPolicy) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) Field(java.lang.reflect.Field) List(java.util.List) Test(org.junit.Test)

Example 10 with RepositoryPolicy

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

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