Search in sources :

Example 16 with DefaultArtifact

use of org.eclipse.aether.artifact.DefaultArtifact in project bazel by bazelbuild.

the class ResultWriterTest method testArtifacts.

@Test
public void testArtifacts() throws Exception {
    Set<Rule> rules = ImmutableSet.of(new Rule(new DefaultArtifact("x:y:1.2.3")));
    String content = getWorkspaceFileContent(ImmutableList.<String>of(), rules);
    assertThat(content).contains("maven_jar(\n" + "    name = \"x_y\",\n" + "    artifact = \"x:y:1.2.3\",\n" + ")");
}
Also used : Rule(com.google.devtools.build.workspace.maven.Rule) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Test(org.junit.Test)

Example 17 with DefaultArtifact

use of org.eclipse.aether.artifact.DefaultArtifact in project buck by facebook.

the class ResolverIntegrationTest method shouldDetectNewestJar.

@Test
public void shouldDetectNewestJar() throws Exception {
    Path groupDir = thirdParty.resolve("example");
    Path existingNewerJar = groupDir.resolve("no-deps-1.1.jar");
    Path existingNewestJar = groupDir.resolve("no-deps-1.2.jar");
    Files.createDirectories(groupDir);
    Path sourceJar = repo.resolve("com/example/no-deps/1.0/no-deps-1.0.jar");
    Files.copy(sourceJar, existingNewerJar);
    Files.copy(sourceJar, existingNewestJar);
    Artifact artifact = new DefaultArtifact("com.example", "no-deps", "jar", "1.0");
    Optional<Path> result = new Resolver(newConfig()).getNewerVersionFile(artifact, groupDir);
    assertTrue(result.isPresent());
    assertThat(result.get(), equalTo(existingNewestJar));
}
Also used : Path(java.nio.file.Path) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Test(org.junit.Test)

Example 18 with DefaultArtifact

use of org.eclipse.aether.artifact.DefaultArtifact in project buck by facebook.

the class Publisher method publish.

public ImmutableSet<DeployResult> publish(SourcePathResolver pathResolver, ImmutableSet<MavenPublishable> publishables) throws DeploymentException {
    ImmutableListMultimap<UnflavoredBuildTarget, UnflavoredBuildTarget> duplicateBuiltinBuileRules = checkForDuplicatePackagedDeps(publishables);
    if (duplicateBuiltinBuileRules.size() > 0) {
        StringBuilder sb = new StringBuilder();
        sb.append("Duplicate transitive dependencies for publishable libraries found!  This means");
        sb.append(StandardSystemProperty.LINE_SEPARATOR);
        sb.append("that the following libraries would have multiple copies if these libraries were");
        sb.append(StandardSystemProperty.LINE_SEPARATOR);
        sb.append("used together.  The can be resolved by adding a maven URL to each target listed");
        sb.append(StandardSystemProperty.LINE_SEPARATOR);
        sb.append("below:");
        for (UnflavoredBuildTarget unflavoredBuildTarget : duplicateBuiltinBuileRules.keySet()) {
            sb.append(StandardSystemProperty.LINE_SEPARATOR);
            sb.append(unflavoredBuildTarget.getFullyQualifiedName());
            sb.append(" (referenced by these build targets: ");
            Joiner.on(", ").appendTo(sb, duplicateBuiltinBuileRules.get(unflavoredBuildTarget));
            sb.append(")");
        }
        throw new DeploymentException(sb.toString());
    }
    ImmutableSet.Builder<DeployResult> deployResultBuilder = ImmutableSet.builder();
    for (MavenPublishable publishable : publishables) {
        DefaultArtifact coords = new DefaultArtifact(Preconditions.checkNotNull(publishable.getMavenCoords().get(), "No maven coordinates specified for published rule ", publishable));
        Path relativePathToOutput = pathResolver.getRelativePath(Preconditions.checkNotNull(publishable.getSourcePathToOutput(), "No path to output present in ", publishable));
        File mainItem = publishable.getProjectFilesystem().resolve(relativePathToOutput).toFile();
        if (!coords.getClassifier().isEmpty()) {
            deployResultBuilder.add(publish(coords, ImmutableList.of(mainItem)));
        }
        try {
            // If this is the "main" artifact (denoted by lack of classifier) generate and publish
            // pom alongside
            File pom = Pom.generatePomFile(pathResolver, publishable).toFile();
            deployResultBuilder.add(publish(coords, ImmutableList.of(mainItem, pom)));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
    return deployResultBuilder.build();
}
Also used : Path(java.nio.file.Path) UnflavoredBuildTarget(com.facebook.buck.model.UnflavoredBuildTarget) IOException(java.io.IOException) MavenPublishable(com.facebook.buck.jvm.java.MavenPublishable) ImmutableSet(com.google.common.collect.ImmutableSet) DeployResult(org.eclipse.aether.deployment.DeployResult) DeploymentException(org.eclipse.aether.deployment.DeploymentException) File(java.io.File) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

Example 19 with DefaultArtifact

use of org.eclipse.aether.artifact.DefaultArtifact 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 20 with DefaultArtifact

use of org.eclipse.aether.artifact.DefaultArtifact 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)

Aggregations

DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)29 Artifact (org.eclipse.aether.artifact.Artifact)13 File (java.io.File)10 ArtifactResolutionException (org.eclipse.aether.resolution.ArtifactResolutionException)8 ArtifactRequest (org.eclipse.aether.resolution.ArtifactRequest)7 ArtifactResult (org.eclipse.aether.resolution.ArtifactResult)7 IOException (java.io.IOException)5 Dependency (org.eclipse.aether.graph.Dependency)5 Path (java.nio.file.Path)4 DefaultRepositorySystemSession (org.eclipse.aether.DefaultRepositorySystemSession)4 RemoteRepository (org.eclipse.aether.repository.RemoteRepository)4 Test (org.junit.Test)4 MavenVersion (aQute.bnd.version.MavenVersion)3 Rule (com.google.devtools.build.workspace.maven.Rule)3 ArrayList (java.util.ArrayList)3 RepositorySystem (org.eclipse.aether.RepositorySystem)3 CollectRequest (org.eclipse.aether.collection.CollectRequest)3 VersionRangeRequest (org.eclipse.aether.resolution.VersionRangeRequest)3 VersionRangeResult (org.eclipse.aether.resolution.VersionRangeResult)3 Version (org.eclipse.aether.version.Version)3