Use .config on deploys

This commit is contained in:
JFronny 2021-11-02 13:43:18 +01:00
parent 6a6b5a62a3
commit 0eb28397e2
No known key found for this signature in database
GPG Key ID: BEC5ACBBD4EE17E5
15 changed files with 127 additions and 61 deletions

View File

@ -13,11 +13,11 @@ stages:
build_test:
stage: build
script:
- gradle --build-cache build publish -Pflavor=nogui -PpublicMaven -Ppipeline=$CI_PIPELINE_ID
- gradle --build-cache build publish -Pflavor=fat -PpublicMaven -Ppipeline=$CI_PIPELINE_ID
- gradle --build-cache build publish -Pflavor=windows -PpublicMaven -Ppipeline=$CI_PIPELINE_ID
- gradle --build-cache build publish -Pflavor=linux -PpublicMaven -Ppipeline=$CI_PIPELINE_ID
- gradle --build-cache build publish -Pflavor=macos -PpublicMaven -Ppipeline=$CI_PIPELINE_ID
- gradle --build-cache build publish -Pflavor=nogui -Ppublic -Ppipeline=$CI_PIPELINE_ID
- gradle --build-cache build publish -Pflavor=fat -Ppublic -Ppipeline=$CI_PIPELINE_ID
- gradle --build-cache build publish -Pflavor=windows -Ppublic -Ppipeline=$CI_PIPELINE_ID
- gradle --build-cache build publish -Pflavor=linux -Ppublic -Ppipeline=$CI_PIPELINE_ID
- gradle --build-cache build publish -Pflavor=macos -Ppublic -Ppipeline=$CI_PIPELINE_ID
- cp build/libs/*-*-*.jar ./
- cp wrapper/build/libs/* build/libs/
- cp wrapper/build/libs/*.exe wrapper.exe
@ -41,8 +41,8 @@ deploy:
- if: $CI_COMMIT_TAG && '$CI_MERGE_REQUEST_SOURCE_BRANCH_NAME =~ /^master/'
stage: deploy
script:
- gradle --build-cache build publish -Pflavor=nogui -PpublicMaven
- gradle --build-cache build publish -Pflavor=fat -PpublicMaven
- gradle --build-cache build publish -Pflavor=windows -PpublicMaven
- gradle --build-cache build publish -Pflavor=linux -PpublicMaven
- gradle --build-cache build publish -Pflavor=macos -PpublicMaven
- gradle --build-cache build publish -Pflavor=nogui -Ppublic
- gradle --build-cache build publish -Pflavor=fat -Ppublic
- gradle --build-cache build publish -Pflavor=windows -Ppublic
- gradle --build-cache build publish -Pflavor=linux -Ppublic
- gradle --build-cache build publish -Pflavor=macos -Ppublic

View File

@ -26,7 +26,7 @@ ext {
log4jVersion = '2.14.1'
flavorProp = project.hasProperty('flavor') ? project.getProperty('flavor') : 'custom'
flavor = flavorProp
isPublicMaven = project.hasProperty('publicMaven')
isPublic = project.hasProperty('public')
}
if (flavor == 'custom') {
@ -75,6 +75,7 @@ processResources {
filesMatching("version.json") {
expand "version": project.version
filter { line -> line.replace("@flavor@", project.ext.flavorProp) }
filter { line -> line.replace("@public@", "$project.ext.isPublic") }
}
}
@ -90,7 +91,7 @@ publishing {
}
}
}
if (project.ext.isPublicMaven) {
if (project.ext.isPublic) {
repositories.maven {
url = "https://gitlab.com/api/v4/projects/30862253/packages/maven"
name = "gitlab"

View File

@ -7,18 +7,17 @@ import io.gitlab.jfronny.inceptum.gson.*;
import io.gitlab.jfronny.inceptum.model.ComparableVersion;
import io.gitlab.jfronny.inceptum.model.inceptum.CommandArguments;
import io.gitlab.jfronny.inceptum.model.inceptum.Config;
import io.gitlab.jfronny.inceptum.model.inceptum.InceptumVersion;
import io.gitlab.jfronny.inceptum.model.microsoft.OauthTokenResponse;
import io.gitlab.jfronny.inceptum.model.mojang.MinecraftArgument;
import io.gitlab.jfronny.inceptum.model.mojang.Rules;
import io.gitlab.jfronny.inceptum.util.MetaHolder;
import io.gitlab.jfronny.inceptum.util.Utils;
import io.gitlab.jfronny.inceptum.util.api.McApi;
import io.gitlab.jfronny.inceptum.windows.AlertWindow;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.Modifier;
import java.nio.file.Files;
import java.nio.file.Path;
@ -27,9 +26,14 @@ import java.util.Set;
//TODO mods browser
//TODO allow instance sync through metadata
public class Inceptum {
public static final Path CACHE_DIR = MetaHolder.BASE_PATH.resolve("cache");
public static final Path INSTANCE_DIR = MetaHolder.BASE_PATH.resolve("instances");
public static final Path ASSETS_DIR = MetaHolder.BASE_PATH.resolve("assets");
public static final Path LIBRARIES_DIR = MetaHolder.BASE_PATH.resolve("libraries");
public static final Path NATIVES_DIR = MetaHolder.BASE_PATH.resolve("natives");
private static final Path CONFIG_PATH = MetaHolder.BASE_PATH.resolve("glaunch2.json");
public static final Path ACCOUNTS_PATH = MetaHolder.BASE_PATH.resolve("accounts.json");
public static final Set<Command> COMMANDS = Set.of(new HelpCommand(), new GuiCommand(), new LaunchCommand(), new UpdateCheckCommand(), new JvmStateCommand());
public static boolean IS_GUI;
public static final Logger LOGGER = LoggerFactory.getLogger("Inceptum");
public static final Gson GSON = new GsonBuilder()
.registerTypeAdapter(MinecraftArgument.class, new MinecraftArgumentDeserializer())
@ -41,22 +45,11 @@ public class Inceptum {
.addSerializationExclusionStrategy(new GsonIgnoreExclusionStrategy())
.setPrettyPrinting()
.create();
//TODO allow moving to .config or elsewhere
public static final Path CACHE_DIR = Path.of("run/cache");
public static final Path INSTANCE_DIR = Path.of("run/instances");
public static final Path ASSETS_DIR = Path.of("run/assets");
public static final Path LIBRARIES_DIR = Path.of("run/libraries");
public static final Path NATIVES_DIR = Path.of("run/natives");
private static final Path CONFIG_PATH = Path.of("run/glaunch2.json");
public static final Path ACCOUNTS_PATH = Path.of("run/accounts.json");
public static InceptumVersion VERSION;
public static Config CONFIG;
public static boolean IS_GUI;
public static void main(String[] _args) throws IOException {
try (InputStream is = Inceptum.class.getClassLoader().getResourceAsStream("version.json");
InputStreamReader isr = new InputStreamReader(is)) {
VERSION = GSON.fromJson(isr, InceptumVersion.class);
}
CommandArguments arg = new CommandArguments(_args);
Command cmd = null;
for (Command command : COMMANDS) {
@ -70,14 +63,20 @@ public class Inceptum {
return;
}
if (cmd.enableLog()) {
LOGGER.info("Launching Inceptum v" + VERSION.version + " (" + VERSION.flavor + ")");
LOGGER.info("Setting up cache dir");
LOGGER.info("Launching Inceptum v" + MetaHolder.VERSION.version + " (" + MetaHolder.VERSION.flavor + ")");
LOGGER.info("Loading from " + MetaHolder.BASE_PATH);
}
if (!Files.exists(CONFIG_PATH.getParent())) Files.createDirectories(CONFIG_PATH.getParent());
if (!Files.exists(CONFIG_PATH)) Utils.writeObject(CONFIG_PATH, new Config());
CONFIG = Utils.loadObject(CONFIG_PATH, Config.class);
if (!Files.exists(CACHE_DIR)) Files.createDirectories(CACHE_DIR);
Utils.clearDirectory(CACHE_DIR);
try {
McApi.getVersions();
Utils.clearDirectory(CACHE_DIR);
}
catch (IOException e) {
Inceptum.LOGGER.error("Could not connect to the internet");
}
if (!Files.exists(INSTANCE_DIR)) Files.createDirectories(INSTANCE_DIR);
if (!Files.exists(ASSETS_DIR)) Files.createDirectories(ASSETS_DIR);
if (!Files.exists(LIBRARIES_DIR)) Files.createDirectories(LIBRARIES_DIR);

View File

@ -2,6 +2,7 @@ package io.gitlab.jfronny.inceptum.cli;
import io.gitlab.jfronny.inceptum.Inceptum;
import io.gitlab.jfronny.inceptum.model.inceptum.CommandArguments;
import io.gitlab.jfronny.inceptum.util.MetaHolder;
public class HelpCommand extends Command {
public HelpCommand() {
@ -9,7 +10,7 @@ public class HelpCommand extends Command {
}
@Override
public void invoke(CommandArguments args) {
System.out.println("Inceptum v" + Inceptum.VERSION.version + " (" + Inceptum.VERSION.flavor + ")\n\nCommands:");
System.out.println("Inceptum v" + MetaHolder.VERSION.version + " (" + MetaHolder.VERSION.flavor + ")\n\nCommands:");
for (Command command : Inceptum.COMMANDS) {
System.out.println(" " + command.getName() + " - " + command.getHelp());
}

View File

@ -3,10 +3,7 @@ package io.gitlab.jfronny.inceptum.cli;
import io.gitlab.jfronny.inceptum.Inceptum;
import io.gitlab.jfronny.inceptum.model.inceptum.CommandArguments;
import io.gitlab.jfronny.inceptum.model.inceptum.UpdateInfo;
import io.gitlab.jfronny.inceptum.util.JvmUtils;
import io.gitlab.jfronny.inceptum.util.OSCheck;
import io.gitlab.jfronny.inceptum.util.UpdateChecker;
import io.gitlab.jfronny.inceptum.util.Utils;
import io.gitlab.jfronny.inceptum.util.*;
import java.io.IOException;
import java.net.URISyntaxException;
@ -44,7 +41,7 @@ public class UpdateCheckCommand extends Command {
}
public static UpdateInfo getUpdate() {
return UpdateChecker.check(Inceptum.CONFIG.channel, Inceptum.VERSION.version, Inceptum.VERSION.flavor, channel -> {
return UpdateChecker.check(Inceptum.CONFIG.channel, MetaHolder.VERSION.version, MetaHolder.VERSION.flavor, channel -> {
Inceptum.LOGGER.error("No stable version was found, switching to experimental channel");
Inceptum.CONFIG.channel = channel;
Inceptum.saveConfig();

View File

@ -24,6 +24,10 @@ import java.util.concurrent.atomic.AtomicReference;
public class ClientLauncher {
public static void launch(Path path, InstanceMeta instance) {
if (AccountManager.accountMissing()) {
Inceptum.showError("You have not set up an account.\nDoing so is required to play Minecraft", "Not authenticated");
return;
}
for (VersionsListInfo version : McApi.getVersions().versions) {
if (version.id.equals(instance.getMinecraftVersion())) {
try {
@ -106,7 +110,7 @@ public class ClientLauncher {
// jvm args
.replace("${natives_directory}", Inceptum.NATIVES_DIR.resolve(instance.getMinecraftVersion()).toAbsolutePath().toString())
.replace("${launcher_name}", "Inceptum")
.replace("${launcher_version}", Inceptum.VERSION.version.toString())
.replace("${launcher_version}", MetaHolder.VERSION.version.toString())
.replace("${classpath}", classPath)
.replace("${user_properties}", "{}");
}

View File

@ -2,9 +2,7 @@ package io.gitlab.jfronny.inceptum.util.api.account;
import com.google.gson.reflect.TypeToken;
import io.gitlab.jfronny.inceptum.Inceptum;
import io.gitlab.jfronny.inceptum.InceptumGui;
import io.gitlab.jfronny.inceptum.util.Utils;
import io.gitlab.jfronny.inceptum.windows.AlertWindow;
import java.io.IOException;
import java.lang.reflect.Type;
@ -19,18 +17,18 @@ public class AccountManager {
private static final AuthInfo NULL_AUTH = new AuthInfo("Joe", "2536abce90e8476a871679918164abc5", "99abe417230342cb8e9e2168ab46297a", "legacy");
public static AuthInfo getSelectedAccount() {
if (SELECTED_ACCOUNT == null) {
return NULL_AUTH;
}
if (SELECTED_ACCOUNT.ensureAccessTokenValid(a -> {})) {
return new AuthInfo(SELECTED_ACCOUNT);
}
if (accountMissing()) return NULL_AUTH;
else if (SELECTED_ACCOUNT.ensureAccessTokenValid(a -> {})) return new AuthInfo(SELECTED_ACCOUNT);
else {
Inceptum.LOGGER.error("Couldn't login properly, using offline mode");
return NULL_AUTH;
}
}
public static boolean accountMissing() {
return SELECTED_ACCOUNT == null;
}
public static List<MicrosoftAccount> getAccounts() {
return List.copyOf(ACCOUNTS);
}

View File

@ -1,7 +1,7 @@
package io.gitlab.jfronny.inceptum.windows;
import imgui.ImGui;
import io.gitlab.jfronny.inceptum.Inceptum;
import io.gitlab.jfronny.inceptum.util.MetaHolder;
public class AboutWindow extends Window {
public AboutWindow() {
@ -10,7 +10,7 @@ public class AboutWindow extends Window {
@Override
public void draw() {
ImGui.text("Inceptum " + Inceptum.VERSION.version + " Copyright (C) 2021 JFronny");
ImGui.text("Inceptum " + MetaHolder.VERSION.version + " Copyright (C) 2021 JFronny");
ImGui.text("This program comes with ABSOLUTELY NO WARRANTY.");
ImGui.text("This is free software, and you are welcome to redistribute it under certain conditions.");
}

View File

@ -1,4 +1,5 @@
{
"version": "${version}",
"flavor": "@flavor@"
"flavor": "@flavor@",
"isPublic": @public@
}

View File

@ -18,6 +18,16 @@ dependencies {
implementation 'com.google.code.gson:gson:2.8.8'
}
processResources {
inputs.property "version", project.version
filesMatching("version.json") {
expand "version": project.version
filter { line -> line.replace("@flavor@", rootProject.ext.flavorProp) }
filter { line -> line.replace("@public@", "$rootProject.ext.isPublic") }
}
}
class FileOutput extends DefaultTask {
@OutputFile
File output
@ -56,7 +66,7 @@ publishing {
}
}
if (project.parent.ext.isPublicMaven) {
if (rootProject.ext.isPublic) {
repositories.maven {
url = "https://gitlab.com/api/v4/projects/30862253/packages/maven"
name = "gitlab"

View File

@ -4,6 +4,7 @@ import io.gitlab.jfronny.inceptum.model.ComparableVersion;
import io.gitlab.jfronny.inceptum.model.inceptum.UpdateChannel;
import io.gitlab.jfronny.inceptum.model.inceptum.UpdateInfo;
import io.gitlab.jfronny.inceptum.util.JvmUtils;
import io.gitlab.jfronny.inceptum.util.MetaHolder;
import io.gitlab.jfronny.inceptum.util.OSCheck;
import io.gitlab.jfronny.inceptum.util.UpdateChecker;
@ -18,15 +19,8 @@ import java.util.List;
public class Wrapper {
public static void main(String[] args) throws IOException {
String path = Wrapper.class.getProtectionDomain().getCodeSource().getLocation().getPath();
Path p;
if (path.endsWith(".jar")) {
p = Path.of(path).getParent();
} else {
System.out.println("Not running in a jar, using ./run");
p = Path.of(".");
}
p = p.resolve("run/libraries/io/gitlab/jfronny/inceptum/Inceptum");
System.out.println("Inceptum Wrapper v" + MetaHolder.VERSION.version + " (" + MetaHolder.VERSION.flavor + ")");
Path p = MetaHolder.BASE_PATH.resolve("libraries/io/gitlab/jfronny/inceptum/Inceptum");
if (!Files.exists(p)) {
System.err.println("No Inceptum jar was identified");
UpdateInfo ui = UpdateChecker.check(UpdateChannel.Stable, new ComparableVersion("0"), OSCheck.OS.getMojName(), c -> {}, System.out::println, System.err::println, (s, e) -> {

View File

@ -5,4 +5,5 @@ import io.gitlab.jfronny.inceptum.model.ComparableVersion;
public class InceptumVersion {
public ComparableVersion version;
public String flavor;
public Boolean isPublic;
}

View File

@ -0,0 +1,55 @@
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.inceptum.model.inceptum.InceptumVersion;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.file.Path;
public class MetaHolder {
public static final InceptumVersion VERSION;
public static final Path BASE_PATH;
static {
try (InputStream is = MetaHolder.class.getClassLoader().getResourceAsStream("version.json");
InputStreamReader isr = new InputStreamReader(is)) {
VERSION = new GsonBuilder()
.registerTypeAdapter(ComparableVersion.class, new ComparableVersionAdapter())
.create()
.fromJson(isr, InceptumVersion.class);
BASE_PATH = VERSION.isPublic
? getConfigPath().resolve("Inceptum")
: getDir().resolve("run");
} catch (IOException e) {
throw new RuntimeException("Could not get version info", e);
}
}
private static Path getConfigPath() {
return switch (OSCheck.OS) {
case WINDOWS -> Path.of(System.getenv("APPDATA"));
case MAC_OS -> Path.of(System.getProperty("user.home")).resolve("Library").resolve("Application Support");
case LINUX -> {
String s = System.getenv().get("XDG_CONFIG_HOME");
if (s == null)
yield Path.of(System.getProperty("user.home")).resolve(".config");
else
yield Path.of(s);
}
};
}
private static Path getDir() {
String p = MetaHolder.class.getProtectionDomain().getCodeSource().getLocation().getPath();
if (p.endsWith(".jar") && !p.endsWith("/build/libs/wrapper-" + VERSION.version + ".jar")) {
return Path.of(p).getParent();
} else {
System.out.println("Not running in a jar, using ./run");
return Path.of(".");
}
}
}

View File

@ -0,0 +1,5 @@
{
"version": "${version}",
"flavor": "@flavor@",
"isPublic": @public@
}