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