From 77ddeabca22bdf33baeb8284652fcd6dc957147f Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Thu, 3 Jan 2019 17:32:21 +0000 Subject: [PATCH] Fix NPE with plot version (update to new versioning within code) Also add date and commit to plugin.properties file. --- Core/build.gradle | 5 +++- .../plotsquared/plot/PlotSquared.java | 16 ++++++---- .../plotsquared/plot/PlotVersion.java | 29 +++++++------------ .../plotsquared/plot/Updater.java | 4 +-- Core/src/main/resources/plugin.properties | 4 ++- build.gradle | 3 -- 6 files changed, 29 insertions(+), 32 deletions(-) diff --git a/Core/build.gradle b/Core/build.gradle index 6e9fcfa0d..14bda6198 100644 --- a/Core/build.gradle +++ b/Core/build.gradle @@ -1,3 +1,5 @@ +import org.ajoberstar.grgit.Grgit + dependencies { testCompile 'junit:junit:4.12' compile 'org.yaml:snakeyaml:1.23' @@ -7,13 +9,14 @@ dependencies { sourceCompatibility = 1.8 targetCompatibility = 1.8 - processResources { from('src/main/resources') { include 'plugin.properties' expand( version: "${project.parent.version}", name: project.parent.name, + commit: "${git.head().abbreviatedId}", + date: "${git.head().getDate().format("yy.MM.dd")}", ) } } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/PlotSquared.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/PlotSquared.java index 62ecfad3f..e08dd718e 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/PlotSquared.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/PlotSquared.java @@ -223,7 +223,7 @@ import java.util.zip.ZipInputStream; }); } - // Check for updates +/* // Check for updates if (Settings.Enabled_Components.UPDATER) { updater = new Updater(); TaskManager.IMP.taskAsync(new Runnable() { @@ -236,7 +236,7 @@ import java.util.zip.ZipInputStream; updater.update(getPlatform(), getVersion()); } }, 36000); - } + }*/ // World generators: final ConfigurationSection section = this.worlds.getConfigurationSection("worlds"); @@ -1699,10 +1699,14 @@ import java.util.zip.ZipInputStream; Settings.load(configFile); try { InputStream stream = getClass().getResourceAsStream("/plugin.properties"); - java.util.Scanner scanner = new java.util.Scanner(stream).useDelimiter("\\A"); - String versionString = scanner.next().trim(); - scanner.close(); - this.version = PlotVersion.tryParse(versionString); + BufferedReader br = new BufferedReader(new InputStreamReader(stream)); + //java.util.Scanner scanner = new java.util.Scanner(stream).useDelimiter("\\A"); + String versionString = br.readLine(); + String commitString = br.readLine(); + String dateString = br.readLine(); + //scanner.close(); + br.close(); + this.version = PlotVersion.tryParse(versionString, commitString, dateString); Settings.DATE = new Date(100 + version.year, version.month, version.day).toGMTString(); Settings.BUILD = "https://ci.athion.net/job/PlotSquared/" + version.build; Settings.COMMIT = "https://github.com/IntellectualSites/PlotSquared/commit/" + Integer diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/PlotVersion.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/PlotVersion.java index 3abf51fde..ecb423970 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/PlotVersion.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/PlotVersion.java @@ -11,28 +11,19 @@ public class PlotVersion { this.build = build; } - public PlotVersion(String version) { - String[] split = version.substring(version.indexOf('=') + 1).split("-"); - if (split[0].equals("unknown")) { - this.year = month = day = hash = build = 0; - return; - } - String[] date = split[0].split("\\."); - this.year = Integer.parseInt(date[0]); - this.month = Integer.parseInt(date[1]); - this.day = Integer.parseInt(date[2]); - if (split[1].equals("SNAPSHOT")) { // fallback when compiling with Maven - this.hash = 0; - this.build = 0; - } else { - this.hash = Integer.parseInt(split[1], 16); - this.build = Integer.parseInt(split[2]); - } + public PlotVersion(String version, String commit, String date) { + String[] split = version.substring(version.indexOf('=') + 1).split("\\."); + this.build = Integer.parseInt(split[1]); + this.hash = Integer.parseInt(commit.substring(commit.indexOf('=') + 1), 16); + String[] split1 = date.substring(date.indexOf('=') + 1).split("\\."); + this.year = Integer.parseInt(split1[0]); + this.month = Integer.parseInt(split1[1]); + this.day = Integer.parseInt(split1[2]); } - public static PlotVersion tryParse(String version) { + public static PlotVersion tryParse(String version, String commit, String date) { try { - return new PlotVersion(version); + return new PlotVersion(version, commit, date); } catch (Exception ignore) { ignore.printStackTrace(); return new PlotVersion(0, 0, 0, 0, 0); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/Updater.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/Updater.java index bd780ae90..4132508a0 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/Updater.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/Updater.java @@ -32,7 +32,7 @@ public class Updater { return newVersion != null; } - public void update(String platform, PlotVersion currentVersion) { + /*public void update(String platform, PlotVersion currentVersion) { if (currentVersion == null || platform == null) { return; } @@ -78,5 +78,5 @@ public class Updater { } } catch (Throwable ignore) { } - } + }*/ } diff --git a/Core/src/main/resources/plugin.properties b/Core/src/main/resources/plugin.properties index 75ac2d200..9ff2dd711 100644 --- a/Core/src/main/resources/plugin.properties +++ b/Core/src/main/resources/plugin.properties @@ -1 +1,3 @@ -version=${version} \ No newline at end of file +version=${version} +commit=${commit} +date=${date} diff --git a/build.gradle b/build.gradle index b74686220..35af2698b 100644 --- a/build.gradle +++ b/build.gradle @@ -43,9 +43,6 @@ ext { version = String.format("%s.%s", rootVersion, buildNumber) description = rootProject.name -if (project.hasProperty("lzNoVersion")) { // gradle build -PlzNoVersion - version = "unknown" -} subprojects { apply plugin: 'java'