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());
}
}
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());
}
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);
}
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());
}
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);
}
Aggregations