use of com.facebook.buck.testutil.FakeProjectFilesystem in project buck by facebook.
the class FilterResourcesStepTest method valuesAlwaysIncludesFallback.
@Test
public void valuesAlwaysIncludesFallback() throws IOException, InterruptedException {
final ResourceFilters.Density targetDensity = ResourceFilters.Density.MDPI;
final String file = "somefile.xml";
final Path resDir = Paths.get("res/foo/bar");
final Path resOutDir = Paths.get("res-out");
ProjectFilesystem filesystem = new FakeProjectFilesystem();
filesystem.mkdirs(resDir);
filesystem.createNewFile(resDir.resolve("values").resolve(file));
filesystem.createNewFile(resDir.resolve(String.format("values-%s", targetDensity)).resolve(file));
FilterResourcesStep command = new FilterResourcesStep(filesystem, ImmutableBiMap.of(resDir, resOutDir), /* filterByDPI */
true, /* enableStringWhitelisting */
false, /* whitelistedStringDirs */
ImmutableSet.of(), /* locales */
ImmutableSet.of(), DefaultFilteredDirectoryCopier.getInstance(), ImmutableSet.of(targetDensity), FilterResourcesStep.DefaultDrawableFinder.getInstance(), /* imageScaler */
null);
command.execute(null);
assertThat(filesystem, ProjectFilesystemMatchers.pathExists(resOutDir.resolve("values").resolve(file)));
assertThat(filesystem, ProjectFilesystemMatchers.pathExists(resOutDir.resolve(String.format("values-%s", targetDensity)).resolve(file)));
}
use of com.facebook.buck.testutil.FakeProjectFilesystem in project buck by facebook.
the class FilterResourcesStepTest method xmlDrawableResourcesFiltered.
@Test
public void xmlDrawableResourcesFiltered() throws IOException, InterruptedException {
final ResourceFilters.Density targetDensity = ResourceFilters.Density.MDPI;
final ResourceFilters.Density excludedDensity = ResourceFilters.Density.LDPI;
final String file = "somefile.xml";
final Path resDir = Paths.get("res");
final Path resOutDir = Paths.get("res-out");
ProjectFilesystem filesystem = new FakeProjectFilesystem();
filesystem.mkdirs(resDir);
filesystem.createNewFile(resDir.resolve(String.format("drawable-%s", targetDensity)).resolve(file));
filesystem.createNewFile(resDir.resolve(String.format("drawable-%s", excludedDensity)).resolve(file));
FilterResourcesStep command = new FilterResourcesStep(filesystem, ImmutableBiMap.of(resDir, resOutDir), /* filterByDPI */
true, /* enableStringWhitelisting */
false, /* whitelistedStringDirs */
ImmutableSet.of(), /* locales */
ImmutableSet.of(), DefaultFilteredDirectoryCopier.getInstance(), ImmutableSet.of(targetDensity), FilterResourcesStep.DefaultDrawableFinder.getInstance(), /* imageScaler */
null);
command.execute(null);
assertThat(filesystem, ProjectFilesystemMatchers.pathExists(resOutDir.resolve(String.format("drawable-%s", targetDensity)).resolve(file)));
assertThat(filesystem, ProjectFilesystemMatchers.pathDoesNotExist(resOutDir.resolve(String.format("drawable-%s", excludedDensity)).resolve(file)));
}
use of com.facebook.buck.testutil.FakeProjectFilesystem in project buck by facebook.
the class FilterResourcesStepTest method fallsBackToDefaultWhenAllTargetsNotPresent.
@Test
public void fallsBackToDefaultWhenAllTargetsNotPresent() throws IOException, InterruptedException {
final ResourceFilters.Density targetDensity = ResourceFilters.Density.MDPI;
final ResourceFilters.Density providedDensity = ResourceFilters.Density.TVDPI;
final String file = "somefile";
final Path resDir = Paths.get("res/foo/bar");
final Path resOutDir = Paths.get("res-out");
ProjectFilesystem filesystem = new FakeProjectFilesystem();
filesystem.mkdirs(resDir);
for (String folderName : ResourceFilters.SUPPORTED_RESOURCE_DIRECTORIES) {
if (folderName.equals("drawable") || folderName.equals("values")) {
continue;
}
filesystem.createNewFile(resDir.resolve(folderName).resolve(file));
filesystem.createNewFile(resDir.resolve(String.format("%s-%s", folderName, providedDensity)).resolve(file));
}
FilterResourcesStep command = new FilterResourcesStep(filesystem, ImmutableBiMap.of(resDir, resOutDir), /* filterByDPI */
true, /* enableStringWhitelisting */
false, /* whitelistedStringDirs */
ImmutableSet.of(), /* locales */
ImmutableSet.of(), DefaultFilteredDirectoryCopier.getInstance(), ImmutableSet.of(targetDensity), FilterResourcesStep.DefaultDrawableFinder.getInstance(), /* imageScaler */
null);
command.execute(null);
for (String folderName : ResourceFilters.SUPPORTED_RESOURCE_DIRECTORIES) {
if (folderName.equals("drawable") || folderName.equals("values")) {
continue;
}
assertThat(filesystem, ProjectFilesystemMatchers.pathExists(resOutDir.resolve(folderName).resolve(file)));
assertThat(filesystem, ProjectFilesystemMatchers.pathDoesNotExist(resOutDir.resolve(String.format("%s-%s", folderName, targetDensity))));
assertThat(filesystem, ProjectFilesystemMatchers.pathDoesNotExist(resOutDir.resolve(String.format("%s-%s", folderName, providedDensity)).resolve(file)));
}
}
use of com.facebook.buck.testutil.FakeProjectFilesystem in project buck by facebook.
the class PreDexedFilesSorterTest method generatePreDexSorterResults.
private ImmutableMap<String, PreDexedFilesSorter.Result> generatePreDexSorterResults(int numberOfPrimaryDexes, int numberOfSecondaryDexes, int numberOfExtraDexes) throws IOException {
ImmutableMultimap.Builder<APKModule, DexWithClasses> inputDexes = ImmutableMultimap.builder();
for (int i = 0; i < numberOfPrimaryDexes; i++) {
inputDexes.put(moduleGraph.getRootAPKModule(), createFakeDexWithClasses(Paths.get("primary").resolve(String.format("/primary%d.dex", i)), ImmutableSet.of(String.format("primary.primary%d.class", i)), STANDARD_DEX_FILE_ESTIMATE));
}
for (int i = 0; i < numberOfSecondaryDexes; i++) {
inputDexes.put(moduleGraph.getRootAPKModule(), createFakeDexWithClasses(Paths.get("secondary").resolve(String.format("secondary%d.dex", i)), ImmutableSet.of(String.format("secondary.secondary%d.class", i)), STANDARD_DEX_FILE_ESTIMATE));
}
for (int i = 0; i < numberOfExtraDexes; i++) {
inputDexes.put(extraModule, createFakeDexWithClasses(Paths.get("extra").resolve(String.format("extra%d.dex", i)), ImmutableSet.of(String.format("extra.extra%d.class", i)), STANDARD_DEX_FILE_ESTIMATE));
}
PreDexedFilesSorter sorter = new PreDexedFilesSorter(Optional.empty(), inputDexes.build(), ImmutableSet.of(PRIMARY_DEX_PATTERN), moduleGraph, tempDir.newFolder("scratch").toPath(), DEX_WEIGHT_LIMIT, DexStore.JAR, tempDir.newFolder("secondary").toPath(), tempDir.newFolder("additional").toPath());
ImmutableList.Builder<Step> steps = ImmutableList.builder();
FakeProjectFilesystem filesystem = new FakeProjectFilesystem();
return sorter.sortIntoPrimaryAndSecondaryDexes(filesystem, steps);
}
use of com.facebook.buck.testutil.FakeProjectFilesystem in project buck by facebook.
the class ProGuardObfuscateStepTest method testAdditionalLibraryJarsParameterFormatting.
@Test
public void testAdditionalLibraryJarsParameterFormatting() {
Path cwd = Paths.get("root");
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(), /* proguardJvmArgs */
Optional.empty(), /* inputAndOutputEntries */
ImmutableMap.of(), /* additionalLibraryJarsForProguard */
ImmutableSet.of(Paths.get("myfavorite.jar"), Paths.get("another.jar")), Paths.get("proguard-directory"), new FakeBuildableContext(), false, steps);
ProGuardObfuscateStep.CommandLineHelperStep commandLineHelperStep = (ProGuardObfuscateStep.CommandLineHelperStep) steps.build().get(1);
ImmutableList<String> parameters = commandLineHelperStep.getParameters(executionContext, cwd);
int libraryJarsArgIndex = parameters.indexOf("-libraryjars");
int libraryJarsValueIndex = parameters.indexOf("myfavorite.jar" + File.pathSeparatorChar + "another.jar");
assertNotEquals(-1, libraryJarsArgIndex);
assertEquals(libraryJarsValueIndex, libraryJarsArgIndex + 1);
}
Aggregations