Search in sources :

Example 6 with ArchiveMemberPath

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

the class DefaultFileHashCache method get.

@Override
public HashCode get(ArchiveMemberPath archiveMemberPath) throws IOException {
    Preconditions.checkArgument(!archiveMemberPath.isAbsolute());
    checkNotIgnored(archiveMemberPath.getArchivePath());
    Path relativeFilePath = archiveMemberPath.getArchivePath().normalize();
    try {
        HashCodeAndFileType fileHashCodeAndFileType = loadingCache.get(relativeFilePath);
        Path memberPath = archiveMemberPath.getMemberPath();
        HashCodeAndFileType memberHashCodeAndFileType = fileHashCodeAndFileType.getContents().get(memberPath);
        if (memberHashCodeAndFileType == null) {
            throw new NoSuchFileException(archiveMemberPath.toString());
        }
        return memberHashCodeAndFileType.getHashCode();
    } catch (ExecutionException e) {
        Throwables.throwIfInstanceOf(e.getCause(), IOException.class);
        throw new RuntimeException(e.getCause());
    }
}
Also used : ArchiveMemberPath(com.facebook.buck.io.ArchiveMemberPath) Path(java.nio.file.Path) NoSuchFileException(java.nio.file.NoSuchFileException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException)

Example 7 with ArchiveMemberPath

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

the class SourcePathResolverTest method testGetRelativePathForArchiveMemberSourcePath.

@Test
public void testGetRelativePathForArchiveMemberSourcePath() {
    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("//foo:bar", pathResolver));
    Path archivePath = filesystem.getBuckPaths().getGenDir().resolve("foo.jar");
    SourcePath archiveSourcePath = new ExplicitBuildTargetSourcePath(rule.getBuildTarget(), archivePath);
    Path memberPath = Paths.get("foo.class");
    ArchiveMemberSourcePath path = new ArchiveMemberSourcePath(archiveSourcePath, memberPath);
    ArchiveMemberPath relativePath = pathResolver.getRelativeArchiveMemberPath(path);
    assertEquals(archivePath, relativePath.getArchivePath());
    assertEquals(memberPath, relativePath.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 8 with ArchiveMemberPath

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

the class RuleKeyTest method createEmptyRuleKey.

private RuleKeyBuilder<RuleKeyResult<RuleKey>> createEmptyRuleKey(SourcePathResolver resolver, SourcePathRuleFinder ruleFinder) {
    FileHashCache fileHashCache = new FileHashCache() {

        @Override
        public void invalidate(Path path) {
        }

        @Override
        public void invalidateAll() {
        }

        @Override
        public HashCode get(Path path) {
            return HashCode.fromString("deadbeef");
        }

        @Override
        public HashCode get(ArchiveMemberPath archiveMemberPath) {
            return HashCode.fromString("deadbeef");
        }

        @Override
        public long getSize(Path path) {
            return 0;
        }

        @Override
        public void set(Path path, HashCode hashCode) {
        }
    };
    BuildTarget buildTarget = BuildTargetFactory.newInstance("//some:example");
    BuildRule buildRule = new FakeBuildRule(buildTarget, resolver);
    return new DefaultRuleKeyFactory(0, fileHashCache, resolver, ruleFinder).newBuilderForTesting(buildRule);
}
Also used : ArchiveMemberPath(com.facebook.buck.io.ArchiveMemberPath) Path(java.nio.file.Path) NullFileHashCache(com.facebook.buck.util.cache.NullFileHashCache) FakeFileHashCache(com.facebook.buck.testutil.FakeFileHashCache) DefaultFileHashCache(com.facebook.buck.util.cache.DefaultFileHashCache) StackedFileHashCache(com.facebook.buck.util.cache.StackedFileHashCache) FileHashCache(com.facebook.buck.util.cache.FileHashCache) ArchiveMemberPath(com.facebook.buck.io.ArchiveMemberPath) HashCode(com.google.common.hash.HashCode) DefaultRuleKeyFactory(com.facebook.buck.rules.keys.DefaultRuleKeyFactory) BuildTarget(com.facebook.buck.model.BuildTarget)

Example 9 with ArchiveMemberPath

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

the class SourcePathResolver method getRelativeArchiveMemberPath.

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

Example 10 with ArchiveMemberPath

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

the class StackedFileHashCacheTest method skipsFirstCacheForArchiveMemberPathAbsolutePath.

@Test
public void skipsFirstCacheForArchiveMemberPathAbsolutePath() throws IOException {
    Path fullPath = Paths.get("world.jar");
    ProjectFilesystem filesystem = new ProjectFilesystem(tmp.getRoot());
    writeJarWithHashes(filesystem, filesystem.resolve(fullPath));
    ArchiveMemberPath archiveMemberPath = ArchiveMemberPath.of(filesystem.resolve(fullPath), Paths.get("Nonexistent.class"));
    ProjectFileHashCache innerCache = DefaultFileHashCache.createDefaultFileHashCache(filesystem);
    StackedFileHashCache cache = new StackedFileHashCache(ImmutableList.of(innerCache));
    expectedException.expect(NoSuchFileException.class);
    cache.get(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) 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