use of org.gradle.security.internal.PublicKeyResultBuilder in project gradle by gradle.
the class CrossBuildCachingKeyService method findByLongId.
@Override
public void findByLongId(long keyId, PublicKeyResultBuilder builder) {
longIdGuard.guardByKey(keyId, () -> {
CacheEntry<List<Fingerprint>> fingerprints = longIdToFingerprint.getIfPresent(keyId);
if (fingerprints == null || hasExpired(fingerprints)) {
buildOperationExecutor.run(new RunnableBuildOperation() {
@Override
public void run(BuildOperationContext context) {
long currentTime = timeProvider.getCurrentTime();
AtomicBoolean missing = new AtomicBoolean(true);
delegate.findByLongId(keyId, new PublicKeyResultBuilder() {
@Override
public void keyRing(PGPPublicKeyRing keyring) {
missing.set(false);
builder.keyRing(keyring);
Iterator<PGPPublicKey> pkIt = keyring.getPublicKeys();
while (pkIt.hasNext()) {
PGPPublicKey publicKey = pkIt.next();
Fingerprint fingerprint = Fingerprint.of(publicKey);
publicKeyRings.put(fingerprint, new CacheEntry<>(currentTime, keyring));
updateLongKeyIndex(fingerprint, keyId);
}
}
@Override
public void publicKey(PGPPublicKey publicKey) {
missing.set(false);
if (publicKey.getKeyID() == keyId) {
builder.publicKey(publicKey);
}
}
});
if (missing.get()) {
longIdToFingerprint.put(keyId, new CacheEntry<>(currentTime, null));
}
}
@Override
public BuildOperationDescriptor.Builder description() {
return BuildOperationDescriptor.displayName("Fetching public key").progressDisplayName("Downloading public key " + toLongIdHexString(keyId));
}
});
} else {
if (fingerprints.value != null) {
for (Fingerprint fingerprint : fingerprints.value) {
findByFingerprint(fingerprint.getBytes(), new PublicKeyResultBuilder() {
@Override
public void keyRing(PGPPublicKeyRing keyring) {
builder.keyRing(keyring);
}
@Override
public void publicKey(PGPPublicKey publicKey) {
if (publicKey.getKeyID() == keyId) {
builder.publicKey(publicKey);
}
}
});
}
}
}
return null;
});
}
Aggregations