use of org.eclipse.aether.repository.RemoteRepository in project buck by facebook.
the class Resolver method resolve.
public void resolve(Collection<String> artifacts) throws RepositoryException, ExecutionException, InterruptedException, IOException {
ImmutableList.Builder<RemoteRepository> repoBuilder = ImmutableList.builder();
ImmutableMap.Builder<String, Dependency> dependencyBuilder = ImmutableMap.builder();
repoBuilder.addAll(repos);
for (String artifact : artifacts) {
if (artifact.endsWith(".pom")) {
Model model = loadPomModel(Paths.get(artifact));
repoBuilder.addAll(getReposFromPom(model));
for (Dependency dep : getDependenciesFromPom(model)) {
dependencyBuilder.put(buildKey(dep.getArtifact()), dep);
}
} else {
Dependency dep = getDependencyFromString(artifact);
dependencyBuilder.put(buildKey(dep.getArtifact()), dep);
}
}
repos = repoBuilder.build();
ImmutableMap<String, Dependency> specifiedDependencies = dependencyBuilder.build();
ImmutableMap<String, Artifact> knownDeps = getRunTimeTransitiveDeps(specifiedDependencies.values());
// We now have the complete set of dependencies. Build the graph of dependencies. We'd like
// aether to do this for us, but it doesn't preserve the complete dependency information we need
// to accurately construct build files.
final MutableDirectedGraph<Artifact> graph = buildDependencyGraph(knownDeps);
// Now we have the graph, grab the sources and jars for each dependency, as well as the relevant
// checksums (which are download by default. Yay!)
ImmutableSetMultimap<Path, Prebuilt> downloadedArtifacts = downloadArtifacts(graph, specifiedDependencies);
createBuckFiles(downloadedArtifacts);
}
use of org.eclipse.aether.repository.RemoteRepository in project spring-boot by spring-projects.
the class AetherGrapeEngine method addResolver.
@Override
public void addResolver(Map<String, Object> args) {
String name = (String) args.get("name");
String root = (String) args.get("root");
RemoteRepository.Builder builder = new RemoteRepository.Builder(name, "default", root);
RemoteRepository repository = builder.build();
addRepository(repository);
}
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 byte-buddy by raphw.
the class ClassLoaderResolverTest method setUp.
@Before
public void setUp() throws Exception {
classLoaderResolver = new ClassLoaderResolver(log, repositorySystem, repositorySystemSession, Collections.<RemoteRepository>emptyList());
when(repositorySystem.collectDependencies(eq(repositorySystemSession), any(CollectRequest.class))).thenReturn(new CollectResult(new CollectRequest()).setRoot(root));
when(child.getDependency()).thenReturn(new Dependency(new DefaultArtifact(FOO, BAR, QUX, BAZ, FOO + BAR, Collections.<String, String>emptyMap(), new File(FOO + "/" + BAR)), QUX + BAZ));
when(root.accept(any(DependencyVisitor.class))).then(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
DependencyVisitor dependencyVisitor = invocationOnMock.getArgumentAt(0, DependencyVisitor.class);
dependencyVisitor.visitEnter(child);
dependencyVisitor.visitLeave(child);
return null;
}
});
}
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;
}
Aggregations