-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CORE-17369: Enable display of CLI command versions (#201)
Read version information from manifest. Example output: ```text corda-cli-plugin-host $ ./build/generatedScripts/corda-cli.sh --version Corda CLI 5.1.0-SNAPSHOT Provider: R3 Commit ID: 25201df corda-cli-plugin-host $ ./build/generatedScripts/corda-cli.sh example-plugin --version example-plugin 5.1.0-SNAPSHOT Provider: R3 Commit ID: 25201df ```
- Loading branch information
1 parent
af3f87f
commit cacb7c1
Showing
7 changed files
with
80 additions
and
2 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
api/src/main/kotlin/net/corda/cli/api/AbstractCordaCliVersionProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package net.corda.cli.api | ||
|
||
import picocli.CommandLine.IVersionProvider | ||
import java.util.jar.Manifest | ||
|
||
/** | ||
* An abstract class that will read version information out of the plugin manifest. | ||
* | ||
* Builds version information using these attributes: | ||
* - Plugin-Name | ||
* - Plugin-Version | ||
* - Plugin-Provider | ||
* - Plugin-Git-Commit | ||
* | ||
* To apply, inherit from this class: | ||
* | ||
* class VersionProvider : AbstractCordaCliVersionProvider() | ||
* | ||
* Then add to your command annotation: | ||
* | ||
* versionProvider = VersionProvider::class | ||
*/ | ||
abstract class AbstractCordaCliVersionProvider : IVersionProvider { | ||
override fun getVersion(): Array<String> = this.javaClass | ||
.getResourceAsStream("/META-INF/MANIFEST.MF") | ||
?.use { | ||
Manifest(it).mainAttributes.run { | ||
arrayOf( | ||
"${getValue("Plugin-Name")} ${getValue("Plugin-Version")}", | ||
"Provider: ${getValue("Plugin-Provider")}", | ||
"Commit ID: ${getValue("Plugin-Git-Commit")}" | ||
) | ||
} | ||
} ?: emptyArray() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Manifest-Version: 1.0 | ||
Main-Class: net.corda.cli.application.BootKt | ||
Multi-Release: true | ||
Plugin-Name: Corda CLI | ||
Plugin-Version: 5.1.0-TEST | ||
Plugin-Provider: R3 | ||
Plugin-Git-Commit: TEST | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters