Search in sources :

Example 46 with RemoteRepository

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

use of org.eclipse.aether.repository.RemoteRepository in project fabric8 by jboss-fuse.

the class AetherBasedResolver method assignProxyAndMirrors.

private void assignProxyAndMirrors(List<RemoteRepository> remoteRepos) {
    Map<String, List<String>> map = new HashMap<>();
    Map<String, RemoteRepository> naming = new HashMap<>();
    List<RemoteRepository> resultingRepos = new ArrayList<>();
    for (RemoteRepository r : remoteRepos) {
        naming.put(r.getId(), r);
        RemoteRepository rProxy = new RemoteRepository.Builder(r).setProxy(m_proxySelector.getProxy(r)).build();
        resultingRepos.add(rProxy);
        RemoteRepository mirror = m_mirrorSelector.getMirror(r);
        if (mirror != null) {
            String key = mirror.getId();
            naming.put(key, mirror);
            if (!map.containsKey(key)) {
                map.put(key, new ArrayList<String>());
            }
            List<String> mirrored = map.get(key);
            mirrored.add(r.getId());
        }
    }
    for (String mirrorId : map.keySet()) {
        RemoteRepository mirror = naming.get(mirrorId);
        List<RemoteRepository> mirroredRepos = new ArrayList<RemoteRepository>();
        for (String rep : map.get(mirrorId)) {
            mirroredRepos.add(naming.get(rep));
        }
        mirror = new RemoteRepository.Builder(mirror).setMirroredRepositories(mirroredRepos).setProxy(m_proxySelector.getProxy(mirror)).build();
        resultingRepos.removeAll(mirroredRepos);
        resultingRepos.add(0, mirror);
    }
    remoteRepos.clear();
    remoteRepos.addAll(resultingRepos);
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) AuthenticationBuilder(org.eclipse.aether.util.repository.AuthenticationBuilder) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) RemoteRepository(org.eclipse.aether.repository.RemoteRepository)

Example 48 with RemoteRepository

use of org.eclipse.aether.repository.RemoteRepository in project fabric8 by jboss-fuse.

the class AetherBasedResolver method resolveFile.

/**
 * Resolve maven artifact as file in repository.
 */
public File resolveFile(Artifact artifact, MavenRepositoryURL repositoryURL, Exception previousException) throws IOException {
    List<LocalRepository> defaultRepos = selectDefaultRepositories();
    List<RemoteRepository> remoteRepos = selectRepositories();
    if (repositoryURL != null) {
        addRepo(remoteRepos, repositoryURL);
    }
    if (previousException != null) {
        // we'll try using previous repositories, without these that will fail again anyway
        List<RemoteRepository> altered = new LinkedList<>();
        RepositoryException repositoryException = findAetherException(previousException);
        if (repositoryException instanceof ArtifactResolutionException) {
            // check only this aggregate exception and assume it's related to current artifact
            ArtifactResult result = ((ArtifactResolutionException) repositoryException).getResult();
            if (result != null && result.getRequest() != null && result.getRequest().getArtifact().equals(artifact)) {
                // - these exceptions contain repository that was checked
                for (Exception exception : result.getExceptions()) {
                    RepositoryException singleException = findAetherException(exception);
                    if (singleException instanceof ArtifactTransferException) {
                        RemoteRepository repository = ((ArtifactTransferException) singleException).getRepository();
                        if (repository != null) {
                            RetryChance chance = isRetryableException(singleException);
                            if (chance == RetryChance.NEVER) {
                                LOG.debug("Removing " + repository + " from list of repositories, previous exception: " + singleException.getClass().getName() + ": " + singleException.getMessage());
                            } else {
                                altered.add(repository);
                            }
                        }
                    }
                }
                // swap list of repos now
                remoteRepos = altered;
            }
        }
    }
    assignProxyAndMirrors(remoteRepos);
    File resolved = resolve(defaultRepos, remoteRepos, artifact);
    LOG.debug("Resolved ({}) as {}", artifact.toString(), resolved.getAbsolutePath());
    return resolved;
}
Also used : ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) ArtifactTransferException(org.eclipse.aether.transfer.ArtifactTransferException) LocalRepository(org.eclipse.aether.repository.LocalRepository) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) RepositoryException(org.eclipse.aether.RepositoryException) File(java.io.File) JarFile(java.util.jar.JarFile) LinkedList(java.util.LinkedList) DependencyCollectionException(org.eclipse.aether.collection.DependencyCollectionException) SocketTimeoutException(java.net.SocketTimeoutException) ConnectException(java.net.ConnectException) IOException(java.io.IOException) ArtifactNotFoundException(org.eclipse.aether.transfer.ArtifactNotFoundException) RepositoryException(org.eclipse.aether.RepositoryException) VersionRangeResolutionException(org.eclipse.aether.resolution.VersionRangeResolutionException) MetadataTransferException(org.eclipse.aether.transfer.MetadataTransferException) NoRouteToHostException(java.net.NoRouteToHostException) ArtifactTransferException(org.eclipse.aether.transfer.ArtifactTransferException) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) DependencyResolutionException(org.eclipse.aether.resolution.DependencyResolutionException) MalformedURLException(java.net.MalformedURLException) MetadataNotFoundException(org.eclipse.aether.transfer.MetadataNotFoundException) InvalidVersionSpecificationException(org.eclipse.aether.version.InvalidVersionSpecificationException) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult)

