diff --git a/Plan/common/build.gradle b/Plan/common/build.gradle index a04c1660f..82b29c744 100644 --- a/Plan/common/build.gradle +++ b/Plan/common/build.gradle @@ -114,10 +114,14 @@ task copyYarnBuildResults { } } -task determineWebAssetModifications { +task determineAssetModifications { + inputs.files(fileTree(dir: 'src/main/resources/assets/plan/web')) + inputs.files(fileTree(dir: 'src/main/resources/assets/plan/locale')) + outputs.file("build/resources/main/assets/plan/AssetVersion.yml") + doLast { mkdir "build/resources/main/assets/plan" - def versionFile = file("build/resources/main/assets/plan/WebAssetVersion.yml") + def versionFile = file("build/resources/main/assets/plan/AssetVersion.yml") versionFile.text = "" // Clear previous build ConfigurableFileTree tree = fileTree(dir: 'src/main/resources/assets/plan/web') tree.forEach { File f -> @@ -134,6 +138,21 @@ task determineWebAssetModifications { "%s: %s\n", relativePath.toString().replace('.', ','), modified ) } + tree = fileTree(dir: 'src/main/resources/assets/plan/locale') + tree.forEach { File f -> + def gitModified = new ByteArrayOutputStream() + exec { + commandLine 'git', 'log', '-1', '--pretty=%ct', f.toString() + standardOutput = gitModified + } + def gitModifiedAsString = gitModified.toString().strip() + // git returns UNIX time in seconds, but most things in Java use UNIX time in milliseconds + def modified = gitModifiedAsString.isEmpty() ? System.currentTimeMillis() : Long.parseLong(gitModifiedAsString) * 1000 + def relativePath = tree.getDir().toPath().relativize(f.toPath()) // File path relative to the tree + versionFile.text += String.format( // writing YAML as raw text probably isn't the best idea + "%s: %s\n", relativePath.toString().replace('.', ','), modified + ) + } } } @@ -161,7 +180,7 @@ artifacts { processResources { dependsOn copyYarnBuildResults - dependsOn determineWebAssetModifications + dependsOn determineAssetModifications dependsOn generateResourceForMySQLDriver dependsOn generateResourceForSQLiteDriver dependsOn updateVersion diff --git a/Plan/common/src/main/java/com/djrapitops/plan/delivery/web/WebAssetVersions.java b/Plan/common/src/main/java/com/djrapitops/plan/delivery/web/AssetVersions.java similarity index 91% rename from Plan/common/src/main/java/com/djrapitops/plan/delivery/web/WebAssetVersions.java rename to Plan/common/src/main/java/com/djrapitops/plan/delivery/web/AssetVersions.java index 9e9b7a828..29de242a2 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/delivery/web/WebAssetVersions.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/delivery/web/AssetVersions.java @@ -27,25 +27,25 @@ import java.io.IOException; import java.util.Optional; @Singleton -public class WebAssetVersions { +public class AssetVersions { private final PlanFiles files; private Config webAssetConfig; @Inject - public WebAssetVersions( + public AssetVersions( PlanFiles files ) { this.files = files; } public void prepare() throws IOException { - try (ConfigReader reader = new ConfigReader(files.getResourceFromJar("WebAssetVersion.yml").asInputStream())) { + try (ConfigReader reader = new ConfigReader(files.getResourceFromJar("AssetVersion.yml").asInputStream())) { webAssetConfig = reader.read(); } } - public Optional getWebAssetVersion(String resource) { + public Optional getAssetVersion(String resource) { if (webAssetConfig == null) return Optional.empty(); return webAssetConfig.getNode(resource.replace('.', ',')).map(ConfigNode::getLong); diff --git a/Plan/common/src/main/java/com/djrapitops/plan/delivery/web/WebAssetVersionCheckTask.java b/Plan/common/src/main/java/com/djrapitops/plan/delivery/web/WebAssetVersionCheckTask.java index 9e907a2cd..b59596b96 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/delivery/web/WebAssetVersionCheckTask.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/delivery/web/WebAssetVersionCheckTask.java @@ -42,7 +42,7 @@ public class WebAssetVersionCheckTask extends TaskSystem.Task { private final PlanConfig config; private final PlanFiles files; private final PluginLogger logger; - private final WebAssetVersions webAssetVersions; + private final AssetVersions assetVersions; private final Formatters formatters; @Inject @@ -50,13 +50,13 @@ public class WebAssetVersionCheckTask extends TaskSystem.Task { PlanConfig config, PlanFiles files, PluginLogger logger, - WebAssetVersions webAssetVersions, + AssetVersions assetVersions, Formatters formatters ) { this.config = config; this.files = files; this.logger = logger; - this.webAssetVersions = webAssetVersions; + this.assetVersions = assetVersions; this.formatters = formatters; } @@ -78,7 +78,7 @@ public class WebAssetVersionCheckTask extends TaskSystem.Task { Optional planCustomizationNode = getPlanCustomizationNode(); if (planCustomizationNode.isPresent()) { try { - webAssetVersions.prepare(); + assetVersions.prepare(); } catch (IOException e) { logger.warn(String.format("Could not read web asset versions, %s", e.toString())); logger.warn("Web asset version check will be skipped!"); @@ -111,7 +111,7 @@ public class WebAssetVersionCheckTask extends TaskSystem.Task { private Optional findOutdatedResource(String resource) { Optional resourceFile = files.attemptToFind(resource); - Optional webAssetVersion = webAssetVersions.getWebAssetVersion(resource); + Optional webAssetVersion = assetVersions.getAssetVersion(resource); if (resourceFile.isPresent() && webAssetVersion.isPresent() && webAssetVersion.get() > resourceFile.get().lastModified()) { return Optional.of(new AssetInfo( resource, diff --git a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/resolver/json/LocaleJSONResolver.java b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/resolver/json/LocaleJSONResolver.java index 364e1c329..722a1188a 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/resolver/json/LocaleJSONResolver.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/resolver/json/LocaleJSONResolver.java @@ -119,12 +119,13 @@ public class LocaleJSONResolver implements NoAuthResolver { Map languages = new TreeMap<>(); Map languageVersions = new TreeMap<>(); - long localeVersion = localeSystem.getLocaleVersion(); + long maxLocaleVersion = localeSystem.getMaxLocaleVersion(); Optional customLocaleVersion = localeSystem.getCustomLocaleVersion(); for (LangCode lang : LangCode.values()) { if (lang == LangCode.CUSTOM && locale.getLangCode() != LangCode.CUSTOM) continue; languages.put(lang.toString(), lang.getName()); + long localeVersion = localeSystem.getLocaleVersion(lang).orElse(maxLocaleVersion); languageVersions.put(lang.toString(), localeVersion); } customLocaleVersion.ifPresent(version -> languageVersions.put(LangCode.CUSTOM.toString(), version)); diff --git a/Plan/common/src/main/java/com/djrapitops/plan/settings/locale/LocaleSystem.java b/Plan/common/src/main/java/com/djrapitops/plan/settings/locale/LocaleSystem.java index 49c30ce55..72e679b52 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/settings/locale/LocaleSystem.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/settings/locale/LocaleSystem.java @@ -17,7 +17,7 @@ package com.djrapitops.plan.settings.locale; import com.djrapitops.plan.SubSystem; -import com.djrapitops.plan.delivery.web.WebAssetVersions; +import com.djrapitops.plan.delivery.web.AssetVersions; import com.djrapitops.plan.delivery.webserver.auth.FailReason; import com.djrapitops.plan.settings.config.PlanConfig; import com.djrapitops.plan.settings.config.paths.PluginSettings; @@ -48,7 +48,7 @@ public class LocaleSystem implements SubSystem { private final PlanFiles files; private final PlanConfig config; - private final WebAssetVersions webAssetVersions; + private final AssetVersions assetVersions; private final PluginLogger logger; private final ErrorLogger errorLogger; @@ -58,13 +58,13 @@ public class LocaleSystem implements SubSystem { public LocaleSystem( PlanFiles files, PlanConfig config, - WebAssetVersions webAssetVersions, + AssetVersions assetVersions, PluginLogger logger, ErrorLogger errorLogger ) { this.files = files; this.config = config; - this.webAssetVersions = webAssetVersions; + this.assetVersions = assetVersions; this.logger = logger; this.errorLogger = errorLogger; this.locale = new Locale(); @@ -221,8 +221,12 @@ public class LocaleSystem implements SubSystem { return locale; } - public long getLocaleVersion() { - return webAssetVersions.getLatestWebAssetVersion().orElse(0L); + public long getMaxLocaleVersion() { + return assetVersions.getLatestWebAssetVersion().orElse(0L); + } + + public Optional getLocaleVersion(LangCode langCode) { + return assetVersions.getAssetVersion(langCode.getFileName()); } public Optional getCustomLocaleVersion() {