Search in sources :

Example 6 with MavenPublishable

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

the class PublisherTest method errorRaisedForDuplicateFirstOrderAndTransitiveDep.

@Test
public void errorRaisedForDuplicateFirstOrderAndTransitiveDep() throws DeploymentException, NoSuchBuildTargetException {
    // Construct a graph that looks like this.  A and B have maven coordinates set.
    // A   B
    // |   |
    // C   |
    //  \ /
    //   D
    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");
    TargetNode<?, ?> transitiveDepNode = JavaLibraryBuilder.createBuilder(targetD).addSrc(Paths.get("d.java")).build();
    TargetNode<?, ?> depNode = JavaLibraryBuilder.createBuilder(targetC).addSrc(Paths.get("c.java")).addDep(targetD).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, 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(targetD.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 7 with MavenPublishable

use of com.facebook.buck.jvm.java.MavenPublishable 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 8 with MavenPublishable

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

the class Publisher method checkForDuplicatePackagedDeps.

/**
   * Checks for any packaged dependencies that exist between more than one of the targets that we
   * are trying to publish.
   * @return A multimap of dependency build targets and the publishable build targets that have them
   * included in the final package that will be uploaded.
   */
private ImmutableListMultimap<UnflavoredBuildTarget, UnflavoredBuildTarget> checkForDuplicatePackagedDeps(ImmutableSet<MavenPublishable> publishables) {
    // First build the multimap of the builtin dependencies and the publishable targets that use
    // them.
    Multimap<UnflavoredBuildTarget, UnflavoredBuildTarget> builtinDeps = HashMultimap.create();
    for (MavenPublishable publishable : publishables) {
        for (BuildRule buildRule : publishable.getPackagedDependencies()) {
            builtinDeps.put(buildRule.getBuildTarget().getUnflavoredBuildTarget(), publishable.getBuildTarget().getUnflavoredBuildTarget());
        }
    }
    // Now, check for any duplicate uses, and if found, return them.
    ImmutableListMultimap.Builder<UnflavoredBuildTarget, UnflavoredBuildTarget> builder = ImmutableListMultimap.builder();
    for (UnflavoredBuildTarget buildTarget : builtinDeps.keySet()) {
        Collection<UnflavoredBuildTarget> publishablesUsingBuildTarget = builtinDeps.get(buildTarget);
        if (publishablesUsingBuildTarget.size() > 1) {
            builder.putAll(buildTarget, publishablesUsingBuildTarget);
        }
    }
    return builder.build();
}
Also used : ImmutableListMultimap(com.google.common.collect.ImmutableListMultimap) BuildRule(com.facebook.buck.rules.BuildRule) UnflavoredBuildTarget(com.facebook.buck.model.UnflavoredBuildTarget) MavenPublishable(com.facebook.buck.jvm.java.MavenPublishable)

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