use of com.facebook.buck.jvm.java.classes.FileLike in project buck by facebook.
the class HashInputJarsToDexStep method execute.
@Override
public StepExecutionResult execute(final ExecutionContext context) {
ImmutableList.Builder<Path> allInputs = ImmutableList.builder();
allInputs.addAll(primaryInputsToDex.get());
if (secondaryOutputToInputs.isPresent()) {
allInputs.addAll(secondaryOutputToInputs.get().get().values());
}
final Map<String, HashCode> classNamesToHashes = classNamesToHashesSupplier.get();
for (Path path : allInputs.build()) {
try {
final Hasher hasher = Hashing.sha1().newHasher();
new DefaultClasspathTraverser().traverse(new ClasspathTraversal(Collections.singleton(path), filesystem) {
@Override
public void visit(FileLike fileLike) throws IOException {
String className = fileLike.getRelativePath().replaceAll("\\.class$", "");
if (classNamesToHashes.containsKey(className)) {
HashCode classHash = Preconditions.checkNotNull(classNamesToHashes.get(className));
hasher.putBytes(classHash.asBytes());
}
}
});
dexInputsToHashes.put(path, Sha1HashCode.fromHashCode(hasher.hash()));
} catch (IOException e) {
context.logError(e, "Error hashing smart dex input: %s", path);
return StepExecutionResult.ERROR;
}
}
stepFinished = true;
return StepExecutionResult.SUCCESS;
}
Aggregations