io.github.algomaster99.terminator.index.JdkIndexer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of classfile-fingerprint Show documentation
Show all versions of classfile-fingerprint Show documentation
Generates fingerprint of all classfiles in a JAR.
The newest version!
package io.github.algomaster99.terminator.index;
import io.github.algomaster99.terminator.commons.fingerprint.JdkClass;
import io.github.algomaster99.terminator.commons.fingerprint.JdkClassFinder;
import io.github.algomaster99.terminator.commons.fingerprint.classfile.ClassFileAttributes;
import io.github.algomaster99.terminator.commons.fingerprint.classfile.ClassFileUtilities;
import io.github.algomaster99.terminator.commons.fingerprint.classfile.HashComputer;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Callable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import picocli.CommandLine;
@CommandLine.Command(
name = "jdk",
mixinStandardHelpOptions = true,
description = "Create an index of the classfiles in JDK")
public class JdkIndexer extends BaseIndexer implements Callable {
private static final Logger LOGGER = LoggerFactory.getLogger(JdkIndexer.class);
Map> createOrMergeProvenances(
Map> referenceProvenance) {
System.out.println("--------------------");
System.out.println("Indexing all JDK classes ...");
List jdkClasses = JdkClassFinder.listJdkClasses();
jdkClasses.forEach(resource -> {
byte[] classfileBytes = resource.bytes();
String classfileVersion = ClassFileUtilities.getVersion(classfileBytes);
String hash = HashComputer.computeHash(classfileBytes);
referenceProvenance.computeIfAbsent(
resource.name(),
k -> new HashSet<>(Set.of(new ClassFileAttributes(classfileVersion, hash, algorithm))));
});
return referenceProvenance;
}
}