Example 49 with RemoteRepository

use of org.eclipse.aether.repository.RemoteRepository in project fabric8 by jboss-fuse.

the class AetherBasedResolver method addLocalRepo.

private void addLocalRepo(List<LocalRepository> list, MavenRepositoryURL repo) {
    if (repo.getFile() != null) {
        LocalRepository local = new LocalRepository(repo.getFile(), "simple");
        list.add(local);
        if (repo.isSnapshotsEnabled()) {
            localRepositoriesWithSnapshots.add(local);
        }
        List<RemoteRepository> remotes = new ArrayList<>(1);
        addRepo(remotes, repo);
        // remember the remote equivalent of local/default repository
        defaultRepositories.put(local.getBasedir(), remotes.get(0));
    }
}
Also used : LocalRepository(org.eclipse.aether.repository.LocalRepository) ArrayList(java.util.ArrayList) RemoteRepository(org.eclipse.aether.repository.RemoteRepository)

Example 50 with RemoteRepository

use of org.eclipse.aether.repository.RemoteRepository in project spf4j by zolyfarkas.

the class MavenRepositoryUtilsTest method testRepositoryOperations.

@Test
public void testRepositoryOperations() throws VersionRangeResolutionException, ArtifactResolutionException, DependencyResolutionException {
    File localRepo = new File(System.getProperty("user.home"), ".m2/repository");
    RemoteRepository mavenCentralRepository = MavenRepositoryUtils.getDefaultRepository();
    List<Version> versions = MavenRepositoryUtils.getVersions(Arrays.asList(mavenCentralRepository), localRepo, "org.spf4j", "spf4j-core", "[8.3,]");
    LOG.debug("Versions = {}", versions);
    String oldest = versions.get(0).toString();
    Assert.assertEquals("8.3.1", oldest);
    versions = MavenRepositoryUtils.getVersions(Arrays.asList(mavenCentralRepository), localRepo, "org.spf4j", "spf4j-core", "[,8.3.9-SNAPSHOT)");
    LOG.debug("Versions = {}", versions);
    File resolveArtifact = MavenRepositoryUtils.resolveArtifact(Arrays.asList(mavenCentralRepository), localRepo, "org.spf4j", "spf4j-core", "sources", "jar", oldest);
    LOG.debug("Artifact file = {}", resolveArtifact);
    Assert.assertTrue(resolveArtifact.canRead());
    Set<File> deps = MavenRepositoryUtils.resolveArtifactAndDependencies(Arrays.asList(mavenCentralRepository), localRepo, "compile", "jdiff", "jdiff", null, "jar", "1.0.9");
    LOG.debug("Dependency files = {}", deps);
}
Also used : Version(org.eclipse.aether.version.Version) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) File(java.io.File) Test(org.junit.Test)

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