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
No known key found for this signature in database
GPG Key ID: 5BC167F73EA558E4

View File

@ -45,6 +45,11 @@ public class AuthlibInjectorDownloader {
private Path artifactLocation;
private Supplier<DownloadProvider> downloadProvider;
/**
* The flag will be reset after application restart.
*/
private boolean updateChecked = false;
/**
* @param artifactsDirectory where to save authlib-injector artifacts
*/
@ -57,14 +62,17 @@ public class AuthlibInjectorDownloader {
synchronized (artifactLocation) {
Optional<AuthlibInjectorArtifactInfo> local = getLocalArtifact();
try {
update(local);
} catch (IOException e) {
LOG.log(Level.WARNING, "Failed to download authlib-injector", e);
if (!local.isPresent()) {
throw e;
if (!local.isPresent() || !updateChecked) {
try {
update(local);
updateChecked = true;
} catch (IOException e) {
LOG.log(Level.WARNING, "Failed to download authlib-injector", e);
if (!local.isPresent()) {
throw e;
}
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"));
@ -72,6 +80,7 @@ public class AuthlibInjectorDownloader {
}
private void update(Optional<AuthlibInjectorArtifactInfo> local) throws IOException {
LOG.info("Checking update of authlib-injector");
AuthlibInjectorVersionInfo latest = getLatestArtifactInfo();
if (local.isPresent() && local.get().getBuildNumber() >= latest.buildNumber) {