use of com.google.common.hash.HashCode in project buck by facebook.
the class ParserTest method deletingSourceFileChangesHash.
@Test
public void deletingSourceFileChangesHash() throws Exception {
tempDir.newFolder("foo");
Path testFooBuckFile = tempDir.newFile("foo/BUCK");
Files.write(testFooBuckFile, "java_library(name = 'lib', srcs=glob(['*.java']), visibility=['PUBLIC'])\n".getBytes(UTF_8));
Path testFooJavaFile = tempDir.newFile("foo/Foo.java");
Files.write(testFooJavaFile, "// Ceci n'est pas une Javafile\n".getBytes(UTF_8));
Path testBarJavaFile = tempDir.newFile("foo/Bar.java");
Files.write(testBarJavaFile, "// Seriously, no Java here\n".getBytes(UTF_8));
BuildTarget fooLibTarget = BuildTarget.builder(cellRoot, "//foo", "lib").build();
HashCode originalHash = buildTargetGraphAndGetHashCodes(parser, fooLibTarget).get(fooLibTarget);
Files.delete(testBarJavaFile);
WatchEvent<Path> deleteEvent = createPathEvent(Paths.get("foo/Bar.java"), StandardWatchEventKinds.ENTRY_DELETE);
parser.onFileSystemChange(deleteEvent);
HashCode updatedHash = buildTargetGraphAndGetHashCodes(parser, fooLibTarget).get(fooLibTarget);
assertNotEquals(originalHash, updatedHash);
}
use of com.google.common.hash.HashCode in project buck by facebook.
the class ParserTest method renamingSourceFileChangesHash.
@Test
public void renamingSourceFileChangesHash() throws Exception {
tempDir.newFolder("foo");
Path testFooBuckFile = tempDir.newFile("foo/BUCK");
Files.write(testFooBuckFile, "java_library(name = 'lib', srcs=glob(['*.java']), visibility=['PUBLIC'])\n".getBytes(UTF_8));
Path testFooJavaFile = tempDir.newFile("foo/Foo.java");
Files.write(testFooJavaFile, "// Ceci n'est pas une Javafile\n".getBytes(UTF_8));
BuildTarget fooLibTarget = BuildTarget.builder(cellRoot, "//foo", "lib").build();
HashCode originalHash = buildTargetGraphAndGetHashCodes(parser, fooLibTarget).get(fooLibTarget);
Files.move(testFooJavaFile, testFooJavaFile.resolveSibling("Bar.java"));
WatchEvent<Path> deleteEvent = createPathEvent(Paths.get("foo/Foo.java"), StandardWatchEventKinds.ENTRY_DELETE);
WatchEvent<Path> createEvent = createPathEvent(Paths.get("foo/Bar.java"), StandardWatchEventKinds.ENTRY_CREATE);
parser.onFileSystemChange(deleteEvent);
parser.onFileSystemChange(createEvent);
HashCode updatedHash = buildTargetGraphAndGetHashCodes(parser, fooLibTarget).get(fooLibTarget);
assertNotEquals(originalHash, updatedHash);
}
use of com.google.common.hash.HashCode in project buck by facebook.
the class FakeProjectFilesystem method computeSha1.
/**
* Does not support symlinks.
*/
@Override
public Sha1HashCode computeSha1(Path pathRelativeToProjectRootOrJustAbsolute) throws IOException {
if (!exists(pathRelativeToProjectRootOrJustAbsolute)) {
throw new NoSuchFileException(pathRelativeToProjectRootOrJustAbsolute.toString());
}
// Because this class is a fake, the file contents may not be available as a stream, so we load
// all of the contents into memory as a byte[] and then hash them.
byte[] fileContents = getFileBytes(pathRelativeToProjectRootOrJustAbsolute);
HashCode hashCode = Hashing.sha1().newHasher().putBytes(fileContents).hash();
return Sha1HashCode.fromHashCode(hashCode);
}
use of com.google.common.hash.HashCode in project buck by facebook.
the class RecordingProjectFileHashCache method get.
@Override
public HashCode get(Path relPath) throws IOException {
checkIsRelative(relPath);
Queue<Path> remainingPaths = new LinkedList<>();
remainingPaths.add(relPath);
while (remainingPaths.size() > 0) {
Path nextPath = remainingPaths.remove();
HashCode hashCode = delegate.get(nextPath);
List<PathWithUnixSeparators> children = ImmutableList.of();
if (projectFilesystem.isDirectory(nextPath)) {
children = processDirectory(nextPath, remainingPaths);
}
synchronized (this) {
if (!remoteFileHashes.containsAndAddPath(nextPath)) {
record(nextPath, Optional.empty(), hashCode, children);
}
}
}
return delegate.get(relPath);
}
use of com.google.common.hash.HashCode in project buck by facebook.
the class DexProducedFromJavaLibraryThatContainsClassFilesTest method testGetBuildStepsWhenThereAreClassesToDex.
@Test
public void testGetBuildStepsWhenThereAreClassesToDex() throws IOException, InterruptedException {
ProjectFilesystem filesystem = FakeProjectFilesystem.createJavaOnlyFilesystem();
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
FakeJavaLibrary javaLibraryRule = new FakeJavaLibrary(BuildTargetFactory.newInstance(filesystem.getRootPath(), "//foo:bar"), pathResolver, filesystem, ImmutableSortedSet.of()) {
@Override
public ImmutableSortedMap<String, HashCode> getClassNamesToHashes() {
return ImmutableSortedMap.of("com/example/Foo", HashCode.fromString("cafebabe"));
}
};
resolver.addToIndex(javaLibraryRule);
Path jarOutput = BuildTargets.getGenPath(filesystem, javaLibraryRule.getBuildTarget(), "%s.jar");
javaLibraryRule.setOutputFile(jarOutput.toString());
BuildContext context = FakeBuildContext.withSourcePathResolver(pathResolver);
FakeBuildableContext buildableContext = new FakeBuildableContext();
Path dexOutput = BuildTargets.getGenPath(filesystem, javaLibraryRule.getBuildTarget().withFlavors(AndroidBinaryGraphEnhancer.DEX_FLAVOR), "%s.dex.jar");
createFiles(filesystem, dexOutput.toString(), jarOutput.toString());
BuildTarget buildTarget = BuildTargetFactory.newInstance(filesystem.getRootPath(), "//foo:bar#dex");
BuildRuleParams params = new FakeBuildRuleParamsBuilder(buildTarget).setProjectFilesystem(filesystem).build();
DexProducedFromJavaLibrary preDex = new DexProducedFromJavaLibrary(params, javaLibraryRule);
List<Step> steps = preDex.getBuildSteps(context, buildableContext);
AndroidPlatformTarget androidPlatformTarget = createMock(AndroidPlatformTarget.class);
expect(androidPlatformTarget.getDxExecutable()).andStubReturn(Paths.get("/usr/bin/dx"));
EasyMock.replay(androidPlatformTarget);
ExecutionContext executionContext = TestExecutionContext.newBuilder().setAndroidPlatformTargetSupplier(Suppliers.ofInstance(androidPlatformTarget)).build();
String expectedDxCommand = String.format("%s --dex --no-optimize --force-jumbo --output %s %s", Paths.get("/usr/bin/dx"), filesystem.resolve(dexOutput), filesystem.resolve(jarOutput));
MoreAsserts.assertSteps("Generate bar.dex.jar.", ImmutableList.of(String.format("rm -f %s", filesystem.resolve(dexOutput)), String.format("mkdir -p %s", filesystem.resolve(dexOutput).getParent()), "estimate_dex_weight", "(cd " + filesystem.getRootPath() + " && " + expectedDxCommand + ")", String.format("zip-scrub %s", dexOutput), "record_dx_success"), steps, executionContext);
((EstimateDexWeightStep) steps.get(2)).setWeightEstimateForTesting(250);
Step recordArtifactAndMetadataStep = steps.get(5);
int exitCode = recordArtifactAndMetadataStep.execute(executionContext).getExitCode();
assertEquals(0, exitCode);
assertEquals("The generated .dex.jar file should be in the set of recorded artifacts.", ImmutableSet.of(BuildTargets.getGenPath(filesystem, buildTarget, "%s.dex.jar")), buildableContext.getRecordedArtifacts());
buildableContext.assertContainsMetadataMapping(DexProducedFromJavaLibrary.WEIGHT_ESTIMATE, "250");
}
Aggregations