[FEATURE] Уведомление о latest релизе на github.

This commit is contained in:
zaxar163 2019-01-21 12:11:56 +03:00
parent ec0948594d
commit 237a2a2f92
No known key found for this signature in database
GPG key ID: E3B309DD3852DE06
4 changed files with 58 additions and 4 deletions

View file

@ -44,8 +44,9 @@ pack project(':libLauncher')
bundle 'org.fusesource.jansi:jansi:1.17.1' bundle 'org.fusesource.jansi:jansi:1.17.1'
bundle 'commons-io:commons-io:2.6' bundle 'commons-io:commons-io:2.6'
bundle 'commons-codec:commons-codec:1.11' 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 '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-simple:1.7.25'
bundle 'org.slf4j:slf4j-api:1.7.25' bundle 'org.slf4j:slf4j-api:1.7.25'

View file

@ -111,7 +111,6 @@ public static final class Config {
public String startScript; public String startScript;
public String getAddress() { public String getAddress() {
return address; return address;
} }
@ -439,6 +438,8 @@ public LaunchServer(Path dir, String[] args) throws IOException, InvalidKeySpecE
// post init modules // post init modules
modulesManager.postInitModules(); modulesManager.postInitModules();
// start updater
new Updater(this);
} }
public static void initGson() { public static void initGson() {

View file

@ -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);
}
}
}

View file

@ -10,7 +10,6 @@
import java.lang.invoke.MethodType; import java.lang.invoke.MethodType;
import java.nio.file.*; import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes; import java.nio.file.attribute.BasicFileAttributes;
import java.util.Collections;
import java.util.jar.JarFile; import java.util.jar.JarFile;
public class ServerAgent { public class ServerAgent {