From 2f140c4a60f85c8ae1aa0162faef127f8ae4caf3 Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Sat, 25 Jul 2020 14:10:06 -0400 Subject: [PATCH] 1.1.8 --- CHANGELOG.md | 4 ++++ MOD_DEVELOPER.md | 18 +++++++++++++++++- gradle.properties | 2 +- .../modupdater/api/ConfigObject.java | 2 ++ .../modupdater/api/UpdateStrategy.java | 8 ++++++++ .../api/impl/ConfigObjectCustom.java | 13 +++++++++++++ .../api/impl/ConfigObjectHardcoded.java | 13 +++++++++++++ .../strategy/CurseForgeStrategy.java | 4 +++- .../strategy/GitHubReleasesStrategy.java | 4 +++- .../modupdater/strategy/MavenStrategy.java | 4 +++- .../strategy/util/UpdateStrategyRunner.java | 14 ++++++++++++-- .../thebrokenrail/modupdater/util/Util.java | 10 ++++++---- 12 files changed, 85 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d0101f1..0d22b9b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +**1.1.8** +* Strict Minecraft Version Checking by Default +* Print Message To Log Showing All Scanned Mods + **1.1.7** * Disable SemVer In JSON Strategy diff --git a/MOD_DEVELOPER.md b/MOD_DEVELOPER.md index 9fbb6b1..a82c4d5 100644 --- a/MOD_DEVELOPER.md +++ b/MOD_DEVELOPER.md @@ -17,6 +17,7 @@ This update strategy uses the CurseForge API to check for updates. ``` - Requires Semantic Versioning +- In Loose Versioning Mode, Can Infer File's Supported Minecraft version From CurseForge Metadata - [Requires ```build.gradle``` modification](#build-gradle-modification) ## GitHub Releases @@ -108,4 +109,19 @@ If you prefer hyphens you can also use: version = "${project.mod_version}-${project.minecraft_version}" ``` -You can also just use the major version of Minecraft instead of the full version (like ```1.16``` instead of ```1.16.1``` or ```20w20a```). \ No newline at end of file +## Loose VS Strict Versioning Mode + +### Strict (Default) +In strict mode it only marks a file as compatibleif the Minecraft version is identical. + +### Loose +```json +{ + "custom": { + "modupdater": { + "strict": false + } + } +} +``` +In loose mode, it will also mark a file as compatible if it has the same release target. \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 0c21a9e..8193cec 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,7 +9,7 @@ org.gradle.jvmargs = -Xmx1G fabric_loader_version = 0.8.8+build.202 # Mod Properties - mod_version = 1.1.7 + mod_version = 1.1.8 maven_group = com.thebrokenrail # Dependencies diff --git a/src/main/java/com/thebrokenrail/modupdater/api/ConfigObject.java b/src/main/java/com/thebrokenrail/modupdater/api/ConfigObject.java index 824062c..ee504d8 100644 --- a/src/main/java/com/thebrokenrail/modupdater/api/ConfigObject.java +++ b/src/main/java/com/thebrokenrail/modupdater/api/ConfigObject.java @@ -5,6 +5,8 @@ public interface ConfigObject { int getInt(String str) throws MissingValueException; + boolean getBoolean(String str) throws MissingValueException; + class MissingValueException extends Exception { private static final String MISSING_MSG = "Missing Configuration Property: %s"; private static final String INVALID_MSG = "Invalid Configuration Property: %s"; diff --git a/src/main/java/com/thebrokenrail/modupdater/api/UpdateStrategy.java b/src/main/java/com/thebrokenrail/modupdater/api/UpdateStrategy.java index c8af551..45770cc 100644 --- a/src/main/java/com/thebrokenrail/modupdater/api/UpdateStrategy.java +++ b/src/main/java/com/thebrokenrail/modupdater/api/UpdateStrategy.java @@ -7,4 +7,12 @@ import javax.annotation.Nullable; public interface UpdateStrategy { @Nullable ModUpdate run(ConfigObject obj, String oldVersion, String name); + + default boolean isStrict(ConfigObject obj) { + try { + return obj.getBoolean("strict"); + } catch (ConfigObject.MissingValueException e) { + return true; + } + } } diff --git a/src/main/java/com/thebrokenrail/modupdater/api/impl/ConfigObjectCustom.java b/src/main/java/com/thebrokenrail/modupdater/api/impl/ConfigObjectCustom.java index f37634c..59fc706 100644 --- a/src/main/java/com/thebrokenrail/modupdater/api/impl/ConfigObjectCustom.java +++ b/src/main/java/com/thebrokenrail/modupdater/api/impl/ConfigObjectCustom.java @@ -35,4 +35,17 @@ public class ConfigObjectCustom implements ConfigObject { throw new MissingValueException(false, str); } } + + @Override + public boolean getBoolean(String str) throws MissingValueException { + if (obj.containsKey(str)) { + try { + return obj.get(str).getAsBoolean(); + } catch (ClassCastException e) { + throw new MissingValueException(true, str); + } + } else { + throw new MissingValueException(false, str); + } + } } \ No newline at end of file diff --git a/src/main/java/com/thebrokenrail/modupdater/api/impl/ConfigObjectHardcoded.java b/src/main/java/com/thebrokenrail/modupdater/api/impl/ConfigObjectHardcoded.java index 2cace9d..a30da6b 100644 --- a/src/main/java/com/thebrokenrail/modupdater/api/impl/ConfigObjectHardcoded.java +++ b/src/main/java/com/thebrokenrail/modupdater/api/impl/ConfigObjectHardcoded.java @@ -36,4 +36,17 @@ public class ConfigObjectHardcoded implements ConfigObject { throw new MissingValueException(false, str); } } + + @Override + public boolean getBoolean(String str) throws MissingValueException { + if (map.containsKey(str)) { + try { + return (Boolean) map.get(str); + } catch (ClassCastException e) { + throw new MissingValueException(true, str); + } + } else { + throw new MissingValueException(false, str); + } + } } diff --git a/src/main/java/com/thebrokenrail/modupdater/strategy/CurseForgeStrategy.java b/src/main/java/com/thebrokenrail/modupdater/strategy/CurseForgeStrategy.java index 3457dc0..97502da 100644 --- a/src/main/java/com/thebrokenrail/modupdater/strategy/CurseForgeStrategy.java +++ b/src/main/java/com/thebrokenrail/modupdater/strategy/CurseForgeStrategy.java @@ -70,11 +70,13 @@ public class CurseForgeStrategy implements UpdateStrategy { versionStr = version.getReleaseTarget() + "-Snapshot"; } + boolean strict = isStrict(obj); + CurseForgeFile newestFile = null; for (CurseForgeFile file : files) { if (Util.isFileCompatible(file.fileName)) { String fileVersion = Util.getVersionFromFileName(file.fileName); - if (Arrays.asList(file.gameVersion).contains(versionStr) || Util.isVersionCompatible(fileVersion)) { + if ((Arrays.asList(file.gameVersion).contains(versionStr) && strict) || Util.isVersionCompatible(fileVersion, strict)) { if (newestFile != null) { String newestFileVersion = Util.getVersionFromFileName(newestFile.fileName); try { diff --git a/src/main/java/com/thebrokenrail/modupdater/strategy/GitHubReleasesStrategy.java b/src/main/java/com/thebrokenrail/modupdater/strategy/GitHubReleasesStrategy.java index aa69519..fcc2c62 100644 --- a/src/main/java/com/thebrokenrail/modupdater/strategy/GitHubReleasesStrategy.java +++ b/src/main/java/com/thebrokenrail/modupdater/strategy/GitHubReleasesStrategy.java @@ -66,12 +66,14 @@ public class GitHubReleasesStrategy implements UpdateStrategy { return null; } + boolean strict = isStrict(obj); + GitHubReleaseAsset newestFile = null; for (GitHubRelease release : releases) { for (GitHubReleaseAsset asset : release.assets) { if (Util.isFileCompatible(asset.name)) { String fileVersion = Util.getVersionFromFileName(asset.name); - if (Util.isVersionCompatible(fileVersion)) { + if (Util.isVersionCompatible(fileVersion, strict)) { if (newestFile != null) { try { if (SemanticVersion.parse(fileVersion).compareTo(SemanticVersion.parse(fileVersion)) > 0) { diff --git a/src/main/java/com/thebrokenrail/modupdater/strategy/MavenStrategy.java b/src/main/java/com/thebrokenrail/modupdater/strategy/MavenStrategy.java index 61c23f7..844ac8d 100644 --- a/src/main/java/com/thebrokenrail/modupdater/strategy/MavenStrategy.java +++ b/src/main/java/com/thebrokenrail/modupdater/strategy/MavenStrategy.java @@ -80,12 +80,14 @@ public class MavenStrategy implements UpdateStrategy { return null; } + boolean strict = isStrict(obj); + String newestVersion = null; for (int i = 0; i < versions.getLength(); i++) { Node node = versions.item(i); String version = node.getTextContent(); - if (Util.isVersionCompatible(version)) { + if (Util.isVersionCompatible(version, strict)) { if (newestVersion != null) { try { if (SemanticVersion.parse(version).compareTo(SemanticVersion.parse(newestVersion)) > 0) { diff --git a/src/main/java/com/thebrokenrail/modupdater/strategy/util/UpdateStrategyRunner.java b/src/main/java/com/thebrokenrail/modupdater/strategy/util/UpdateStrategyRunner.java index b074435..76eeff7 100644 --- a/src/main/java/com/thebrokenrail/modupdater/strategy/util/UpdateStrategyRunner.java +++ b/src/main/java/com/thebrokenrail/modupdater/strategy/util/UpdateStrategyRunner.java @@ -14,10 +14,11 @@ import javax.annotation.Nullable; import java.util.ArrayList; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; +import java.util.function.Consumer; public class UpdateStrategyRunner { @Nullable - private static ModUpdate checkModForUpdate(ModMetadata metadata) { + private static ModUpdate checkModForUpdate(ModMetadata metadata, Consumer scan) { String name = metadata.getName() + " (" + metadata.getId() + ')'; ConfigObject obj; @@ -51,6 +52,8 @@ public class UpdateStrategyRunner { return null; } + scan.accept(name); + return strategyObj.run(obj, oldVersion, name); } @@ -58,6 +61,7 @@ public class UpdateStrategyRunner { ModUpdater.logInfo("Checking For Mod Updates..."); List updates = new ArrayList<>(); + List scannedMods = new ArrayList<>(); AtomicInteger remaining = new AtomicInteger(0); @@ -66,7 +70,11 @@ public class UpdateStrategyRunner { try { ModMetadata metadata = mod.getMetadata(); - ModUpdate update = checkModForUpdate(metadata); + ModUpdate update = checkModForUpdate(metadata, name -> { + synchronized (scannedMods) { + scannedMods.add(name); + } + }); if (update != null) { ModUpdater.logInfo(update.text + " (" + update.downloadURL + ')'); @@ -100,6 +108,8 @@ public class UpdateStrategyRunner { ModUpdater.logInfo(updates.size() + String.format(" Mod Update%s Found", updates.size() == 1 ? "" : "s")); + ModUpdater.logInfo("Scanned " + scannedMods.size() + " Mods: " + String.join(", ", scannedMods)); + return updates.toArray(new ModUpdate[0]); } } diff --git a/src/main/java/com/thebrokenrail/modupdater/util/Util.java b/src/main/java/com/thebrokenrail/modupdater/util/Util.java index e5bc5f7..6414c01 100644 --- a/src/main/java/com/thebrokenrail/modupdater/util/Util.java +++ b/src/main/java/com/thebrokenrail/modupdater/util/Util.java @@ -75,13 +75,13 @@ public class Util { } } - private static boolean isVersionCompatible(String versionStr, char prefix) { + private static boolean isVersionCompatible(String versionStr, char prefix, boolean strict) { updateMinecraftVersion(); - return versionStr.endsWith(prefix + minecraftVersionSemantic) || versionStr.endsWith(prefix + minecraftVersion.getReleaseTarget()) || versionStr.endsWith(prefix + getMajorVersion()); + return versionStr.endsWith(prefix + minecraftVersionSemantic) || versionStr.endsWith(prefix + minecraftVersion.getName()) || (!strict && (versionStr.endsWith(prefix + minecraftVersion.getReleaseTarget()) || versionStr.endsWith(prefix + getMajorVersion()))); } - public static boolean isVersionCompatible(String versionStr) { - return isVersionCompatible(versionStr, '+') || isVersionCompatible(versionStr, '-'); + public static boolean isVersionCompatible(String versionStr, boolean strict) { + return isVersionCompatible(versionStr, '+', strict) || isVersionCompatible(versionStr, '-', strict); } public static boolean isFileCompatible(String fileName) { @@ -99,12 +99,14 @@ public class Util { Map map = new HashMap<>(); map.put("strategy", "curseforge"); map.put("projectID", 306612); + map.put("strict", false); return new ConfigObjectHardcoded(map); } case "modmenu": { Map map = new HashMap<>(); map.put("strategy", "curseforge"); map.put("projectID", 308702); + map.put("strict", false); return new ConfigObjectHardcoded(map); } default: {