use of com.google.common.collect.ImmutableSet in project buck by facebook.
the class TestRunning method getRulesUnderTest.
/**
* Generates the set of Java library rules under test.
*/
private static ImmutableSet<JavaLibrary> getRulesUnderTest(Iterable<TestRule> tests) {
ImmutableSet.Builder<JavaLibrary> rulesUnderTest = ImmutableSet.builder();
// Gathering all rules whose source will be under test.
for (TestRule test : tests) {
if (test instanceof JavaTest) {
// Look at the transitive dependencies for `tests` attribute that refers to this test.
JavaTest javaTest = (JavaTest) test;
ImmutableSet<JavaLibrary> transitiveDeps = javaTest.getCompiledTestsLibrary().getTransitiveClasspathDeps();
for (JavaLibrary dep : transitiveDeps) {
if (dep instanceof JavaLibraryWithTests) {
ImmutableSortedSet<BuildTarget> depTests = ((JavaLibraryWithTests) dep).getTests();
if (depTests.contains(test.getBuildTarget())) {
rulesUnderTest.add(dep);
}
}
}
}
}
return rulesUnderTest.build();
}
use of com.google.common.collect.ImmutableSet in project buck by facebook.
the class APKModuleTest method testAPKModuleGraphSimple.
/*
+ - - - - - -+
' root: '
' '
' +--------+ '
+-------------- ' | Binary | ' --------+
| ' +--------+ ' |
| ' | ' |
| ' | ' |
v ' | ' v
+ - - - - - - + ' | ' +- - - - - +
' android: ' ' | ' ' java: '
' ' ' | ' ' '
' +---------+ ' ' | ' ' +------+ '
' | Android | ' ' | ' ' | Java | '
' +---------+ ' ' | ' ' +------+ '
' ' ' | ' ' '
+ - - - - - - + ' | ' +- - - - - +
| ' | ' |
| ' | ' |
| ' v ' |
| ' +--------+ ' |
+-------------> ' | Common | ' <-------+
' +--------+ '
' '
+ - - - - - -+
*/
@Test
public void testAPKModuleGraphSimple() throws Exception {
ImmutableSet.Builder<TargetNode<?, ?>> nodeBuilder = ImmutableSet.builder();
BuildTarget commonLibraryTarget = BuildTargetFactory.newInstance("//src/com/facebook/test-common-library:test-common-library");
nodeBuilder.add(AndroidLibraryBuilder.createBuilder(commonLibraryTarget).addSrc(Paths.get("src/com/facebook/TestCommonLibrary.java")).build());
BuildTarget javaLibraryTarget = BuildTargetFactory.newInstance("//src/com/facebook/test-java-library:test-java-library").withFlavors(InternalFlavor.of("flavor"));
nodeBuilder.add(JavaLibraryBuilder.createBuilder(javaLibraryTarget).addSrc(Paths.get("src/com/facebook/TestJavaLibrary.java")).addDep(commonLibraryTarget).build());
BuildTarget androidLibraryTarget = BuildTargetFactory.newInstance("//src/com/facebook/test-android-library:test-android-library");
nodeBuilder.add(AndroidLibraryBuilder.createBuilder(androidLibraryTarget).addSrc(Paths.get("src/com/facebook/TestAndroidLibrary.java")).addDep(commonLibraryTarget).build());
BuildTarget keystoreTarget = BuildTargetFactory.newInstance("//:keystore");
nodeBuilder.add(KeystoreBuilder.createBuilder(keystoreTarget).setStore(new FakeSourcePath("debug.keystore")).setProperties(new FakeSourcePath("keystore.properties")).build());
BuildTarget androidBinaryTarget = BuildTargetFactory.newInstance("//src/com/facebook/test-android-binary:test-android-binary");
nodeBuilder.add(AndroidBinaryBuilder.createBuilder(androidBinaryTarget).setManifest(new FakeSourcePath("AndroidManifest.xml")).setKeystore(keystoreTarget).setOriginalDeps(ImmutableSortedSet.of(androidLibraryTarget, javaLibraryTarget, commonLibraryTarget)).build());
TargetGraph graph = TargetGraphFactory.newInstance(nodeBuilder.build());
Set<BuildTarget> seedTargets = new HashSet<>();
seedTargets.add(androidLibraryTarget);
seedTargets.add(javaLibraryTarget);
APKModuleGraph dag = new APKModuleGraph(graph, androidBinaryTarget, Optional.of(seedTargets));
ImmutableSet<APKModule> topLevelNodes = dag.getGraph().getNodesWithNoIncomingEdges();
assertThat(topLevelNodes.size(), is(2));
for (APKModule apkModule : topLevelNodes) {
assertThat(apkModule.getName(), oneOf("src.com.facebook.test.android.library", "src.com.facebook.test.java.library.test.java.library.flavor"));
ImmutableSet<APKModule> dependencies = dag.getGraph().getOutgoingNodesFor(apkModule);
assertThat(apkModule.isRootModule(), is(false));
assertThat(dependencies.size(), is(1));
assertThat(Iterables.getFirst(dependencies, null).getName(), is(APKModuleGraph.ROOT_APKMODULE_NAME));
assertThat(Iterables.getFirst(dependencies, null).isRootModule(), is(true));
}
assertThat(dag.getAPKModules().stream().map(APKModule::getName).collect(MoreCollectors.toImmutableSet()), containsInAnyOrder("dex", "src.com.facebook.test.android.library", "src.com.facebook.test.java.library.test.java.library.flavor"));
}
use of com.google.common.collect.ImmutableSet in project buck by facebook.
the class TargetNodeTranslator method translateNode.
/**
* @return a copy of the given {@link TargetNode} with all found {@link BuildTarget}s translated,
* or {@link Optional#empty()} if the node requires no translation.
*/
public <A> Optional<TargetNode<A, ?>> translateNode(TargetNode<A, ?> node) {
CellPathResolver cellPathResolver = node.getCellNames();
BuildTargetPatternParser<BuildTargetPattern> pattern = BuildTargetPatternParser.forBaseName(node.getBuildTarget().getBaseName());
Optional<BuildTarget> target = translateBuildTarget(node.getBuildTarget());
Optional<A> constructorArg = translateConstructorArg(cellPathResolver, pattern, node);
Optional<ImmutableSet<BuildTarget>> declaredDeps = translateSet(cellPathResolver, pattern, node.getDeclaredDeps());
Optional<ImmutableSet<BuildTarget>> extraDeps = translateSet(cellPathResolver, pattern, node.getExtraDeps());
Optional<ImmutableMap<BuildTarget, Version>> newSelectedVersions = getSelectedVersions(node.getBuildTarget());
Optional<ImmutableMap<BuildTarget, Version>> oldSelectedVersions = node.getSelectedVersions();
Optional<Optional<ImmutableMap<BuildTarget, Version>>> selectedVersions = oldSelectedVersions.equals(newSelectedVersions) ? Optional.empty() : Optional.of(newSelectedVersions);
// If nothing has changed, don't generate a new node.
if (!target.isPresent() && !constructorArg.isPresent() && !declaredDeps.isPresent() && !extraDeps.isPresent() && !selectedVersions.isPresent()) {
return Optional.empty();
}
return Optional.of(node.withTargetConstructorArgDepsAndSelectedVerisons(target.orElse(node.getBuildTarget()), constructorArg.orElse(node.getConstructorArg()), declaredDeps.orElse(node.getDeclaredDeps()), extraDeps.orElse(node.getExtraDeps()), selectedVersions.orElse(oldSelectedVersions)));
}
use of com.google.common.collect.ImmutableSet in project buck by facebook.
the class AndroidBinaryIntegrationTest method verifyTrimmedRDotJava.
private void verifyTrimmedRDotJava(ImmutableSet<String> expected) throws IOException {
List<String> lines = filesystem.readLines(Paths.get("buck-out/gen/apps/multidex/disassemble_app_r_dot_java/all_r_fields.smali"));
ImmutableSet.Builder<String> found = ImmutableSet.builder();
for (String line : lines) {
Matcher m = SMALI_STATIC_FINAL_INT_PATTERN.matcher(line);
assertTrue("Could not match line: " + line, m.matches());
assertThat(m.group(1), IsIn.in(expected));
found.add(m.group(1));
}
assertEquals(expected, found.build());
}
use of com.google.common.collect.ImmutableSet in project buck by facebook.
the class MiniAaptTest method testFindingResourceIdsInXml.
@Test
public void testFindingResourceIdsInXml() throws IOException, XPathExpressionException, ResourceParseException {
filesystem.writeLinesToPath(RESOURCES, Paths.get("resource.xml"));
MiniAapt aapt = new MiniAapt(resolver, filesystem, new FakeSourcePath(filesystem, "res"), Paths.get("R.txt"), ImmutableSet.of());
ImmutableSet.Builder<RDotTxtEntry> references = ImmutableSet.builder();
aapt.processXmlFile(filesystem, Paths.get("resource.xml"), references);
Set<RDotTxtEntry> definitions = aapt.getResourceCollector().getResources();
assertEquals(definitions, ImmutableSet.<RDotTxtEntry>of(new FakeRDotTxtEntry(IdType.INT, RType.ID, "button1"), new FakeRDotTxtEntry(IdType.INT, RType.ID, "button3")));
assertEquals(references.build(), ImmutableSet.<RDotTxtEntry>of(new FakeRDotTxtEntry(IdType.INT, RType.DRAWABLE, "some_image"), new FakeRDotTxtEntry(IdType.INT, RType.STRING, "text"), new FakeRDotTxtEntry(IdType.INT, RType.STYLE, "Buck_Theme"), new FakeRDotTxtEntry(IdType.INT, RType.ID, "button2")));
}
Aggregations