From 4dbc633d7d1c7ab7d5b4f375b191a63af0f7a124 Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Sat, 21 Dec 2024 13:41:37 +0100 Subject: [PATCH] version --extended: Include sop-java version Fixes #454 --- .../kotlin/org/pgpainless/sop/VersionImpl.kt | 31 +++++++++++++++++-- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/pgpainless-sop/src/main/kotlin/org/pgpainless/sop/VersionImpl.kt b/pgpainless-sop/src/main/kotlin/org/pgpainless/sop/VersionImpl.kt index 6b7f5968..c6761a39 100644 --- a/pgpainless-sop/src/main/kotlin/org/pgpainless/sop/VersionImpl.kt +++ b/pgpainless-sop/src/main/kotlin/org/pgpainless/sop/VersionImpl.kt @@ -8,6 +8,7 @@ import java.io.IOException import java.io.InputStream import java.util.* import org.bouncycastle.jce.provider.BouncyCastleProvider +import sop.SOP import sop.operation.Version /** Implementation of the `version` operation using PGPainless. */ @@ -32,7 +33,7 @@ https://datatracker.ietf.org/doc/html/draft-dkg-openpgp-stateless-cli-$specVersi Based on pgpainless-core ${getVersion()} https://pgpainless.org - +${formatSopJavaVersion()} Using $bcVersion https://www.bouncycastle.org/java.html""" } @@ -49,8 +50,8 @@ https://www.bouncycastle.org/java.html""" // See https://stackoverflow.com/a/50119235 return try { val resourceIn: InputStream = - javaClass.getResourceAsStream("/pgpainless-sop.properties") - ?: throw IOException("File version.properties not found.") + SOP::class.java.getResourceAsStream("/pgpainless-sop.properties") + ?: throw IOException("File pgpainless-sop.properties not found.") val properties = Properties().apply { load(resourceIn) } properties.getProperty("pgpainless-sop-version") @@ -59,5 +60,29 @@ https://www.bouncycastle.org/java.html""" } } + private fun formatSopJavaVersion(): String { + return getSopJavaVersion()?.let { + """ + + sop-java $it + + """ + .trimIndent() + } + ?: "" + } + + private fun getSopJavaVersion(): String? { + return try { + val resourceIn: InputStream = + javaClass.getResourceAsStream("/sop-java-version.properties") + ?: throw IOException("File sop-java-version.properties not found.") + val properties = Properties().apply { load(resourceIn) } + properties.getProperty("sop-java-version") + } catch (e: IOException) { + null + } + } + override fun isSopSpecImplementationIncomplete(): Boolean = false }