diff --git a/src/main/java/net/ornithemc/meta/OrnitheMeta.java b/src/main/java/net/ornithemc/meta/OrnitheMeta.java index dd7f8ae..f4a6ec7 100644 --- a/src/main/java/net/ornithemc/meta/OrnitheMeta.java +++ b/src/main/java/net/ornithemc/meta/OrnitheMeta.java @@ -26,8 +26,6 @@ import org.tinylog.Logger; import org.tinylog.TaggedLogger; -import javax.xml.stream.XMLStreamException; -import java.io.IOException; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; @@ -55,7 +53,7 @@ private static void update(){ try { databaseOld = VersionDatabaseOld.generate(); database = VersionDatabase.generate(); - } catch (IOException | XMLStreamException e) { + } catch (Exception e) { Logger.error(e); } } diff --git a/src/main/java/net/ornithemc/meta/data/ConfigV3.java b/src/main/java/net/ornithemc/meta/data/ConfigV3.java new file mode 100644 index 0000000..d5dd2b3 --- /dev/null +++ b/src/main/java/net/ornithemc/meta/data/ConfigV3.java @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2019 FabricMC + * + * Modifications copyright (c) 2022 OrnitheMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.ornithemc.meta.data; + +import java.io.File; + +import net.ornithemc.meta.OrnitheMeta; + +public class ConfigV3 { + + private static final File FILE = new File("config-v3.json"); + + public int latestIntermediaryGeneration = -1; + public int stableIntermediaryGeneration = -1; + + public static ConfigV3 load() throws Exception { + return OrnitheMeta.MAPPER.readValue(FILE, ConfigV3.class); + } +} diff --git a/src/main/java/net/ornithemc/meta/data/VersionDatabase.java b/src/main/java/net/ornithemc/meta/data/VersionDatabase.java index b294ea5..9d5dde2 100644 --- a/src/main/java/net/ornithemc/meta/data/VersionDatabase.java +++ b/src/main/java/net/ornithemc/meta/data/VersionDatabase.java @@ -33,7 +33,6 @@ import net.ornithemc.meta.web.LibraryUpgradesV3.LibraryUpgrade; import net.ornithemc.meta.web.models.*; -import javax.xml.stream.XMLStreamException; import java.io.IOException; import java.io.InputStreamReader; import java.net.URL; @@ -52,9 +51,6 @@ public class VersionDatabase { public static final String ORNITHE_MAVEN_VERSIONS_URL = "https://maven.ornithemc.net/api/maven/versions/releases/"; public static final String MINECRAFT_LIBRARIES_URL = "https://libraries.minecraft.net/"; - public static final int LATEST_GENERATION = 2; - public static final int LATEST_STABLE_GENERATION = 1; - public static final PomParser RAVEN_PARSER = new PomParser(ORNITHE_MAVEN_URL + "net/ornithemc/raven/maven-metadata.xml"); public static final PomParser SPARROW_PARSER = new PomParser(ORNITHE_MAVEN_URL + "net/ornithemc/sparrow/maven-metadata.xml"); public static final PomParser NESTS_PARSER = new PomParser(ORNITHE_MAVEN_URL + "net/ornithemc/nests/maven-metadata.xml"); @@ -63,6 +59,9 @@ public class VersionDatabase { public static final PomParser INSTALLER_PARSER = new PomParser(ORNITHE_MAVEN_URL + "net/ornithemc/ornithe-installer/maven-metadata.xml"); public static final PomParser OSL_PARSER = new PomParser(ORNITHE_MAVEN_URL + "net/ornithemc/osl/maven-metadata.xml"); public static final PomDependencyParser OSL_DEPENDENCY_PARSER = new PomDependencyParser(ORNITHE_MAVEN_URL + "net/ornithemc/osl"); + + public static ConfigV3 config; + public final VersionManifest manifest = new VersionManifest(); private final Int2ObjectMap> game; private final Int2ObjectMap> intermediary; @@ -88,13 +87,13 @@ private VersionDatabase() { public static final PomParser intermediaryParser(int generation) { return generation == 1 ? new PomParser(ORNITHE_MAVEN_URL + "net/ornithemc/calamus-intermediary/maven-metadata.xml") - : new PomParser(ORNITHE_MAVEN_URL + "net/ornithemc/calamus-intermediary-gen" + generation + "/maven-metadata.xml", generation <= LATEST_STABLE_GENERATION); + : new PomParser(ORNITHE_MAVEN_URL + "net/ornithemc/calamus-intermediary-gen" + generation + "/maven-metadata.xml", generation <= config.stableIntermediaryGeneration); } public static final PomParser featherParser(int generation) { return generation == 1 ? new PomParser(ORNITHE_MAVEN_URL + "net/ornithemc/feather/maven-metadata.xml") - : new PomParser(ORNITHE_MAVEN_URL + "net/ornithemc/feather-gen" + generation + "/maven-metadata.xml", generation <= LATEST_STABLE_GENERATION); + : new PomParser(ORNITHE_MAVEN_URL + "net/ornithemc/feather-gen" + generation + "/maven-metadata.xml", generation <= config.stableIntermediaryGeneration); } public static final Map getOslModulePomParsers(List osl) { @@ -139,10 +138,11 @@ public static final Map getOslModulePomParsers(List launcherMetas = new Int2ObjectOpenHashMap<>(); - for (int generation = 1; generation <= LATEST_GENERATION; generation++) { + for (int generation = 1; generation <= config.latestIntermediaryGeneration; generation++) { final int gen = generation; final MinecraftLauncherMeta launcherMeta = MinecraftLauncherMeta.getSortedMeta(gen); launcherMetas.put(generation, launcherMeta); @@ -247,7 +247,7 @@ private void loadMcData() throws IOException { Function> p = src -> { return o -> { - for (int generation = 1; generation <= LATEST_GENERATION; generation++) { + for (int generation = 1; generation <= config.latestIntermediaryGeneration; generation++) { if (launcherMetas.get(generation).getVersions().stream().anyMatch(metaVersion -> metaVersion.getId().equals(o.getVersionNoSide()))) { return false; } @@ -259,7 +259,7 @@ private void loadMcData() throws IOException { Comparator c = (v1, v2) -> { int i1 = Integer.MAX_VALUE; int i2 = Integer.MAX_VALUE; - for (int generation = 1; generation <= LATEST_GENERATION; generation++) { + for (int generation = 1; generation <= config.latestIntermediaryGeneration; generation++) { MinecraftLauncherMeta launcherMeta = launcherMetas.get(generation); i1 = Math.min(i1, launcherMeta.getIndex(v1.getVersionNoSide())); i2 = Math.min(i2, launcherMeta.getIndex(v2.getVersionNoSide())); diff --git a/src/main/java/net/ornithemc/meta/web/EndpointsV3.java b/src/main/java/net/ornithemc/meta/web/EndpointsV3.java index f06a32f..8c8b56d 100644 --- a/src/main/java/net/ornithemc/meta/web/EndpointsV3.java +++ b/src/main/java/net/ornithemc/meta/web/EndpointsV3.java @@ -102,31 +102,31 @@ private static void jsonGet(String path, Function function) { } private static void jsonGetS(String path, Function> supplier) { - for (int generation = 1; generation <= VersionDatabase.LATEST_GENERATION; generation++) { + for (int generation = 1; generation <= VersionDatabase.config.latestIntermediaryGeneration; generation++) { Handler handler = WebServer.jsonGet("/v3/versions/gen" + generation + path, supplier.apply(generation)); - if (generation == VersionDatabase.LATEST_STABLE_GENERATION) { + if (generation == VersionDatabase.config.stableIntermediaryGeneration) { WebServer.javalin.get("/v3/versions" + path, handler); } } } private static void jsonGetF(String path, Function> function) { - for (int generation = 1; generation <= VersionDatabase.LATEST_GENERATION; generation++) { + for (int generation = 1; generation <= VersionDatabase.config.latestIntermediaryGeneration; generation++) { Handler handler = WebServer.jsonGet("/v3/versions/gen" + generation + path, function.apply(generation)); - if (generation == VersionDatabase.LATEST_STABLE_GENERATION) { + if (generation == VersionDatabase.config.stableIntermediaryGeneration) { WebServer.javalin.get("/v3/versions" + path, handler); } } } private static void jsonGetH(String path, Function function) { - for (int generation = 1; generation <= VersionDatabase.LATEST_GENERATION; generation++) { + for (int generation = 1; generation <= VersionDatabase.config.latestIntermediaryGeneration; generation++) { Handler handler = function.apply(generation); WebServer.javalin.get("/v3/versions/gen" + generation + path, handler); - if (generation == VersionDatabase.LATEST_STABLE_GENERATION) { + if (generation == VersionDatabase.config.stableIntermediaryGeneration) { WebServer.javalin.get("/v3/versions" + path, handler); } }