use of org.eclipse.aether.repository.RemoteRepository in project spring-boot by spring-projects.
the class SettingsXmlRepositorySystemSessionAutoConfigurationTests method assertMirrorSelectorConfiguration.
private void assertMirrorSelectorConfiguration(DefaultRepositorySystemSession session, RemoteRepository repository) {
RemoteRepository mirror = session.getMirrorSelector().getMirror(repository);
assertThat(mirror).as("Mirror configured for repository " + repository.getId()).isNotNull();
assertThat(mirror.getHost()).isEqualTo("maven.example.com");
}
use of org.eclipse.aether.repository.RemoteRepository in project bazel by bazelbuild.
the class MavenDownloader method download.
/**
* Download the Maven artifact to the output directory. Returns the path to the jar.
*/
public Path download(String name, WorkspaceAttributeMapper mapper, Path outputDirectory, MavenServerValue serverValue) throws IOException, EvalException {
this.name = name;
this.outputDirectory = outputDirectory;
String url = serverValue.getUrl();
Server server = serverValue.getServer();
Artifact artifact;
String artifactId = mapper.get("artifact", Type.STRING);
String sha1 = mapper.isAttributeValueExplicitlySpecified("sha1") ? mapper.get("sha1", Type.STRING) : null;
if (sha1 != null && !KeyType.SHA1.isValid(sha1)) {
throw new IOException("Invalid SHA-1 for maven_jar " + name + ": '" + sha1 + "'");
}
try {
artifact = new DefaultArtifact(artifactId);
} catch (IllegalArgumentException e) {
throw new IOException(e.getMessage());
}
boolean isCaching = repositoryCache.isEnabled() && KeyType.SHA1.isValid(sha1);
if (isCaching) {
Path downloadPath = getDownloadDestination(artifact);
Path cachedDestination = repositoryCache.get(sha1, downloadPath, KeyType.SHA1);
if (cachedDestination != null) {
return cachedDestination;
}
}
MavenConnector connector = new MavenConnector(outputDirectory.getPathString());
RepositorySystem system = connector.newRepositorySystem();
RepositorySystemSession session = connector.newRepositorySystemSession(system);
RemoteRepository repository = new RemoteRepository.Builder(name, MavenServerValue.DEFAULT_ID, url).setAuthentication(new MavenAuthentication(server)).build();
ArtifactRequest artifactRequest = new ArtifactRequest();
artifactRequest.setArtifact(artifact);
artifactRequest.setRepositories(ImmutableList.of(repository));
try {
ArtifactResult artifactResult = system.resolveArtifact(session, artifactRequest);
artifact = artifactResult.getArtifact();
} catch (ArtifactResolutionException e) {
throw new IOException("Failed to fetch Maven dependency: " + e.getMessage());
}
Path downloadPath = outputDirectory.getRelative(artifact.getFile().getAbsolutePath());
// Verify checksum.
if (!Strings.isNullOrEmpty(sha1)) {
RepositoryCache.assertFileChecksum(sha1, downloadPath, KeyType.SHA1);
}
if (isCaching) {
repositoryCache.put(sha1, downloadPath, KeyType.SHA1);
}
return downloadPath;
}
use of org.eclipse.aether.repository.RemoteRepository in project bnd by bndtools.
the class RemotePostProcessor method postProcessSnapshot.
private ArtifactResult postProcessSnapshot(ArtifactRequest request, Artifact artifact) throws MojoExecutionException {
for (RemoteRepository repository : request.getRepositories()) {
if (!repository.getPolicy(true).isEnabled()) {
// Skip the repo if it isn't enabled for snapshots
continue;
}
// Remove the workspace from the session so that we don't use it
DefaultRepositorySystemSession newSession = new DefaultRepositorySystemSession(session);
newSession.setWorkspaceReader(null);
// Find the snapshot metadata for the module
MetadataRequest mr = new MetadataRequest().setRepository(repository).setMetadata(new DefaultMetadata(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), "maven-metadata.xml", SNAPSHOT));
for (MetadataResult metadataResult : system.resolveMetadata(newSession, singletonList(mr))) {
if (metadataResult.isResolved()) {
String version;
try {
Metadata read = metadataReader.read(metadataResult.getMetadata().getFile(), null);
Versioning versioning = read.getVersioning();
if (versioning == null || versioning.getSnapshotVersions() == null || versioning.getSnapshotVersions().isEmpty()) {
continue;
} else {
version = versioning.getSnapshotVersions().get(0).getVersion();
}
} catch (Exception e) {
throw new MojoExecutionException("Unable to read project metadata for " + artifact, e);
}
Artifact fullVersionArtifact = new org.eclipse.aether.artifact.DefaultArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getClassifier(), artifact.getExtension(), version);
try {
ArtifactResult result = system.resolveArtifact(newSession, new ArtifactRequest().setArtifact(fullVersionArtifact).addRepository(repository));
if (result.isResolved()) {
File toUse = new File(session.getLocalRepository().getBasedir(), session.getLocalRepositoryManager().getPathForRemoteArtifact(fullVersionArtifact, repository, artifact.toString()));
if (!toUse.exists()) {
logger.warn("The resolved artifact {} does not exist at {}", fullVersionArtifact, toUse);
continue;
} else {
logger.debug("Located snapshot file {} for artifact {}", toUse, artifact);
}
result.getArtifact().setFile(toUse);
return result;
}
} catch (ArtifactResolutionException e) {
logger.debug("Unable to locate the artifact {}", fullVersionArtifact, e);
}
}
}
}
logger.debug("Unable to resolve a remote repository containing {}", artifact);
return null;
}
use of org.eclipse.aether.repository.RemoteRepository in project bnd by bndtools.
the class BaselineMojo method execute.
public void execute() throws MojoExecutionException, MojoFailureException {
if (skip) {
logger.debug("skip project as configured");
return;
}
Artifact artifact = RepositoryUtils.toArtifact(project.getArtifact());
List<RemoteRepository> aetherRepos = getRepositories(artifact);
setupBase(artifact);
try {
if (base.getVersion() == null || base.getVersion().isEmpty()) {
searchForBaseVersion(artifact, aetherRepos);
}
if (base.getVersion() != null && !base.getVersion().isEmpty()) {
ArtifactResult artifactResult = locateBaseJar(aetherRepos);
Reporter reporter;
if (fullReport) {
reporter = new ReporterAdapter(System.out);
((ReporterAdapter) reporter).setTrace(true);
} else {
reporter = new ReporterAdapter();
}
Baseline baseline = new Baseline(reporter, new DiffPluginImpl());
if (checkFailures(artifact, artifactResult, baseline)) {
if (continueOnError) {
logger.warn("The baselining check failed when checking {} against {} but the bnd-baseline-maven-plugin is configured not to fail the build.", artifact, artifactResult.getArtifact());
} else {
throw new MojoExecutionException("The baselining plugin detected versioning errors");
}
} else {
logger.info("Baselining check succeeded checking {} against {}", artifact, artifactResult.getArtifact());
}
} else {
if (failOnMissing) {
throw new MojoExecutionException("Unable to locate a previous version of the artifact");
} else {
logger.warn("No previous version of {} could be found to baseline against", artifact);
}
}
} catch (RepositoryException re) {
throw new MojoExecutionException("Unable to locate a previous version of the artifact", re);
} catch (Exception e) {
throw new MojoExecutionException("An error occurred while calculating the baseline", e);
}
}
use of org.eclipse.aether.repository.RemoteRepository in project camel by apache.
the class BOMResolver method retrieveUpstreamBOMVersions.
private void retrieveUpstreamBOMVersions() throws Exception {
RepositorySystem system = newRepositorySystem();
DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
LocalRepository localRepo = new LocalRepository(LOCAL_REPO);
session.setLocalRepositoryManager(system.newLocalRepositoryManager(session, localRepo));
String camelVersion = DependencyResolver.resolveCamelParentProperty("${project.version}");
List<Artifact> neededArtifacts = new LinkedList<>();
neededArtifacts.add(new DefaultArtifact("org.apache.camel:camel:pom:" + camelVersion).setFile(camelRoot("pom.xml")));
neededArtifacts.add(new DefaultArtifact("org.apache.camel:camel-parent:pom:" + camelVersion).setFile(camelRoot("parent/pom.xml")));
neededArtifacts.add(new DefaultArtifact("org.apache.camel:spring-boot:pom:" + camelVersion).setFile(camelRoot("platforms/spring-boot/pom.xml")));
neededArtifacts.add(new DefaultArtifact("org.apache.camel:camel-spring-boot-dm:pom:" + camelVersion).setFile(camelRoot("platforms/spring-boot/spring-boot-dm/pom.xml")));
neededArtifacts.add(new DefaultArtifact("org.apache.camel:camel-spring-boot-dependencies:pom:" + camelVersion).setFile(camelRoot("platforms/spring-boot/spring-boot-dm/camel-spring-boot-dependencies/pom.xml")));
Artifact camelSpringBootParent = new DefaultArtifact("org.apache.camel:camel-starter-parent:pom:" + camelVersion).setFile(camelRoot("platforms/spring-boot/spring-boot-dm/camel-starter-parent/pom.xml"));
neededArtifacts.add(camelSpringBootParent);
RemoteRepository localRepoDist = new RemoteRepository.Builder("org.apache.camel.itest.springboot", "default", new File(LOCAL_REPO).toURI().toString()).build();
for (Artifact artifact : neededArtifacts) {
DeployRequest deployRequest = new DeployRequest();
deployRequest.addArtifact(artifact);
deployRequest.setRepository(localRepoDist);
system.deploy(session, deployRequest);
}
RemoteRepository mavenCentral = new RemoteRepository.Builder("central", "default", "http://repo1.maven.org/maven2/").build();
ArtifactDescriptorRequest dReq = new ArtifactDescriptorRequest(camelSpringBootParent, Arrays.asList(localRepoDist, mavenCentral), null);
ArtifactDescriptorResult dRes = system.readArtifactDescriptor(session, dReq);
this.versions = new TreeMap<>();
for (Dependency dependency : dRes.getManagedDependencies()) {
Artifact a = dependency.getArtifact();
String key = a.getGroupId() + ":" + a.getArtifactId();
versions.put(key, dependency.getArtifact().getVersion());
}
}
Aggregations