mirror of
https://github.com/BlueMap-Minecraft/BlueMapAPI.git
synced 2024-11-23 10:45:47 +01:00
Make version file json again
This commit is contained in:
parent
06359955b5
commit
b466fb4ed8
@ -2,8 +2,12 @@ plugins {
|
||||
java
|
||||
`java-library`
|
||||
id("com.diffplug.spotless") version "6.1.2"
|
||||
id ("com.palantir.git-version") version "0.12.3"
|
||||
}
|
||||
|
||||
val versionDetails: groovy.lang.Closure<com.palantir.gradle.gitversion.VersionDetails> by extra
|
||||
val git = versionDetails()
|
||||
|
||||
group = "de.bluecolored.bluemap.api"
|
||||
|
||||
val apiVersion: String by project
|
||||
@ -56,3 +60,16 @@ tasks.javadoc {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tasks.processResources {
|
||||
from("src/main/resources") {
|
||||
include("de/bluecolored/bluemap/api/version.json")
|
||||
duplicatesStrategy = DuplicatesStrategy.INCLUDE
|
||||
|
||||
expand (
|
||||
"version" to project.version,
|
||||
"gitHash" to git.gitHashFull,
|
||||
"gitClean" to git.isCleanTag
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -24,10 +24,14 @@
|
||||
*/
|
||||
package de.bluecolored.bluemap.api;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import de.bluecolored.bluemap.api.debug.DebugDump;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Reader;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Path;
|
||||
import java.util.*;
|
||||
@ -44,13 +48,15 @@ public abstract class BlueMapAPI {
|
||||
private static final String VERSION, GIT_HASH, GIT_CLEAN;
|
||||
static {
|
||||
String version = "DEV", gitHash = "DEV", gitClean = "DEV";
|
||||
URL url = BlueMapAPI.class.getResource("/de/bluecolored/bluemap/api/version");
|
||||
URL url = BlueMapAPI.class.getResource("/de/bluecolored/bluemap/api/version.json");
|
||||
if (url != null) {
|
||||
try (InputStream in = url.openStream(); Scanner scanner = new Scanner(in)) {
|
||||
version = scanner.nextLine();
|
||||
gitHash = scanner.nextLine();
|
||||
gitClean = scanner.nextLine();
|
||||
} catch (IOException ex) {
|
||||
Gson gson = new Gson();
|
||||
try (InputStream in = url.openStream(); Reader reader = new InputStreamReader(in)) {
|
||||
JsonObject element = gson.fromJson(reader, JsonElement.class).getAsJsonObject();
|
||||
version = element.get("version").getAsString();
|
||||
gitHash = element.get("git-hash").getAsString();
|
||||
gitClean = element.get("git-clean").getAsString();
|
||||
} catch (Exception ex) {
|
||||
System.err.println("Failed to load version from resources!");
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
@ -1,3 +0,0 @@
|
||||
${version}
|
||||
${gitHash}
|
||||
${gitClean}
|
@ -0,0 +1,5 @@
|
||||
{
|
||||
"version": "${version}",
|
||||
"git-hash": "${gitHash}",
|
||||
"git-clean": "${gitClean}"
|
||||
}
|
Loading…
Reference in New Issue
Block a user