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