Search in sources :

Example 1 with MavenPublishable

use of com.facebook.buck.jvm.java.MavenPublishable in project buck by facebook.

the class PublisherTest method errorRaisedForDuplicateFirstOrderDeps.

@Test
public void errorRaisedForDuplicateFirstOrderDeps() throws DeploymentException, NoSuchBuildTargetException {
    // Construct a graph that looks like this.  A and B have maven coordinates set.
    // A   B
    //  \ /
    //   C
    BuildTarget publishableTargetA = BuildTargetFactory.newInstance("//:a").withFlavors(JavaLibrary.MAVEN_JAR);
    BuildTarget publishableTargetB = BuildTargetFactory.newInstance("//:b").withFlavors(JavaLibrary.MAVEN_JAR);
    BuildTarget targetC = BuildTargetFactory.newInstance("//:c");
    TargetNode<?, ?> depNode = JavaLibraryBuilder.createBuilder(targetC).addSrc(Paths.get("c.java")).build();
    TargetNode<?, ?> publishableANode = JavaLibraryBuilder.createBuilder(publishableTargetA).addSrc(Paths.get("a.java")).setMavenCoords(MVN_COORDS_A).addDep(targetC).build();
    TargetNode<?, ?> publishableBNode = JavaLibraryBuilder.createBuilder(publishableTargetB).addSrc(Paths.get("b.java")).setMavenCoords(MVN_COORDS_B).addDep(targetC).build();
    TargetGraph targetGraph = TargetGraphFactory.newInstance(depNode, publishableANode, publishableBNode);
    BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
    MavenPublishable publishableA = (MavenPublishable) resolver.requireRule(publishableTargetA);
    MavenPublishable publishableB = (MavenPublishable) resolver.requireRule(publishableTargetB);
    expectedException.expect(DeploymentException.class);
    expectedException.expectMessage(Matchers.containsString(targetC.getUnflavoredBuildTarget().getFullyQualifiedName()));
    expectedException.expectMessage(Matchers.containsString(publishableTargetA.getUnflavoredBuildTarget().getFullyQualifiedName()));
    expectedException.expectMessage(Matchers.containsString(publishableTargetB.getUnflavoredBuildTarget().getFullyQualifiedName()));
    publisher.publish(pathResolver, ImmutableSet.of(publishableA, publishableB));
}
Also used : BuildTarget(com.facebook.buck.model.BuildTarget) TargetGraph(com.facebook.buck.rules.TargetGraph) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) MavenPublishable(com.facebook.buck.jvm.java.MavenPublishable) Test(org.junit.Test)

Example 2 with MavenPublishable

use of com.facebook.buck.jvm.java.MavenPublishable in project buck by facebook.

the class PublisherTest method errorRaisedForDuplicateTransitiveDeps.

@Test
public void errorRaisedForDuplicateTransitiveDeps() throws DeploymentException, NoSuchBuildTargetException {
    // Construct a graph that looks like this.  A and B have maven coordinates set.
    // A   B
    // |   |
    // C   D
    //  \ /
    //   E
    BuildTarget publishableTargetA = BuildTargetFactory.newInstance("//:a").withFlavors(JavaLibrary.MAVEN_JAR);
    BuildTarget publishableTargetB = BuildTargetFactory.newInstance("//:b").withFlavors(JavaLibrary.MAVEN_JAR);
    BuildTarget targetC = BuildTargetFactory.newInstance("//:c");
    BuildTarget targetD = BuildTargetFactory.newInstance("//:d");
    BuildTarget targetE = BuildTargetFactory.newInstance("//:e");
    TargetNode<?, ?> transitiveDepNode = JavaLibraryBuilder.createBuilder(targetE).addSrc(Paths.get("e.java")).build();
    TargetNode<?, ?> dep1Node = JavaLibraryBuilder.createBuilder(targetC).addSrc(Paths.get("c.java")).addDep(targetE).build();
    TargetNode<?, ?> dep2Node = JavaLibraryBuilder.createBuilder(targetD).addSrc(Paths.get("d.java")).addDep(targetE).build();
    TargetNode<?, ?> publishableANode = JavaLibraryBuilder.createBuilder(publishableTargetA).addSrc(Paths.get("a.java")).setMavenCoords(MVN_COORDS_A).addDep(targetC).build();
    TargetNode<?, ?> publishableBNode = JavaLibraryBuilder.createBuilder(publishableTargetB).addSrc(Paths.get("b.java")).setMavenCoords(MVN_COORDS_B).addDep(targetD).build();
    TargetGraph targetGraph = TargetGraphFactory.newInstance(transitiveDepNode, dep1Node, dep2Node, publishableANode, publishableBNode);
    BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
    MavenPublishable publishableA = (MavenPublishable) resolver.requireRule(publishableTargetA);
    MavenPublishable publishableB = (MavenPublishable) resolver.requireRule(publishableTargetB);
    expectedException.expect(DeploymentException.class);
    expectedException.expectMessage(Matchers.containsString(targetE.getUnflavoredBuildTarget().getFullyQualifiedName()));
    expectedException.expectMessage(Matchers.containsString(publishableTargetA.getUnflavoredBuildTarget().getFullyQualifiedName()));
    expectedException.expectMessage(Matchers.containsString(publishableTargetB.getUnflavoredBuildTarget().getFullyQualifiedName()));
    publisher.publish(pathResolver, ImmutableSet.of(publishableA, publishableB));
}
Also used : BuildTarget(com.facebook.buck.model.BuildTarget) TargetGraph(com.facebook.buck.rules.TargetGraph) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) MavenPublishable(com.facebook.buck.jvm.java.MavenPublishable) Test(org.junit.Test)

