diff --git a/external-sop/src/main/java/sop/external/operation/VersionExternal.java b/external-sop/src/main/java/sop/external/operation/VersionExternal.java index 6848cab..95dc8f5 100644 --- a/external-sop/src/main/java/sop/external/operation/VersionExternal.java +++ b/external-sop/src/main/java/sop/external/operation/VersionExternal.java @@ -99,4 +99,23 @@ public class VersionExternal implements Version { throw new RuntimeException(e); } } + + @Override + public String getSopSpecVersion() { + String[] command = new String[] {binary, "version", "--sop-spec"}; + String[] env = ExternalSOP.propertiesToEnv(environment).toArray(new String[0]); + try { + Process process = runtime.exec(command, env); + BufferedReader stdInput = new BufferedReader(new InputStreamReader(process.getInputStream())); + StringBuilder sb = new StringBuilder(); + String line; + while ((line = stdInput.readLine()) != null) { + sb.append(line).append('\n'); + } + ExternalSOP.finish(process); + return sb.toString(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } } diff --git a/sop-java-picocli/src/main/java/sop/cli/picocli/commands/VersionCmd.java b/sop-java-picocli/src/main/java/sop/cli/picocli/commands/VersionCmd.java index 3610ff4..c11d050 100644 --- a/sop-java-picocli/src/main/java/sop/cli/picocli/commands/VersionCmd.java +++ b/sop-java-picocli/src/main/java/sop/cli/picocli/commands/VersionCmd.java @@ -22,6 +22,9 @@ public class VersionCmd extends AbstractSopCmd { @CommandLine.Option(names = "--backend") boolean backend; + + @CommandLine.Option(names = "--sop-spec") + boolean sopSpec; } @@ -45,5 +48,10 @@ public class VersionCmd extends AbstractSopCmd { Print.outln(version.getBackendVersion()); return; } + + if (exclusive.sopSpec) { + Print.outln(version.getSopSpecVersion()); + return; + } } } diff --git a/sop-java/src/main/java/sop/operation/Version.java b/sop-java/src/main/java/sop/operation/Version.java index 0b50993..1cd2698 100644 --- a/sop-java/src/main/java/sop/operation/Version.java +++ b/sop-java/src/main/java/sop/operation/Version.java @@ -46,4 +46,14 @@ public interface Version { * @return extended version string */ String getExtendedVersion(); + + /** + * Return the revision of the SOP specification that this implementation is implementing, for example, + *
draft-dkg-openpgp-stateless-cli-06. + * If the implementation targets a specific draft but the implementer knows the implementation is incomplete, + * it should prefix the draft title with a "~" (TILDE, U+007E), for example:
~draft-dkg-openpgp-stateless-cli-06. + * + * @return implemented SOP spec version + */ + String getSopSpecVersion(); } diff --git a/sop-java/src/testFixtures/java/sop/testsuite/operation/VersionTest.java b/sop-java/src/testFixtures/java/sop/testsuite/operation/VersionTest.java index 16aff4d..5ad1a52 100644 --- a/sop-java/src/testFixtures/java/sop/testsuite/operation/VersionTest.java +++ b/sop-java/src/testFixtures/java/sop/testsuite/operation/VersionTest.java @@ -14,6 +14,7 @@ import java.util.stream.Stream; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; @EnabledIf("sop.testsuite.operation.AbstractSOPTest#hasBackends") public class VersionTest extends AbstractSOPTest { @@ -51,4 +52,11 @@ public class VersionTest extends AbstractSOPTest { assertFalse(extended.isEmpty()); } + @ParameterizedTest + @MethodSource("provideInstances") + public void sopSpecVersionTest(SOP sop) { + String sopSpec = sop.version().getSopSpecVersion(); + assertTrue(sopSpec.startsWith("draft-dkg-openpgp-stateless-cli-") || + sopSpec.startsWith("~draft-dkg-openpgp-stateless-cli-")); + } }