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);
}
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);
}
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;
}
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));
}
}
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);
}
Aggregations