Skip to content

Commit 13d2a7a

Browse files
committed
checksum-dependency: cache PGP public keys under %{ROOT_DIR}/gradle/checksum-dependency-plugin/cached-pgp-keys
Fixes #42
1 parent fb2fb6b commit 13d2a7a

File tree

4 files changed

+32
-4
lines changed

4 files changed

+32
-4
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ This library is distributed under terms of Apache License 2.0
8787

8888
Change log
8989
----------
90+
v1.85
91+
* licence-gather: better support for build cache by adding PathSensitivity
92+
* checksum-dependency: cache PGP public keys under `%{ROOT_DIR}/gradle/checksum-dependency-plugin/cached-pgp-keys`
93+
9094
v1.84
9195
* no-op release, since some of the plugins failed to publish to Gradle Plugin Portal in v1.83
9296

plugins/checksum-dependency-plugin/README.md

+16-2
Original file line numberDiff line numberDiff line change
@@ -390,14 +390,25 @@ Configuration properties
390390

391391
since 1.29.0
392392

393-
* checksumCpuThreads (int, default: `ForkJoinPool.getCommonPoolParallelism()`) specifies the number of threads for CPU-bound tasks (PGP verification and SHA computation)
393+
* `checksumCpuThreads` (int, default: `ForkJoinPool.getCommonPoolParallelism()`) specifies the number of threads for CPU-bound tasks (PGP verification and SHA computation)
394394

395395
since 1.29.0
396396

397-
* checksumIoThreads (int, default: `50`) specifies the number of threads to use for PGP key resolution
397+
* `checksumIoThreads` (int, default: `50`) specifies the number of threads to use for PGP key resolution
398398

399399
since 1.29.0
400400

401+
* `checksumCachedPgpKeysDir` (string, default: `%{ROOT_DIR}/gradle/checksum-dependency-plugin/cached-pgp-keys`) specifies the location for cached PGP keys
402+
403+
Public PGP keys are needed for verification, so it is recommended to cache them and commit the keys under source control.
404+
It makes the build faster (as the keys are not downloaded on each build) and it reduces the chances for build failure caused by misbehaving PGP keyservers.
405+
406+
Placeholders:
407+
408+
* `%{ROOT_DIR}` replaces to `settings.rootDir.absolutePath`
409+
410+
since 1.85.0
411+
401412
* `pgpKeyserver` (string, comma separated) specifies keyserver for retrieval of the keys.
402413

403414
`*.asc` signatures alone are not sufficient for signature validation, so PGP public keys needs to be downloaded
@@ -487,6 +498,9 @@ Verification options
487498

488499
Changelog
489500
---------
501+
v1.85
502+
* Cache public PGP keys under `%{ROOT_DIR}/gradle/checksum-dependency-plugin/cached-pgp-keys` directory
503+
490504
v1.78
491505
* Retrieve keys from https://keyserver.ubuntu.com, and https://keys.openpgp.org by default (drop SKS keyserver pool since it has been deprecated)
492506

plugins/checksum-dependency-plugin/src/main/kotlin/com/github/vlsi/gradle/checksum/ChecksumDependencyPlugin.kt

+5-1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ open class ChecksumDependencyPlugin : Plugin<Settings> {
7474
val checksums = File(settings.rootDir, checksumFileName)
7575
val buildDir = settings.property("checksumBuildDir", "build/checksum")
7676
val buildFolder = File(settings.rootDir, buildDir)
77+
val cachedKeysRoot =
78+
settings.property("checksumCachedPgpKeysDir", "%{ROOT_DIR}/gradle/checksum-dependency-plugin/cached-pgp-keys")
79+
.replace("%{ROOT_DIR}", settings.rootDir.absolutePath)
80+
.let { File(it) }
7781

7882
val checksumUpdateAll = settings.boolProperty("checksumUpdateAll")
7983
val checksumUpdate = checksumUpdateAll || settings.boolProperty("checksumUpdate")
@@ -133,7 +137,7 @@ open class ChecksumDependencyPlugin : Plugin<Settings> {
133137
readTimeout = Duration.ofSeconds(pgpReadTimeout)
134138
)
135139
)
136-
val keyStore = KeyStore(File(buildFolder, "keystore"), keyDownloader)
140+
val keyStore = KeyStore(cachedKeysRoot, keyDownloader)
137141
val verification =
138142
if (checksums.exists()) {
139143
DependencyVerificationStore.load(checksums)

plugins/checksum-dependency-plugin/src/main/kotlin/com/github/vlsi/gradle/checksum/pgp/KeyStore.kt

+7-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,13 @@ class KeyStore(
8282
Files.createDirectories(parentFile.toPath())
8383
writeBytes(keyBytes)
8484
if (!renameTo(cacheFile)) {
85-
logger.warn("Unable to rename $this to $cacheFile")
85+
if (cacheFile.exists()) {
86+
// Another thread (e.g. another build) has already received the same key
87+
// Ignore the error
88+
delete()
89+
} else {
90+
logger.warn("Unable to rename $this to $cacheFile")
91+
}
8692
}
8793
}
8894
keyBytes.inputStream()

0 commit comments

Comments
 (0)