Move more things to commons
This commit is contained in:
parent
617a8cf9df
commit
c205603bae
11
build.gradle
11
build.gradle
|
@ -41,6 +41,9 @@ ext {
|
|||
lwjglVersion = '3.3.0'
|
||||
imguiVersion = '1.86.4'
|
||||
log4jVersion = '2.14.1'
|
||||
slf4jVersion = '1.7.36'
|
||||
logbackVersion = '1.2.11'
|
||||
jfCommonsVersion = '0.1.0.2022.4.28.21.6.56'
|
||||
flavorProp = project.hasProperty('flavor') ? project.getProperty('flavor') : 'custom'
|
||||
flavor = flavorProp
|
||||
isPublic = project.hasProperty('public')
|
||||
|
@ -62,10 +65,10 @@ if (flavor == 'custom') {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'com.google.code.gson:gson:2.9.0'
|
||||
implementation 'org.slf4j:slf4j-api:1.7.36'
|
||||
implementation 'ch.qos.logback:logback-classic:1.2.11'
|
||||
implementation 'io.gitlab.jfronny:commons:0.1.0.2022.4.28.18.56.28'
|
||||
implementation "org.slf4j:slf4j-api:$slf4jVersion"
|
||||
implementation "ch.qos.logback:logback-classic:$logbackVersion"
|
||||
implementation "io.gitlab.jfronny:commons:$jfCommonsVersion"
|
||||
implementation "io.gitlab.jfronny:commons-gson:$jfCommonsVersion"
|
||||
implementation 'org.eclipse.jgit:org.eclipse.jgit:6.1.0.202203080745-r'
|
||||
implementation project(":wrapper")
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package io.gitlab.jfronny.inceptum;
|
||||
|
||||
import io.gitlab.jfronny.commons.serialize.gson.GsonHolder;
|
||||
import io.gitlab.jfronny.inceptum.frontend.cli.CommandResolution;
|
||||
import io.gitlab.jfronny.inceptum.frontend.cli.Commands;
|
||||
import io.gitlab.jfronny.inceptum.frontend.gui.window.dialog.AlertWindow;
|
||||
|
@ -33,6 +34,7 @@ public class Inceptum {
|
|||
GsonHolder.registerTypeAdapter(OauthTokenResponse.class, new OauthTokenResponseDeserializer());
|
||||
GsonHolder.registerTypeAdapter(ModSource.class, new ModSourceTypeAdapter());
|
||||
GsonHolder.registerTypeAdapter(ModSourceMapDeserializer.modSourceMapType, new ModSourceMapDeserializer());
|
||||
GsonHolder.register();
|
||||
|
||||
CommandResolution command = Commands.resolve(args, false);
|
||||
if (command.command().enableLog()) {
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package io.gitlab.jfronny.inceptum.frontend.cli.commands;
|
||||
|
||||
import io.gitlab.jfronny.commons.ArgumentsTokenizer;
|
||||
import io.gitlab.jfronny.inceptum.frontend.cli.Command;
|
||||
import io.gitlab.jfronny.inceptum.frontend.cli.CommandArgs;
|
||||
import io.gitlab.jfronny.inceptum.frontend.cli.CommandResolution;
|
||||
import io.gitlab.jfronny.inceptum.frontend.cli.Commands;
|
||||
import io.gitlab.jfronny.inceptum.util.ArgumentTokenizer;
|
||||
import io.gitlab.jfronny.inceptum.util.Utils;
|
||||
|
||||
import java.nio.file.Files;
|
||||
|
@ -37,7 +37,7 @@ public class BatchCommand extends Command {
|
|||
}
|
||||
try {
|
||||
for (String line : Files.readAllLines(p)) {
|
||||
CommandResolution resolution = Commands.resolve(ArgumentTokenizer.tokenize(line), args.wrapped);
|
||||
CommandResolution resolution = Commands.resolve(ArgumentsTokenizer.tokenize(line), args.wrapped);
|
||||
if (resolution.command() instanceof WrapperCommand)
|
||||
throw new Exception("You may not use the wrapper command in a command batch");
|
||||
resolved.add(resolution);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package io.gitlab.jfronny.inceptum.frontend.cli.commands;
|
||||
|
||||
import io.gitlab.jfronny.commons.OSUtils;
|
||||
import io.gitlab.jfronny.inceptum.frontend.cli.Command;
|
||||
import io.gitlab.jfronny.inceptum.frontend.cli.CommandArgs;
|
||||
import io.gitlab.jfronny.inceptum.model.inceptum.UpdateInfo;
|
||||
|
@ -61,14 +62,14 @@ public class UpdateCheckCommand extends Command {
|
|||
Utils.LOGGER.info("Downloading " + source.url());
|
||||
Path jarPath = MetaHolder.LIBRARIES_DIR.resolve("io/gitlab/jfronny/inceptum/Inceptum")
|
||||
.resolve(source.newVersion().toString())
|
||||
.resolve("Inceptum-" + source.newVersion() + '-' + OSCheck.OS.getMojName() + ".jar")
|
||||
.resolve("Inceptum-" + source.newVersion() + '-' + OSUtils.TYPE.getMojName() + ".jar")
|
||||
.toAbsolutePath();
|
||||
Files.createDirectories(jarPath.getParent());
|
||||
Utils.downloadFile(source.url(), source.sha1(), jarPath);
|
||||
if (relaunch) {
|
||||
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
|
||||
try {
|
||||
new ProcessBuilder(JvmUtils.getJvm(),
|
||||
new ProcessBuilder(OSUtils.getJvmBinary(),
|
||||
"-jar",
|
||||
jarPath.toString())
|
||||
.inheritIO()
|
||||
|
|
|
@ -2,8 +2,8 @@ package io.gitlab.jfronny.inceptum.frontend.gui.window;
|
|||
|
||||
import com.sun.net.httpserver.HttpServer;
|
||||
import imgui.ImGui;
|
||||
import io.gitlab.jfronny.commons.serialize.gson.GsonHolder;
|
||||
import io.gitlab.jfronny.inceptum.Inceptum;
|
||||
import io.gitlab.jfronny.inceptum.gson.GsonHolder;
|
||||
import io.gitlab.jfronny.inceptum.model.microsoft.*;
|
||||
import io.gitlab.jfronny.inceptum.util.Utils;
|
||||
import io.gitlab.jfronny.inceptum.util.api.account.AccountManager;
|
||||
|
|
|
@ -3,12 +3,12 @@ package io.gitlab.jfronny.inceptum.frontend.gui.window.edit;
|
|||
import imgui.ImGui;
|
||||
import imgui.type.ImBoolean;
|
||||
import imgui.type.ImString;
|
||||
import io.gitlab.jfronny.commons.OSUtils;
|
||||
import io.gitlab.jfronny.inceptum.Inceptum;
|
||||
import io.gitlab.jfronny.inceptum.InceptumGui;
|
||||
import io.gitlab.jfronny.inceptum.frontend.gui.control.InstanceManageControls;
|
||||
import io.gitlab.jfronny.inceptum.frontend.gui.control.Tab;
|
||||
import io.gitlab.jfronny.inceptum.frontend.gui.window.GuiUtil;
|
||||
import io.gitlab.jfronny.inceptum.util.JvmUtils;
|
||||
import io.gitlab.jfronny.inceptum.util.MetaHolder;
|
||||
import io.gitlab.jfronny.inceptum.util.Utils;
|
||||
|
||||
|
@ -60,7 +60,7 @@ public class GeneralTab extends Tab {
|
|||
}, () -> {});
|
||||
if (ImGui.checkbox("Custom Java", customJava)) {
|
||||
if (customJava.get()) {
|
||||
window.instance.java = JvmUtils.getJvm();
|
||||
window.instance.java = OSUtils.getJvmBinary();
|
||||
customJavaPath.set(window.instance.java);
|
||||
} else {
|
||||
window.instance.java = null;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package io.gitlab.jfronny.inceptum.gson;
|
||||
|
||||
import com.google.gson.*;
|
||||
import io.gitlab.jfronny.gson.*;
|
||||
import io.gitlab.jfronny.inceptum.model.mojang.MinecraftArgument;
|
||||
import io.gitlab.jfronny.inceptum.model.mojang.Rules;
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package io.gitlab.jfronny.inceptum.gson;
|
||||
|
||||
import com.google.gson.*;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import io.gitlab.jfronny.gson.*;
|
||||
import io.gitlab.jfronny.gson.reflect.TypeToken;
|
||||
import io.gitlab.jfronny.inceptum.util.source.ModSource;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package io.gitlab.jfronny.inceptum.gson;
|
||||
|
||||
import com.google.gson.*;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import io.gitlab.jfronny.gson.*;
|
||||
import io.gitlab.jfronny.gson.reflect.TypeToken;
|
||||
import io.gitlab.jfronny.inceptum.util.source.CurseforgeModSource;
|
||||
import io.gitlab.jfronny.inceptum.util.source.DirectModSource;
|
||||
import io.gitlab.jfronny.inceptum.util.source.ModSource;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package io.gitlab.jfronny.inceptum.gson;
|
||||
|
||||
import com.google.gson.*;
|
||||
import io.gitlab.jfronny.gson.*;
|
||||
import io.gitlab.jfronny.inceptum.model.microsoft.OauthTokenResponse;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package io.gitlab.jfronny.inceptum.gson;
|
||||
|
||||
import com.google.gson.*;
|
||||
import io.gitlab.jfronny.gson.*;
|
||||
import io.gitlab.jfronny.commons.OSUtils;
|
||||
import io.gitlab.jfronny.inceptum.model.mojang.Rules;
|
||||
import io.gitlab.jfronny.inceptum.util.OSCheck;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
|
@ -23,7 +23,7 @@ public class RulesDeserializer implements JsonDeserializer<Rules> {
|
|||
if (ro.has("os")) {
|
||||
JsonObject osObject = ro.get("os").getAsJsonObject();
|
||||
if (osObject.has("name")) {
|
||||
if (!OSCheck.OS.getMojName().equals(osObject.get("name").getAsString())) {
|
||||
if (!OSUtils.TYPE.getMojName().equals(osObject.get("name").getAsString())) {
|
||||
matched = false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
package io.gitlab.jfronny.inceptum.model.inceptum;
|
||||
|
||||
import io.gitlab.jfronny.inceptum.gson.GsonIgnore;
|
||||
import io.gitlab.jfronny.commons.serialize.gson.GsonIgnore;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class InstanceMeta {
|
||||
@GsonIgnore public static final String floaderPrefix = "fabric-loader-";
|
||||
@GsonIgnore
|
||||
public static final String floaderPrefix = "fabric-loader-";
|
||||
public String version;
|
||||
public String java;
|
||||
public Long minMem;
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package io.gitlab.jfronny.inceptum.model.inceptum;
|
||||
|
||||
import io.gitlab.jfronny.commons.HashUtils;
|
||||
import io.gitlab.jfronny.inceptum.model.curseforge.CurseforgeFingerprint;
|
||||
import io.gitlab.jfronny.inceptum.util.source.CurseforgeModSource;
|
||||
import io.gitlab.jfronny.inceptum.util.source.ModSource;
|
||||
import io.gitlab.jfronny.inceptum.util.source.ModrinthModSource;
|
||||
import io.gitlab.jfronny.inceptum.util.HashUtils;
|
||||
import io.gitlab.jfronny.inceptum.util.Utils;
|
||||
import io.gitlab.jfronny.inceptum.util.api.CurseforgeApi;
|
||||
import io.gitlab.jfronny.inceptum.util.api.ModrinthApi;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package io.gitlab.jfronny.inceptum.model.microsoft;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import io.gitlab.jfronny.gson.annotations.SerializedName;
|
||||
|
||||
public class LoginResponse {
|
||||
public String username;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package io.gitlab.jfronny.inceptum.model.microsoft;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import io.gitlab.jfronny.gson.annotations.SerializedName;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package io.gitlab.jfronny.inceptum.model.microsoft;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import io.gitlab.jfronny.gson.annotations.SerializedName;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package io.gitlab.jfronny.inceptum.model.mojang;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import io.gitlab.jfronny.gson.annotations.SerializedName;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
|
|
@ -1,61 +0,0 @@
|
|||
package io.gitlab.jfronny.inceptum.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ArgumentTokenizer {
|
||||
public static String[] tokenize(String toProcess) {
|
||||
List<String> tokens = new ArrayList<>();
|
||||
StringBuilder currentToken = new StringBuilder();
|
||||
State state = State.None;
|
||||
char[] chars = toProcess.toCharArray();
|
||||
for (int i = 0; i < chars.length; i++) {
|
||||
switch (chars[i]) {
|
||||
case '\'' -> state = switch (state) {
|
||||
case None -> State.QuoteSingle;
|
||||
case QuoteSingle -> State.None;
|
||||
case QuoteDouble -> {
|
||||
currentToken.append('"');
|
||||
yield State.QuoteDouble;
|
||||
}
|
||||
};
|
||||
case '"' -> state = switch (state) {
|
||||
case None -> State.QuoteDouble;
|
||||
case QuoteSingle -> {
|
||||
currentToken.append('"');
|
||||
yield State.QuoteSingle;
|
||||
}
|
||||
case QuoteDouble -> State.None;
|
||||
};
|
||||
case '\\' -> {
|
||||
if (i++ < chars.length) {
|
||||
currentToken.append(switch (chars[i]) {
|
||||
case 'b' -> '\b';
|
||||
case 'f' -> '\f';
|
||||
case 'n' -> '\n';
|
||||
case 'r' -> '\r';
|
||||
case 't' -> '\t';
|
||||
default -> chars[i];
|
||||
});
|
||||
} else currentToken.append('\\');
|
||||
}
|
||||
case ' ' -> {
|
||||
if (state == State.None) {
|
||||
tokens.add(currentToken.toString());
|
||||
currentToken = new StringBuilder();
|
||||
}
|
||||
else {
|
||||
currentToken.append(' ');
|
||||
}
|
||||
}
|
||||
default -> currentToken.append(chars[i]);
|
||||
}
|
||||
}
|
||||
if (!currentToken.isEmpty()) tokens.add(currentToken.toString());
|
||||
return tokens.toArray(String[]::new);
|
||||
}
|
||||
|
||||
enum State {
|
||||
None, QuoteSingle, QuoteDouble
|
||||
}
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
package io.gitlab.jfronny.inceptum.util;
|
||||
|
||||
import io.gitlab.jfronny.commons.OSUtils;
|
||||
import io.gitlab.jfronny.inceptum.Inceptum;
|
||||
import io.gitlab.jfronny.inceptum.model.inceptum.ArtifactInfo;
|
||||
import io.gitlab.jfronny.inceptum.model.inceptum.InstanceMeta;
|
||||
|
@ -73,7 +74,7 @@ public class InstanceLauncher {
|
|||
{
|
||||
final VersionInfo lambdaVersionInfo = versionInfo;
|
||||
args.add(Objects.requireNonNullElseGet(instance.java, () ->
|
||||
JvmUtils.getJvmMain(MetaHolder.NATIVES_DIR
|
||||
OSUtils.getJvmBinary(MetaHolder.NATIVES_DIR
|
||||
.resolve(lambdaVersionInfo.javaVersion.component)
|
||||
.resolve(Integer.toString(lambdaVersionInfo.javaVersion.majorVersion)))
|
||||
.toAbsolutePath().toString()));
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
package io.gitlab.jfronny.inceptum.util;
|
||||
|
||||
import io.gitlab.jfronny.inceptum.model.OSType;
|
||||
import io.gitlab.jfronny.commons.OSUtils;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
public class ProcessUtils {
|
||||
public static boolean isProcessAlive(String pid) {
|
||||
return isProcessIdRunning(pid, OSCheck.OS == OSType.WINDOWS
|
||||
return isProcessIdRunning(pid, OSUtils.TYPE == OSUtils.Type.WINDOWS
|
||||
? "cmd /c tasklist /FI \"PID eq " + pid + "\""
|
||||
: "ps -p " + pid);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package io.gitlab.jfronny.inceptum.util;
|
||||
|
||||
import io.gitlab.jfronny.commons.OSUtils;
|
||||
import io.gitlab.jfronny.inceptum.model.inceptum.ArtifactInfo;
|
||||
import io.gitlab.jfronny.inceptum.model.mojang.VersionInfo;
|
||||
|
||||
|
@ -11,8 +12,8 @@ public class VersionInfoLibraryResolver {
|
|||
Set<ArtifactInfo> artifacts = new LinkedHashSet<>();
|
||||
for (VersionInfo.Library library : version.libraries) {
|
||||
if (library.rules != null && !library.rules.allow()) continue;
|
||||
if (library.downloads.classifiers != null && library.natives != null && library.natives.containsKey(OSCheck.OS.getMojName())) {
|
||||
artifacts.add(new ArtifactInfo(library.downloads.classifiers.get(library.natives.get(OSCheck.OS.getMojName())), true));
|
||||
if (library.downloads.classifiers != null && library.natives != null && library.natives.containsKey(OSUtils.TYPE.getMojName())) {
|
||||
artifacts.add(new ArtifactInfo(library.downloads.classifiers.get(library.natives.get(OSUtils.TYPE.getMojName())), true));
|
||||
}
|
||||
if (library.downloads.artifact == null) {
|
||||
Utils.LOGGER.info("Null library artifact @ " + library.name);
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package io.gitlab.jfronny.inceptum.util.api;
|
||||
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import io.gitlab.jfronny.commons.HttpUtils;
|
||||
import io.gitlab.jfronny.gson.reflect.TypeToken;
|
||||
import io.gitlab.jfronny.inceptum.model.curseforge.CurseforgeFile;
|
||||
import io.gitlab.jfronny.inceptum.model.curseforge.CurseforgeFingerprint;
|
||||
import io.gitlab.jfronny.inceptum.model.curseforge.CurseforgeMod;
|
||||
import io.gitlab.jfronny.inceptum.util.HttpUtils;
|
||||
import io.gitlab.jfronny.inceptum.util.Utils;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -41,6 +41,6 @@ public class CurseforgeApi {
|
|||
}
|
||||
|
||||
public static CurseforgeFingerprint checkFingerprint(String hash) throws IOException, URISyntaxException {
|
||||
return HttpUtils.post(API_URL + "fingerprint").bodyJson("[" + hash + "]").sendJson(CurseforgeFingerprint.class);
|
||||
return HttpUtils.post(API_URL + "fingerprint").bodyJson("[" + hash + "]").sendSerialized(CurseforgeFingerprint.class);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package io.gitlab.jfronny.inceptum.util.api;
|
||||
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import io.gitlab.jfronny.gson.reflect.TypeToken;
|
||||
import io.gitlab.jfronny.inceptum.model.fabric.FabricVersionLoaderInfo;
|
||||
import io.gitlab.jfronny.inceptum.model.inceptum.InstanceMeta;
|
||||
import io.gitlab.jfronny.inceptum.model.mojang.Rules;
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package io.gitlab.jfronny.inceptum.util.api;
|
||||
|
||||
import io.gitlab.jfronny.commons.OSUtils;
|
||||
import io.gitlab.jfronny.inceptum.model.mojang.*;
|
||||
import io.gitlab.jfronny.inceptum.util.MetaHolder;
|
||||
import io.gitlab.jfronny.inceptum.util.OSCheck;
|
||||
import io.gitlab.jfronny.inceptum.util.Utils;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -43,7 +43,7 @@ public class McApi {
|
|||
public static Map<String, JvmFileInfo.File> getJvm(String component, int majorVersion) throws IOException {
|
||||
// https://github.com/ATLauncher/ATLauncher/blob/master/src/main/java/com/atlauncher/constants/Constants.java#L123
|
||||
JvmInfo info = Utils.downloadObject("https://launchermeta.mojang.com/v1/products/java-runtime/2ec0cc96c44e5a76b9c8b7c39df7210883d12871/all.json", JvmInfo.class);
|
||||
Map<String, List<JvmInfo.Jvm>> vms = switch (OSCheck.OS) {
|
||||
Map<String, List<JvmInfo.Jvm>> vms = switch (OSUtils.TYPE) {
|
||||
case WINDOWS -> info.windowsX64;
|
||||
case LINUX -> info.linux;
|
||||
case MAC_OS -> info.macOs;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package io.gitlab.jfronny.inceptum.util.api;
|
||||
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import io.gitlab.jfronny.gson.reflect.TypeToken;
|
||||
import io.gitlab.jfronny.inceptum.model.modrinth.ModrinthProject;
|
||||
import io.gitlab.jfronny.inceptum.model.modrinth.ModrinthProjectType;
|
||||
import io.gitlab.jfronny.inceptum.model.modrinth.ModrinthSearchResult;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package io.gitlab.jfronny.inceptum.util.api.account;
|
||||
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import io.gitlab.jfronny.gson.reflect.TypeToken;
|
||||
import io.gitlab.jfronny.inceptum.Inceptum;
|
||||
import io.gitlab.jfronny.inceptum.util.ConfigHolder;
|
||||
import io.gitlab.jfronny.inceptum.util.MetaHolder;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package io.gitlab.jfronny.inceptum.util.api.account;
|
||||
|
||||
import io.gitlab.jfronny.commons.HttpUtils;
|
||||
import io.gitlab.jfronny.inceptum.model.microsoft.*;
|
||||
import io.gitlab.jfronny.inceptum.util.HttpUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
|
@ -37,7 +37,7 @@ public class MicrosoftAuthAPI {
|
|||
"grant_type", "authorization_code",
|
||||
"redirect_uri", MICROSOFT_LOGIN_REDIRECT_URL,
|
||||
"scope", String.join(" ", MICROSOFT_LOGIN_SCOPES)))
|
||||
.sendJson(OauthTokenResponse.class);
|
||||
.sendSerialized(OauthTokenResponse.class);
|
||||
}
|
||||
|
||||
public static OauthTokenResponse refreshAccessToken(String refreshToken) throws IOException, URISyntaxException {
|
||||
|
@ -46,7 +46,7 @@ public class MicrosoftAuthAPI {
|
|||
"refresh_token", refreshToken,
|
||||
"grant_type", "refresh_token",
|
||||
"redirect_uri", MICROSOFT_LOGIN_REDIRECT_URL))
|
||||
.sendJson(OauthTokenResponse.class);
|
||||
.sendSerialized(OauthTokenResponse.class);
|
||||
}
|
||||
|
||||
public static XboxLiveAuthResponse getXBLToken(String accessToken) throws IOException, URISyntaxException {
|
||||
|
@ -62,8 +62,8 @@ public class MicrosoftAuthAPI {
|
|||
|
||||
return HttpUtils.post(MICROSOFT_XBL_AUTH_TOKEN_URL)
|
||||
.header("x-xbl-contract-version", "1")
|
||||
.bodyJson(data)
|
||||
.sendJson(XboxLiveAuthResponse.class);
|
||||
.bodySerialized(data)
|
||||
.sendSerialized(XboxLiveAuthResponse.class);
|
||||
}
|
||||
|
||||
public static XboxLiveAuthResponse getXstsToken(String xblToken) throws IOException, URISyntaxException {
|
||||
|
@ -81,8 +81,8 @@ public class MicrosoftAuthAPI {
|
|||
|
||||
return HttpUtils.post(MICROSOFT_XSTS_AUTH_TOKEN_URL)
|
||||
.header("x-xbl-contract-version", "1")
|
||||
.bodyJson(data)
|
||||
.sendJson(XboxLiveAuthResponse.class);
|
||||
.bodySerialized(data)
|
||||
.sendSerialized(XboxLiveAuthResponse.class);
|
||||
}
|
||||
|
||||
public static LoginResponse loginToMinecraft(String xstsToken) throws IOException, URISyntaxException {
|
||||
|
@ -90,15 +90,15 @@ public class MicrosoftAuthAPI {
|
|||
data.put("identityToken", xstsToken);
|
||||
|
||||
return HttpUtils.post(MICROSOFT_MINECRAFT_LOGIN_URL)
|
||||
.bodyJson(data)
|
||||
.sendJson(LoginResponse.class);
|
||||
.bodySerialized(data)
|
||||
.sendSerialized(LoginResponse.class);
|
||||
}
|
||||
|
||||
public static Store getMcEntitlements(String accessToken) throws IOException, URISyntaxException {
|
||||
return HttpUtils.get(MICROSOFT_MINECRAFT_STORE_URL).bearer(accessToken).sendJson(Store.class);
|
||||
return HttpUtils.get(MICROSOFT_MINECRAFT_STORE_URL).bearer(accessToken).sendSerialized(Store.class);
|
||||
}
|
||||
|
||||
public static Profile getMcProfile(String accessToken) throws IOException, URISyntaxException {
|
||||
return HttpUtils.get(MICROSOFT_MINECRAFT_PROFILE_URL).bearer(accessToken).sendJson(Profile.class);
|
||||
return HttpUtils.get(MICROSOFT_MINECRAFT_PROFILE_URL).bearer(accessToken).sendSerialized(Profile.class);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package io.gitlab.jfronny.inceptum.util.install.steps;
|
||||
|
||||
import io.gitlab.jfronny.commons.ComparableVersion;
|
||||
import io.gitlab.jfronny.inceptum.util.install.SetupStepInfo;
|
||||
import io.gitlab.jfronny.inceptum.util.install.Step;
|
||||
import io.gitlab.jfronny.inceptum.model.ComparableVersion;
|
||||
import io.gitlab.jfronny.inceptum.model.inceptum.InstanceMeta;
|
||||
import io.gitlab.jfronny.inceptum.model.mojang.MojangFileDownload;
|
||||
import io.gitlab.jfronny.inceptum.util.MetaHolder;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package io.gitlab.jfronny.inceptum.util.mds;
|
||||
|
||||
import com.google.gson.JsonParseException;
|
||||
import io.gitlab.jfronny.commons.throwable.ThrowingConsumer;
|
||||
import io.gitlab.jfronny.gson.JsonParseException;
|
||||
import io.gitlab.jfronny.inceptum.model.fabric.FabricModJson;
|
||||
import io.gitlab.jfronny.inceptum.model.inceptum.ModDescription;
|
||||
import io.gitlab.jfronny.inceptum.util.PathUtil;
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
package io.gitlab.jfronny.inceptum.util.source;
|
||||
|
||||
import io.gitlab.jfronny.commons.HashUtils;
|
||||
import io.gitlab.jfronny.commons.tuple.Triple;
|
||||
import io.gitlab.jfronny.commons.tuple.Tuple;
|
||||
import io.gitlab.jfronny.inceptum.model.curseforge.CurseforgeDependency;
|
||||
import io.gitlab.jfronny.inceptum.model.curseforge.CurseforgeFile;
|
||||
import io.gitlab.jfronny.inceptum.model.curseforge.CurseforgeMod;
|
||||
import io.gitlab.jfronny.inceptum.util.HashUtils;
|
||||
import io.gitlab.jfronny.inceptum.util.Utils;
|
||||
import io.gitlab.jfronny.inceptum.util.api.CurseforgeApi;
|
||||
import io.gitlab.jfronny.inceptum.util.cache.MemoryCache;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package io.gitlab.jfronny.inceptum.util.source;
|
||||
|
||||
import io.gitlab.jfronny.inceptum.util.HashUtils;
|
||||
import io.gitlab.jfronny.commons.HashUtils;
|
||||
import io.gitlab.jfronny.inceptum.util.Utils;
|
||||
|
||||
import java.io.IOException;
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package io.gitlab.jfronny.inceptum.util.source;
|
||||
|
||||
import io.gitlab.jfronny.commons.HashUtils;
|
||||
import io.gitlab.jfronny.commons.tuple.Tuple;
|
||||
import io.gitlab.jfronny.inceptum.model.modrinth.ModrinthProject;
|
||||
import io.gitlab.jfronny.inceptum.model.modrinth.ModrinthVersion;
|
||||
import io.gitlab.jfronny.inceptum.util.HashUtils;
|
||||
import io.gitlab.jfronny.inceptum.util.Utils;
|
||||
import io.gitlab.jfronny.inceptum.util.api.ModrinthApi;
|
||||
import io.gitlab.jfronny.inceptum.util.cache.MemoryCache;
|
||||
|
|
|
@ -18,10 +18,10 @@ repositories {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'com.google.code.gson:gson:2.9.0'
|
||||
implementation 'org.slf4j:slf4j-api:1.7.36'
|
||||
implementation 'ch.qos.logback:logback-classic:1.2.11'
|
||||
implementation 'io.gitlab.jfronny:commons:0.1.0.2022.4.28.18.56.28'
|
||||
implementation "org.slf4j:slf4j-api:${rootProject.slf4jVersion}"
|
||||
implementation "ch.qos.logback:logback-classic:${rootProject.logbackVersion}"
|
||||
implementation "io.gitlab.jfronny:commons:${rootProject.jfCommonsVersion}"
|
||||
implementation "io.gitlab.jfronny:commons-gson:${rootProject.jfCommonsVersion}"
|
||||
}
|
||||
|
||||
processResources {
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package io.gitlab.jfronny.inceptum;
|
||||
|
||||
import io.gitlab.jfronny.inceptum.model.ComparableVersion;
|
||||
import io.gitlab.jfronny.commons.ComparableVersion;
|
||||
import io.gitlab.jfronny.commons.OSUtils;
|
||||
import io.gitlab.jfronny.commons.serialize.gson.GsonHolder;
|
||||
import io.gitlab.jfronny.inceptum.model.inceptum.UpdateChannel;
|
||||
import io.gitlab.jfronny.inceptum.model.inceptum.UpdateInfo;
|
||||
import io.gitlab.jfronny.inceptum.util.*;
|
||||
|
@ -21,6 +23,7 @@ public class Wrapper {
|
|||
|
||||
public static void main(String[] args) throws IOException, ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException, URISyntaxException, NoSuchFieldException {
|
||||
System.out.println("Inceptum Wrapper v" + MetaHolder.VERSION.version + " (" + MetaHolder.VERSION.flavor + ")");
|
||||
GsonHolder.register();
|
||||
ConfigHolder.load();
|
||||
if (!Files.exists(INCEPTUM_LIB_DIR)) downloadLatest();
|
||||
Optional<Path> localBinary = selectLocalBinary();
|
||||
|
@ -42,7 +45,7 @@ public class Wrapper {
|
|||
|
||||
private static void downloadLatest() throws IOException {
|
||||
System.err.println("No Inceptum jar was identified");
|
||||
UpdateInfo ui = UpdateChecker.check(UpdateChannel.Stable, new ComparableVersion("0"), OSCheck.OS.getMojName(), c -> {});
|
||||
UpdateInfo ui = UpdateChecker.check(UpdateChannel.Stable, new ComparableVersion("0"), OSUtils.TYPE.getMojName(), c -> {});
|
||||
if (ui == null) {
|
||||
throw new FileNotFoundException("Could not identify a valid inceptum version. Are you connected to the internet?");
|
||||
}
|
||||
|
@ -50,7 +53,7 @@ public class Wrapper {
|
|||
Path dir = INCEPTUM_LIB_DIR.resolve(ui.newVersion().toString());
|
||||
Files.createDirectories(dir);
|
||||
try (InputStream is = new URL(ui.url()).openStream()) {
|
||||
Files.write(dir.resolve("Inceptum-" + ui.newVersion() + '-' + OSCheck.OS.getMojName() + ".jar"), is.readAllBytes());
|
||||
Files.write(dir.resolve("Inceptum-" + ui.newVersion() + '-' + OSUtils.TYPE.getMojName() + ".jar"), is.readAllBytes());
|
||||
}
|
||||
catch (Throwable t) {
|
||||
Files.delete(dir);
|
||||
|
@ -64,7 +67,7 @@ public class Wrapper {
|
|||
for (Path inceptumVersionPath : inceptumLibVersionDirStream.toList()) {
|
||||
ComparableVersion versionCurrent = new ComparableVersion(inceptumVersionPath.getFileName().toString());
|
||||
if (versionCurrent.compareTo(versionChosen) > 0) {
|
||||
inceptumVersionPath = inceptumVersionPath.resolve("Inceptum-" + versionCurrent + '-' + OSCheck.OS.getMojName() + ".jar");
|
||||
inceptumVersionPath = inceptumVersionPath.resolve("Inceptum-" + versionCurrent + '-' + OSUtils.TYPE.getMojName() + ".jar");
|
||||
if (Files.exists(inceptumVersionPath)) {
|
||||
versionChosen = versionCurrent;
|
||||
pathChosen = inceptumVersionPath;
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
package io.gitlab.jfronny.inceptum.gson;
|
||||
|
||||
import com.google.gson.*;
|
||||
import io.gitlab.jfronny.inceptum.model.ComparableVersion;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
public class ComparableVersionAdapter implements JsonDeserializer<ComparableVersion>, JsonSerializer<ComparableVersion> {
|
||||
@Override
|
||||
public ComparableVersion deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||
if (json.isJsonPrimitive() && json.getAsJsonPrimitive().isString())
|
||||
return new ComparableVersion(json.getAsString());
|
||||
else throw new JsonParseException("Expected Version to be a string");
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonElement serialize(ComparableVersion src, Type typeOfSrc, JsonSerializationContext context) {
|
||||
return new JsonPrimitive(src.toString());
|
||||
}
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
package io.gitlab.jfronny.inceptum.gson;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.TypeAdapterFactory;
|
||||
import io.gitlab.jfronny.inceptum.model.ComparableVersion;
|
||||
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
public class GsonHolder {
|
||||
private static final GsonBuilder builder = new GsonBuilder()
|
||||
.registerTypeAdapter(ComparableVersion.class, new ComparableVersionAdapter())
|
||||
.excludeFieldsWithModifiers(Modifier.TRANSIENT)
|
||||
.excludeFieldsWithModifiers(Modifier.PRIVATE)
|
||||
.addSerializationExclusionStrategy(new GsonIgnoreExclusionStrategy())
|
||||
.setPrettyPrinting();
|
||||
private static boolean clean = false;
|
||||
private static Gson gson;
|
||||
public static Gson getGson() {
|
||||
if (!clean) {
|
||||
gson = builder.create();
|
||||
clean = true;
|
||||
}
|
||||
return gson;
|
||||
}
|
||||
|
||||
public static void registerTypeAdapter(Type type, Object typeAdapter) {
|
||||
builder.registerTypeAdapter(type, typeAdapter);
|
||||
clean = false;
|
||||
}
|
||||
|
||||
public static void registerTypeAdapterFactory(TypeAdapterFactory factory) {
|
||||
builder.registerTypeAdapterFactory(factory);
|
||||
clean = false;
|
||||
}
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
package io.gitlab.jfronny.inceptum.gson;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.FIELD)
|
||||
public @interface GsonIgnore {
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
package io.gitlab.jfronny.inceptum.gson;
|
||||
|
||||
import com.google.gson.ExclusionStrategy;
|
||||
import com.google.gson.FieldAttributes;
|
||||
|
||||
public class GsonIgnoreExclusionStrategy implements ExclusionStrategy {
|
||||
@Override
|
||||
public boolean shouldSkipClass(Class<?> clazz) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldSkipField(FieldAttributes f) {
|
||||
return f.getAnnotation(GsonIgnore.class) != null;
|
||||
}
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
package io.gitlab.jfronny.inceptum.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ComparableVersion implements Comparable<ComparableVersion> {
|
||||
private final String string;
|
||||
private final Long[] numbers;
|
||||
|
||||
public ComparableVersion(String string) {
|
||||
this.string = string;
|
||||
String[] split = string.split("[^0-9]+");
|
||||
List<Long> numbersList = new ArrayList<>();
|
||||
for (String s : split) {
|
||||
if (!s.isEmpty())
|
||||
numbersList.add(Long.parseLong(s));
|
||||
}
|
||||
this.numbers = numbersList.toArray(Long[]::new);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return string;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(ComparableVersion version) {
|
||||
final int maxLength = Math.max(numbers.length, version.numbers.length);
|
||||
for (int i = 0; i < maxLength; i++) {
|
||||
final long left = i < numbers.length ? numbers[i] : 0;
|
||||
final long right = i < version.numbers.length ? version.numbers[i] : 0;
|
||||
if (left != right) {
|
||||
return left < right ? -1 : 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int compareTo(String version) {
|
||||
return compareTo(new ComparableVersion(version));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return string.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof ComparableVersion cv && compareTo(cv) == 0
|
||||
|| obj instanceof String str && compareTo(str) == 0)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
package io.gitlab.jfronny.inceptum.model;
|
||||
|
||||
public enum OSType {
|
||||
WINDOWS("windows"), MAC_OS("osx"), LINUX("linux");
|
||||
|
||||
private final String mojName;
|
||||
|
||||
OSType(String mojName) {
|
||||
this.mojName = mojName;
|
||||
}
|
||||
|
||||
public String getMojName() {
|
||||
return mojName;
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
package io.gitlab.jfronny.inceptum.model.inceptum;
|
||||
|
||||
import io.gitlab.jfronny.inceptum.model.ComparableVersion;
|
||||
import io.gitlab.jfronny.commons.ComparableVersion;
|
||||
|
||||
public class InceptumVersion {
|
||||
public ComparableVersion version;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package io.gitlab.jfronny.inceptum.model.inceptum;
|
||||
|
||||
import io.gitlab.jfronny.inceptum.model.ComparableVersion;
|
||||
import io.gitlab.jfronny.commons.ComparableVersion;
|
||||
|
||||
public record UpdateInfo(String url, String sha1, ComparableVersion newVersion) {
|
||||
}
|
||||
|
|
|
@ -1,99 +0,0 @@
|
|||
package io.gitlab.jfronny.inceptum.util;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.Formatter;
|
||||
|
||||
public class HashUtils {
|
||||
public static String sha1(byte[] data) {
|
||||
Formatter formatter = new Formatter();
|
||||
try {
|
||||
for (byte b : MessageDigest.getInstance("SHA-1").digest(data))
|
||||
formatter.format("%02x", b);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new RuntimeException("Could not hash using SHA1", e);
|
||||
}
|
||||
return formatter.toString();
|
||||
}
|
||||
|
||||
public static String murmur2(byte[] data) {
|
||||
final int m = 0x5bd1e995;
|
||||
final int r = 24;
|
||||
long k = 0x0L;
|
||||
int seed = 1;
|
||||
int shift = 0x0;
|
||||
|
||||
long length = 0;
|
||||
char b;
|
||||
// get good bytes from file
|
||||
for (byte datum : data) {
|
||||
b = (char) datum;
|
||||
|
||||
if (b == 0x9 || b == 0xa || b == 0xd || b == 0x20) {
|
||||
continue;
|
||||
}
|
||||
|
||||
length += 1;
|
||||
}
|
||||
long h = (seed ^ length);
|
||||
|
||||
for (byte datum : data) {
|
||||
b = (char) datum;
|
||||
|
||||
if (b == 0x9 || b == 0xa || b == 0xd || b == 0x20) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (b > 255) {
|
||||
while (b > 255) {
|
||||
b -= 255;
|
||||
}
|
||||
}
|
||||
|
||||
k = k | ((long) b << shift);
|
||||
|
||||
shift = shift + 0x8;
|
||||
|
||||
if (shift == 0x20) {
|
||||
h = 0x00000000FFFFFFFFL & h;
|
||||
|
||||
k = k * m;
|
||||
k = 0x00000000FFFFFFFFL & k;
|
||||
|
||||
k = k ^ (k >> r);
|
||||
k = 0x00000000FFFFFFFFL & k;
|
||||
|
||||
k = k * m;
|
||||
k = 0x00000000FFFFFFFFL & k;
|
||||
|
||||
h = h * m;
|
||||
h = 0x00000000FFFFFFFFL & h;
|
||||
|
||||
h = h ^ k;
|
||||
h = 0x00000000FFFFFFFFL & h;
|
||||
|
||||
k = 0x0;
|
||||
shift = 0x0;
|
||||
}
|
||||
}
|
||||
|
||||
if (shift > 0) {
|
||||
h = h ^ k;
|
||||
h = 0x00000000FFFFFFFFL & h;
|
||||
|
||||
h = h * m;
|
||||
h = 0x00000000FFFFFFFFL & h;
|
||||
}
|
||||
|
||||
h = h ^ (h >> 13);
|
||||
h = 0x00000000FFFFFFFFL & h;
|
||||
|
||||
h = h * m;
|
||||
h = 0x00000000FFFFFFFFL & h;
|
||||
|
||||
h = h ^ (h >> 15);
|
||||
h = 0x00000000FFFFFFFFL & h;
|
||||
|
||||
return String.valueOf(h);
|
||||
}
|
||||
}
|
|
@ -1,202 +0,0 @@
|
|||
package io.gitlab.jfronny.inceptum.util;
|
||||
|
||||
import io.gitlab.jfronny.inceptum.gson.GsonHolder;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.lang.reflect.Type;
|
||||
import java.net.*;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class HttpUtils {
|
||||
static {
|
||||
// Enables HTTPS proxying
|
||||
System.setProperty("jdk.http.auth.tunneling.disabledSchemes", "");
|
||||
}
|
||||
|
||||
private static final HttpClient CLIENT = HttpClient.newBuilder().proxy(new ProxySelector() {
|
||||
@Override
|
||||
public List<Proxy> select(URI uri) {
|
||||
String host = System.getProperty("http.proxyHost");
|
||||
String port = System.getProperty("http.proxyPort");
|
||||
if (host == null || port == null)
|
||||
return List.of();
|
||||
if (!port.matches("\\d+")) {
|
||||
Utils.LOGGER.error("Could not parse proxy settings: Port is not a number");
|
||||
return List.of();
|
||||
}
|
||||
return List.of(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(host, Integer.parseInt(port))));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connectFailed(URI uri, SocketAddress socketAddress, IOException e) {
|
||||
|
||||
}
|
||||
})
|
||||
.followRedirects(HttpClient.Redirect.ALWAYS)
|
||||
.authenticator(new Authenticator() {
|
||||
@Override
|
||||
protected PasswordAuthentication getPasswordAuthentication() {
|
||||
String name = System.getProperty("http.proxyUserName");
|
||||
String pass = System.getProperty("http.proxyUserPassword");
|
||||
if (name == null
|
||||
|| pass == null
|
||||
|| getRequestorType() != RequestorType.PROXY)
|
||||
return super.getPasswordAuthentication();
|
||||
return new PasswordAuthentication(name, pass.toCharArray());
|
||||
}
|
||||
})
|
||||
|
||||
.build();
|
||||
|
||||
private enum Method {
|
||||
GET,
|
||||
POST
|
||||
}
|
||||
|
||||
public static class Request {
|
||||
private static final Pattern CURSEFORGE_API = Pattern.compile("(?:http(s)?://)?addons-ecs\\.forgesvc\\.net/api/+");
|
||||
private final String url;
|
||||
private final HttpRequest.Builder builder;
|
||||
private Method method;
|
||||
private int sent = 0;
|
||||
|
||||
public Request(Method method, String url) throws URISyntaxException {
|
||||
this.url = url.replace(" ", "%20");
|
||||
this.builder = HttpRequest.newBuilder()
|
||||
.uri(new URI(this.url))
|
||||
.header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36");
|
||||
this.method = method;
|
||||
}
|
||||
|
||||
public Request bearer(String token) {
|
||||
builder.header("Authorization", "Bearer " + token);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public Request header(String name, String value) {
|
||||
builder.header(name, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Request bodyString(String string) {
|
||||
builder.header("Content-Type", "text/plain");
|
||||
builder.method(method.name(), HttpRequest.BodyPublishers.ofString(string));
|
||||
method = null;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public Request bodyForm(String string) {
|
||||
builder.header("Content-Type", "application/x-www-form-urlencoded");
|
||||
builder.method(method.name(), HttpRequest.BodyPublishers.ofString(string));
|
||||
method = null;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public Request bodyForm(Map<String, String> entries) {
|
||||
return bodyForm(entries.entrySet()
|
||||
.stream()
|
||||
.map(entry -> URLEncoder.encode(entry.getKey(), StandardCharsets.UTF_8) + '=' + URLEncoder.encode(entry.getValue(), StandardCharsets.UTF_8))
|
||||
.collect(Collectors.joining("&")));
|
||||
}
|
||||
|
||||
public Request bodyJson(String string) {
|
||||
builder.header("Content-Type", "application/json");
|
||||
builder.method(method.name(), HttpRequest.BodyPublishers.ofString(string));
|
||||
method = null;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public Request bodyJson(Object object) {
|
||||
builder.header("Content-Type", "application/json");
|
||||
builder.method(method.name(), HttpRequest.BodyPublishers.ofString(GsonHolder.getGson().toJson(object)));
|
||||
method = null;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
private <T> T _send(String accept, HttpResponse.BodyHandler<T> responseBodyHandler) throws IOException {
|
||||
sent++;
|
||||
if (sent > 3) throw new IOException("Attempted third redirect, stopping");
|
||||
builder.header("Accept", accept);
|
||||
if (method != null) builder.method(method.name(), HttpRequest.BodyPublishers.noBody());
|
||||
|
||||
HttpResponse<T> res;
|
||||
try {
|
||||
res = CLIENT.send(builder.build(), responseBodyHandler);
|
||||
} catch (InterruptedException e) {
|
||||
throw new IOException("Could not send request", e);
|
||||
}
|
||||
if (res.statusCode() == 200) return res.body();
|
||||
Optional<String> location = res.headers().firstValue("location");
|
||||
// Redirect
|
||||
if (location.isPresent() && (res.statusCode() == 302 || res.statusCode() == 307) && method == Method.GET) {
|
||||
try {
|
||||
return HttpUtils.get(location.get())._send(accept, responseBodyHandler);
|
||||
} catch (URISyntaxException e) {
|
||||
throw new IOException("Could not follow redirect", e);
|
||||
}
|
||||
}
|
||||
// CurseForge serverside error
|
||||
if (CURSEFORGE_API.matcher(url).matches() && res.statusCode() >= 500 && res.statusCode() < 600) {
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
throw new IOException("Could not sleep before resending request" + e);
|
||||
}
|
||||
return _send(accept, responseBodyHandler);
|
||||
}
|
||||
throw new IOException("Unexpected return method: " + res.statusCode() + " (URL=" + url + ")");
|
||||
}
|
||||
|
||||
public void send() throws IOException {
|
||||
_send("*/*", HttpResponse.BodyHandlers.discarding());
|
||||
}
|
||||
|
||||
public InputStream sendInputStream() throws IOException {
|
||||
return _send("*/*", HttpResponse.BodyHandlers.ofInputStream());
|
||||
}
|
||||
|
||||
public String sendString() throws IOException {
|
||||
return _send("*/*", HttpResponse.BodyHandlers.ofString());
|
||||
}
|
||||
|
||||
public Stream<String> sendLines() throws IOException {
|
||||
return _send("*/*", HttpResponse.BodyHandlers.ofLines());
|
||||
}
|
||||
|
||||
public <T> T sendJson(Type type) throws IOException {
|
||||
InputStream in = _send("application/json", HttpResponse.BodyHandlers.ofInputStream());
|
||||
return in == null ? null : GsonHolder.getGson().fromJson(new InputStreamReader(in), type);
|
||||
}
|
||||
|
||||
private String getString(Object a) throws IOException {
|
||||
if (a instanceof InputStream s) return new String(s.readAllBytes());
|
||||
if (a instanceof String s) return s;
|
||||
if (a instanceof Stream s) return ((Stream<String>)s).collect(Collectors.joining());
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public static Request get(String url) throws URISyntaxException {
|
||||
return new Request(Method.GET, url);
|
||||
}
|
||||
|
||||
public static Request post(String url) throws URISyntaxException {
|
||||
return new Request(Method.POST, url);
|
||||
}
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
package io.gitlab.jfronny.inceptum.util;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
public class JvmUtils {
|
||||
public static boolean executableInPath(String executableName) {
|
||||
try {
|
||||
return java.util.stream.Stream
|
||||
.of(System.getenv("PATH").split(java.util.regex.Pattern.quote(File.pathSeparator)))
|
||||
.map(path -> path.replace("\"", "")).map(Paths::get)
|
||||
.anyMatch(path -> Files.exists(path.resolve(executableName))
|
||||
&& Files.isExecutable(path.resolve(executableName)));
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static Path getJvmMain(Path jvmDir) {
|
||||
Path f = jvmDir.resolve("bin");
|
||||
Path t = f.resolve("java");
|
||||
if (!Files.exists(t)) t = f.resolve("javaw");
|
||||
if (!Files.exists(t)) t = f.resolve("java.exe");
|
||||
if (!Files.exists(t)) t = f.resolve("javaw.exe");
|
||||
return t;
|
||||
}
|
||||
|
||||
public static String getJvm() {
|
||||
return getJvmMain(Paths.get(System.getProperty("java.home"))).toAbsolutePath().toString();
|
||||
}
|
||||
}
|
|
@ -1,8 +1,9 @@
|
|||
package io.gitlab.jfronny.inceptum.util;
|
||||
|
||||
import com.google.gson.GsonBuilder;
|
||||
import io.gitlab.jfronny.inceptum.gson.ComparableVersionAdapter;
|
||||
import io.gitlab.jfronny.inceptum.model.ComparableVersion;
|
||||
import io.gitlab.jfronny.commons.ComparableVersion;
|
||||
import io.gitlab.jfronny.commons.OSUtils;
|
||||
import io.gitlab.jfronny.commons.serialize.gson.ComparableVersionAdapter;
|
||||
import io.gitlab.jfronny.gson.GsonBuilder;
|
||||
import io.gitlab.jfronny.inceptum.model.inceptum.InceptumVersion;
|
||||
|
||||
import java.io.File;
|
||||
|
@ -49,7 +50,7 @@ public class MetaHolder {
|
|||
public static final Path CACHE_DIR = BASE_PATH.resolve("cache");
|
||||
|
||||
private static Path getConfigPath() {
|
||||
return switch (OSCheck.OS) {
|
||||
return switch (OSUtils.TYPE) {
|
||||
case WINDOWS -> Paths.get(System.getenv("APPDATA"));
|
||||
case MAC_OS -> Paths.get(System.getProperty("user.home")).resolve("Library").resolve("Application Support");
|
||||
case LINUX -> {
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
package io.gitlab.jfronny.inceptum.util;
|
||||
|
||||
import io.gitlab.jfronny.inceptum.model.OSType;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public class OSCheck {
|
||||
public static final OSType OS;
|
||||
|
||||
static {
|
||||
String os = System.getProperty("os.name", "generic").toLowerCase(Locale.ROOT);
|
||||
if ((os.contains("mac")) || (os.contains("darwin"))) {
|
||||
OS = OSType.MAC_OS;
|
||||
} else if (os.contains("win")) {
|
||||
OS = OSType.WINDOWS;
|
||||
} else if (os.contains("nux")) {
|
||||
OS = OSType.LINUX;
|
||||
} else {
|
||||
throw new RuntimeException("Unrecognized OS");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
package io.gitlab.jfronny.inceptum.util;
|
||||
|
||||
import io.gitlab.jfronny.inceptum.model.ComparableVersion;
|
||||
import io.gitlab.jfronny.commons.ComparableVersion;
|
||||
import io.gitlab.jfronny.commons.HttpUtils;
|
||||
import io.gitlab.jfronny.inceptum.model.gitlab.*;
|
||||
import io.gitlab.jfronny.inceptum.model.inceptum.InceptumVersion;
|
||||
import io.gitlab.jfronny.inceptum.model.inceptum.UpdateChannel;
|
||||
|
@ -32,7 +33,7 @@ public class UpdateChecker {
|
|||
for (GitlabJob job : GitlabApi.getJobs(project, pipeline.id)) {
|
||||
if (!job.name.equals("build_test")) continue;
|
||||
try {
|
||||
InceptumVersion iv = HttpUtils.get(GitlabApi.PROJECTS + project.id + "/jobs/" + job.id + "/artifacts/version.json").sendJson(InceptumVersion.class);
|
||||
InceptumVersion iv = HttpUtils.get(GitlabApi.PROJECTS + project.id + "/jobs/" + job.id + "/artifacts/version.json").sendSerialized(InceptumVersion.class);
|
||||
if (iv.jvm > jvm) {
|
||||
Utils.LOGGER.error("A newer JVM is required to use the latest inceptum version. Please update!");
|
||||
continue packageLoop;
|
||||
|
|
|
@ -1,10 +1,14 @@
|
|||
package io.gitlab.jfronny.inceptum.util;
|
||||
|
||||
import io.gitlab.jfronny.commons.HashUtils;
|
||||
import io.gitlab.jfronny.commons.HttpUtils;
|
||||
import io.gitlab.jfronny.commons.OSUtils;
|
||||
import io.gitlab.jfronny.commons.serialize.Serializer;
|
||||
import io.gitlab.jfronny.commons.serialize.SerializerHolder;
|
||||
import io.gitlab.jfronny.commons.serialize.gson.GsonHolder;
|
||||
import io.gitlab.jfronny.commons.throwable.ThrowingConsumer;
|
||||
import io.gitlab.jfronny.commons.throwable.ThrowingSupplier;
|
||||
import io.gitlab.jfronny.inceptum.WrapperStrap;
|
||||
import io.gitlab.jfronny.inceptum.gson.GsonHolder;
|
||||
import io.gitlab.jfronny.inceptum.model.OSType;
|
||||
import io.gitlab.jfronny.inceptum.util.cache.GsonFileCache;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -213,7 +217,7 @@ public class Utils {
|
|||
|
||||
public static void openWebBrowser(URI uri) {
|
||||
try {
|
||||
if (OSCheck.OS == OSType.LINUX && JvmUtils.executableInPath("xdg-open")) {
|
||||
if (OSUtils.TYPE == OSUtils.Type.LINUX && OSUtils.executablePathContains("xdg-open")) {
|
||||
Runtime.getRuntime().exec(new String[]{"xdg-open", uri.toString()});
|
||||
} else if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) {
|
||||
Desktop.getDesktop().browse(uri);
|
||||
|
@ -225,7 +229,7 @@ public class Utils {
|
|||
|
||||
public static void openFile(File file) {
|
||||
try {
|
||||
if (OSCheck.OS == OSType.LINUX && JvmUtils.executableInPath("xdg-open")) {
|
||||
if (OSUtils.TYPE == OSUtils.Type.LINUX && OSUtils.executablePathContains("xdg-open")) {
|
||||
Runtime.getRuntime().exec(new String[]{"xdg-open", file.getAbsoluteFile().toString()});
|
||||
} else if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) {
|
||||
Desktop.getDesktop().open(file);
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
package io.gitlab.jfronny.inceptum.util.api;
|
||||
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import io.gitlab.jfronny.commons.HttpUtils;
|
||||
import io.gitlab.jfronny.gson.reflect.TypeToken;
|
||||
import io.gitlab.jfronny.inceptum.model.gitlab.GitlabJob;
|
||||
import io.gitlab.jfronny.inceptum.model.gitlab.GitlabPackage;
|
||||
import io.gitlab.jfronny.inceptum.model.gitlab.GitlabPackageFile;
|
||||
import io.gitlab.jfronny.inceptum.model.gitlab.GitlabProject;
|
||||
import io.gitlab.jfronny.inceptum.util.HttpUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Type;
|
||||
|
@ -20,15 +20,15 @@ public class GitlabApi {
|
|||
private static final Type packageFileInfoListType = new TypeToken<List<GitlabPackageFile>>() {}.getType();
|
||||
|
||||
public static GitlabProject getProject(Long projectId) throws IOException, URISyntaxException {
|
||||
return HttpUtils.get(PROJECTS + projectId).sendJson(GitlabProject.class);
|
||||
return HttpUtils.get(PROJECTS + projectId).sendSerialized(GitlabProject.class);
|
||||
}
|
||||
|
||||
public static List<GitlabPackage> getPackages(GitlabProject project) throws IOException, URISyntaxException {
|
||||
return HttpUtils.get(PROJECTS + project.id + "/packages?order_by=created_at&sort=desc").sendJson(packageInfoListType);
|
||||
return HttpUtils.get(PROJECTS + project.id + "/packages?order_by=created_at&sort=desc").sendSerialized(packageInfoListType);
|
||||
}
|
||||
|
||||
public static List<GitlabJob> getJobs(GitlabProject project, Long pipelineId) throws IOException, URISyntaxException {
|
||||
List<GitlabJob> list = HttpUtils.get(PROJECTS + project.id + "/pipelines/" + pipelineId + "/jobs").sendJson(jobListType);
|
||||
List<GitlabJob> list = HttpUtils.get(PROJECTS + project.id + "/pipelines/" + pipelineId + "/jobs").sendSerialized(jobListType);
|
||||
list.sort((left, right) -> right.created_at.compareTo(left.created_at));
|
||||
return list;
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ public class GitlabApi {
|
|||
public static GitlabPackageFile getFile(GitlabProject project, GitlabPackage packageInfo, Predicate<GitlabPackageFile> isValid) throws IOException, URISyntaxException {
|
||||
int page = 0;
|
||||
while (true) {
|
||||
List<GitlabPackageFile> files = HttpUtils.get(PROJECTS + project.id + "/packages/" + packageInfo.id + "/package_files?per_page=100&page=" + ++page).sendJson(packageFileInfoListType);
|
||||
List<GitlabPackageFile> files = HttpUtils.get(PROJECTS + project.id + "/packages/" + packageInfo.id + "/package_files?per_page=100&page=" + ++page).sendSerialized(packageFileInfoListType);
|
||||
if (files.isEmpty()) return null;
|
||||
for (GitlabPackageFile file : files) {
|
||||
if (isValid.test(file))
|
||||
|
|
Loading…
Reference in New Issue