[xmlsectool] branch main updated: XSTJ-95 - Add a version option to the command line
Ian Young
ian at iay.org.uk
Wed Mar 19 16:55:25 UTC 2025
This is an automated email from the git hooks/post-receive script.
iay pushed a commit to branch main
in repository xmlsectool.
View the commit online:
http://git.shibboleth.net/view/?p=xmlsectool.git;a=commit;h=9ff3ed03f3e44d068cecb474ed3df8c180c7f8ef
The following commit(s) were added to refs/heads/main by this push:
new 9ff3ed0 XSTJ-95 - Add a version option to the command line
9ff3ed0 is described below
commit 9ff3ed03f3e44d068cecb474ed3df8c180c7f8ef
Author: Ian Young <ian at iay.org.uk>
AuthorDate: Wed Mar 19 16:55:22 2025 +0000
XSTJ-95 - Add a version option to the command line
https://shibboleth.atlassian.net/browse/XSTJ-95
---
pom.xml | 23 +++++
.../tool/xmlsectool/CommandLineArguments.java | 11 ++-
.../net/shibboleth/tool/xmlsectool/Version.java | 110 +++++++++++++++++++++
.../net/shibboleth/tool/xmlsectool/XMLSecTool.java | 5 +
.../shibboleth/tool/xmlsectool/VersionTest.java | 28 ++++++
.../net/shibboleth/tool/xmlsectool/XSTJ95Test.java | 36 +++++++
6 files changed, 212 insertions(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 672c53c..ea1f403 100644
--- a/pom.xml
+++ b/pom.xml
@@ -148,6 +148,29 @@
<build>
<plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <configuration>
+ <archive>
+ <index>true</index>
+ <manifestEntries>
+ <Main-Class>net.shibboleth.tool.xmlsectool.Version</Main-Class>
+ </manifestEntries>
+ <manifestSections>
+ <manifestSection>
+ <name>net/shibboleth/tool/xmlsectool/</name>
+ <manifestEntries>
+ <Implementation-Title>${project.artifactId}</Implementation-Title>
+ <Implementation-Version>${project.version}</Implementation-Version>
+ <Implementation-Vendor>shibboleth.net</Implementation-Vendor>
+ </manifestEntries>
+ </manifestSection>
+ </manifestSections>
+ </archive>
+ </configuration>
+ </plugin>
+
<!-- Copy the executable's dependencies into a directory. -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
diff --git a/src/main/java/net/shibboleth/tool/xmlsectool/CommandLineArguments.java b/src/main/java/net/shibboleth/tool/xmlsectool/CommandLineArguments.java
index 9ec3bd7..a9e8a1e 100644
--- a/src/main/java/net/shibboleth/tool/xmlsectool/CommandLineArguments.java
+++ b/src/main/java/net/shibboleth/tool/xmlsectool/CommandLineArguments.java
@@ -31,6 +31,7 @@ public class CommandLineArguments {
// Command-line option names, in their order of first appearance in the usage text
private static final String HELP_ARG = "help";
+ private static final String VERSION_ARG = "version";
private static final String SIGN_ARG = "sign";
private static final String V_SIG_ARG = "verifySignature";
private static final String V_SCHEMA_ARG = "validateSchema";
@@ -247,6 +248,9 @@ public class CommandLineArguments {
@Parameter(names = HELP_ARG, help = true)
private boolean help;
+ @Parameter(names = OPT + VERSION_ARG)
+ private boolean version;
+
/**
* Parse the command-line arguments.
*
@@ -521,11 +525,15 @@ public class CommandLineArguments {
return help;
}
+ public boolean doVersion() {
+ return version;
+ }
+
// Checkstyle: MethodLength OFF
// Checkstyle: CyclomaticComplexity OFF
private void validateCommandLineArguments() {
- if (doHelp()) {
+ if (doHelp() || doVersion()) {
return;
}
@@ -628,6 +636,7 @@ public class CommandLineArguments {
out.println("==== Command Line Options ====");
out.println();
out.println(String.format(" --%-20s %s", HELP_ARG, "Prints this help information"));
+ out.println(String.format(" --%-20s %s", VERSION_ARG, "Prints the version of xmlsectool"));
out.println();
out.println("Action Options - '" + SIGN_ARG + "' and '" + V_SIG_ARG
+ "' are mutually exclusive. At least one option is required.");
diff --git a/src/main/java/net/shibboleth/tool/xmlsectool/Version.java b/src/main/java/net/shibboleth/tool/xmlsectool/Version.java
new file mode 100644
index 0000000..90ebd42
--- /dev/null
+++ b/src/main/java/net/shibboleth/tool/xmlsectool/Version.java
@@ -0,0 +1,110 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.shibboleth.tool.xmlsectool;
+
+import javax.annotation.Nonnull;
+
+/**
+ * Class for getting and printing the version of the tool.
+ *
+ * @since 4.0.0
+ */
+public final class Version {
+
+ /** Tool version. */
+ private static final @Nonnull String VERSION;
+
+ /** Tool major version number. */
+ private static final int MAJOR_VERSION;
+
+ /** Tool minor version number. */
+ private static final int MINOR_VERSION;
+
+ /** Tool patch version number. */
+ private static final int PATCH_VERSION;
+
+ /** Constructor. */
+ private Version() {
+ }
+
+ /**
+ * Main entry point to program.
+ *
+ * @param args command line arguments
+ */
+ public static void main(final String[] args) {
+ final Package pkg = Version.class.getPackage();
+ System.out.println(pkg.getImplementationTitle() + " version " + VERSION);
+ }
+
+ /**
+ * Gets the version of the tool.
+ *
+ * @return version of the tool
+ */
+ @Nonnull public static String getVersion() {
+ return VERSION;
+ }
+
+ /**
+ * Gets the major version number of the tool.
+ *
+ * @return major version number of the tool
+ */
+ public static int getMajorVersion() {
+ return MAJOR_VERSION;
+ }
+
+ /**
+ * Gets the minor version number of the tool.
+ *
+ * @return minor version number of the tool
+ */
+ public static int getMinorVersion() {
+ return MINOR_VERSION;
+ }
+
+ /**
+ * Gets the patch version number of the tool.
+ *
+ * @return patch version number of the tool
+ */
+ public static int getPatchVersion() {
+ return PATCH_VERSION;
+ }
+
+ static {
+ final String version = Version.class.getPackage().getImplementationVersion();
+
+ if (version != null) {
+ // If we're running from a package with metadata (i.e., from a .jar)
+ VERSION = version;
+
+ // Semantic versioning: three dot-separated numbers, followed by extensions
+ // separated by '-' and '+'.
+ final String[] versionParts = VERSION.split("[\\.\\+\\-]");
+
+ MAJOR_VERSION = Integer.parseInt(versionParts[0]);
+ MINOR_VERSION = Integer.parseInt(versionParts[1]);
+ PATCH_VERSION = Integer.parseInt(versionParts[2]);
+ } else {
+ // We don't have the package metadata available; probably a test environment
+ VERSION = "unknown";
+ MAJOR_VERSION = 0;
+ MINOR_VERSION = 0;
+ PATCH_VERSION = 0;
+ }
+ }
+}
diff --git a/src/main/java/net/shibboleth/tool/xmlsectool/XMLSecTool.java b/src/main/java/net/shibboleth/tool/xmlsectool/XMLSecTool.java
index e20051d..86bf630 100644
--- a/src/main/java/net/shibboleth/tool/xmlsectool/XMLSecTool.java
+++ b/src/main/java/net/shibboleth/tool/xmlsectool/XMLSecTool.java
@@ -131,6 +131,11 @@ public final class XMLSecTool {
return;
}
+ if (cli.doVersion()) {
+ System.out.println(Version.getVersion());
+ return;
+ }
+
if (cli.doListAlgorithms()) {
cli.getDisallowedAlgorithms().list(System.out);
return;
diff --git a/src/test/java/net/shibboleth/tool/xmlsectool/VersionTest.java b/src/test/java/net/shibboleth/tool/xmlsectool/VersionTest.java
new file mode 100644
index 0000000..c4c6196
--- /dev/null
+++ b/src/test/java/net/shibboleth/tool/xmlsectool/VersionTest.java
@@ -0,0 +1,28 @@
+package net.shibboleth.tool.xmlsectool;
+
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+public class VersionTest {
+
+ @Test
+ public void getMajorVersionTest() {
+ Assert.assertEquals(Version.getMajorVersion(), 0);
+ }
+
+ @Test
+ public void getMinorVersionTest() {
+ Assert.assertEquals(Version.getMinorVersion(), 0);
+ }
+
+ @Test
+ public void getPatchVersionTest() {
+ Assert.assertEquals(Version.getPatchVersion(), 0);
+ }
+
+ @Test
+ public void getVersionTest() {
+ Assert.assertEquals(Version.getVersion(), "unknown");
+ }
+
+}
diff --git a/src/test/java/net/shibboleth/tool/xmlsectool/XSTJ95Test.java b/src/test/java/net/shibboleth/tool/xmlsectool/XSTJ95Test.java
new file mode 100644
index 0000000..5f08b1a
--- /dev/null
+++ b/src/test/java/net/shibboleth/tool/xmlsectool/XSTJ95Test.java
@@ -0,0 +1,36 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.shibboleth.tool.xmlsectool;
+
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+public class XSTJ95Test extends BaseTest {
+
+ XSTJ95Test() {
+ super(XSTJ95Test.class);
+ }
+
+ @Test
+ public void xstj51_version() throws Exception {
+ // build command-line arguments
+ final String[] args = {
+ "--version",
+ };
+ final CommandLineArguments cli = new CommandLineArguments();
+ cli.parseCommandLineArguments(args);
+ Assert.assertEquals(cli.doVersion(), true);
+ }
+}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list