Skip to content

Commit

Permalink
Cli add version argument (#376)
Browse files Browse the repository at this point in the history
  • Loading branch information
ttomasz authored Nov 26, 2022
1 parent 7a3db3d commit 6a893a4
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
6 changes: 6 additions & 0 deletions planetiler-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,12 @@
</dependencies>

<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<testResources>
<testResource>
<directory>src/test/resources</directory>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@
import com.onthegomap.planetiler.util.Translations;
import com.onthegomap.planetiler.util.Wikidata;
import com.onthegomap.planetiler.worker.RunnableThatThrows;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.function.Function;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -439,6 +442,11 @@ public Planetiler overwriteOutput(String argument, Path fallback) {
* @throws Exception if an error occurs while processing
*/
public void run() throws Exception {
var showVersion = arguments.getBoolean("version", "show version then exit", false);
printVersionInfoFromManifest();
if (showVersion) {
System.exit(0);
}
if (profile() == null) {
throw new IllegalArgumentException("No profile specified");
}
Expand Down Expand Up @@ -543,6 +551,22 @@ public void run() throws Exception {
stats.close();
}

public static void printVersionInfoFromManifest() {
try (var properties = Planetiler.class.getResourceAsStream("/buildinfo.properties")) {
var parsed = new Properties();
parsed.load(properties);
LOGGER.info("Planetiler build git hash: {}", parsed.getProperty("githash"));
LOGGER.info("Planetiler build version: {}", parsed.getProperty("version"));
var epochMs = parsed.getProperty("timestamp");
if (epochMs != null && !epochMs.isBlank() && epochMs.matches("^\\d+$")) {
var time = Instant.ofEpochMilli(Long.parseLong(epochMs));
LOGGER.info("Planetiler build timestamp: {}", time);
}
} catch (IOException e) {
LOGGER.error("Error getting build properties");
}
}

private void checkDiskSpace() {
ResourceUsage readPhase = new ResourceUsage("read phase disk");
ResourceUsage writePhase = new ResourceUsage("write phase disk");
Expand Down
3 changes: 3 additions & 0 deletions planetiler-core/src/main/resources/buildinfo.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
githash=${buildNumber}
timestamp=${timestamp}
version=${revision}
14 changes: 14 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<sonar.moduleKey>${project.artifactId}</sonar.moduleKey>
<sonar.exclusions>planetiler-benchmarks/**/*, planetiler-openmaptiles/**/*</sonar.exclusions>
<revision>0.6-SNAPSHOT</revision>
<timestamp>${maven.build.timestamp}</timestamp>
</properties>

<scm>
Expand Down Expand Up @@ -160,6 +161,19 @@

<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>create</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
Expand Down

0 comments on commit 6a893a4

Please sign in to comment.