Search in sources :

Example 6 with ImmutableSet

use of org.apache.beam.vendor.calcite.v1_28_0.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();
}
Also used : TestRule(com.facebook.buck.rules.TestRule) JavaLibraryWithTests(com.facebook.buck.jvm.java.JavaLibraryWithTests) ImmutableSet(com.google.common.collect.ImmutableSet) JavaLibrary(com.facebook.buck.jvm.java.JavaLibrary) DefaultJavaLibrary(com.facebook.buck.jvm.java.DefaultJavaLibrary) BuildTarget(com.facebook.buck.model.BuildTarget) JavaTest(com.facebook.buck.jvm.java.JavaTest)

Example 7 with ImmutableSet

use of org.apache.beam.vendor.calcite.v1_28_0.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"));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) TargetNode(com.facebook.buck.rules.TargetNode) ImmutableSet(com.google.common.collect.ImmutableSet) BuildTarget(com.facebook.buck.model.BuildTarget) TargetGraph(com.facebook.buck.rules.TargetGraph) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 8 with ImmutableSet

use of org.apache.beam.vendor.calcite.v1_28_0.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)));
}
Also used : BuildTargetPattern(com.facebook.buck.model.BuildTargetPattern) Optional(java.util.Optional) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableSet(com.google.common.collect.ImmutableSet) BuildTarget(com.facebook.buck.model.BuildTarget) CellPathResolver(com.facebook.buck.rules.CellPathResolver)

Example 9 with ImmutableSet

use of org.apache.beam.vendor.calcite.v1_28_0.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());
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Matcher(java.util.regex.Matcher) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString)

Example 10 with ImmutableSet

use of org.apache.beam.vendor.calcite.v1_28_0.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")));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) ImmutableSet(com.google.common.collect.ImmutableSet) Test(org.junit.Test)

Aggregations

ImmutableSet (com.google.common.collect.ImmutableSet)346 Set (java.util.Set)85 ImmutableList (com.google.common.collect.ImmutableList)72 Path (java.nio.file.Path)70 ImmutableMap (com.google.common.collect.ImmutableMap)69 IOException (java.io.IOException)66 Optional (java.util.Optional)65 Map (java.util.Map)63 List (java.util.List)60 BuildTarget (com.facebook.buck.model.BuildTarget)58 Test (org.junit.Test)55 HashMap (java.util.HashMap)42 Collection (java.util.Collection)34 HashSet (java.util.HashSet)33 SourcePath (com.facebook.buck.rules.SourcePath)31 ArrayList (java.util.ArrayList)31 TargetNode (com.facebook.buck.rules.TargetNode)28 BuildRule (com.facebook.buck.rules.BuildRule)26 VisibleForTesting (com.google.common.annotations.VisibleForTesting)25 ImmutableSortedSet (com.google.common.collect.ImmutableSortedSet)25