From 4e08fe36651874f93d21d8a96336c3d79dca5ce9 Mon Sep 17 00:00:00 2001 From: Bixilon Date: Tue, 8 Sep 2020 14:25:23 +0200 Subject: [PATCH] add maven assembly plugin, disable assets extraction --- pom.xml | 19 ++++++ .../java/de/bixilon/minosoft/Launcher.java | 2 +- .../java/de/bixilon/minosoft/Minosoft.java | 18 +----- .../de/bixilon/minosoft/util/FolderUtil.java | 62 ------------------- .../java/de/bixilon/minosoft/util/Util.java | 8 +++ 5 files changed, 30 insertions(+), 79 deletions(-) delete mode 100644 src/main/java/de/bixilon/minosoft/util/FolderUtil.java diff --git a/pom.xml b/pom.xml index e1d26450f..802a5000f 100644 --- a/pom.xml +++ b/pom.xml @@ -38,6 +38,19 @@ de.bixilon.minosoft.Minosoft + + maven-assembly-plugin + + + + de.bixilon.minosoft.Minosoft + + + + jar-with-dependencies + + + @@ -84,5 +97,11 @@ commons-compress 1.20 + + org.apache.maven.plugins + maven-assembly-plugin + 2.3 + maven-plugin + \ No newline at end of file diff --git a/src/main/java/de/bixilon/minosoft/Launcher.java b/src/main/java/de/bixilon/minosoft/Launcher.java index 113101327..148985d66 100644 --- a/src/main/java/de/bixilon/minosoft/Launcher.java +++ b/src/main/java/de/bixilon/minosoft/Launcher.java @@ -37,7 +37,7 @@ import java.util.Map; public class Launcher extends Application { - public static void main() { + public static void start() { launch(); } diff --git a/src/main/java/de/bixilon/minosoft/Minosoft.java b/src/main/java/de/bixilon/minosoft/Minosoft.java index f04b703a6..767cf6bb1 100644 --- a/src/main/java/de/bixilon/minosoft/Minosoft.java +++ b/src/main/java/de/bixilon/minosoft/Minosoft.java @@ -21,7 +21,6 @@ import de.bixilon.minosoft.gui.main.AccountListCell; import de.bixilon.minosoft.gui.main.Server; import de.bixilon.minosoft.logging.Log; import de.bixilon.minosoft.logging.LogLevels; -import de.bixilon.minosoft.util.FolderUtil; import de.bixilon.minosoft.util.OSUtil; import de.bixilon.minosoft.util.Util; import de.bixilon.minosoft.util.mojang.api.MojangAccount; @@ -55,13 +54,10 @@ public class Minosoft { // set log level from config Log.setLevel(LogLevels.valueOf(config.getString(GameConfiguration.GENERAL_LOG_LEVEL))); Log.info(String.format("Logging info with level: %s", Log.getLevel())); - Log.info("Checking assets..."); - checkAssets(); - Log.info("Assets checking done"); Log.info("Loading versions.json..."); long mappingStartLoadingTime = System.currentTimeMillis(); try { - Versions.load(Util.readJsonFromFile(Config.homeDir + "assets/mapping/versions.json")); + Versions.load(Util.readJsonAsset("mapping/versions.json")); } catch (IOException e) { e.printStackTrace(); System.exit(1); @@ -75,7 +71,7 @@ public class Minosoft { serverList = config.getServers(); - Launcher.main(); + Launcher.start(); } /** @@ -111,16 +107,6 @@ public class Minosoft { } } - private static void checkAssets() { - try { - FolderUtil.copyFolder(Minosoft.class.getResource("/assets").toURI(), Config.homeDir + "assets/"); - } catch (Exception e) { - Log.fatal("Error occurred while checking assets: " + e.getLocalizedMessage()); - e.printStackTrace(); - System.exit(1); - } - } - public static ArrayList getServerList() { return serverList; } diff --git a/src/main/java/de/bixilon/minosoft/util/FolderUtil.java b/src/main/java/de/bixilon/minosoft/util/FolderUtil.java deleted file mode 100644 index 9825c18d1..000000000 --- a/src/main/java/de/bixilon/minosoft/util/FolderUtil.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Codename Minosoft - * Copyright (C) 2020 Moritz Zwerger - * - * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with this program. If not, see . - * - * This software is not affiliated with Mojang AB, the original developer of Minecraft. - */ - -package de.bixilon.minosoft.util; - -import de.bixilon.minosoft.logging.Log; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.net.URI; -import java.nio.file.Files; -import java.nio.file.Path; - -public final class FolderUtil { - - public static void copyFolder(URI from, String to) throws IOException { - File folder = new File(from); - for (String entry : folder.list()) { - File entryFile = new File(folder.getPath() + File.separator + entry); - if (entryFile.isDirectory()) { - copyFolder(entryFile.toURI(), to + File.separator + entry); - continue; - } - File out = new File(to + File.separator + entry); - if (out.exists()) { - // check - if (Files.mismatch(Path.of(entryFile.getPath()), Path.of(out.getPath())) == -1) { - // identically - continue; - } - // move file to an other location and re extract - moveFileToOld(out); - } - File outFolder = new File(out.getParent()); - if (!outFolder.exists()) { - outFolder.mkdirs(); - } - Files.copy(new FileInputStream(entryFile), out.toPath()); - } - } - - private static void moveFileToOld(File file) { - File newFile = new File(file.getAbsolutePath() + ".old"); - if (newFile.exists()) { - newFile.delete(); - Log.verbose(String.format("Deleted file: %s", newFile.getAbsoluteFile())); - } - file.renameTo(newFile); - Log.verbose(String.format("Renamed %s to: %s", newFile.getAbsoluteFile(), newFile.getName())); - } -} diff --git a/src/main/java/de/bixilon/minosoft/util/Util.java b/src/main/java/de/bixilon/minosoft/util/Util.java index f1b99389f..7a73e69da 100644 --- a/src/main/java/de/bixilon/minosoft/util/Util.java +++ b/src/main/java/de/bixilon/minosoft/util/Util.java @@ -128,6 +128,14 @@ public final class Util { return readFile(new File(fileName)); } + public static String readAsset(String path) throws IOException { + return readFile(new BufferedReader((new InputStreamReader(Util.class.getResourceAsStream("/assets/" + path)))), true); + } + + public static JsonObject readJsonAsset(String path) throws IOException { + return (JsonObject) JsonParser.parseString(readAsset(path)); + } + public static String readFile(BufferedReader reader, boolean closeStream) throws IOException { StringBuilder stringBuilder = new StringBuilder(); String ls = System.getProperty("line.separator");