Search in sources :

Example 6 with FileLike

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;
}
Also used : Path(java.nio.file.Path) ClasspathTraversal(com.facebook.buck.jvm.java.classes.ClasspathTraversal) Hasher(com.google.common.hash.Hasher) HashCode(com.google.common.hash.HashCode) Sha1HashCode(com.facebook.buck.util.sha1.Sha1HashCode) ImmutableList(com.google.common.collect.ImmutableList) DefaultClasspathTraverser(com.facebook.buck.jvm.java.classes.DefaultClasspathTraverser) IOException(java.io.IOException) FileLike(com.facebook.buck.jvm.java.classes.FileLike)

Aggregations

FileLike (com.facebook.buck.jvm.java.classes.FileLike)6 ClasspathTraversal (com.facebook.buck.jvm.java.classes.ClasspathTraversal)5 DefaultClasspathTraverser (com.facebook.buck.jvm.java.classes.DefaultClasspathTraverser)5 Path (java.nio.file.Path)5 IOException (java.io.IOException)4 ClasspathTraverser (com.facebook.buck.jvm.java.classes.ClasspathTraverser)2 ImmutableMultimap (com.google.common.collect.ImmutableMultimap)2 HashCode (com.google.common.hash.HashCode)2 HashMap (java.util.HashMap)2 APKModule (com.facebook.buck.android.APKModule)1 AbstractFileLike (com.facebook.buck.jvm.java.classes.AbstractFileLike)1 Sha1HashCode (com.facebook.buck.util.sha1.Sha1HashCode)1 ImmutableCollection (com.google.common.collect.ImmutableCollection)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Hasher (com.google.common.hash.Hasher)1 ByteSource (com.google.common.io.ByteSource)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1