Search in sources :

Example 1 with ArchiveMemberPath

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

the class SourcePathResolver method getAbsoluteArchiveMemberPath.

public ArchiveMemberPath getAbsoluteArchiveMemberPath(SourcePath sourcePath) {
    Preconditions.checkState(sourcePath instanceof ArchiveMemberSourcePath);
    ArchiveMemberSourcePath archiveMemberSourcePath = (ArchiveMemberSourcePath) sourcePath;
    Path archiveAbsolutePath = getAbsolutePath(archiveMemberSourcePath.getArchiveSourcePath());
    return ArchiveMemberPath.of(archiveAbsolutePath, archiveMemberSourcePath.getMemberPath());
}
Also used : ArchiveMemberPath(com.facebook.buck.io.ArchiveMemberPath) Path(java.nio.file.Path)

Example 2 with ArchiveMemberPath

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

the class DistBuildFileHashesTest method readsHashesForArchiveMembers.

@Test
public void readsHashesForArchiveMembers() throws Exception {
    try (ArchiveFilesFixture f = ArchiveFilesFixture.create(archiveTempDir)) {
        List<BuildJobStateFileHashes> recordedHashes = f.distributedBuildFileHashes.getFileHashes();
        ProjectFilesystem readProjectFilesystem = new ProjectFilesystem(tempDir.newFolder("read_hashes").toPath().toRealPath());
        ProjectFileHashCache mockCache = EasyMock.createMock(ProjectFileHashCache.class);
        EasyMock.expect(mockCache.getFilesystem()).andReturn(readProjectFilesystem).anyTimes();
        EasyMock.replay(mockCache);
        ProjectFileHashCache fileHashCache = DistBuildFileHashes.createFileHashCache(mockCache, recordedHashes.get(0));
        ArchiveMemberPath archiveMemberPath = ArchiveMemberPath.of(readProjectFilesystem.resolve(f.archivePath), f.archiveMemberPath);
        assertThat(fileHashCache.willGet(archiveMemberPath), Matchers.is(true));
        assertThat(fileHashCache.get(archiveMemberPath), Matchers.is(f.archiveMemberHash));
    }
}
Also used : BuildJobStateFileHashes(com.facebook.buck.distributed.thrift.BuildJobStateFileHashes) ArchiveMemberPath(com.facebook.buck.io.ArchiveMemberPath) ProjectFileHashCache(com.facebook.buck.util.cache.ProjectFileHashCache) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Test(org.junit.Test)

Example 3 with ArchiveMemberPath

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

the class SourcePathResolverTest method testGetAbsolutePathForArchiveMemberSourcePath.

@Test
public void testGetAbsolutePathForArchiveMemberSourcePath() {
    ProjectFilesystem filesystem = new FakeProjectFilesystem();
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
    BuildRule rule = resolver.addToIndex(new FakeBuildRule(BuildTargetFactory.newInstance("//foo:bar"), filesystem, pathResolver));
    Path archivePath = filesystem.getBuckPaths().getGenDir().resolve("foo.jar");
    Path archiveAbsolutePath = filesystem.resolve(archivePath);
    SourcePath archiveSourcePath = new ExplicitBuildTargetSourcePath(rule.getBuildTarget(), archivePath);
    Path memberPath = Paths.get("foo.class");
    ArchiveMemberSourcePath path = new ArchiveMemberSourcePath(archiveSourcePath, memberPath);
    ArchiveMemberPath absolutePath = pathResolver.getAbsoluteArchiveMemberPath(path);
    assertEquals(archiveAbsolutePath, absolutePath.getArchivePath());
    assertEquals(memberPath, absolutePath.getMemberPath());
}
Also used : ArchiveMemberPath(com.facebook.buck.io.ArchiveMemberPath) Path(java.nio.file.Path) ArchiveMemberPath(com.facebook.buck.io.ArchiveMemberPath) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Test(org.junit.Test)

Example 4 with ArchiveMemberPath

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

the class StackedFileHashCacheTest method skipsFirstCacheBecauseIgnoredForArchiveMemberPath.

@Test
public void skipsFirstCacheBecauseIgnoredForArchiveMemberPath() throws IOException {
    Config config = ConfigBuilder.createFromText("[project]", "ignore = world.jar");
    ProjectFilesystem filesystem = new ProjectFilesystem(tmp.getRoot(), config);
    Path path = filesystem.getPath("world.jar");
    writeJarWithHashes(filesystem, path);
    ArchiveMemberPath archiveMemberPath = ArchiveMemberPath.of(path, filesystem.getPath("Nonexistent.class"));
    ProjectFileHashCache innerCache = DefaultFileHashCache.createDefaultFileHashCache(filesystem);
    StackedFileHashCache cache = new StackedFileHashCache(ImmutableList.of(innerCache));
    expectedException.expect(NoSuchFileException.class);
    cache.get(filesystem, archiveMemberPath);
}
Also used : ArchiveMemberPath(com.facebook.buck.io.ArchiveMemberPath) Path(java.nio.file.Path) ArchiveMemberPath(com.facebook.buck.io.ArchiveMemberPath) Config(com.facebook.buck.config.Config) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Test(org.junit.Test)

Example 5 with ArchiveMemberPath

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

the class StackedFileHashCacheTest method usesFirstCacheForArchivePath.

@Test
public void usesFirstCacheForArchivePath() throws IOException {
    ProjectFilesystem filesystem = new FakeProjectFilesystem();
    Path path = filesystem.getPath("world.jar");
    writeJarWithHashes(filesystem, path);
    ArchiveMemberPath archiveMemberPath = ArchiveMemberPath.of(path, Paths.get(SOME_FILE_INSIDE_JAR));
    ProjectFileHashCache innerCache = DefaultFileHashCache.createDefaultFileHashCache(filesystem);
    StackedFileHashCache cache = new StackedFileHashCache(ImmutableList.of(innerCache));
    cache.get(filesystem, archiveMemberPath);
    assertTrue(innerCache.willGet(archiveMemberPath));
}
Also used : ArchiveMemberPath(com.facebook.buck.io.ArchiveMemberPath) Path(java.nio.file.Path) ArchiveMemberPath(com.facebook.buck.io.ArchiveMemberPath) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Test(org.junit.Test)

Aggregations

ArchiveMemberPath (com.facebook.buck.io.ArchiveMemberPath)16 Path (java.nio.file.Path)14 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)11 Test (org.junit.Test)11 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)10 Config (com.facebook.buck.config.Config)2 BuildJobStateFileHashes (com.facebook.buck.distributed.thrift.BuildJobStateFileHashes)1 BuildTarget (com.facebook.buck.model.BuildTarget)1 ArchiveMemberSourcePath (com.facebook.buck.rules.ArchiveMemberSourcePath)1 DefaultRuleKeyFactory (com.facebook.buck.rules.keys.DefaultRuleKeyFactory)1 FakeFileHashCache (com.facebook.buck.testutil.FakeFileHashCache)1 DefaultFileHashCache (com.facebook.buck.util.cache.DefaultFileHashCache)1 FileHashCache (com.facebook.buck.util.cache.FileHashCache)1 NullFileHashCache (com.facebook.buck.util.cache.NullFileHashCache)1 ProjectFileHashCache (com.facebook.buck.util.cache.ProjectFileHashCache)1 StackedFileHashCache (com.facebook.buck.util.cache.StackedFileHashCache)1 HashCode (com.google.common.hash.HashCode)1 IOException (java.io.IOException)1 NoSuchFileException (java.nio.file.NoSuchFileException)1 ExecutionException (java.util.concurrent.ExecutionException)1