Search in sources :

Example 31 with ProjectFilesystem

use of com.facebook.buck.io.ProjectFilesystem in project buck by facebook.

the class AndroidManifestTest method testBuildInternal.

@Test
public void testBuildInternal() throws IOException {
    AndroidManifest androidManifest = createSimpleAndroidManifestRule();
    ProjectFilesystem filesystem = androidManifest.getProjectFilesystem();
    Path skeletonPath = Paths.get("java/com/example/AndroidManifestSkeleton.xml");
    // Mock out a BuildContext whose DependencyGraph will be traversed.
    BuildContext buildContext = FakeBuildContext.NOOP_CONTEXT;
    SourcePathResolver pathResolver = buildContext.getSourcePathResolver();
    expect(pathResolver.getAbsolutePath(new PathSourcePath(filesystem, skeletonPath))).andStubReturn(filesystem.resolve(skeletonPath));
    expect(pathResolver.getAllAbsolutePaths(ImmutableSortedSet.of())).andStubReturn(ImmutableSortedSet.of());
    Path outPath = Paths.get("foo/bar");
    expect(pathResolver.getRelativePath(androidManifest.getSourcePathToOutput())).andStubReturn(outPath);
    replay(pathResolver);
    List<Step> steps = androidManifest.getBuildSteps(buildContext, new FakeBuildableContext());
    Step generateManifestStep = steps.get(2);
    assertEquals(new GenerateManifestStep(filesystem, filesystem.resolve(skeletonPath), /* libraryManifestPaths */
    ImmutableSet.of(), outPath), generateManifestStep);
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) Path(java.nio.file.Path) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) FakeBuildableContext(com.facebook.buck.rules.FakeBuildableContext) FakeBuildContext(com.facebook.buck.rules.FakeBuildContext) BuildContext(com.facebook.buck.rules.BuildContext) PathSourcePath(com.facebook.buck.rules.PathSourcePath) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Step(com.facebook.buck.step.Step) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) Test(org.junit.Test)

Example 32 with ProjectFilesystem

use of com.facebook.buck.io.ProjectFilesystem in project buck by facebook.

the class DxStepTest method testDxCommandOptimizeNoJumbo.

@Test
public void testDxCommandOptimizeNoJumbo() throws IOException {
    // Context with --verbose 2.
    try (ExecutionContext context = createExecutionContext(2)) {
        ProjectFilesystem filesystem = FakeProjectFilesystem.createJavaOnlyFilesystem();
        DxStep dx = new DxStep(filesystem, SAMPLE_OUTPUT_PATH, SAMPLE_FILES_TO_DEX);
        String expected = String.format("%s --output %s %s", EXPECTED_DX_PREFIX, SAMPLE_OUTPUT_PATH, Joiner.on(' ').join(Iterables.transform(SAMPLE_FILES_TO_DEX, filesystem::resolve)));
        MoreAsserts.assertShellCommands("Neither --no-optimize nor --force-jumbo should be present.", ImmutableList.of(expected), ImmutableList.of(dx), context);
        verifyAll();
    }
}
Also used : ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Test(org.junit.Test)

Example 33 with ProjectFilesystem

use of com.facebook.buck.io.ProjectFilesystem in project buck by facebook.

the class DxStepTest method testDxCommandNoOptimizeNoJumbo.

@Test
public void testDxCommandNoOptimizeNoJumbo() throws IOException {
    // Context with --verbose 2.
    try (ExecutionContext context = createExecutionContext(2)) {
        ProjectFilesystem filesystem = FakeProjectFilesystem.createJavaOnlyFilesystem();
        DxStep dx = new DxStep(filesystem, SAMPLE_OUTPUT_PATH, SAMPLE_FILES_TO_DEX, EnumSet.of(Option.NO_OPTIMIZE));
        String expected = String.format("%s --no-optimize --output %s %s", EXPECTED_DX_PREFIX, SAMPLE_OUTPUT_PATH, Joiner.on(' ').join(Iterables.transform(SAMPLE_FILES_TO_DEX, filesystem::resolve)));
        MoreAsserts.assertShellCommands("--no-optimize should be present, but --force-jumbo should not.", ImmutableList.of(expected), ImmutableList.of(dx), context);
        verifyAll();
    }
}
Also used : ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Test(org.junit.Test)

Example 34 with ProjectFilesystem

use of com.facebook.buck.io.ProjectFilesystem 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 35 with ProjectFilesystem

use of com.facebook.buck.io.ProjectFilesystem 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)

Aggregations

ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)654 Test (org.junit.Test)542 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)401 Path (java.nio.file.Path)324 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)207 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)204 BuildTarget (com.facebook.buck.model.BuildTarget)203 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)126 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)121 TargetGraph (com.facebook.buck.rules.TargetGraph)119 PathSourcePath (com.facebook.buck.rules.PathSourcePath)96 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)92 ProjectWorkspace (com.facebook.buck.testutil.integration.ProjectWorkspace)90 SourcePath (com.facebook.buck.rules.SourcePath)79 ExecutionContext (com.facebook.buck.step.ExecutionContext)67 AllExistingProjectFilesystem (com.facebook.buck.testutil.AllExistingProjectFilesystem)67 TestExecutionContext (com.facebook.buck.step.TestExecutionContext)63 BuildRule (com.facebook.buck.rules.BuildRule)56 RuleKey (com.facebook.buck.rules.RuleKey)43 ArchiveMemberPath (com.facebook.buck.io.ArchiveMemberPath)42