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..a1f3d3ce 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; } @@ -289,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,6 +440,8 @@ public LaunchServer(Path dir, String[] args) throws IOException, InvalidKeySpecE // post init modules modulesManager.postInitModules(); + // start updater + this.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 { diff --git a/modules b/modules index 38e11640..53106ee2 160000 --- a/modules +++ b/modules @@ -1 +1 @@ -Subproject commit 38e11640ce4a4ed3e9745718db02a888770a22bb +Subproject commit 53106ee20700cb73ad65fd7dddf69b0d0b766f4c