From e40d45b71151e2b8d4d6e5e6cd40ae1e9baa98d3 Mon Sep 17 00:00:00 2001 From: Carl Wilson Date: Wed, 25 Sep 2024 14:22:00 +0100 Subject: [PATCH 1/2] FIX: CLI version output - replaced hard coded version in `CliValidator`: - now uses `BuildVersionProvider` which implements `IVersionProvider`; and - reads release details from a java properties resource file `odf-apps/src/main/resources/org/openpreservation/odf/apps/build.properties`; - updated version to `0.14.0-SNAPSHOT` for development; and - checked in templated changes to batch files and documentation. --- README.md | 2 +- docs/developer/index.md | 2 +- odf-apps/pom.xml | 10 +++- .../odf/apps/BuildVersionProvider.java | 50 +++++++++++++++++++ .../odf/apps/CliValidator.java | 2 +- .../odf/apps/build.properties | 4 ++ odf-core/pom.xml | 2 +- odf-reporting/pom.xml | 2 +- odf-validator | 2 +- odf-validator.bat | 2 +- pom.xml | 2 +- 11 files changed, 70 insertions(+), 10 deletions(-) create mode 100644 odf-apps/src/main/java/org/openpreservation/odf/apps/BuildVersionProvider.java create mode 100644 odf-apps/src/main/resources/org/openpreservation/odf/apps/build.properties diff --git a/README.md b/README.md index d6b65985..f4e2a3d4 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # ODF Validator -Latest version is 0.13.1. +Latest version is 0.14.0-SNAPSHOT. ## About diff --git a/docs/developer/index.md b/docs/developer/index.md index 412af381..58af9511 100644 --- a/docs/developer/index.md +++ b/docs/developer/index.md @@ -44,7 +44,7 @@ To include the core validation library in your project, add the following depend org.openpreservation.odf odf-core - 0.13.1 + 0.14.0-SNAPSHOT ``` diff --git a/odf-apps/pom.xml b/odf-apps/pom.xml index 0130d281..debdc9f0 100644 --- a/odf-apps/pom.xml +++ b/odf-apps/pom.xml @@ -5,7 +5,7 @@ org.openpreservation.odf odf-validator - 0.13.1 + 0.14.0-SNAPSHOT ../pom.xml @@ -20,6 +20,12 @@ + + + src/main/resources + true + + org.apache.maven.plugins @@ -82,7 +88,7 @@ org.apache.commons commons-compress - 1.23.0 + 1.27.1 diff --git a/odf-apps/src/main/java/org/openpreservation/odf/apps/BuildVersionProvider.java b/odf-apps/src/main/java/org/openpreservation/odf/apps/BuildVersionProvider.java new file mode 100644 index 00000000..db36a9b4 --- /dev/null +++ b/odf-apps/src/main/java/org/openpreservation/odf/apps/BuildVersionProvider.java @@ -0,0 +1,50 @@ +package org.openpreservation.odf.apps; + +import java.io.IOException; +import java.io.InputStream; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Properties; +import java.util.logging.Level; + +import picocli.CommandLine.IVersionProvider; + +public class BuildVersionProvider implements IVersionProvider { + private static final String RAW_DATE_FORMAT = "${maven.build.timestamp.format}"; + + @Override + public String[] getVersion() throws Exception { + Properties props = fromResource("org/openpreservation/odf/apps/build.properties"); + String name = props.getProperty("project.name"); //$NON-NLS-1$ + String version = props.getProperty("release.version"); //$NON-NLS-1$ + String dateFormat = props.getProperty("date.format"); //$NON-NLS-1$ + Date date = new Date(); + if (!dateFormat.equals(RAW_DATE_FORMAT)) { + SimpleDateFormat formatter = new SimpleDateFormat(dateFormat); + try { + date = formatter.parse(props.getProperty("release.date")); //$NON-NLS-1$ + } catch (ParseException e) { + /** + * Safe to ignore this exception as release simply set to new + * date. + */ + } + } + return new String[] { name + " v" + version, //$NON-NLS-1$ + "Built: " + new SimpleDateFormat("yyyy-MM-dd").format(date) }; //$NON-NLS-1$ + } + + private static Properties fromResource(final String resourceName) { + try (InputStream is = BuildVersionProvider.class.getClassLoader().getResourceAsStream(resourceName)) { + Properties props = new Properties(); + if (is != null) { + props.load(is); + } + return props; + } catch (IOException excep) { + throw new IllegalStateException("Couldn't load resource:" + resourceName, excep); //$NON-NLS-1$ + } + } + +} diff --git a/odf-apps/src/main/java/org/openpreservation/odf/apps/CliValidator.java b/odf-apps/src/main/java/org/openpreservation/odf/apps/CliValidator.java index 9c81a4a5..ee7293ac 100644 --- a/odf-apps/src/main/java/org/openpreservation/odf/apps/CliValidator.java +++ b/odf-apps/src/main/java/org/openpreservation/odf/apps/CliValidator.java @@ -28,7 +28,7 @@ import picocli.CommandLine.Option; import picocli.CommandLine.Parameters; -@Command(name = "odf-validator", mixinStandardHelpOptions = true, version = "odf-validator 0.1", description = "Validates Open Document Format spreadsheets.") +@Command(name = "odf-validator", mixinStandardHelpOptions = true, versionProvider = BuildVersionProvider.class, description = "Validates Open Document Format spreadsheets.") class CliValidator implements Callable { private static final MessageFactory FACTORY = Messages .getInstance("org.openpreservation.odf.apps.messages.Messages"); diff --git a/odf-apps/src/main/resources/org/openpreservation/odf/apps/build.properties b/odf-apps/src/main/resources/org/openpreservation/odf/apps/build.properties new file mode 100644 index 00000000..6a051fe1 --- /dev/null +++ b/odf-apps/src/main/resources/org/openpreservation/odf/apps/build.properties @@ -0,0 +1,4 @@ +project.name=${project.name} +release.version=${project.version} +release.date=${odfapps.timestamp} +date.format=${maven.build.timestamp.format} diff --git a/odf-core/pom.xml b/odf-core/pom.xml index 29c5a7d2..33e81cff 100644 --- a/odf-core/pom.xml +++ b/odf-core/pom.xml @@ -5,7 +5,7 @@ org.openpreservation.odf odf-validator - 0.13.1 + 0.14.0-SNAPSHOT ../pom.xml diff --git a/odf-reporting/pom.xml b/odf-reporting/pom.xml index d4d229df..1e100240 100644 --- a/odf-reporting/pom.xml +++ b/odf-reporting/pom.xml @@ -5,7 +5,7 @@ org.openpreservation.odf odf-validator - 0.13.1 + 0.14.0-SNAPSHOT ../pom.xml diff --git a/odf-validator b/odf-validator index 91b0343e..9448fb55 100755 --- a/odf-validator +++ b/odf-validator @@ -78,5 +78,5 @@ fi exec "$JAVACMD" -Dfile.encoding=UTF8 -XX:+IgnoreUnrecognizedVMOptions \ -Dapp.name="ODF Validator" \ - -jar odf-apps/target/odf-apps-0.13.1-jar-with-dependencies.jar \ + -jar odf-apps/target/odf-apps-0.14.0-SNAPSHOT-jar-with-dependencies.jar \ "$@" diff --git a/odf-validator.bat b/odf-validator.bat index 8b53871a..1a3b9445 100644 --- a/odf-validator.bat +++ b/odf-validator.bat @@ -85,7 +85,7 @@ if NOT "%CLASSPATH_PREFIX%" == "" set CLASSPATH=%CLASSPATH_PREFIX%;%CLASSPATH% @REM Reaching here means variables are defined and arguments have been captured :endInit -"%JAVACMD%" -Dfile.encoding=UTF8 -XX:+IgnoreUnrecognizedVMOptions -Dapp.name="ODF Validator" -jar .\odf-apps\target\odf-apps-0.13.1-jar-with-dependencies.jar %CMD_LINE_ARGS% +"%JAVACMD%" -Dfile.encoding=UTF8 -XX:+IgnoreUnrecognizedVMOptions -Dapp.name="ODF Validator" -jar .\odf-apps\target\odf-apps-0.14.0-SNAPSHOT-jar-with-dependencies.jar %CMD_LINE_ARGS% if %ERRORLEVEL% NEQ 0 goto error goto end diff --git a/pom.xml b/pom.xml index e790b387..1a454e24 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ org.openpreservation.odf odf-validator - 0.13.1 + 0.14.0-SNAPSHOT pom From c3076ab73376ff50f221a01c63e86b011f8212a3 Mon Sep 17 00:00:00 2001 From: Carl Wilson Date: Wed, 25 Sep 2024 14:22:00 +0100 Subject: [PATCH 2/2] FIX: CLI version output - replaced hard coded version in `CliValidator`: - now uses `BuildVersionProvider` which implements `IVersionProvider`; and - reads release details from a java properties resource file `odf-apps/src/main/resources/org/openpreservation/odf/apps/build.properties`; - updated version to `0.14.0-SNAPSHOT` for development; and - checked in templated changes to batch files and documentation. --- README.md | 2 +- docs/developer/index.md | 2 +- odf-apps/pom.xml | 10 +++- .../odf/apps/BuildVersionProvider.java | 50 +++++++++++++++++++ .../odf/apps/CliValidator.java | 2 +- .../odf/apps/build.properties | 4 ++ odf-core/pom.xml | 2 +- odf-reporting/pom.xml | 2 +- odf-validator | 2 +- odf-validator.bat | 2 +- pom.xml | 2 +- 11 files changed, 70 insertions(+), 10 deletions(-) create mode 100644 odf-apps/src/main/java/org/openpreservation/odf/apps/BuildVersionProvider.java create mode 100644 odf-apps/src/main/resources/org/openpreservation/odf/apps/build.properties diff --git a/README.md b/README.md index d6b65985..f4e2a3d4 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # ODF Validator -Latest version is 0.13.1. +Latest version is 0.14.0-SNAPSHOT. ## About diff --git a/docs/developer/index.md b/docs/developer/index.md index 412af381..58af9511 100644 --- a/docs/developer/index.md +++ b/docs/developer/index.md @@ -44,7 +44,7 @@ To include the core validation library in your project, add the following depend org.openpreservation.odf odf-core - 0.13.1 + 0.14.0-SNAPSHOT ``` diff --git a/odf-apps/pom.xml b/odf-apps/pom.xml index 0130d281..debdc9f0 100644 --- a/odf-apps/pom.xml +++ b/odf-apps/pom.xml @@ -5,7 +5,7 @@ org.openpreservation.odf odf-validator - 0.13.1 + 0.14.0-SNAPSHOT ../pom.xml @@ -20,6 +20,12 @@ + + + src/main/resources + true + + org.apache.maven.plugins @@ -82,7 +88,7 @@ org.apache.commons commons-compress - 1.23.0 + 1.27.1 diff --git a/odf-apps/src/main/java/org/openpreservation/odf/apps/BuildVersionProvider.java b/odf-apps/src/main/java/org/openpreservation/odf/apps/BuildVersionProvider.java new file mode 100644 index 00000000..db36a9b4 --- /dev/null +++ b/odf-apps/src/main/java/org/openpreservation/odf/apps/BuildVersionProvider.java @@ -0,0 +1,50 @@ +package org.openpreservation.odf.apps; + +import java.io.IOException; +import java.io.InputStream; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Properties; +import java.util.logging.Level; + +import picocli.CommandLine.IVersionProvider; + +public class BuildVersionProvider implements IVersionProvider { + private static final String RAW_DATE_FORMAT = "${maven.build.timestamp.format}"; + + @Override + public String[] getVersion() throws Exception { + Properties props = fromResource("org/openpreservation/odf/apps/build.properties"); + String name = props.getProperty("project.name"); //$NON-NLS-1$ + String version = props.getProperty("release.version"); //$NON-NLS-1$ + String dateFormat = props.getProperty("date.format"); //$NON-NLS-1$ + Date date = new Date(); + if (!dateFormat.equals(RAW_DATE_FORMAT)) { + SimpleDateFormat formatter = new SimpleDateFormat(dateFormat); + try { + date = formatter.parse(props.getProperty("release.date")); //$NON-NLS-1$ + } catch (ParseException e) { + /** + * Safe to ignore this exception as release simply set to new + * date. + */ + } + } + return new String[] { name + " v" + version, //$NON-NLS-1$ + "Built: " + new SimpleDateFormat("yyyy-MM-dd").format(date) }; //$NON-NLS-1$ + } + + private static Properties fromResource(final String resourceName) { + try (InputStream is = BuildVersionProvider.class.getClassLoader().getResourceAsStream(resourceName)) { + Properties props = new Properties(); + if (is != null) { + props.load(is); + } + return props; + } catch (IOException excep) { + throw new IllegalStateException("Couldn't load resource:" + resourceName, excep); //$NON-NLS-1$ + } + } + +} diff --git a/odf-apps/src/main/java/org/openpreservation/odf/apps/CliValidator.java b/odf-apps/src/main/java/org/openpreservation/odf/apps/CliValidator.java index 9c81a4a5..ee7293ac 100644 --- a/odf-apps/src/main/java/org/openpreservation/odf/apps/CliValidator.java +++ b/odf-apps/src/main/java/org/openpreservation/odf/apps/CliValidator.java @@ -28,7 +28,7 @@ import picocli.CommandLine.Option; import picocli.CommandLine.Parameters; -@Command(name = "odf-validator", mixinStandardHelpOptions = true, version = "odf-validator 0.1", description = "Validates Open Document Format spreadsheets.") +@Command(name = "odf-validator", mixinStandardHelpOptions = true, versionProvider = BuildVersionProvider.class, description = "Validates Open Document Format spreadsheets.") class CliValidator implements Callable { private static final MessageFactory FACTORY = Messages .getInstance("org.openpreservation.odf.apps.messages.Messages"); diff --git a/odf-apps/src/main/resources/org/openpreservation/odf/apps/build.properties b/odf-apps/src/main/resources/org/openpreservation/odf/apps/build.properties new file mode 100644 index 00000000..6a051fe1 --- /dev/null +++ b/odf-apps/src/main/resources/org/openpreservation/odf/apps/build.properties @@ -0,0 +1,4 @@ +project.name=${project.name} +release.version=${project.version} +release.date=${odfapps.timestamp} +date.format=${maven.build.timestamp.format} diff --git a/odf-core/pom.xml b/odf-core/pom.xml index 29c5a7d2..33e81cff 100644 --- a/odf-core/pom.xml +++ b/odf-core/pom.xml @@ -5,7 +5,7 @@ org.openpreservation.odf odf-validator - 0.13.1 + 0.14.0-SNAPSHOT ../pom.xml diff --git a/odf-reporting/pom.xml b/odf-reporting/pom.xml index d4d229df..1e100240 100644 --- a/odf-reporting/pom.xml +++ b/odf-reporting/pom.xml @@ -5,7 +5,7 @@ org.openpreservation.odf odf-validator - 0.13.1 + 0.14.0-SNAPSHOT ../pom.xml diff --git a/odf-validator b/odf-validator index 91b0343e..9448fb55 100755 --- a/odf-validator +++ b/odf-validator @@ -78,5 +78,5 @@ fi exec "$JAVACMD" -Dfile.encoding=UTF8 -XX:+IgnoreUnrecognizedVMOptions \ -Dapp.name="ODF Validator" \ - -jar odf-apps/target/odf-apps-0.13.1-jar-with-dependencies.jar \ + -jar odf-apps/target/odf-apps-0.14.0-SNAPSHOT-jar-with-dependencies.jar \ "$@" diff --git a/odf-validator.bat b/odf-validator.bat index 8b53871a..1a3b9445 100644 --- a/odf-validator.bat +++ b/odf-validator.bat @@ -85,7 +85,7 @@ if NOT "%CLASSPATH_PREFIX%" == "" set CLASSPATH=%CLASSPATH_PREFIX%;%CLASSPATH% @REM Reaching here means variables are defined and arguments have been captured :endInit -"%JAVACMD%" -Dfile.encoding=UTF8 -XX:+IgnoreUnrecognizedVMOptions -Dapp.name="ODF Validator" -jar .\odf-apps\target\odf-apps-0.13.1-jar-with-dependencies.jar %CMD_LINE_ARGS% +"%JAVACMD%" -Dfile.encoding=UTF8 -XX:+IgnoreUnrecognizedVMOptions -Dapp.name="ODF Validator" -jar .\odf-apps\target\odf-apps-0.14.0-SNAPSHOT-jar-with-dependencies.jar %CMD_LINE_ARGS% if %ERRORLEVEL% NEQ 0 goto error goto end diff --git a/pom.xml b/pom.xml index e790b387..1a454e24 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ org.openpreservation.odf odf-validator - 0.13.1 + 0.14.0-SNAPSHOT pom