Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: CLI version output #186

Merged
merged 3 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ODF Validator

Latest version is 0.13.1.
Latest version is 0.14.0-SNAPSHOT.

## About

Expand Down
2 changes: 1 addition & 1 deletion docs/developer/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ To include the core validation library in your project, add the following depend
<dependency>
<groupId>org.openpreservation.odf</groupId>
<artifactId>odf-core</artifactId>
<version>0.13.1</version>
<version>0.14.0-SNAPSHOT</version>
</dependency>
```

Expand Down
10 changes: 8 additions & 2 deletions odf-apps/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.openpreservation.odf</groupId>
<artifactId>odf-validator</artifactId>
<version>0.13.1</version>
<version>0.14.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand All @@ -20,6 +20,12 @@
</properties>

<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down Expand Up @@ -82,7 +88,7 @@
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
<version>1.23.0</version>
<version>1.27.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -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$
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Integer> {
private static final MessageFactory FACTORY = Messages
.getInstance("org.openpreservation.odf.apps.messages.Messages");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
project.name=${project.name}
release.version=${project.version}
release.date=${odfapps.timestamp}
date.format=${maven.build.timestamp.format}
2 changes: 1 addition & 1 deletion odf-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.openpreservation.odf</groupId>
<artifactId>odf-validator</artifactId>
<version>0.13.1</version>
<version>0.14.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion odf-reporting/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.openpreservation.odf</groupId>
<artifactId>odf-validator</artifactId>
<version>0.13.1</version>
<version>0.14.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion odf-validator
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
"$@"
2 changes: 1 addition & 1 deletion odf-validator.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<groupId>org.openpreservation.odf</groupId>
<artifactId>odf-validator</artifactId>
<version>0.13.1</version>
<version>0.14.0-SNAPSHOT</version>
<packaging>pom</packaging>

<modules>
Expand Down
Loading