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));
}
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();
}
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();
}
Aggregations