Search in sources :

Example 31 with ImmutableList

use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.collect.ImmutableList in project buck by facebook.

the class AndroidBinaryIntegrationTest method testDxFindsReferencedResources.

@Test
public void testDxFindsReferencedResources() throws IOException {
    DefaultOnDiskBuildInfo buildInfo = new DefaultOnDiskBuildInfo(BuildTargetFactory.newInstance("//java/com/sample/lib:lib#dex"), new ProjectFilesystem(tmpFolder.getRoot()), ObjectMappers.newDefaultInstance());
    Optional<ImmutableList<String>> resourcesFromMetadata = buildInfo.getValues(DexProducedFromJavaLibrary.REFERENCED_RESOURCES);
    assertTrue(resourcesFromMetadata.isPresent());
    assertEquals(ImmutableSet.of("com.sample.top_layout", "com.sample2.title"), ImmutableSet.copyOf(resourcesFromMetadata.get()));
}
Also used : DefaultOnDiskBuildInfo(com.facebook.buck.rules.DefaultOnDiskBuildInfo) ImmutableList(com.google.common.collect.ImmutableList) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Test(org.junit.Test)

Example 32 with ImmutableList

use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.collect.ImmutableList in project buck by facebook.

the class AndroidBinaryTest method testCreateFilterResourcesStep.

@Test
public void testCreateFilterResourcesStep() throws Exception {
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    BuildRule keystoreRule = addKeystoreRule(resolver);
    BuildTarget target = BuildTargetFactory.newInstance("//:target");
    AndroidBinaryBuilder builder = AndroidBinaryBuilder.createBuilder(target).setManifest(new FakeSourcePath("AndroidManifest.xml")).setKeystore(keystoreRule.getBuildTarget()).setResourceFilter(new ResourceFilter(ImmutableList.of("mdpi"))).setResourceCompressionMode(ResourceCompressionMode.ENABLED_WITH_STRINGS_AS_ASSETS);
    AndroidBinary buildRule = builder.build(resolver);
    ImmutableList<Path> resourceDirectories = ImmutableList.of(Paths.get("one"), Paths.get("two"));
    FilteredResourcesProvider resourcesProvider = buildRule.getEnhancementResult().getAaptPackageResources().getFilteredResourcesProvider();
    assertTrue(resourcesProvider instanceof ResourcesFilter);
    ImmutableList.Builder<Path> filteredDirs = ImmutableList.builder();
    ((ResourcesFilter) resourcesProvider).createFilterResourcesStep(resourceDirectories, /* whitelistedStringsDir */
    ImmutableSet.of(), /* locales */
    ImmutableSet.of(), filteredDirs);
    assertEquals(ImmutableList.of(BuildTargets.getScratchPath(buildRule.getProjectFilesystem(), target.withFlavors(AndroidBinaryGraphEnhancer.RESOURCES_FILTER_FLAVOR), "__filtered__%s__/0"), BuildTargets.getScratchPath(buildRule.getProjectFilesystem(), target.withFlavors(AndroidBinaryGraphEnhancer.RESOURCES_FILTER_FLAVOR), "__filtered__%s__/1")), filteredDirs.build());
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) Path(java.nio.file.Path) ImmutableList(com.google.common.collect.ImmutableList) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) ResourceFilter(com.facebook.buck.android.FilterResourcesStep.ResourceFilter) BuildTarget(com.facebook.buck.model.BuildTarget) BuildRule(com.facebook.buck.rules.BuildRule) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Example 33 with ImmutableList

use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.collect.ImmutableList in project buck by facebook.

the class ClassNodeListSupplierTest method testOneJar.

