Skip to content

Commit b466fb4

Browse files
committed
Make version file json again
1 parent 0635995 commit b466fb4

File tree

4 files changed

+35
-10
lines changed

4 files changed

+35
-10
lines changed

build.gradle.kts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@ plugins {
22
java
33
`java-library`
44
id("com.diffplug.spotless") version "6.1.2"
5+
id ("com.palantir.git-version") version "0.12.3"
56
}
67

8+
val versionDetails: groovy.lang.Closure<com.palantir.gradle.gitversion.VersionDetails> by extra
9+
val git = versionDetails()
10+
711
group = "de.bluecolored.bluemap.api"
812

913
val apiVersion: String by project
@@ -56,3 +60,16 @@ tasks.javadoc {
5660
}
5761
}
5862
}
63+
64+
tasks.processResources {
65+
from("src/main/resources") {
66+
include("de/bluecolored/bluemap/api/version.json")
67+
duplicatesStrategy = DuplicatesStrategy.INCLUDE
68+
69+
expand (
70+
"version" to project.version,
71+
"gitHash" to git.gitHashFull,
72+
"gitClean" to git.isCleanTag
73+
)
74+
}
75+
}

src/main/java/de/bluecolored/bluemap/api/BlueMapAPI.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,14 @@
2424
*/
2525
package de.bluecolored.bluemap.api;
2626

27+
import com.google.gson.Gson;
28+
import com.google.gson.JsonElement;
29+
import com.google.gson.JsonObject;
2730
import de.bluecolored.bluemap.api.debug.DebugDump;
2831

29-
import java.io.IOException;
3032
import java.io.InputStream;
33+
import java.io.InputStreamReader;
34+
import java.io.Reader;
3135
import java.net.URL;
3236
import java.nio.file.Path;
3337
import java.util.*;
@@ -44,13 +48,15 @@ public abstract class BlueMapAPI {
4448
private static final String VERSION, GIT_HASH, GIT_CLEAN;
4549
static {
4650
String version = "DEV", gitHash = "DEV", gitClean = "DEV";
47-
URL url = BlueMapAPI.class.getResource("/de/bluecolored/bluemap/api/version");
51+
URL url = BlueMapAPI.class.getResource("/de/bluecolored/bluemap/api/version.json");
4852
if (url != null) {
49-
try (InputStream in = url.openStream(); Scanner scanner = new Scanner(in)) {
50-
version = scanner.nextLine();
51-
gitHash = scanner.nextLine();
52-
gitClean = scanner.nextLine();
53-
} catch (IOException ex) {
53+
Gson gson = new Gson();
54+
try (InputStream in = url.openStream(); Reader reader = new InputStreamReader(in)) {
55+
JsonObject element = gson.fromJson(reader, JsonElement.class).getAsJsonObject();
56+
version = element.get("version").getAsString();
57+
gitHash = element.get("git-hash").getAsString();
58+
gitClean = element.get("git-clean").getAsString();
59+
} catch (Exception ex) {
5460
System.err.println("Failed to load version from resources!");
5561
ex.printStackTrace();
5662
}

src/main/resources/de.bluecolored.bluemap.api/version

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"version": "${version}",
3+
"git-hash": "${gitHash}",
4+
"git-clean": "${gitClean}"
5+
}

0 commit comments

Comments
 (0)