Skip to content

Commit

Permalink
Add version information (fixes #112)
Browse files Browse the repository at this point in the history
  • Loading branch information
rsenden committed Sep 30, 2022
1 parent ec94632 commit 07000f9
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ jobs:
- name: Build release ${{env.RELEASE_VERSION}}
if: env.DO_BUILD
run: ./gradlew clean build dist distThirdParty -Pversion=%{{
run: ./gradlew clean build dist distThirdParty -Pversion=${{env.RELEASE_VERSION}}

- name: Publish build artifacts
uses: actions/upload-artifact@v2
Expand Down
21 changes: 20 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,15 @@ plugins {
id "org.asciidoctor.jvm.convert" version "3.3.2"
}

version = "0.1"
group = "com.fortify.cli"

ext.buildTime = LocalDateTime.now()
ext.getVersion = {
def result = project.findProperty('version');
return !result || result=='unspecified' ? buildTime.format('0.yyyyMMdd.HHmmss') : result;
}
version = ext.getVersion();

apply plugin: "io.micronaut.application"
subprojects {
apply plugin: "io.micronaut.library"
Expand Down Expand Up @@ -129,6 +135,19 @@ apply from: "${gradleHelpersLocation}/readme2html.gradle"

mainClassName = "com.fortify.cli.app.FCLIRootCommands"

task generateBuildProperties {
doLast {
def buildPropertiesDir = "${sourceSets.main.output.resourcesDir}/com/fortify/cli/app"
mkdir "${buildPropertiesDir}"
ant.propertyfile(file: "${buildPropertiesDir}/fcli-build.properties") {
entry(key: "projectName", value: project.name)
entry(key: "projectVersion", value: project.version)
entry(key: "buildDate", value: buildTime.format('yyyy-MM-dd HH:mm:ss'))
}
}
}
processResources.dependsOn(generateBuildProperties)

tasks.register('generateAutoCompleteDir') {
doLast {
mkdir "${autoCompleteDir}"
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/fortify/cli/app/FCLIRootCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
sortOptions = false,
showAtFileInUsageHelp = false,
resourceBundle = "com.fortify.cli.i18n.FortifyCLIMessages",
versionProvider = FortifyCLIVersionProvider.class,
subcommands = {
ConfigCommands.class,
SSCCommands.class,
Expand Down
30 changes: 30 additions & 0 deletions src/main/java/com/fortify/cli/app/FortifyCLIVersionProvider.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.fortify.cli.app;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import picocli.CommandLine.IVersionProvider;

public class FortifyCLIVersionProvider implements IVersionProvider {
private static final Properties buildProperties = loadProperties();

@Override
public String[] getVersion() throws Exception {
return new String[] {String.format("%s version %s, built on %s"
, buildProperties.getProperty("projectName", "fcli")
, buildProperties.getProperty("projectVersion", "unknown")
, buildProperties.getProperty("buildDate", "unknown"))};
}

private static final Properties loadProperties() {
final Properties p = new Properties();
try (final InputStream stream = FortifyCLIVersionProvider.class.getResourceAsStream("fcli-build.properties")) {
if ( stream!=null ) { p.load(stream); }
} catch ( IOException ioe ) {
System.err.println("Error reading fcli-build.properties from classpath");
}
return p;
}

}

0 comments on commit 07000f9

Please sign in to comment.