@Test
public void testOneJar() throws IOException {
    File jar = new File(tmpDir.getRoot(), "primary.jar");
    ZipOutputStream jarOut = new JarOutputStream(new FileOutputStream(jar));
    jarOut.putNextEntry(new JarEntry("com/facebook/buck/android/ClassNodeListSupplierTest.class"));
    writeClassBytes(ClassNodeListSupplierTest.class, jarOut);
    jarOut.close();
    Supplier<ImmutableList<ClassNode>> supplier = ClassNodeListSupplier.createMemoized(ImmutableList.of(jar.toPath()));
    ImmutableList<ClassNode> classNodes = supplier.get();
    assertEquals(1, classNodes.size());
    assertEquals(Type.getType(ClassNodeListSupplierTest.class).getInternalName(), classNodes.get(0).name);
    // Memoized should always return the same object
    assertSame(classNodes, supplier.get());
}
Also used : ClassNode(org.objectweb.asm.tree.ClassNode) ZipOutputStream(java.util.zip.ZipOutputStream) ImmutableList(com.google.common.collect.ImmutableList) FileOutputStream(java.io.FileOutputStream) JarOutputStream(java.util.jar.JarOutputStream) JarEntry(java.util.jar.JarEntry) File(java.io.File) Test(org.junit.Test)

Example 34 with ImmutableList

use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.collect.ImmutableList in project buck by facebook.

the class CompileStringsStepTest method testScrapeNodesWithSameName.

@Test
public void testScrapeNodesWithSameName() throws IOException, SAXException {
    String xmlInput = "<string name='name1' gender='unknown'>1</string>" + "<string name='name1_f1gender' gender='female'>1 f1</string>" + "<plurals name='name1' gender='unknown'>" + "<item quantity='one'>2</item>" + "<item quantity='other'>3</item>" + "</plurals>" + "<plurals name='name1_f1gender' gender='female'>" + "<item quantity='one'>2 f1</item>" + "<item quantity='other'>3 f1</item>" + "</plurals>" + "<string-array name='name1' gender='unknown'>" + "<item>4</item>" + "<item>5</item>" + "</string-array>" + "<string-array name='name1_f1gender' gender='female'>" + "<item>4 f1</item>" + "<item>5 f1</item>" + "</string-array>";
    NodeList stringNodes = XmlDomParser.parse(createResourcesXml(xmlInput)).getElementsByTagName("string");
    NodeList pluralsNodes = XmlDomParser.parse(createResourcesXml(xmlInput)).getElementsByTagName("plurals");
    NodeList arrayNodes = XmlDomParser.parse(createResourcesXml(xmlInput)).getElementsByTagName("string-array");
    Map<Integer, EnumMap<Gender, String>> stringMap = Maps.newTreeMap();
    Map<Integer, EnumMap<Gender, ImmutableMap<String, String>>> pluralsMap = Maps.newTreeMap();
    Map<Integer, EnumMap<Gender, ImmutableList<String>>> arraysMap = Maps.newTreeMap();
    EnumMap<Gender, String> map1 = Maps.newEnumMap(Gender.class);
    map1.put(Gender.unknown, "1");
    map1.put(Gender.female, "1 f1");
    EnumMap<Gender, Map<String, String>> map2 = Maps.newEnumMap(Gender.class);
    map2.put(Gender.unknown, ImmutableMap.of("one", "2", "other", "3"));
    map2.put(Gender.female, ImmutableMap.of("one", "2 f1", "other", "3 f1"));
    EnumMap<Gender, ImmutableList<String>> map3 = Maps.newEnumMap(Gender.class);
    map3.put(Gender.unknown, ImmutableList.of("4", "5"));
    map3.put(Gender.female, ImmutableList.of("4 f1", "5 f1"));
    CompileStringsStep step = createNonExecutingStep();
    step.addStringResourceNameToIdMap(ImmutableMap.of("name1", 1));
    step.addPluralsResourceNameToIdMap(ImmutableMap.of("name1", 2));
    step.addArrayResourceNameToIdMap(ImmutableMap.of("name1", 3));
    step.scrapeStringNodes(stringNodes, stringMap);
    step.scrapePluralsNodes(pluralsNodes, pluralsMap);
    step.scrapeStringArrayNodes(arrayNodes, arraysMap);
    assertEquals("Incorrect map of resource id to string.", ImmutableMap.of(1, map1), stringMap);
    assertEquals("Incorrect map of resource id to plurals.", ImmutableMap.of(2, map2), pluralsMap);
    assertEquals("Incorrect map of resource id to string arrays.", ImmutableMap.of(3, map3), arraysMap);
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) NodeList(org.w3c.dom.NodeList) Gender(com.facebook.buck.android.StringResources.Gender) EnumMap(java.util.EnumMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) EnumMap(java.util.EnumMap) Test(org.junit.Test)

