Skip to content

Commit

Permalink
Externalise version information.
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Brown committed Dec 29, 2023
1 parent 0d22ed1 commit e37752a
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 5 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,6 @@ build
out
*.puml
*.wsd
*.sh
*.sh

src/main/resources/build.properties
7 changes: 6 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defaultTasks 'clean', 'build', 'getDeps', 'buildZip'

description = 'Structurizr CLI'
group = 'com.structurizr'
version = '1.35.0'
version = ''

sourceCompatibility = 17
targetCompatibility = 17
Expand Down Expand Up @@ -42,6 +42,11 @@ test {
useJUnitPlatform()
}

sourceSets.main.resources {
srcDirs = ['src/main/resources']
include 'build.properties'
}

jar {
manifest {
attributes(
Expand Down
32 changes: 31 additions & 1 deletion src/main/java/com/structurizr/cli/VersionCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,45 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.io.InputStream;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Properties;

class VersionCommand extends AbstractCommand {

private static final Log log = LogFactory.getLog(VersionCommand.class);

VersionCommand() {
}

private static final String BUILD_VERSION_KEY = "build.number";
private static final String BUILD_TIMESTAMP_KEY = "build.timestamp";
private static final String GIT_COMMIT_KEY = "git.commit";

private static final String ISO_DATE_TIME_FORMAT = "yyyy-MM-dd'T'HH:mm:ss'Z'";

public void run(String... args) throws Exception {
String version = getClass().getPackage().getImplementationVersion();
String version = "";
String buildTimestamp = "";
String gitCommit = "";

try {
Properties buildProperties = new Properties();
InputStream in = VersionCommand.class.getClassLoader().getResourceAsStream("build.properties");
DateFormat format = new SimpleDateFormat(ISO_DATE_TIME_FORMAT);
if (in != null) {
buildProperties.load(in);
version = buildProperties.getProperty(BUILD_VERSION_KEY);
buildTimestamp = buildProperties.getProperty(BUILD_TIMESTAMP_KEY);
gitCommit = buildProperties.getProperty(GIT_COMMIT_KEY);
in.close();
}
} catch (Exception e) {
e.printStackTrace();
}

log.info("structurizr-cli: " + version);

try {
Expand Down
2 changes: 0 additions & 2 deletions src/main/resources/application.properties

This file was deleted.

1 change: 1 addition & 0 deletions version.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2023.1.1

0 comments on commit e37752a

Please sign in to comment.