Search in sources :

Example 26 with Artifact

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);
}
Also used : Path(java.nio.file.Path) STGroupString(org.stringtemplate.v4.STGroupString) SubArtifact(org.eclipse.aether.util.artifact.SubArtifact) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

Example 27 with Artifact

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);
}
Also used : DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

Example 28 with Artifact

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);
    }
}
Also used : Dependency(org.apache.maven.model.Dependency) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

Example 29 with Artifact

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());
    }
}
Also used : DeployRequest(org.eclipse.aether.deployment.DeployRequest) LocalRepository(org.eclipse.aether.repository.LocalRepository) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) Dependency(org.eclipse.aether.graph.Dependency) LinkedList(java.util.LinkedList) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) RepositorySystem(org.eclipse.aether.RepositorySystem) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) File(java.io.File) ArtifactDescriptorResult(org.eclipse.aether.resolution.ArtifactDescriptorResult) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) ArtifactDescriptorRequest(org.eclipse.aether.resolution.ArtifactDescriptorRequest)

Example 30 with Artifact

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());
}
Also used : DependencyCollectionException(org.eclipse.aether.collection.DependencyCollectionException) MalformedURLException(java.net.MalformedURLException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArrayList(java.util.ArrayList) MojoFailureException(org.apache.maven.plugin.MojoFailureException) ByteBuddy(net.bytebuddy.ByteBuddy) Dependency(org.eclipse.aether.graph.Dependency) CollectRequest(org.eclipse.aether.collection.CollectRequest) PreorderNodeListGenerator(org.eclipse.aether.util.graph.visitor.PreorderNodeListGenerator) URL(java.net.URL) Artifact(org.eclipse.aether.artifact.Artifact) DependencyRequest(org.eclipse.aether.resolution.DependencyRequest) DependencyNode(org.eclipse.aether.graph.DependencyNode) URLClassLoader(java.net.URLClassLoader) DependencyResolutionException(org.eclipse.aether.resolution.DependencyResolutionException)

Aggregations

Artifact (org.eclipse.aether.artifact.Artifact)41 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)30 File (java.io.File)11 Dependency (org.eclipse.aether.graph.Dependency)9 SubArtifact (org.eclipse.aether.util.artifact.SubArtifact)9 IOException (java.io.IOException)8 ArtifactResolutionException (org.eclipse.aether.resolution.ArtifactResolutionException)8 ArrayList (java.util.ArrayList)7 ArtifactResult (org.eclipse.aether.resolution.ArtifactResult)7 DependencyRequest (org.eclipse.aether.resolution.DependencyRequest)7 Path (java.nio.file.Path)6 DefaultRepositorySystemSession (org.eclipse.aether.DefaultRepositorySystemSession)6 CollectRequest (org.eclipse.aether.collection.CollectRequest)6 RemoteRepository (org.eclipse.aether.repository.RemoteRepository)5 STGroupString (org.stringtemplate.v4.STGroupString)5 Jar (aQute.bnd.osgi.Jar)4 URISyntaxException (java.net.URISyntaxException)4 URL (java.net.URL)4 List (java.util.List)4 ArtifactRequest (org.eclipse.aether.resolution.ArtifactRequest)4