use of com.facebook.buck.testutil.FakeProjectFilesystem in project buck by facebook.
the class ProGuardObfuscateStepTest method checkSdkConfig.
private void checkSdkConfig(ExecutionContext context, Path cwd, ProGuardObfuscateStep.SdkProguardType sdkProguardConfig, Optional<String> proguardAgentPath, String expectedPath) {
ImmutableList.Builder<Step> steps = ImmutableList.builder();
ProGuardObfuscateStep.create(JavaCompilationConstants.DEFAULT_JAVA_OPTIONS.getJavaRuntimeLauncher(), new FakeProjectFilesystem(), /* proguardJarOverride */
Optional.empty(), "1024M", proguardAgentPath, Paths.get("generated/proguard.txt"), /* customProguardConfigs */
ImmutableSet.of(), sdkProguardConfig, /* optimizationPasses */
Optional.empty(), /* proguardJvmArgs */
Optional.empty(), /* inputAndOutputEntries */
ImmutableMap.of(), /* additionalLibraryJarsForProguard */
ImmutableSet.of(), Paths.get("proguard-directory"), new FakeBuildableContext(), false, steps);
ProGuardObfuscateStep.CommandLineHelperStep commandLineHelperStep = (ProGuardObfuscateStep.CommandLineHelperStep) steps.build().get(1);
String found = null;
Iterator<String> argsIt = commandLineHelperStep.getParameters(context, cwd).iterator();
while (argsIt.hasNext()) {
String arg = argsIt.next();
if (!arg.equals("-include")) {
continue;
}
assertTrue(argsIt.hasNext());
String file = argsIt.next();
if (file.startsWith("sdk-")) {
found = file;
break;
}
}
assertEquals(expectedPath, found);
}
use of com.facebook.buck.testutil.FakeProjectFilesystem in project buck by facebook.
the class ProGuardObfuscateStepTest method testProguardJvmArgs.
@Test
public void testProguardJvmArgs() {
List<String> proguardJvmArgs = Arrays.asList("-Dparam1=value1", "-Dparam2=value2");
ImmutableList.Builder<Step> steps = ImmutableList.builder();
ProGuardObfuscateStep.create(JavaCompilationConstants.DEFAULT_JAVA_OPTIONS.getJavaRuntimeLauncher(), new FakeProjectFilesystem(), /* proguardJarOverride */
Optional.empty(), "1024M", Optional.empty(), Paths.get("generated/proguard.txt"), /* customProguardConfigs */
ImmutableSet.of(), ProGuardObfuscateStep.SdkProguardType.DEFAULT, /* optimizationPasses */
Optional.empty(), Optional.of(proguardJvmArgs), /* inputAndOutputEntries */
ImmutableMap.of(), /* additionalLibraryJarsForProguard */
ImmutableSet.of(Paths.get("myfavorite.jar"), Paths.get("another.jar")), Paths.get("proguard-directory"), new FakeBuildableContext(), false, steps);
ProGuardObfuscateStep proguardStep = (ProGuardObfuscateStep) steps.build().get(2);
ImmutableList<String> parameters = proguardStep.getShellCommandInternal(executionContext);
for (String s : proguardJvmArgs) {
assertNotEquals(-1, parameters.indexOf(s));
}
}
use of com.facebook.buck.testutil.FakeProjectFilesystem in project buck by facebook.
the class MergeAndroidResourcesStepTest method testGenerateRDotJavaWithPreviouslyEmptyResourceUnionPackage.
@Test
public void testGenerateRDotJavaWithPreviouslyEmptyResourceUnionPackage() throws IOException {
BuildTarget res1Target = BuildTargetFactory.newInstance("//:res1");
RDotTxtEntryBuilder entriesBuilder = new RDotTxtEntryBuilder();
entriesBuilder.add(new RDotTxtFile("com.res1", BuildTargets.getGenPath(entriesBuilder.getProjectFilesystem(), res1Target, "__%s_text_symbols__/R.txt").toString(), ImmutableList.of("int id id1 0x7f020000")));
FakeProjectFilesystem filesystem = entriesBuilder.getProjectFilesystem();
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
SourcePathResolver resolver = new SourcePathResolver(ruleFinder);
HasAndroidResourceDeps res1 = AndroidResourceRuleBuilder.newBuilder().setRuleFinder(ruleFinder).setBuildTarget(res1Target).setRes(new FakeSourcePath("res1")).setRDotJavaPackage("res1").build();
MergeAndroidResourcesStep mergeStep = MergeAndroidResourcesStep.createStepForDummyRDotJava(filesystem, resolver, ImmutableList.of(res1), Paths.get("output"), /* forceFinalResourceIds */
false, Optional.of("resM"), /* rName */
Optional.empty(), /* useOldStyleableFormat */
false);
ExecutionContext executionContext = TestExecutionContext.newInstance();
assertEquals(0, mergeStep.execute(executionContext).getExitCode());
String res1java = filesystem.readFileIfItExists(Paths.get("output/res1/R.java")).get();
String resMjava = filesystem.readFileIfItExists(Paths.get("output/resM/R.java")).get();
assertThat(res1java, StringContains.containsString("id1"));
assertThat(resMjava, StringContains.containsString("id1"));
}
use of com.facebook.buck.testutil.FakeProjectFilesystem in project buck by facebook.
the class MergeAndroidResourcesStepTest method testGenerateRDotJavaWithRName.
@Test
public void testGenerateRDotJavaWithRName() throws IOException {
BuildTarget res1Target = BuildTargetFactory.newInstance("//:res1");
RDotTxtEntryBuilder entriesBuilder = new RDotTxtEntryBuilder();
entriesBuilder.add(new RDotTxtFile("com.res1", BuildTargets.getGenPath(entriesBuilder.getProjectFilesystem(), res1Target, "__%s_text_symbols__/R.txt").toString(), ImmutableList.of("int id id1 0x7f020000", "int id id2 0x7f020002")));
FakeProjectFilesystem filesystem = entriesBuilder.getProjectFilesystem();
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
SourcePathResolver resolver = new SourcePathResolver(ruleFinder);
HasAndroidResourceDeps res1 = AndroidResourceRuleBuilder.newBuilder().setRuleFinder(ruleFinder).setBuildTarget(res1Target).setRes(new FakeSourcePath("res1")).setRDotJavaPackage("res1").build();
MergeAndroidResourcesStep mergeStep = MergeAndroidResourcesStep.createStepForDummyRDotJava(filesystem, resolver, ImmutableList.of(res1), Paths.get("output"), /* forceFinalResourceIds */
true, Optional.of("res1"), Optional.of("R2"), /* useOldStyleableFormat */
false);
ExecutionContext executionContext = TestExecutionContext.newInstance();
assertEquals(0, mergeStep.execute(executionContext).getExitCode());
String resR2Java = filesystem.readFileIfItExists(Paths.get("output/res1/R2.java")).get();
assertThat(resR2Java, StringContains.containsString("static final int id1=0x07f01001;"));
assertThat(resR2Java, StringContains.containsString("static final int id2=0x07f01002;"));
}
use of com.facebook.buck.testutil.FakeProjectFilesystem in project buck by facebook.
the class MergeAndroidResourcesStepTest method testGenerateRDotJavaWithResourceUnionPackage.
@Test
public void testGenerateRDotJavaWithResourceUnionPackage() throws IOException {
BuildTarget res1Target = BuildTargetFactory.newInstance("//:res1");
BuildTarget res2Target = BuildTargetFactory.newInstance("//:res2");
RDotTxtEntryBuilder entriesBuilder = new RDotTxtEntryBuilder();
entriesBuilder.add(new RDotTxtFile("com.res1", BuildTargets.getGenPath(entriesBuilder.getProjectFilesystem(), res1Target, "__%s_text_symbols__/R.txt").toString(), ImmutableList.of("int id id1 0x7f020000")));
entriesBuilder.add(new RDotTxtFile("com.res2", BuildTargets.getGenPath(entriesBuilder.getProjectFilesystem(), res2Target, "__%s_text_symbols__/R.txt").toString(), ImmutableList.of("int id id2 0x7f020000")));
FakeProjectFilesystem filesystem = entriesBuilder.getProjectFilesystem();
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
SourcePathResolver resolver = new SourcePathResolver(ruleFinder);
HasAndroidResourceDeps res1 = AndroidResourceRuleBuilder.newBuilder().setRuleFinder(ruleFinder).setBuildTarget(res1Target).setRes(new FakeSourcePath("res1")).setRDotJavaPackage("res1").build();
HasAndroidResourceDeps res2 = AndroidResourceRuleBuilder.newBuilder().setRuleFinder(ruleFinder).setBuildTarget(res2Target).setRes(new FakeSourcePath("res2")).setRDotJavaPackage("res2").build();
MergeAndroidResourcesStep mergeStep = MergeAndroidResourcesStep.createStepForDummyRDotJava(filesystem, resolver, ImmutableList.of(res1, res2), Paths.get("output"), /* forceFinalResourceIds */
false, Optional.of("res1"), /* rName */
Optional.empty(), /* useOldStyleableFormat */
false);
ExecutionContext executionContext = TestExecutionContext.newInstance();
assertEquals(0, mergeStep.execute(executionContext).getExitCode());
String res1java = filesystem.readFileIfItExists(Paths.get("output/res1/R.java")).get();
String res2java = filesystem.readFileIfItExists(Paths.get("output/res2/R.java")).get();
assertThat(res1java, StringContains.containsString("id1"));
assertThat(res1java, StringContains.containsString("id2"));
assertThat(res2java, CoreMatchers.not(StringContains.containsString("id1")));
assertThat(res2java, StringContains.containsString("id2"));
}
Aggregations