Search in sources :

Example 6 with FakeProjectFilesystem

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)));
}
Also used : Path(java.nio.file.Path) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Test(org.junit.Test)

Example 7 with FakeProjectFilesystem

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)));
}
Also used : Path(java.nio.file.Path) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Test(org.junit.Test)

Example 8 with FakeProjectFilesystem

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)));
    }
}
Also used : Path(java.nio.file.Path) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Test(org.junit.Test)

Example 9 with FakeProjectFilesystem

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);
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) Step(com.facebook.buck.step.Step)

Example 10 with FakeProjectFilesystem

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);
}
Also used : Path(java.nio.file.Path) FakeBuildableContext(com.facebook.buck.rules.FakeBuildableContext) ImmutableList(com.google.common.collect.ImmutableList) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) Step(com.facebook.buck.step.Step) Test(org.junit.Test)

Aggregations

FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)438 Test (org.junit.Test)384 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)268 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)189 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)186 Path (java.nio.file.Path)169 BuildTarget (com.facebook.buck.model.BuildTarget)138 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)111 TargetGraph (com.facebook.buck.rules.TargetGraph)107 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)103 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)85 PathSourcePath (com.facebook.buck.rules.PathSourcePath)68 BuildRule (com.facebook.buck.rules.BuildRule)61 SourcePath (com.facebook.buck.rules.SourcePath)56 RuleKey (com.facebook.buck.rules.RuleKey)42 AllExistingProjectFilesystem (com.facebook.buck.testutil.AllExistingProjectFilesystem)40 TestExecutionContext (com.facebook.buck.step.TestExecutionContext)39 ExecutionContext (com.facebook.buck.step.ExecutionContext)38 Before (org.junit.Before)30 FakeFileHashCache (com.facebook.buck.testutil.FakeFileHashCache)29