Do not check for update of authlib-injector each time

This commit is contained in:
yushijinhun
2018-10-06 11:56:02 +08:00
parent c3dcb0292c
commit f3dca75a10

View File

@@ -45,6 +45,11 @@ public class AuthlibInjectorDownloader {
private Path artifactLocation; private Path artifactLocation;
private Supplier<DownloadProvider> downloadProvider; private Supplier<DownloadProvider> downloadProvider;
/**
* The flag will be reset after application restart.
*/
private boolean updateChecked = false;
/** /**
* @param artifactsDirectory where to save authlib-injector artifacts * @param artifactsDirectory where to save authlib-injector artifacts
*/ */
@@ -57,8 +62,10 @@ public class AuthlibInjectorDownloader {
synchronized (artifactLocation) { synchronized (artifactLocation) {
Optional<AuthlibInjectorArtifactInfo> local = getLocalArtifact(); Optional<AuthlibInjectorArtifactInfo> local = getLocalArtifact();
if (!local.isPresent() || !updateChecked) {
try { try {
update(local); update(local);
updateChecked = true;
} catch (IOException e) { } catch (IOException e) {
LOG.log(Level.WARNING, "Failed to download authlib-injector", e); LOG.log(Level.WARNING, "Failed to download authlib-injector", e);
if (!local.isPresent()) { if (!local.isPresent()) {
@@ -66,12 +73,14 @@ public class AuthlibInjectorDownloader {
} }
LOG.warning("Fallback to use cached artifact: " + local.get()); LOG.warning("Fallback to use cached artifact: " + local.get());
} }
}
return getLocalArtifact().orElseThrow(() -> new IOException("The updated authlib-inejector cannot be recognized")); return getLocalArtifact().orElseThrow(() -> new IOException("The updated authlib-inejector cannot be recognized"));
} }
} }
private void update(Optional<AuthlibInjectorArtifactInfo> local) throws IOException { private void update(Optional<AuthlibInjectorArtifactInfo> local) throws IOException {
LOG.info("Checking update of authlib-injector");
AuthlibInjectorVersionInfo latest = getLatestArtifactInfo(); AuthlibInjectorVersionInfo latest = getLatestArtifactInfo();
if (local.isPresent() && local.get().getBuildNumber() >= latest.buildNumber) { if (local.isPresent() && local.get().getBuildNumber() >= latest.buildNumber) {