use of org.eclipse.aether.artifact.Artifact in project buck by facebook.
the class Resolver method downloadArtifact.
private Map.Entry<Path, Prebuilt> downloadArtifact(final Artifact artifactToDownload, TraversableGraph<Artifact> graph, ImmutableMap<String, Dependency> specifiedDependencies) throws IOException, ArtifactResolutionException {
String projectName = getProjectName(artifactToDownload);
Path project = buckRepoRoot.resolve(buckThirdPartyRelativePath).resolve(projectName);
Files.createDirectories(project);
Prebuilt library = resolveLib(artifactToDownload, project);
// Populate deps
Iterable<Artifact> incoming = graph.getIncomingNodesFor(artifactToDownload);
for (Artifact artifact : incoming) {
String groupName = getProjectName(artifact);
if (projectName.equals(groupName)) {
library.addDep(String.format(":%s", artifact.getArtifactId()));
} else {
library.addDep(buckThirdPartyRelativePath, artifact);
}
}
// Populate visibility
Iterable<Artifact> outgoing = graph.getOutgoingNodesFor(artifactToDownload);
for (Artifact artifact : outgoing) {
String groupName = getProjectName(artifact);
if (!groupName.equals(projectName)) {
library.addVisibility(buckThirdPartyRelativePath, artifact);
}
}
if (specifiedDependencies.containsKey(buildKey(artifactToDownload))) {
for (String rule : visibility) {
library.addVisibility(rule);
}
}
return Maps.immutableEntry(project, library);
}
use of org.eclipse.aether.artifact.Artifact in project buck by facebook.
the class Pom method applyBuildRule.
private void applyBuildRule() {
if (!HasMavenCoordinates.isMavenCoordsPresent(publishable)) {
throw new IllegalArgumentException("Cannot retrieve maven coordinates for target" + publishable.getBuildTarget().getFullyQualifiedName());
}
DefaultArtifact artifact = new DefaultArtifact(getMavenCoords(publishable).get());
Iterable<Artifact> deps = FluentIterable.from(publishable.getMavenDeps()).filter(HasMavenCoordinates::isMavenCoordsPresent).transform(input -> new DefaultArtifact(input.getMavenCoords().get()));
updateModel(artifact, deps);
}
use of org.eclipse.aether.artifact.Artifact in project buck by facebook.
the class Pom method updateModel.
private void updateModel(Artifact mavenCoordinates, Iterable<Artifact> deps) {
model.setGroupId(mavenCoordinates.getGroupId());
model.setArtifactId(mavenCoordinates.getArtifactId());
model.setVersion(mavenCoordinates.getVersion());
if (Strings.isNullOrEmpty(model.getName())) {
// better than nothing
model.setName(mavenCoordinates.getArtifactId());
}
// Dependencies
ImmutableMap<DepKey, Dependency> depIndex = Maps.uniqueIndex(getModel().getDependencies(), DepKey::new);
for (Artifact artifactDep : deps) {
DepKey key = new DepKey(artifactDep);
Dependency dependency = depIndex.get(key);
if (dependency == null) {
dependency = key.createDependency();
getModel().addDependency(dependency);
}
updateDependency(dependency, artifactDep);
}
}
use of org.eclipse.aether.artifact.Artifact 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());
}
}
use of org.eclipse.aether.artifact.Artifact in project byte-buddy by raphw.
the class ClassLoaderResolver method doResolve.
/**
* Resolves a Maven coordinate to a class loader that can load all of the coordinates classes.
*
* @param mavenCoordinate The Maven coordinate to resolve.
* @return A class loader that references all of the class loader's dependencies and which is a child of this class's class loader.
* @throws MojoExecutionException If the user configuration results in an error.
* @throws MojoFailureException If the plugin application raises an error.
*/
private ClassLoader doResolve(MavenCoordinate mavenCoordinate) throws MojoExecutionException, MojoFailureException {
List<URL> urls = new ArrayList<URL>();
log.info("Resolving transformer dependency: " + mavenCoordinate);
try {
DependencyNode root = repositorySystem.collectDependencies(repositorySystemSession, new CollectRequest(new Dependency(mavenCoordinate.asArtifact(), "runtime"), remoteRepositories)).getRoot();
repositorySystem.resolveDependencies(repositorySystemSession, new DependencyRequest().setRoot(root));
PreorderNodeListGenerator preorderNodeListGenerator = new PreorderNodeListGenerator();
root.accept(preorderNodeListGenerator);
for (Artifact artifact : preorderNodeListGenerator.getArtifacts(false)) {
urls.add(artifact.getFile().toURI().toURL());
}
} catch (DependencyCollectionException exception) {
throw new MojoExecutionException("Could not collect dependencies for " + mavenCoordinate, exception);
} catch (DependencyResolutionException exception) {
throw new MojoExecutionException("Could not resolve dependencies for " + mavenCoordinate, exception);
} catch (MalformedURLException exception) {
throw new MojoFailureException("Could not resolve file as URL for " + mavenCoordinate, exception);
}
return new URLClassLoader(urls.toArray(new URL[urls.size()]), ByteBuddy.class.getClassLoader());
}
Aggregations