use of com.facebook.buck.jvm.java.JavaBinaryRuleBuilder in project buck by facebook.
the class AuditClasspathCommandTest method testClassPathWithVersions.
@Test
public void testClassPathWithVersions() throws Exception {
// Build the test target graph.
TargetNode<?, ?> javaLibrary = JavaLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//:test-java-library")).addSrc(Paths.get("src/com/facebook/TestJavaLibrary.java")).build();
TargetNode<?, ?> androidLibrary = JavaLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//:test-android-library")).addSrc(Paths.get("src/com/facebook/TestAndroidLibrary.java")).addDep(javaLibrary.getBuildTarget()).build();
TargetNode<?, ?> version = new VersionedAliasBuilder(BuildTargetFactory.newInstance("//:version")).setVersions("1.0", "//:test-android-library").build();
TargetNode<?, ?> binary = new JavaBinaryRuleBuilder(BuildTargetFactory.newInstance("//:rule")).setDeps(ImmutableSortedSet.of(version.getBuildTarget())).build();
TargetGraph targetGraph = TargetGraphFactory.newInstance(javaLibrary, androidLibrary, version, binary);
// Run the command.
auditClasspathCommand.printClasspath(params.withBuckConfig(FakeBuckConfig.builder().setSections(ImmutableMap.of("build", ImmutableMap.of("versions", "true"))).build()), targetGraph, ImmutableSet.of(androidLibrary.getBuildTarget(), javaLibrary.getBuildTarget()));
// Verify output.
Path root = javaLibrary.getBuildTarget().getUnflavoredBuildTarget().getCellPath();
ImmutableSortedSet<String> expectedPaths = ImmutableSortedSet.of(root.resolve(BuildTargets.getGenPath(params.getCell().getFilesystem(), androidLibrary.getBuildTarget(), "lib__%s__output").resolve(androidLibrary.getBuildTarget().getShortName() + ".jar")).toString(), root.resolve(BuildTargets.getGenPath(params.getCell().getFilesystem(), javaLibrary.getBuildTarget(), "lib__%s__output").resolve(javaLibrary.getBuildTarget().getShortName() + ".jar")).toString());
String expectedClasspath = Joiner.on("\n").join(expectedPaths) + "\n";
assertEquals(expectedClasspath, console.getTextWrittenToStdOut());
assertEquals("", console.getTextWrittenToStdErr());
}
use of com.facebook.buck.jvm.java.JavaBinaryRuleBuilder in project buck by facebook.
the class AuditClasspathCommandTest method testJsonClassPathWithVersions.
@Test
public void testJsonClassPathWithVersions() throws Exception {
// Build the test target graph.
TargetNode<?, ?> javaLibrary = JavaLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//:test-java-library")).addSrc(Paths.get("src/com/facebook/TestJavaLibrary.java")).build();
TargetNode<?, ?> androidLibrary = JavaLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//:test-android-library")).addSrc(Paths.get("src/com/facebook/TestAndroidLibrary.java")).addDep(javaLibrary.getBuildTarget()).build();
TargetNode<?, ?> version = new VersionedAliasBuilder(BuildTargetFactory.newInstance("//:version")).setVersions("1.0", "//:test-android-library").build();
TargetNode<?, ?> binary = new JavaBinaryRuleBuilder(BuildTargetFactory.newInstance("//:rule")).setDeps(ImmutableSortedSet.of(version.getBuildTarget())).build();
TargetGraph targetGraph = TargetGraphFactory.newInstance(javaLibrary, androidLibrary, version, binary);
// Run the command.
auditClasspathCommand.printJsonClasspath(params.withBuckConfig(FakeBuckConfig.builder().setSections(ImmutableMap.of("build", ImmutableMap.of("versions", "true"))).build()), targetGraph, ImmutableSet.of(androidLibrary.getBuildTarget(), javaLibrary.getBuildTarget()));
// Verify output.
Path root = javaLibrary.getBuildTarget().getCellPath();
ObjectMapper mapper = ObjectMappers.newDefaultInstance();
String expected = String.format(EXPECTED_JSON, mapper.valueToTree(root.resolve(BuildTargets.getGenPath(params.getCell().getFilesystem(), javaLibrary.getBuildTarget(), "lib__%s__output").resolve(javaLibrary.getBuildTarget().getShortName() + ".jar"))), mapper.valueToTree(root.resolve(BuildTargets.getGenPath(params.getCell().getFilesystem(), androidLibrary.getBuildTarget(), "lib__%s__output").resolve(androidLibrary.getBuildTarget().getShortName() + ".jar"))), mapper.valueToTree(root.resolve(BuildTargets.getGenPath(params.getCell().getFilesystem(), javaLibrary.getBuildTarget(), "lib__%s__output").resolve(javaLibrary.getBuildTarget().getShortName() + ".jar"))));
assertEquals(expected, console.getTextWrittenToStdOut());
assertEquals("", console.getTextWrittenToStdErr());
}
use of com.facebook.buck.jvm.java.JavaBinaryRuleBuilder in project buck by facebook.
the class ProjectCommandIntellijTest method buildGraph.
@Before
public void buildGraph() {
// Create the following dep tree:
//
// FooBin -has-test-> FooBinTest
// |
// V
// FooLib -has-test-> FooLibTest
// | |
// V V
// BarLib BazLib -has-test-> BazLibTest
// ^
// |
// QuxBin
BuildTarget dummyRootBinTarget = BuildTargetFactory.newInstance("//:bindummy");
BuildTarget barLibTarget = BuildTargetFactory.newInstance("//bar:lib");
BuildTarget fooLibTarget = BuildTargetFactory.newInstance("//foo:lib");
BuildTarget fooBinTarget = BuildTargetFactory.newInstance("//foo:binbinary");
BuildTarget bazLibTarget = BuildTargetFactory.newInstance("//baz:lib");
BuildTarget bazTestTarget = BuildTargetFactory.newInstance("//baz:xctest");
BuildTarget fooTestTarget = BuildTargetFactory.newInstance("//foo:lib-xctest");
BuildTarget fooBinTestTarget = BuildTargetFactory.newInstance("//foo:bin-xctest");
BuildTarget quxBinTarget = BuildTargetFactory.newInstance("//qux:bin");
BuildTarget fooProjectTarget = BuildTargetFactory.newInstance("//foo:foo");
BuildTarget bazProjectTarget = BuildTargetFactory.newInstance("//baz:baz");
BuildTarget dummyProjectTarget = BuildTargetFactory.newInstance("//:dummy");
dummyRootBinNode = new JavaBinaryRuleBuilder(dummyRootBinTarget).build();
barLibNode = JavaLibraryBuilder.createBuilder(barLibTarget).build();
fooLibNode = JavaLibraryBuilder.createBuilder(fooLibTarget).addDep(barLibTarget).addTest(fooTestTarget).build();
fooBinNode = new JavaBinaryRuleBuilder(fooBinTarget).setDeps(ImmutableSortedSet.of(fooLibTarget)).addTest(fooBinTestTarget).build();
bazLibNode = JavaLibraryBuilder.createBuilder(bazLibTarget).addTest(bazTestTarget).build();
bazTestNode = JavaTestBuilder.createBuilder(bazTestTarget).build();
fooTestNode = JavaTestBuilder.createBuilder(fooTestTarget).addDep(bazLibTarget).build();
fooBinTestNode = JavaTestBuilder.createBuilder(fooBinTestTarget).build();
quxBinNode = new JavaBinaryRuleBuilder(quxBinTarget).setDeps(ImmutableSortedSet.of(barLibTarget)).build();
fooProjectNode = ProjectConfigBuilder.createBuilder(fooProjectTarget).setSrcRule(fooBinTarget).build();
bazProjectNode = ProjectConfigBuilder.createBuilder(bazProjectTarget).setSrcRule(bazLibTarget).build();
dummyProjectNode = ProjectConfigBuilder.createBuilder(dummyProjectTarget).setSrcRule(dummyRootBinTarget).build();
targetGraph = TargetGraphFactory.newInstance(dummyRootBinNode, barLibNode, fooLibNode, fooBinNode, bazLibNode, bazTestNode, fooTestNode, fooBinTestNode, quxBinNode, fooProjectNode, bazProjectNode, dummyProjectNode);
}
use of com.facebook.buck.jvm.java.JavaBinaryRuleBuilder in project buck by facebook.
the class LocationMacroExpanderTest method createSampleJavaBinaryRule.
private BuildRule createSampleJavaBinaryRule(BuildRuleResolver ruleResolver) throws NoSuchBuildTargetException {
// Create a java_binary that depends on a java_library so it is possible to create a
// java_binary rule with a classpath entry and a main class.
BuildRule javaLibrary = JavaLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//java/com/facebook/util:util")).addSrc(Paths.get("java/com/facebook/util/ManifestGenerator.java")).build(ruleResolver);
BuildTarget buildTarget = BuildTargetFactory.newInstance("//java/com/facebook/util:ManifestGenerator");
return new JavaBinaryRuleBuilder(buildTarget).setDeps(ImmutableSortedSet.of(javaLibrary.getBuildTarget())).setMainClass("com.facebook.util.ManifestGenerator").build(ruleResolver);
}
use of com.facebook.buck.jvm.java.JavaBinaryRuleBuilder in project buck by facebook.
the class ExecutableMacroExpanderTest method createSampleJavaBinaryRule.
private BuildRule createSampleJavaBinaryRule(BuildRuleResolver ruleResolver) throws Exception {
// Create a java_binary that depends on a java_library so it is possible to create a
// java_binary rule with a classpath entry and a main class.
BuildRule javaLibrary = JavaLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//java/com/facebook/util:util")).addSrc(Paths.get("java/com/facebook/util/ManifestGenerator.java")).build(ruleResolver);
BuildTarget buildTarget = BuildTargetFactory.newInstance("//java/com/facebook/util:ManifestGenerator");
return new JavaBinaryRuleBuilder(buildTarget).setDeps(ImmutableSortedSet.of(javaLibrary.getBuildTarget())).setMainClass("com.facebook.util.ManifestGenerator").build(ruleResolver);
}
Aggregations