Example 35 with ImmutableList

use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.collect.ImmutableList in project buck by facebook.

the class CompileStringsStepTest method testScrapeStringArrayNodes.

@Test
public void testScrapeStringArrayNodes() throws IOException, SAXException {
    String xmlInput = "<string-array name='name1' gender='unknown'>" + "<item>Value12</item>" + "<item>Value11</item>" + "</string-array>" + "<string-array name='name1_f1gender' gender='female'>" + "<item>Value12 f1</item>" + "<item>Value11 f1</item>" + "</string-array>" + "<string-array name='name2' gender='unknown'>" + "<item>Value21</item>" + "</string-array>" + "<string-array name='name2_m2gender' gender='male'>" + "<item>Value21 m2</item>" + "</string-array>" + "<string-array name='name3' gender='unknown'></string-array>" + "<string-array name='name2' gender='unknown'>" + // Ignored because "name2" already found above.
    "<item>ignored</item>" + "</string-array>";
    EnumMap<Gender, List<String>> map1 = Maps.newEnumMap(Gender.class);
    map1.put(Gender.unknown, ImmutableList.of("Value12", "Value11"));
    map1.put(Gender.female, ImmutableList.of("Value12 f1", "Value11 f1"));
    EnumMap<Gender, List<String>> map2 = Maps.newEnumMap(Gender.class);
    map2.put(Gender.unknown, ImmutableList.of("Value21"));
    map2.put(Gender.male, ImmutableList.of("Value21 m2"));
    NodeList arrayNodes = XmlDomParser.parse(createResourcesXml(xmlInput)).getElementsByTagName("string-array");
    Map<Integer, EnumMap<Gender, ImmutableList<String>>> arraysMap = Maps.newTreeMap();
    CompileStringsStep step = createNonExecutingStep();
    step.addArrayResourceNameToIdMap(ImmutableMap.of("name1", 1, "name2", 2, "name3", 3));
    step.scrapeStringArrayNodes(arrayNodes, arraysMap);
    assertEquals("Incorrect map of resource id to string arrays.", ImmutableMap.of(1, map1, 2, map2), arraysMap);
}
Also used : NodeList(org.w3c.dom.NodeList) ImmutableList(com.google.common.collect.ImmutableList) NodeList(org.w3c.dom.NodeList) List(java.util.List) Gender(com.facebook.buck.android.StringResources.Gender) EnumMap(java.util.EnumMap) Test(org.junit.Test)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1079 List (java.util.List)293 ArrayList (java.util.ArrayList)169 Test (org.junit.Test)161 Map (java.util.Map)152 Path (java.nio.file.Path)149 ImmutableMap (com.google.common.collect.ImmutableMap)127 IOException (java.io.IOException)112 Set (java.util.Set)99 ImmutableSet (com.google.common.collect.ImmutableSet)98 SourcePath (com.facebook.buck.rules.SourcePath)91 Optional (java.util.Optional)89 HashMap (java.util.HashMap)85 Step (com.facebook.buck.step.Step)76 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)71 Collectors (java.util.stream.Collectors)62 File (java.io.File)58 HashSet (java.util.HashSet)58 Nullable (javax.annotation.Nullable)54 ExplicitBuildTargetSourcePath (com.facebook.buck.rules.ExplicitBuildTargetSourcePath)52