use of com.facebook.buck.rules.FakeBuildRuleParamsBuilder in project buck by facebook.
the class AndroidLibraryGraphEnhancerTest method testEmptyResources.
@Test
public void testEmptyResources() {
BuildTarget buildTarget = BuildTargetFactory.newInstance("//java/com/example:library");
AndroidLibraryGraphEnhancer graphEnhancer = new AndroidLibraryGraphEnhancer(buildTarget, new FakeBuildRuleParamsBuilder(buildTarget).build(), DEFAULT_JAVAC_OPTIONS, DependencyMode.FIRST_ORDER, /* forceFinalResourceIds */
false, /* unionPackage */
Optional.empty(), /* rName */
Optional.empty(), false);
Optional<DummyRDotJava> result = graphEnhancer.getBuildableForAndroidResources(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()), /* createdBuildableIfEmptyDeps */
false);
assertFalse(result.isPresent());
}
use of com.facebook.buck.rules.FakeBuildRuleParamsBuilder in project buck by facebook.
the class AndroidLibraryGraphEnhancerTest method testBuildableIsCreated.
@Test
public void testBuildableIsCreated() {
BuildTarget buildTarget = BuildTargetFactory.newInstance("//java/com/example:library");
BuildRuleResolver ruleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(ruleResolver);
BuildRule resourceRule1 = ruleResolver.addToIndex(AndroidResourceRuleBuilder.newBuilder().setRuleFinder(ruleFinder).setBuildTarget(BuildTargetFactory.newInstance("//android_res/com/example:res1")).setRDotJavaPackage("com.facebook").setRes(new FakeSourcePath("android_res/com/example/res1")).build());
BuildRule resourceRule2 = ruleResolver.addToIndex(AndroidResourceRuleBuilder.newBuilder().setRuleFinder(ruleFinder).setBuildTarget(BuildTargetFactory.newInstance("//android_res/com/example:res2")).setRDotJavaPackage("com.facebook").setRes(new FakeSourcePath("android_res/com/example/res2")).build());
BuildRuleParams buildRuleParams = new FakeBuildRuleParamsBuilder(buildTarget).setDeclaredDeps(ImmutableSortedSet.of(resourceRule1, resourceRule2)).build();
AndroidLibraryGraphEnhancer graphEnhancer = new AndroidLibraryGraphEnhancer(buildTarget, buildRuleParams, DEFAULT_JAVAC_OPTIONS, DependencyMode.FIRST_ORDER, /* forceFinalResourceIds */
false, /* unionPackage */
Optional.empty(), /* rName */
Optional.empty(), false);
Optional<DummyRDotJava> dummyRDotJava = graphEnhancer.getBuildableForAndroidResources(ruleResolver, /* createBuildableIfEmptyDeps */
false);
assertTrue(dummyRDotJava.isPresent());
assertEquals("DummyRDotJava must contain these exact AndroidResourceRules.", // Note: these are the reverse order to which they are in the buildRuleParams.
ImmutableList.of(resourceRule1, resourceRule2), dummyRDotJava.get().getAndroidResourceDeps());
assertEquals("//java/com/example:library#dummy_r_dot_java", dummyRDotJava.get().getFullyQualifiedName());
assertEquals("DummyRDotJava must depend on the two AndroidResourceRules.", ImmutableSet.of("//android_res/com/example:res1", "//android_res/com/example:res2"), dummyRDotJava.get().getDeps().stream().map(Object::toString).collect(MoreCollectors.toImmutableSet()));
}
use of com.facebook.buck.rules.FakeBuildRuleParamsBuilder in project buck by facebook.
the class AndroidResourceTest method testGetRDotJavaPackageWhenPackageIsSpecified.
@Test
public void testGetRDotJavaPackageWhenPackageIsSpecified() throws IOException {
ProjectFilesystem projectFilesystem = FakeProjectFilesystem.createRealTempFilesystem();
BuildTarget buildTarget = BuildTargetFactory.newInstance(projectFilesystem, "//java/src/com/facebook/base:res");
BuildRuleParams params = new FakeBuildRuleParamsBuilder(buildTarget).setProjectFilesystem(projectFilesystem).build();
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
SourcePathResolver resolver = new SourcePathResolver(ruleFinder);
AndroidResource androidResource = new AndroidResource(params, ruleFinder, /* deps */
ImmutableSortedSet.of(), new FakeSourcePath("foo/res"), ImmutableSortedMap.of(Paths.get("values/strings.xml"), new FakeSourcePath("foo/res/values/strings.xml")), /* rDotJavaPackage */
"com.example.android", /* assets */
null, /* assetsSrcs */
ImmutableSortedMap.of(), /* manifestFile */
null, /* hasWhitelistedStrings */
false);
projectFilesystem.writeContentsToPath("com.example.android\n", resolver.getRelativePath(androidResource.getPathToRDotJavaPackageFile()));
FakeOnDiskBuildInfo onDiskBuildInfo = new FakeOnDiskBuildInfo();
androidResource.initializeFromDisk(onDiskBuildInfo);
assertEquals("com.example.android", androidResource.getRDotJavaPackage());
}
use of com.facebook.buck.rules.FakeBuildRuleParamsBuilder in project buck by facebook.
the class AndroidResourceTest method testGetRDotJavaPackageWhenPackageIsNotSpecified.
@Test
public void testGetRDotJavaPackageWhenPackageIsNotSpecified() throws IOException {
ProjectFilesystem projectFilesystem = FakeProjectFilesystem.createRealTempFilesystem();
BuildTarget buildTarget = BuildTargetFactory.newInstance(projectFilesystem, "//java/src/com/facebook/base:res");
BuildRuleParams params = new FakeBuildRuleParamsBuilder(buildTarget).setProjectFilesystem(projectFilesystem).build();
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
SourcePathResolver resolver = new SourcePathResolver(ruleFinder);
AndroidResource androidResource = new AndroidResource(params, ruleFinder, /* deps */
ImmutableSortedSet.of(), new FakeSourcePath("foo/res"), ImmutableSortedMap.of(Paths.get("values/strings.xml"), new FakeSourcePath("foo/res/values/strings.xml")), /* rDotJavaPackage */
null, /* assets */
null, /* assetsSrcs */
ImmutableSortedMap.of(), /* manifestFile */
new PathSourcePath(projectFilesystem, Paths.get("foo/AndroidManifest.xml")), /* hasWhitelistedStrings */
false);
projectFilesystem.writeContentsToPath("com.ex.pkg\n", resolver.getRelativePath(androidResource.getPathToRDotJavaPackageFile()));
FakeOnDiskBuildInfo onDiskBuildInfo = new FakeOnDiskBuildInfo();
androidResource.initializeFromDisk(onDiskBuildInfo);
assertEquals("com.ex.pkg", androidResource.getRDotJavaPackage());
}
use of com.facebook.buck.rules.FakeBuildRuleParamsBuilder in project buck by facebook.
the class AndroidLibraryGraphEnhancerTest method testCreatedBuildableHasOverriddenJavacConfig.
@Test
public void testCreatedBuildableHasOverriddenJavacConfig() {
BuildTarget buildTarget = BuildTargetFactory.newInstance("//java/com/example:library");
BuildRuleResolver ruleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(ruleResolver);
BuildRule resourceRule1 = ruleResolver.addToIndex(AndroidResourceRuleBuilder.newBuilder().setRuleFinder(ruleFinder).setBuildTarget(BuildTargetFactory.newInstance("//android_res/com/example:res1")).setRDotJavaPackage("com.facebook").setRes(new FakeSourcePath("android_res/com/example/res1")).build());
BuildRule resourceRule2 = ruleResolver.addToIndex(AndroidResourceRuleBuilder.newBuilder().setRuleFinder(ruleFinder).setBuildTarget(BuildTargetFactory.newInstance("//android_res/com/example:res2")).setRDotJavaPackage("com.facebook").setRes(new FakeSourcePath("android_res/com/example/res2")).build());
BuildRuleParams buildRuleParams = new FakeBuildRuleParamsBuilder(buildTarget).setDeclaredDeps(ImmutableSortedSet.of(resourceRule1, resourceRule2)).build();
AndroidLibraryGraphEnhancer graphEnhancer = new AndroidLibraryGraphEnhancer(buildTarget, buildRuleParams, JavacOptions.builder(ANDROID_JAVAC_OPTIONS).setAnnotationProcessingParams(new AnnotationProcessingParams.Builder().setProcessOnly(true).build()).setSourceLevel("7").setTargetLevel("7").build(), DependencyMode.FIRST_ORDER, /* forceFinalResourceIds */
false, /* unionPackage */
Optional.empty(), /* rName */
Optional.empty(), false);
Optional<DummyRDotJava> dummyRDotJava = graphEnhancer.getBuildableForAndroidResources(ruleResolver, /* createBuildableIfEmptyDeps */
false);
assertTrue(dummyRDotJava.isPresent());
JavacOptions javacOptions = dummyRDotJava.get().getJavacOptions();
assertFalse(javacOptions.getAnnotationProcessingParams().getProcessOnly());
assertEquals("7", javacOptions.getSourceLevel());
}
Aggregations