From 237a2a2f927dc2c9529cbfc0936d3c855a64761f Mon Sep 17 00:00:00 2001 From: zaxar163 Date: Mon, 21 Jan 2019 12:11:56 +0300 Subject: [PATCH 1/2] =?UTF-8?q?[FEATURE]=20=D0=A3=D0=B2=D0=B5=D0=B4=D0=BE?= =?UTF-8?q?=D0=BC=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BE=20latest=20=D1=80?= =?UTF-8?q?=D0=B5=D0=BB=D0=B8=D0=B7=D0=B5=20=D0=BD=D0=B0=20github.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LaunchServer/build.gradle | 5 +- .../ru/gravit/launchserver/LaunchServer.java | 3 +- .../java/ru/gravit/launchserver/Updater.java | 53 +++++++++++++++++++ .../gravit/launcher/server/ServerAgent.java | 1 - 4 files changed, 58 insertions(+), 4 deletions(-) create mode 100644 LaunchServer/src/main/java/ru/gravit/launchserver/Updater.java diff --git a/LaunchServer/build.gradle b/LaunchServer/build.gradle index 4889e6a6..c6702389 100644 --- a/LaunchServer/build.gradle +++ b/LaunchServer/build.gradle @@ -44,9 +44,10 @@ pack project(':libLauncher') bundle 'org.fusesource.jansi:jansi:1.17.1' bundle 'commons-io:commons-io:2.6' bundle 'commons-codec:commons-codec:1.11' - bundle 'org.javassist:javassist:3.23.1-GA' + bundle 'org.javassist:javassist:3.24.1-GA' bundle 'io.netty:netty-all:4.1.32.Final' - + bundle 'org.kohsuke:github-api:1.95' + bundle 'org.slf4j:slf4j-simple:1.7.25' bundle 'org.slf4j:slf4j-api:1.7.25' diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java index ced4b54a..9ef85b0a 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java @@ -111,7 +111,6 @@ public static final class Config { public String startScript; - public String getAddress() { return address; } @@ -439,6 +438,8 @@ public LaunchServer(Path dir, String[] args) throws IOException, InvalidKeySpecE // post init modules modulesManager.postInitModules(); + // start updater + new Updater(this); } public static void initGson() { diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/Updater.java b/LaunchServer/src/main/java/ru/gravit/launchserver/Updater.java new file mode 100644 index 00000000..9a666501 --- /dev/null +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/Updater.java @@ -0,0 +1,53 @@ +package ru.gravit.launchserver; + +import java.io.IOException; +import java.time.Instant; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; +import java.util.Date; +import java.util.Locale; +import java.util.Timer; +import java.util.TimerTask; + +import org.kohsuke.github.GHRelease; +import org.kohsuke.github.GHRepository; +import org.kohsuke.github.GitHub; + +import ru.gravit.utils.helper.LogHelper; + +public class Updater extends TimerTask { + private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy.MM.dd HH:mm:ss", Locale.US); + private static final long period = 1000*3600; + private final Timer taskPool; + private final GHRepository gravitLauncher; + private GHRelease parenRel = null; + + public Updater(LaunchServer srv) { + this.taskPool = new Timer("Updater thread", true); + + GHRepository gravitLauncherTmp = null; + try { + gravitLauncherTmp = GitHub.connectAnonymously().getOrganization("GravitLauncher").getRepository("Launcher"); + } catch (IOException e) { + LogHelper.error(e); + } + this.gravitLauncher = gravitLauncherTmp; + + run(); + taskPool.schedule(this, new Date(System.currentTimeMillis()+period), period); + } + + @Override + public void run() { + try { + GHRelease rel = gravitLauncher.getLatestRelease(); + if (rel.equals(parenRel)) return; + LogHelper.warning("Latest release: %s", rel.getName()); + LogHelper.warning("It`s published at: " + DATE_TIME_FORMATTER.format(LocalDateTime.ofInstant(Instant.ofEpochMilli(rel.getPublished_at().getTime()), ZoneId.systemDefault()))); + } catch (IOException e) { + LogHelper.error(e); + } + } + +} diff --git a/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerAgent.java b/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerAgent.java index 607cca82..fbcb6b23 100644 --- a/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerAgent.java +++ b/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerAgent.java @@ -10,7 +10,6 @@ import java.lang.invoke.MethodType; import java.nio.file.*; import java.nio.file.attribute.BasicFileAttributes; -import java.util.Collections; import java.util.jar.JarFile; public class ServerAgent { From 9e4df1d1960e348c044ca99825cfdc81bf160a7b Mon Sep 17 00:00:00 2001 From: zaxar163 Date: Mon, 21 Jan 2019 16:06:13 +0300 Subject: [PATCH 2/2] =?UTF-8?q?[FIX]=20=D0=A2=D0=B5=D0=BF=D0=B5=D1=80?= =?UTF-8?q?=D1=8C=20GC=20=D0=BD=D0=B5=20=D1=81=D1=8A=D0=B5=D1=81=D1=82=20U?= =?UTF-8?q?pdater.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zaxar163 --- .../src/main/java/ru/gravit/launchserver/LaunchServer.java | 4 +++- modules | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java index 9ef85b0a..a1f3d3ce 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java @@ -288,6 +288,8 @@ public static void main(String... args) throws Throwable { public volatile Map> updatesDirMap; + public final Updater updater; + public static Gson gson; public static GsonBuilder gsonBuilder; @@ -439,7 +441,7 @@ public LaunchServer(Path dir, String[] args) throws IOException, InvalidKeySpecE // post init modules modulesManager.postInitModules(); // start updater - new Updater(this); + this.updater = new Updater(this); } public static void initGson() { diff --git a/modules b/modules index 38e11640..53106ee2 160000 --- a/modules +++ b/modules @@ -1 +1 @@ -Subproject commit 38e11640ce4a4ed3e9745718db02a888770a22bb +Subproject commit 53106ee20700cb73ad65fd7dddf69b0d0b766f4c