Example 3 with MavenPublishable

use of com.facebook.buck.jvm.java.MavenPublishable in project buck by facebook.

the class PublishCommand method publishTargets.

private boolean publishTargets(ImmutableList<BuildTarget> buildTargets, CommandRunnerParams params) {
    ImmutableSet.Builder<MavenPublishable> publishables = ImmutableSet.builder();
    boolean success = true;
    for (BuildTarget buildTarget : buildTargets) {
        BuildRule buildRule = null;
        try {
            buildRule = getBuild().getRuleResolver().requireRule(buildTarget);
        } catch (NoSuchBuildTargetException e) {
            // This doesn't seem physically possible!
            throw new RuntimeException(e);
        }
        Preconditions.checkNotNull(buildRule);
        if (!(buildRule instanceof MavenPublishable)) {
            params.getBuckEventBus().post(ConsoleEvent.severe("Cannot publish rule of type %s", buildRule.getClass().getName()));
            success &= false;
            continue;
        }
        MavenPublishable publishable = (MavenPublishable) buildRule;
        if (!publishable.getMavenCoords().isPresent()) {
            params.getBuckEventBus().post(ConsoleEvent.severe("No maven coordinates specified for %s", buildTarget.getUnflavoredBuildTarget().getFullyQualifiedName()));
            success &= false;
            continue;
        }
        publishables.add(publishable);
    }
    Publisher publisher = new Publisher(params.getCell().getFilesystem(), Optional.ofNullable(remoteRepo), Optional.ofNullable(username), Optional.ofNullable(password), dryRun);
    try {
        ImmutableSet<DeployResult> deployResults = publisher.publish(new SourcePathResolver(new SourcePathRuleFinder(getBuild().getRuleResolver())), publishables.build());
        for (DeployResult deployResult : deployResults) {
            printArtifactsInformation(params, deployResult);
        }
    } catch (DeploymentException e) {
        params.getConsole().printBuildFailureWithoutStacktraceDontUnwrap(e);
        return false;
    }
    return success;
}
Also used : Publisher(com.facebook.buck.maven.Publisher) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) MavenPublishable(com.facebook.buck.jvm.java.MavenPublishable) ImmutableSet(com.google.common.collect.ImmutableSet) DeployResult(org.eclipse.aether.deployment.DeployResult) BuildTarget(com.facebook.buck.model.BuildTarget) NoSuchBuildTargetException(com.facebook.buck.parser.NoSuchBuildTargetException) BuildRule(com.facebook.buck.rules.BuildRule) DeploymentException(org.eclipse.aether.deployment.DeploymentException)

Example 4 with MavenPublishable

use of com.facebook.buck.jvm.java.MavenPublishable in project buck by facebook.

the class PomIntegrationTest method testMultipleInvocation.

