From f4ed8a4bcb4ada7e4858eca7e9918ef6c7f15eee Mon Sep 17 00:00:00 2001 From: JFronny Date: Wed, 8 Nov 2023 09:15:59 +0100 Subject: [PATCH] chore: bump commons and update for new modules --- build.gradle.kts | 4 ++-- common/build.gradle.kts | 5 ++++- .../common/InceptumEnvironmentInitializer.java | 8 ++++---- .../io/gitlab/jfronny/inceptum/common/Net.java | 12 ++++++------ .../io/gitlab/jfronny/inceptum/common/Utils.java | 2 +- .../jfronny/inceptum/common/api/MavenApi.java | 6 +++--- common/src/main/java/module-info.java | 3 +++ launcher-gtk/build.gradle.kts | 4 ++-- .../io/gitlab/jfronny/inceptum/gtk/util/Log.kt | 2 +- .../io/gitlab/jfronny/inceptum/gtk/util/UIExt.kt | 11 ++++++++++- .../gtk/window/create/NewInstanceWindow.kt | 7 ++++--- .../window/dialog/ProcessStateWatcherDialog.kt | 3 ++- .../gtk/window/settings/instance/ModsTab.kt | 7 ++----- launcher-gtk/src/main/kotlin/module-info.java | 2 ++ launcher/build.gradle.kts | 2 +- .../inceptum/launcher/api/CurseforgeApi.java | 4 ++-- .../inceptum/launcher/api/FabricMetaApi.java | 2 +- .../launcher/api/account/MicrosoftAuthAPI.java | 16 ++++++++-------- .../api/account/MicrosoftAuthServer.java | 4 ++-- .../launcher/model/inceptum/ModMeta.java | 2 +- .../system/source/CurseforgeModSource.java | 4 ++-- .../launcher/system/source/DirectModSource.java | 2 +- .../system/source/ModrinthModSource.java | 4 ++-- launcher/src/main/java/module-info.java | 2 +- 24 files changed, 67 insertions(+), 51 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index c49a8ca..796040e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -10,8 +10,8 @@ allprojects { } // common -val jfCommonsVersion by extra("1.3-SNAPSHOT") -val gsonCompileVersion by extra("1.3-SNAPSHOT") +val jfCommonsVersion by extra("1.5-SNAPSHOT") +val gsonCompileVersion by extra("1.4-SNAPSHOT") val jbAnnotationsVersion by extra("24.0.1") // launcher-imgui val lwjglVersion by extra("3.3.2") diff --git a/common/build.gradle.kts b/common/build.gradle.kts index cb2e0d0..43abd37 100644 --- a/common/build.gradle.kts +++ b/common/build.gradle.kts @@ -11,7 +11,10 @@ dependencies { val jfCommonsVersion: String by rootProject.extra api("io.gitlab.jfronny:commons:$jfCommonsVersion") - api("io.gitlab.jfronny:commons-gson:$jfCommonsVersion") + api("io.gitlab.jfronny:commons-http-client:$jfCommonsVersion") + api("io.gitlab.jfronny:commons-io:$jfCommonsVersion") + api("io.gitlab.jfronny:commons-logging:$jfCommonsVersion") + api("io.gitlab.jfronny:commons-serialize-gson:$jfCommonsVersion") } val javaVersion by extra(project.java.targetCompatibility) diff --git a/common/src/main/java/io/gitlab/jfronny/inceptum/common/InceptumEnvironmentInitializer.java b/common/src/main/java/io/gitlab/jfronny/inceptum/common/InceptumEnvironmentInitializer.java index 9a03f3c..b7ecf0a 100644 --- a/common/src/main/java/io/gitlab/jfronny/inceptum/common/InceptumEnvironmentInitializer.java +++ b/common/src/main/java/io/gitlab/jfronny/inceptum/common/InceptumEnvironmentInitializer.java @@ -1,15 +1,15 @@ package io.gitlab.jfronny.inceptum.common; -import io.gitlab.jfronny.commons.HttpUtils; -import io.gitlab.jfronny.commons.log.Logger; -import io.gitlab.jfronny.commons.log.StdoutLogger; +import io.gitlab.jfronny.commons.http.client.HttpClient; +import io.gitlab.jfronny.commons.logging.Logger; +import io.gitlab.jfronny.commons.logging.StdoutLogger; import java.io.IOException; public class InceptumEnvironmentInitializer { public static void initialize() throws IOException { Logger.registerFactory(InceptumEnvironmentInitializer::defaultFactory); - HttpUtils.setUserAgent("jfmods/inceptum/" + BuildMetadata.VERSION); + HttpClient.setUserAgent("jfmods/inceptum/" + BuildMetadata.VERSION); InceptumConfig.load(); } diff --git a/common/src/main/java/io/gitlab/jfronny/inceptum/common/Net.java b/common/src/main/java/io/gitlab/jfronny/inceptum/common/Net.java index 2cda26d..2ea0132 100644 --- a/common/src/main/java/io/gitlab/jfronny/inceptum/common/Net.java +++ b/common/src/main/java/io/gitlab/jfronny/inceptum/common/Net.java @@ -1,7 +1,7 @@ package io.gitlab.jfronny.inceptum.common; -import io.gitlab.jfronny.commons.HashUtils; -import io.gitlab.jfronny.commons.HttpUtils; +import io.gitlab.jfronny.commons.http.client.HttpClient; +import io.gitlab.jfronny.commons.io.HashUtils; import io.gitlab.jfronny.commons.throwable.ThrowingFunction; import io.gitlab.jfronny.commons.throwable.ThrowingSupplier; @@ -18,7 +18,7 @@ public class Net { private static final ObjectCache OBJECT_CACHE = new ObjectCache(MetaHolder.CACHE_DIR); public static byte[] downloadData(String url) throws IOException, URISyntaxException { - try (InputStream is = HttpUtils.get(url).sendInputStream()) { + try (InputStream is = HttpClient.get(url).sendInputStream()) { return is.readAllBytes(); } } @@ -35,7 +35,7 @@ public class Net { } public static T downloadObject(String url, ThrowingFunction func, boolean cache) throws IOException { - return downloadObject(url, () -> HttpUtils.get(url).sendString(), func, cache); + return downloadObject(url, () -> HttpClient.get(url).sendString(), func, cache); } public static T downloadObject(String url, ThrowingFunction func, String apiKey) throws IOException { @@ -75,7 +75,7 @@ public class Net { } public static String downloadString(String url) throws IOException, URISyntaxException { - return HttpUtils.get(url).sendString(); + return HttpClient.get(url).sendString(); } public static String downloadString(String url, String sha1) throws IOException, URISyntaxException { @@ -83,7 +83,7 @@ public class Net { } public static String downloadStringAuthenticated(String url, String apiKey) throws IOException, URISyntaxException { - return HttpUtils.get(url).header("x-api-key", apiKey).sendString(); + return HttpClient.get(url).header("x-api-key", apiKey).sendString(); } public static void downloadFile(String url, Path path) throws IOException, URISyntaxException { diff --git a/common/src/main/java/io/gitlab/jfronny/inceptum/common/Utils.java b/common/src/main/java/io/gitlab/jfronny/inceptum/common/Utils.java index 0d14315..6cacc99 100644 --- a/common/src/main/java/io/gitlab/jfronny/inceptum/common/Utils.java +++ b/common/src/main/java/io/gitlab/jfronny/inceptum/common/Utils.java @@ -2,7 +2,7 @@ package io.gitlab.jfronny.inceptum.common; import io.gitlab.jfronny.commons.OSUtils; import io.gitlab.jfronny.commons.io.JFiles; -import io.gitlab.jfronny.commons.log.Logger; +import io.gitlab.jfronny.commons.logging.Logger; import java.awt.*; import java.io.File; diff --git a/common/src/main/java/io/gitlab/jfronny/inceptum/common/api/MavenApi.java b/common/src/main/java/io/gitlab/jfronny/inceptum/common/api/MavenApi.java index 9ba6f8b..663bdb3 100644 --- a/common/src/main/java/io/gitlab/jfronny/inceptum/common/api/MavenApi.java +++ b/common/src/main/java/io/gitlab/jfronny/inceptum/common/api/MavenApi.java @@ -1,6 +1,6 @@ package io.gitlab.jfronny.inceptum.common.api; -import io.gitlab.jfronny.commons.HttpUtils; +import io.gitlab.jfronny.commons.http.client.HttpClient; import io.gitlab.jfronny.inceptum.common.Net; import io.gitlab.jfronny.inceptum.common.Utils; import io.gitlab.jfronny.inceptum.common.model.maven.*; @@ -35,7 +35,7 @@ public class MavenApi { } public static Pom getPom(String repo, ArtifactMeta meta) throws IOException, SAXException, URISyntaxException, XMLStreamException { - try (InputStream is = HttpUtils.get(Utils.join("/", repo, meta.getPomPath())).sendInputStream()) { + try (InputStream is = HttpClient.get(Utils.join("/", repo, meta.getPomPath())).sendInputStream()) { Document doc = FACTORY.parse(is); doc.getDocumentElement().normalize(); if (!"project".equals(doc.getDocumentElement().getNodeName())) throw new IOException("Illegal document name"); @@ -132,7 +132,7 @@ public class MavenApi { public static ArtifactMeta getMetadata(String repo, String artifact) throws IOException, SAXException, URISyntaxException { ArtifactMeta sourceMeta = ArtifactMeta.parse(artifact); - try (InputStream is = HttpUtils.get(Utils.join("/", repo, sourceMeta.getMetadataPath())).sendInputStream()) { + try (InputStream is = HttpClient.get(Utils.join("/", repo, sourceMeta.getMetadataPath())).sendInputStream()) { Document doc = FACTORY.parse(is); doc.getDocumentElement().normalize(); if (!"metadata".equals(doc.getDocumentElement().getNodeName())) throw new IOException("Illegal document name"); diff --git a/common/src/main/java/module-info.java b/common/src/main/java/module-info.java index 66ee0f5..c859b1b 100644 --- a/common/src/main/java/module-info.java +++ b/common/src/main/java/module-info.java @@ -8,6 +8,9 @@ module io.gitlab.jfronny.inceptum.common { requires java.xml; requires transitive io.gitlab.jfronny.commons; requires transitive io.gitlab.jfronny.commons.gson; + requires transitive io.gitlab.jfronny.commons.http.client; + requires transitive io.gitlab.jfronny.commons.io; + requires transitive io.gitlab.jfronny.commons.logging; requires transitive io.gitlab.jfronny.gson; requires transitive io.gitlab.jfronny.gson.compile.core; requires static org.jetbrains.annotations; diff --git a/launcher-gtk/build.gradle.kts b/launcher-gtk/build.gradle.kts index 6368c1e..5826f2f 100644 --- a/launcher-gtk/build.gradle.kts +++ b/launcher-gtk/build.gradle.kts @@ -3,8 +3,8 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { id("inceptum.application") id("com.github.johnrengelman.shadow") - kotlin("jvm") version "1.9.0" - kotlin("plugin.sam.with.receiver") version "1.9.0" + kotlin("jvm") version "1.9.20" + kotlin("plugin.sam.with.receiver") version "1.9.20" } application { diff --git a/launcher-gtk/src/main/kotlin/io/gitlab/jfronny/inceptum/gtk/util/Log.kt b/launcher-gtk/src/main/kotlin/io/gitlab/jfronny/inceptum/gtk/util/Log.kt index 841d03f..a987cd9 100644 --- a/launcher-gtk/src/main/kotlin/io/gitlab/jfronny/inceptum/gtk/util/Log.kt +++ b/launcher-gtk/src/main/kotlin/io/gitlab/jfronny/inceptum/gtk/util/Log.kt @@ -1,6 +1,6 @@ package io.gitlab.jfronny.inceptum.gtk.util -import io.gitlab.jfronny.commons.log.Logger +import io.gitlab.jfronny.commons.logging.Logger import io.gitlab.jfronny.inceptum.common.Utils object Log : Logger by Utils.LOGGER \ No newline at end of file diff --git a/launcher-gtk/src/main/kotlin/io/gitlab/jfronny/inceptum/gtk/util/UIExt.kt b/launcher-gtk/src/main/kotlin/io/gitlab/jfronny/inceptum/gtk/util/UIExt.kt index d8e1600..f2e12e9 100644 --- a/launcher-gtk/src/main/kotlin/io/gitlab/jfronny/inceptum/gtk/util/UIExt.kt +++ b/launcher-gtk/src/main/kotlin/io/gitlab/jfronny/inceptum/gtk/util/UIExt.kt @@ -29,9 +29,18 @@ var Widget.marginHorizontal: Int get() = throw NotImplementedError() var MessageDialog.markup: String - set(value) { setMarkup(value) } + set(value) { setMarkup(value.escapedMarkup) } get() = throw NotImplementedError() +var Label.markup: String + set(value) { setMarkup(value.escapedMarkup) } + get() = throw NotImplementedError() + +val String.escapedMarkup: String + get() = replace(unmatchedAnd, "&") + +private val unmatchedAnd = Regex("&(?![a-z]{1,6};|#[0-9]+;|#x[0-9A-F]+;)") + fun ActionRow.fixSubtitle() = ILabel.theme(firstChild!!.lastChild!!.prevSibling!!.lastChild as Label, ILabel.Mode.SUBTITLE) fun EntryBuffer.clear() = deleteText(0, length) \ No newline at end of file diff --git a/launcher-gtk/src/main/kotlin/io/gitlab/jfronny/inceptum/gtk/window/create/NewInstanceWindow.kt b/launcher-gtk/src/main/kotlin/io/gitlab/jfronny/inceptum/gtk/window/create/NewInstanceWindow.kt index 534d212..ab06809 100644 --- a/launcher-gtk/src/main/kotlin/io/gitlab/jfronny/inceptum/gtk/window/create/NewInstanceWindow.kt +++ b/launcher-gtk/src/main/kotlin/io/gitlab/jfronny/inceptum/gtk/window/create/NewInstanceWindow.kt @@ -8,6 +8,7 @@ import io.gitlab.jfronny.inceptum.gtk.control.assistant.KAssistant import io.gitlab.jfronny.inceptum.gtk.schedule import io.gitlab.jfronny.inceptum.gtk.util.I18n import io.gitlab.jfronny.inceptum.gtk.util.Log +import io.gitlab.jfronny.inceptum.gtk.util.markup import io.gitlab.jfronny.inceptum.gtk.util.toTypedArray import io.gitlab.jfronny.inceptum.gtk.window.dialog.ProcessStateWatcherDialog import io.gitlab.jfronny.inceptum.launcher.api.FabricMetaApi @@ -127,7 +128,7 @@ class NewInstanceWindow(app: Application) : KAssistant(app) { val nc = ProcessStateWatcherDialog.State(pState) if (nc != cachedState) { cachedState = nc - stage.setMarkup(cachedState!!.msg) + stage.markup = cachedState!!.msg progress.fraction = cachedState!!.progress.coerceAtMost(1f).toDouble() widget.queueDraw() } @@ -165,9 +166,9 @@ class NewInstanceWindow(app: Application) : KAssistant(app) { val status = Label("") onOpen { if (isFailure) { - status.setMarkup("Something went wrong while creating the instance.\n\n$failureMessage") + status.markup = "Something went wrong while creating the instance.\n\n$failureMessage" } else { - status.setMarkup("The instance was successfully created. You can now launch it using the main menu") + status.markup = "The instance was successfully created. You can now launch it using the main menu" } } diff --git a/launcher-gtk/src/main/kotlin/io/gitlab/jfronny/inceptum/gtk/window/dialog/ProcessStateWatcherDialog.kt b/launcher-gtk/src/main/kotlin/io/gitlab/jfronny/inceptum/gtk/window/dialog/ProcessStateWatcherDialog.kt index c40f922..a04b72f 100644 --- a/launcher-gtk/src/main/kotlin/io/gitlab/jfronny/inceptum/gtk/window/dialog/ProcessStateWatcherDialog.kt +++ b/launcher-gtk/src/main/kotlin/io/gitlab/jfronny/inceptum/gtk/window/dialog/ProcessStateWatcherDialog.kt @@ -6,6 +6,7 @@ import io.gitlab.jfronny.inceptum.gtk.GtkEnvBackend import io.gitlab.jfronny.inceptum.gtk.schedule import io.gitlab.jfronny.inceptum.gtk.util.I18n import io.gitlab.jfronny.inceptum.gtk.util.Log +import io.gitlab.jfronny.inceptum.gtk.util.markup import io.gitlab.jfronny.inceptum.launcher.util.ProcessState import org.gnome.glib.GLib import org.gnome.gtk.* @@ -54,7 +55,7 @@ class ProcessStateWatcherDialog( val nc = State(state) if (nc != cachedState) { cachedState = nc - setMarkup(cachedState!!.msg) + markup = cachedState!!.msg progress.fraction = cachedState!!.progress.coerceAtMost(1f).toDouble() widget.queueDraw() } diff --git a/launcher-gtk/src/main/kotlin/io/gitlab/jfronny/inceptum/gtk/window/settings/instance/ModsTab.kt b/launcher-gtk/src/main/kotlin/io/gitlab/jfronny/inceptum/gtk/window/settings/instance/ModsTab.kt index e748ca3..6139700 100644 --- a/launcher-gtk/src/main/kotlin/io/gitlab/jfronny/inceptum/gtk/window/settings/instance/ModsTab.kt +++ b/launcher-gtk/src/main/kotlin/io/gitlab/jfronny/inceptum/gtk/window/settings/instance/ModsTab.kt @@ -7,10 +7,7 @@ import io.gitlab.jfronny.inceptum.gtk.control.KDropDown import io.gitlab.jfronny.inceptum.gtk.control.KSignalListItemFactory import io.gitlab.jfronny.inceptum.gtk.control.LoadingRevealer import io.gitlab.jfronny.inceptum.gtk.control.settings.SettingsTab -import io.gitlab.jfronny.inceptum.gtk.util.I18n -import io.gitlab.jfronny.inceptum.gtk.util.clear -import io.gitlab.jfronny.inceptum.gtk.util.fixSubtitle -import io.gitlab.jfronny.inceptum.gtk.util.replaceAll +import io.gitlab.jfronny.inceptum.gtk.util.* import io.gitlab.jfronny.inceptum.launcher.LauncherEnv import io.gitlab.jfronny.inceptum.launcher.api.CurseforgeApi import io.gitlab.jfronny.inceptum.launcher.api.ModrinthApi @@ -163,7 +160,7 @@ class ModsTab(window: InstanceSettingsWindow) : SettingsTab