Search in sources :

Example 26 with FakeSourcePath

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", ""));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) Path(java.nio.file.Path) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) RType(com.facebook.buck.android.aapt.RDotTxtEntry.RType) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) BuildTarget(com.facebook.buck.model.BuildTarget) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Example 27 with FakeSourcePath

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"))));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 28 with FakeSourcePath

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);
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) Path(java.nio.file.Path) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 29 with FakeSourcePath

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"));
    }
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) Path(java.nio.file.Path) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) Matchers.containsString(org.hamcrest.Matchers.containsString) ResourceParseException(com.facebook.buck.android.aapt.MiniAapt.ResourceParseException) Test(org.junit.Test)

Example 30 with FakeSourcePath

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'"));
    }
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) Path(java.nio.file.Path) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) Matchers.containsString(org.hamcrest.Matchers.containsString) ResourceParseException(com.facebook.buck.android.aapt.MiniAapt.ResourceParseException) Test(org.junit.Test)

Aggregations

FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)318 Test (org.junit.Test)297 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)188 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)188 BuildTarget (com.facebook.buck.model.BuildTarget)182 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)116 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)104 SourcePath (com.facebook.buck.rules.SourcePath)90 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)85 TargetGraph (com.facebook.buck.rules.TargetGraph)84 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)68 Path (java.nio.file.Path)67 BuildRule (com.facebook.buck.rules.BuildRule)52 PathSourcePath (com.facebook.buck.rules.PathSourcePath)48 DefaultBuildTargetSourcePath (com.facebook.buck.rules.DefaultBuildTargetSourcePath)46 PBXTarget (com.facebook.buck.apple.xcode.xcodeproj.PBXTarget)45 FakeBuildRuleParamsBuilder (com.facebook.buck.rules.FakeBuildRuleParamsBuilder)45 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)35 CxxLibraryBuilder (com.facebook.buck.cxx.CxxLibraryBuilder)25 NSString (com.dd.plist.NSString)24