@Test
public void testMultipleInvocation() throws Exception {
    // Setup: deps: com.example:with-deps:jar:1.0 -> com.othercorp:no-deps:jar:1.0
    BuildRule dep = createMavenPublishable("//example:dep", "com.othercorp:no-deps:1.0", null);
    MavenPublishable item = createMavenPublishable("//example:has-deps", "com.example:with-deps:1.0", null, dep);
    Path pomPath = tmp.getRoot().resolve("pom.xml");
    assertFalse(Files.exists(pomPath));
    // Basic case
    Pom.generatePomFile(pathResolver, item, pomPath);
    Model pomModel = parse(pomPath);
    assertEquals("com.example", pomModel.getGroupId());
    assertEquals("with-deps", pomModel.getArtifactId());
    assertEquals("1.0", pomModel.getVersion());
    List<Dependency> dependencies = pomModel.getDependencies();
    assertEquals(1, dependencies.size());
    Dependency dependency = dependencies.get(0);
    assertEquals("com.othercorp", dependency.getGroupId());
    assertEquals("no-deps", dependency.getArtifactId());
    assertEquals("1.0", dependency.getVersion());
    // Corrupt dependency data and ensure buck restores that
    removeDependencies(pomModel, pomPath);
    Pom.generatePomFile(pathResolver, item, pomPath);
    pomModel = parse(pomPath);
    // Add extra pom data and ensure buck preserves that
    pomModel.setUrl(URL);
    serializePom(pomModel, pomPath);
    Pom.generatePomFile(pathResolver, item, pomPath);
    pomModel = parse(pomPath);
    assertEquals(URL, pomModel.getUrl());
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) Path(java.nio.file.Path) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) Model(org.apache.maven.model.Model) BuildRule(com.facebook.buck.rules.BuildRule) Dependency(org.apache.maven.model.Dependency) MavenPublishable(com.facebook.buck.jvm.java.MavenPublishable) Test(org.junit.Test)

Example 5 with MavenPublishable

use of com.facebook.buck.jvm.java.MavenPublishable in project buck by facebook.

the class PomIntegrationTest method shouldUseTemplateIfProvided.

@Test
public void shouldUseTemplateIfProvided() throws Exception {
    MavenPublishable withoutTemplate = createMavenPublishable("//example:no-template", "example.com:project:1.0.0", null);
    Model noTemplate = parse(Pom.generatePomFile(pathResolver, withoutTemplate));
    MavenPublishable withTemplate = createMavenPublishable("//example:template", "example.com:project:1.0.0", new FakeSourcePath(TestDataHelper.getTestDataDirectory(getClass()).resolve("poms/template-pom.xml").toString()));
    Model templated = parse(Pom.generatePomFile(pathResolver, withTemplate));
    // Template sets developers and an example dep. Check that these aren't in the non-templated
    // version
    assertTrue(noTemplate.getDevelopers().isEmpty());
    assertTrue(noTemplate.getDependencies().isEmpty());
    // Now check the same fields in the templated version.
    Developer seenDev = Iterables.getOnlyElement(templated.getDevelopers());
    assertEquals("susan", seenDev.getId());
    assertEquals("Susan The Developer", seenDev.getName());
    assertEquals(ImmutableList.of("Owner"), seenDev.getRoles());
    Dependency seenDep = Iterables.getOnlyElement(templated.getDependencies());
    assertEquals("com.google.guava", seenDep.getGroupId());
    assertEquals("guava", seenDep.getArtifactId());
    assertEquals("19.0", seenDep.getVersion());
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) Model(org.apache.maven.model.Model) Developer(org.apache.maven.model.Developer) Dependency(org.apache.maven.model.Dependency) MavenPublishable(com.facebook.buck.jvm.java.MavenPublishable) Test(org.junit.Test)

Aggregations

MavenPublishable (com.facebook.buck.jvm.java.MavenPublishable)8 Test (org.junit.Test)5 BuildTarget (com.facebook.buck.model.BuildTarget)4 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)4 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)4 BuildRule (com.facebook.buck.rules.BuildRule)3 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)3 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)3 TargetGraph (com.facebook.buck.rules.TargetGraph)3 UnflavoredBuildTarget (com.facebook.buck.model.UnflavoredBuildTarget)2 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 Path (java.nio.file.Path)2 Dependency (org.apache.maven.model.Dependency)2 Model (org.apache.maven.model.Model)2 DeployResult (org.eclipse.aether.deployment.DeployResult)2 DeploymentException (org.eclipse.aether.deployment.DeploymentException)2 Publisher (com.facebook.buck.maven.Publisher)1 NoSuchBuildTargetException (com.facebook.buck.parser.NoSuchBuildTargetException)1 ExplicitBuildTargetSourcePath (com.facebook.buck.rules.ExplicitBuildTargetSourcePath)1