use of com.facebook.buck.rules.FakeSourcePath in project buck by facebook.
the class MergeAndroidResourcesStepTest method testGenerateRDotJavaForCustomDrawables.
@Test
public void testGenerateRDotJavaForCustomDrawables() throws IOException {
BuildTarget target = BuildTargetFactory.newInstance("//android_res/com/facebook/http:res");
RDotTxtEntryBuilder entriesBuilder = new RDotTxtEntryBuilder();
String symbolsFile = BuildTargets.getGenPath(entriesBuilder.getProjectFilesystem(), target, "__%s_text_symbols__/R.txt").toString();
String rDotJavaPackage = "com.facebook";
final ImmutableList<String> outputTextSymbols = ImmutableList.<String>builder().add("int drawable android_drawable 0x7f010000").add("int drawable fb_drawable 0x7f010001 #").build();
entriesBuilder.add(new RDotTxtFile(rDotJavaPackage, symbolsFile, outputTextSymbols));
FakeProjectFilesystem filesystem = entriesBuilder.getProjectFilesystem();
Path uberRDotTxt = filesystem.resolve("R.txt").toAbsolutePath();
filesystem.writeLinesToPath(outputTextSymbols, uberRDotTxt);
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
SourcePathResolver resolver = new SourcePathResolver(ruleFinder);
HasAndroidResourceDeps resource = AndroidResourceRuleBuilder.newBuilder().setRuleFinder(ruleFinder).setBuildTarget(target).setRes(new FakeSourcePath("res")).setRDotJavaPackage("com.facebook").build();
MergeAndroidResourcesStep mergeStep = new MergeAndroidResourcesStep(filesystem, resolver, ImmutableList.of(resource), Optional.of(uberRDotTxt), Paths.get("output"), /* forceFinalResourceIds */
true, /* bannedDuplicateResourceTypes */
EnumSet.noneOf(RType.class), /* unionPackage */
Optional.empty(), /* rName */
Optional.empty(), /* useOldStyleableFormat */
false);
ExecutionContext executionContext = TestExecutionContext.newInstance();
assertEquals(0, mergeStep.execute(executionContext).getExitCode());
// Verify that the correct Java code is generated.
assertEquals("package com.facebook;\n" + "\n" + "public class R {\n" + " public static class drawable {\n" + " public static final int android_drawable=0x7f010000;\n" + " public static final int fb_drawable=0x7f010001;\n" + " }\n" + "\n" + " public static final int[] custom_drawables = { 0x7f010001 };\n" + "\n" + "}\n", filesystem.readFileIfItExists(Paths.get("output/com/facebook/R.java")).get().replace("\r", ""));
}
use of com.facebook.buck.rules.FakeSourcePath in project buck by facebook.
the class MiniAaptTest method testParsingAndroidDrawables.
@Test
public void testParsingAndroidDrawables() throws IOException, ResourceParseException {
ImmutableList<String> lines = ImmutableList.<String>builder().add("<?xml version=\"1.0\" encoding=\"UTF-8\"?>", "<bitmap xmlns:android=\"http://schemas.android.com/apk/res/android\">", " xmlns:fbui=\"http://schemas.android.com/apk/res-auto\"", " android:src=\"@drawable/other_bitmap\"", " >", "</bitmap>").build();
filesystem.writeLinesToPath(lines, Paths.get("android_drawable.xml"));
MiniAapt aapt = new MiniAapt(resolver, filesystem, new FakeSourcePath(filesystem, "res"), Paths.get("R.txt"), ImmutableSet.of());
aapt.processDrawables(filesystem, Paths.get("android_drawable.xml"));
Set<RDotTxtEntry> definitions = aapt.getResourceCollector().getResources();
assertThat(definitions, IsEqual.equalToObject(ImmutableSet.<RDotTxtEntry>of(new FakeRDotTxtEntry(IdType.INT, RType.DRAWABLE, "android_drawable"))));
}
use of com.facebook.buck.rules.FakeSourcePath in project buck by facebook.
the class MiniAaptTest method testUnionResources.
@Test
public void testUnionResources() throws IOException, XPathExpressionException, ResourceParseException {
ImmutableList<String> lines = ImmutableList.<String>builder().add("<?xml version=\"1.0\" encoding=\"UTF-8\"?>", "<resources>", "<string name=\"buck_string_1\">buck text 1 original</string>", "<id name=\"buck_id_1\"/>", "<style name=\"Buck.Style.1\">", " <item name=\"ignoreMe\" />", "</style>", "<declare-styleable name=\"Buck_Styleable_1\">", " <attr name=\"attr1_1\" />", " <attr name=\"attr1_2\" format=\"string\" />", " <attr name=\"attr1_3\" />", "</declare-styleable>", "</resources>").build();
filesystem.writeLinesToPath(lines, Paths.get("values.xml"));
ImmutableList<String> rDotTxt = ImmutableList.of("int string buck_string_1 0x07010001", "int string buck_string_2 0x07010002", "int id buck_id_2 0x07020002", "int style Buck_Style_2 0x07030002", "int[] styleable Buck_Styleable_2 { 0x07040001,0x07040002,0x07040003 }", "int styleable Buck_Styleable_2_attr2_1 0", "int styleable Buck_Styleable_2_attr2_2 1", "int styleable Buck_Styleable_2_attr2_3 2", "int attr attr2_1 0x07050001", "int attr attr2_2 0x07050002", "int attr attr2_3 0x07050003");
Path depRTxt = Paths.get("dep/R.txt");
filesystem.writeLinesToPath(rDotTxt, depRTxt);
MiniAapt aapt = new MiniAapt(resolver, filesystem, new FakeSourcePath(filesystem, "res"), Paths.get("R.txt"), ImmutableSet.of(depRTxt), /* resourceUnion */
true, /* isGrayscaleImageProcessingEnabled */
false);
aapt.processValuesFile(filesystem, Paths.get("values.xml"));
aapt.resourceUnion();
Set<RDotTxtEntry> resources = aapt.getResourceCollector().getResources();
assertEquals(ImmutableSet.<RDotTxtEntry>of(new FakeRDotTxtEntry(IdType.INT, RType.STRING, "buck_string_1"), new FakeRDotTxtEntry(IdType.INT, RType.ID, "buck_id_1"), new FakeRDotTxtEntry(IdType.INT, RType.STYLE, "Buck_Style_1"), new FakeRDotTxtEntry(IdType.INT_ARRAY, RType.STYLEABLE, "Buck_Styleable_1"), new FakeRDotTxtEntry(IdType.INT, RType.STYLEABLE, "Buck_Styleable_1_attr1_1"), new FakeRDotTxtEntry(IdType.INT, RType.STYLEABLE, "Buck_Styleable_1_attr1_2"), new FakeRDotTxtEntry(IdType.INT, RType.STYLEABLE, "Buck_Styleable_1_attr1_3"), new FakeRDotTxtEntry(IdType.INT, RType.ATTR, "attr1_1"), new FakeRDotTxtEntry(IdType.INT, RType.ATTR, "attr1_2"), new FakeRDotTxtEntry(IdType.INT, RType.ATTR, "attr1_3"), new FakeRDotTxtEntry(IdType.INT, RType.STRING, "buck_string_2"), new FakeRDotTxtEntry(IdType.INT, RType.ID, "buck_id_2"), new FakeRDotTxtEntry(IdType.INT, RType.STYLE, "Buck_Style_2"), new FakeRDotTxtEntry(IdType.INT_ARRAY, RType.STYLEABLE, "Buck_Styleable_2"), new FakeRDotTxtEntry(IdType.INT, RType.STYLEABLE, "Buck_Styleable_2_attr2_1"), new FakeRDotTxtEntry(IdType.INT, RType.STYLEABLE, "Buck_Styleable_2_attr2_2"), new FakeRDotTxtEntry(IdType.INT, RType.STYLEABLE, "Buck_Styleable_2_attr2_3"), new FakeRDotTxtEntry(IdType.INT, RType.ATTR, "attr2_1"), new FakeRDotTxtEntry(IdType.INT, RType.ATTR, "attr2_2"), new FakeRDotTxtEntry(IdType.INT, RType.ATTR, "attr2_3")), resources);
}
use of com.facebook.buck.rules.FakeSourcePath in project buck by facebook.
the class MiniAaptTest method testInvalidDefinition.
@Test
public void testInvalidDefinition() throws XPathExpressionException, IOException {
ImmutableList<String> lines = ImmutableList.<String>builder().add("<?xml version=\"1.0\" encoding=\"UTF-8\"?>", "<LinearLayout>", "<Button android:id=\"@+string/button1\" ", "android:layout_toLeftOf=\"@id/button2\" ", "android:text=\"@string/text\" />", "</LinearLayout>").build();
Path resource = Paths.get("resource.xml");
filesystem.writeLinesToPath(lines, resource);
MiniAapt aapt = new MiniAapt(resolver, filesystem, new FakeSourcePath(filesystem, "res"), Paths.get("R.txt"), ImmutableSet.of());
try {
aapt.processXmlFile(filesystem, resource, ImmutableSet.builder());
fail("MiniAapt should throw parsing '@+string/button1'");
} catch (ResourceParseException e) {
assertThat(e.getMessage(), containsString("Invalid definition of a resource"));
}
}
use of com.facebook.buck.rules.FakeSourcePath in project buck by facebook.
the class MiniAaptTest method testInvalidReference.
@Test
public void testInvalidReference() throws IOException, XPathExpressionException {
ImmutableList<String> lines = ImmutableList.<String>builder().add("<?xml version=\"1.0\" encoding=\"UTF-8\"?>", "<LinearLayout>", "<Button android:id=\"@+id/button1\" ", "android:layout_toLeftOf=\"@someresource/button2\" ", "android:text=\"@string/text\" />", "</LinearLayout>").build();
Path resource = Paths.get("resource.xml");
filesystem.writeLinesToPath(lines, resource);
MiniAapt aapt = new MiniAapt(resolver, filesystem, new FakeSourcePath(filesystem, "res"), Paths.get("R.txt"), ImmutableSet.of());
try {
aapt.processXmlFile(filesystem, resource, ImmutableSet.builder());
fail("MiniAapt should throw parsing '@someresource/button2'");
} catch (ResourceParseException e) {
assertThat(e.getMessage(), containsString("Invalid reference '@someresource/button2'"));
}
}
Aggregations