From 78766d0c5c7a88c338295721ab2c19b8dfb6fce4 Mon Sep 17 00:00:00 2001 From: Gravit Date: Sat, 22 Sep 2018 21:22:39 +0700 Subject: [PATCH] Move LauncherVersion and LauncherClassLoader --- .../ru/gravit/launchserver/LaunchServer.java | 6 +-- .../binary/EXEL4JLauncherBinary.java | 7 ++- .../command/basic/VersionCommand.java | 4 +- .../manangers/ModulesManager.java | 4 +- .../launchserver/modules/CoreModule.java | 7 +-- .../modules/LaunchServerModuleContext.java | 6 +-- .../launchserver/modules/SimpleModule.java | 6 +-- .../launcher/client/ClientLauncher.java | 9 ++-- .../launcher/server/ModulesManager.java | 4 +- .../launcher/server/ServerModuleContext.java | 6 +-- .../java/ru/gravit/launcher/Launcher.java | 33 ++++++------ .../ru/gravit/launcher/modules/Module.java | 4 +- .../launcher/modules/SimpleModuleManager.java | 4 +- .../launcher/modules/TestClientModule.java | 7 +-- .../SystemClassLoaderTransformer.java | 6 +-- .../PublicURLClassLoader.java} | 10 ++-- .../Version.java} | 50 ++++++++----------- .../ru/gravit/utils/helper/CommonHelper.java | 1 - .../ru/gravit/utils/helper/LogHelper.java | 8 +-- 19 files changed, 88 insertions(+), 94 deletions(-) rename libLauncher/src/main/java/ru/gravit/{launcher/LauncherClassLoader.java => utils/PublicURLClassLoader.java} (91%) rename libLauncher/src/main/java/ru/gravit/{launcher/LauncherVersion.java => utils/Version.java} (69%) diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java index 9e163d16..0636284e 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java @@ -29,8 +29,8 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.zip.CRC32; +import ru.gravit.launcher.Launcher; import ru.gravit.launcher.LauncherAPI; -import ru.gravit.launcher.LauncherVersion; import ru.gravit.launcher.hasher.HashedDir; import ru.gravit.utils.helper.CommonHelper; import ru.gravit.utils.helper.IOHelper; @@ -196,9 +196,9 @@ private ExeConf(BlockConfigEntry block) { trademarks = block.hasEntry("trademarks") ? block.getEntryValue("trademarks", StringConfigEntry.class) : "This product is licensed under MIT License"; txtFileVersion = block.hasEntry("txtFileVersion") ? block.getEntryValue("txtFileVersion", StringConfigEntry.class) - : String.format("%s, build %d", LauncherVersion.getVersion().getVersionString(),LauncherVersion.getVersion().build); + : String.format("%s, build %d", Launcher.getVersion().getVersionString(), Launcher.getVersion().build); txtProductVersion = block.hasEntry("txtProductVersion") ? block.getEntryValue("txtProductVersion", StringConfigEntry.class) - : String.format("%s, build %d", LauncherVersion.getVersion().getVersionString(),LauncherVersion.getVersion().build); + : String.format("%s, build %d", Launcher.getVersion().getVersionString(), Launcher.getVersion().build); } } private final class ProfilesFileVisitor extends SimpleFileVisitor { diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/EXEL4JLauncherBinary.java b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/EXEL4JLauncherBinary.java index b9fc4498..46e4c3f0 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/EXEL4JLauncherBinary.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/EXEL4JLauncherBinary.java @@ -3,9 +3,8 @@ import java.io.IOException; import java.nio.file.Path; +import ru.gravit.launcher.Launcher; import ru.gravit.launcher.LauncherAPI; -import ru.gravit.launcher.LauncherVersion; -import ru.gravit.utils.helper.CommonHelper; import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.LogHelper; import ru.gravit.launchserver.LaunchServer; @@ -114,8 +113,8 @@ private void setConfig() { // Return prepared config ConfigPersister.getInstance().setAntConfig(config, null); } - private static String VERSION = LauncherVersion.getVersion().getVersionString(); - private static int BUILD = LauncherVersion.getVersion().build; + private static String VERSION = Launcher.getVersion().getVersionString(); + private static int BUILD = Launcher.getVersion().build; public static String formatVars(String mask) { return String.format(mask, VERSION, BUILD); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/basic/VersionCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/basic/VersionCommand.java index 4363a208..40f60995 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/basic/VersionCommand.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/basic/VersionCommand.java @@ -1,6 +1,6 @@ package ru.gravit.launchserver.command.basic; -import ru.gravit.launcher.LauncherVersion; +import ru.gravit.launcher.Launcher; import ru.gravit.utils.helper.LogHelper; import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.command.Command; @@ -22,6 +22,6 @@ public String getUsageDescription() { @Override public void invoke(String... args) { - LogHelper.subInfo("LaunchServer version: %d.%d.%d (build #%d)", LauncherVersion.MAJOR, LauncherVersion.MINOR, LauncherVersion.PATCH, LauncherVersion.BUILD); + LogHelper.subInfo("LaunchServer version: %d.%d.%d (build #%d)", Launcher.MAJOR, Launcher.MINOR, Launcher.PATCH, Launcher.BUILD); } } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/ModulesManager.java b/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/ModulesManager.java index 2efef5f9..89ca0a4e 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/ModulesManager.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/ModulesManager.java @@ -3,7 +3,7 @@ import java.net.URL; import java.util.ArrayList; -import ru.gravit.launcher.LauncherClassLoader; +import ru.gravit.utils.PublicURLClassLoader; import ru.gravit.launcher.modules.SimpleModuleManager; import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.modules.CoreModule; @@ -12,7 +12,7 @@ public class ModulesManager extends SimpleModuleManager { public ModulesManager(LaunchServer lsrv) { modules = new ArrayList<>(1); - classloader = new LauncherClassLoader(new URL[0], ClassLoader.getSystemClassLoader()); + classloader = new PublicURLClassLoader(new URL[0], ClassLoader.getSystemClassLoader()); context = new LaunchServerModuleContext(lsrv, classloader); } private void registerCoreModule() { diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/modules/CoreModule.java b/LaunchServer/src/main/java/ru/gravit/launchserver/modules/CoreModule.java index bed40420..c118b558 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/modules/CoreModule.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/modules/CoreModule.java @@ -1,6 +1,7 @@ package ru.gravit.launchserver.modules; -import ru.gravit.launcher.LauncherVersion; +import ru.gravit.launcher.Launcher; +import ru.gravit.utils.Version; import ru.gravit.launcher.modules.Module; import ru.gravit.launcher.modules.ModuleContext; @@ -16,8 +17,8 @@ public String getName() { } @Override - public LauncherVersion getVersion() { - return LauncherVersion.getVersion(); + public Version getVersion() { + return Launcher.getVersion(); } @Override diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/modules/LaunchServerModuleContext.java b/LaunchServer/src/main/java/ru/gravit/launchserver/modules/LaunchServerModuleContext.java index d1162039..6e3f3678 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/modules/LaunchServerModuleContext.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/modules/LaunchServerModuleContext.java @@ -1,14 +1,14 @@ package ru.gravit.launchserver.modules; -import ru.gravit.launcher.LauncherClassLoader; +import ru.gravit.utils.PublicURLClassLoader; import ru.gravit.launcher.modules.ModuleContext; import ru.gravit.launcher.modules.ModulesManagerInterface; import ru.gravit.launchserver.LaunchServer; public class LaunchServerModuleContext implements ModuleContext { public final LaunchServer launchServer; - public final LauncherClassLoader classloader; - public LaunchServerModuleContext(LaunchServer server, LauncherClassLoader classloader) + public final PublicURLClassLoader classloader; + public LaunchServerModuleContext(LaunchServer server, PublicURLClassLoader classloader) { launchServer = server; this.classloader = classloader; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/modules/SimpleModule.java b/LaunchServer/src/main/java/ru/gravit/launchserver/modules/SimpleModule.java index 366a4a37..30899e2b 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/modules/SimpleModule.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/modules/SimpleModule.java @@ -1,6 +1,6 @@ package ru.gravit.launchserver.modules; -import ru.gravit.launcher.LauncherVersion; +import ru.gravit.utils.Version; import ru.gravit.launcher.modules.Module; import ru.gravit.launcher.modules.ModuleContext; @@ -16,8 +16,8 @@ public String getName() { } @Override - public LauncherVersion getVersion() { - return new LauncherVersion(1,0,0,0, LauncherVersion.Type.UNKNOWN); + public Version getVersion() { + return new Version(1,0,0,0, Version.Type.UNKNOWN); } @Override diff --git a/Launcher/src/main/java/ru/gravit/launcher/client/ClientLauncher.java b/Launcher/src/main/java/ru/gravit/launcher/client/ClientLauncher.java index cfd8734e..2b447d32 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/client/ClientLauncher.java +++ b/Launcher/src/main/java/ru/gravit/launcher/client/ClientLauncher.java @@ -33,6 +33,7 @@ import ru.gravit.launcher.hasher.DirWatcher; import ru.gravit.launcher.hasher.FileNameMatcher; import ru.gravit.launcher.hasher.HashedDir; +import ru.gravit.utils.PublicURLClassLoader; import ru.gravit.utils.helper.CommonHelper; import ru.gravit.utils.helper.EnvHelper; import ru.gravit.utils.helper.IOHelper; @@ -161,7 +162,7 @@ public void write(HOutput output) throws IOException { // Constants private static final Path NATIVES_DIR = IOHelper.toPath("natives"); private static final Path RESOURCEPACKS_DIR = IOHelper.toPath("resourcepacks"); - private static LauncherClassLoader classLoader; + private static PublicURLClassLoader classLoader; // Authlib constants @LauncherAPI public static final String SKIN_URL_PROPERTY = "skinURL"; @@ -222,7 +223,7 @@ private static void addClientArgs(Collection args, ClientProfile profile Collections.addAll(args, "--assetsDir", params.assetDir.toString()); Collections.addAll(args, "--resourcePackDir", params.clientDir.resolve(RESOURCEPACKS_DIR).toString()); if (version.compareTo(ClientProfile.Version.MC194) >= 0) - Collections.addAll(args, "--versionType", "Launcher v" + LauncherVersion.getVersion().getVersionString()); + Collections.addAll(args, "--versionType", "Launcher v" + Launcher.getVersion().getVersionString()); // Add server args if (params.autoEnter) { @@ -451,9 +452,9 @@ public static void main(String... args) throws Throwable { LauncherAgent.addJVMClassPath(classpathURL.toAbsolutePath().toString()); } URL[] classpathurls = resolveClassPath(params.clientDir, profile.object.getClassPath()); - classLoader = new LauncherClassLoader(classpathurls, ClassLoader.getSystemClassLoader()); + classLoader = new PublicURLClassLoader(classpathurls, ClassLoader.getSystemClassLoader()); Thread.currentThread().setContextClassLoader(classLoader); - LauncherClassLoader.systemclassloader = classLoader; + PublicURLClassLoader.systemclassloader = classLoader; // Start client with WatchService monitoring boolean digest = !profile.object.isUpdateFastCheck(); LogHelper.debug("Starting JVM and client WatchService"); diff --git a/Launcher/src/main/java/ru/gravit/launcher/server/ModulesManager.java b/Launcher/src/main/java/ru/gravit/launcher/server/ModulesManager.java index 40bd46ff..b8dd1439 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/server/ModulesManager.java +++ b/Launcher/src/main/java/ru/gravit/launcher/server/ModulesManager.java @@ -3,13 +3,13 @@ import java.net.URL; import java.util.ArrayList; -import ru.gravit.launcher.LauncherClassLoader; +import ru.gravit.utils.PublicURLClassLoader; import ru.gravit.launcher.modules.SimpleModuleManager; public class ModulesManager extends SimpleModuleManager { public ModulesManager(ServerWrapper wrapper) { modules = new ArrayList<>(); - classloader = new LauncherClassLoader(new URL[0], ClassLoader.getSystemClassLoader()); + classloader = new PublicURLClassLoader(new URL[0], ClassLoader.getSystemClassLoader()); context = new ServerModuleContext(wrapper, classloader); } } diff --git a/Launcher/src/main/java/ru/gravit/launcher/server/ServerModuleContext.java b/Launcher/src/main/java/ru/gravit/launcher/server/ServerModuleContext.java index a112b54e..99b23c55 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/server/ServerModuleContext.java +++ b/Launcher/src/main/java/ru/gravit/launcher/server/ServerModuleContext.java @@ -1,15 +1,15 @@ package ru.gravit.launcher.server; import ru.gravit.launcher.Launcher; -import ru.gravit.launcher.LauncherClassLoader; +import ru.gravit.utils.PublicURLClassLoader; import ru.gravit.launcher.modules.ModuleContext; import ru.gravit.launcher.modules.ModulesManagerInterface; public class ServerModuleContext implements ModuleContext { - public final LauncherClassLoader classLoader; + public final PublicURLClassLoader classLoader; public final ServerWrapper wrapper; - public ServerModuleContext(ServerWrapper wrapper, LauncherClassLoader classLoader) { + public ServerModuleContext(ServerWrapper wrapper, PublicURLClassLoader classLoader) { this.classLoader = classLoader; this.wrapper = wrapper; } diff --git a/libLauncher/src/main/java/ru/gravit/launcher/Launcher.java b/libLauncher/src/main/java/ru/gravit/launcher/Launcher.java index c0b5151d..4d479965 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/Launcher.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/Launcher.java @@ -9,23 +9,22 @@ import java.util.concurrent.atomic.AtomicReference; import java.util.regex.Pattern; +import ru.gravit.utils.Version; import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.SecurityHelper; import ru.gravit.launcher.modules.ModulesManagerInterface; import ru.gravit.launcher.serialize.HInput; public final class Launcher { + + static int readBuildNumber() { + try { + return Integer.valueOf(IOHelper.request(IOHelper.getResourceURL("buildnumber"))); + } catch (IOException ignored) { + return 0; // Maybe dev env? + } + } private static final AtomicReference CONFIG = new AtomicReference<>(); - // Version info - //Все версии оригинального Sashok Launcher v3 считаются как 3.xx.xx, например 3.15.3 3.15.4 - //Все версии модификации считаются так: 3.16.xx Например 3.16.5 для коммита от 20 Августа - @Deprecated - @LauncherAPI - public static final String VERSION = LauncherVersion.getVersion().getVersionString(); - @Deprecated - @LauncherAPI - public static final String BUILD = String.valueOf(LauncherVersion.readBuildNumber()); - //Начиная с 4.0.0 PROTOCOL_MAGIC изменит свою форму @LauncherAPI public static ModulesManagerInterface modulesManager = null; @LauncherAPI @@ -44,6 +43,11 @@ public final class Launcher { public static final String API_SCRIPT_FILE = "engine/api.js"; private static final Pattern UUID_PATTERN = Pattern.compile("-", Pattern.LITERAL); + public static int MAJOR = 4; + public static int MINOR = 0; + public static int PATCH = 0; + public static int BUILD = readBuildNumber(); + public static Version.Type RELEASE = Version.Type.DEV; @LauncherAPI public static LauncherConfig getConfig() { @@ -75,15 +79,12 @@ public static URL getResourceURL(String name) throws IOException { return url; } - @LauncherAPI - @SuppressWarnings({"SameReturnValue", "MethodReturnAlwaysConstant"}) - public static String getVersion() { - return LauncherVersion.getVersion().toString(); // Because Java constants are known at compile-time - } - @LauncherAPI public static String toHash(UUID uuid) { return UUID_PATTERN.matcher(uuid.toString()).replaceAll(""); } + public static Version getVersion() { + return new Version(MAJOR,MINOR,PATCH,BUILD,RELEASE); + } } diff --git a/libLauncher/src/main/java/ru/gravit/launcher/modules/Module.java b/libLauncher/src/main/java/ru/gravit/launcher/modules/Module.java index 51c5f960..65ace3db 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/modules/Module.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/modules/Module.java @@ -1,12 +1,12 @@ package ru.gravit.launcher.modules; -import ru.gravit.launcher.LauncherVersion; +import ru.gravit.utils.Version; public interface Module extends AutoCloseable { String getName(); - LauncherVersion getVersion(); + Version getVersion(); int getPriority(); void init(ModuleContext context); diff --git a/libLauncher/src/main/java/ru/gravit/launcher/modules/SimpleModuleManager.java b/libLauncher/src/main/java/ru/gravit/launcher/modules/SimpleModuleManager.java index aa040385..85f99666 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/modules/SimpleModuleManager.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/modules/SimpleModuleManager.java @@ -1,7 +1,7 @@ package ru.gravit.launcher.modules; import ru.gravit.launcher.LauncherAPI; -import ru.gravit.launcher.LauncherClassLoader; +import ru.gravit.utils.PublicURLClassLoader; import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.LogHelper; @@ -36,7 +36,7 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO } } public ArrayList modules; - public LauncherClassLoader classloader; + public PublicURLClassLoader classloader; protected ModuleContext context; @LauncherAPI diff --git a/libLauncher/src/main/java/ru/gravit/launcher/modules/TestClientModule.java b/libLauncher/src/main/java/ru/gravit/launcher/modules/TestClientModule.java index 7968f68b..dc416b96 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/modules/TestClientModule.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/modules/TestClientModule.java @@ -1,7 +1,8 @@ package ru.gravit.launcher.modules; -import ru.gravit.launcher.LauncherVersion; +import ru.gravit.launcher.Launcher; +import ru.gravit.utils.Version; public class TestClientModule implements Module { @Override @@ -15,8 +16,8 @@ public String getName() { } @Override - public LauncherVersion getVersion() { - return LauncherVersion.getVersion(); + public Version getVersion() { + return Launcher.getVersion(); } @Override diff --git a/libLauncher/src/main/java/ru/gravit/launcher/transformers/SystemClassLoaderTransformer.java b/libLauncher/src/main/java/ru/gravit/launcher/transformers/SystemClassLoaderTransformer.java index ab2bd602..d0ffd92f 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/transformers/SystemClassLoaderTransformer.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/transformers/SystemClassLoaderTransformer.java @@ -11,7 +11,7 @@ import javassist.CtConstructor; import javassist.CtMethod; import javassist.LoaderClassPath; -import ru.gravit.launcher.LauncherClassLoader; +import ru.gravit.utils.PublicURLClassLoader; public class SystemClassLoaderTransformer implements ClassFileTransformer { @Override @@ -24,11 +24,11 @@ public byte[] transform(ClassLoader classLoader, String classname, Class aCla if(classname.startsWith("jdk/")) return bytes; try { ClassPool pool = ClassPool.getDefault(); - pool.appendClassPath(new LoaderClassPath(LauncherClassLoader.systemclassloader)); + pool.appendClassPath(new LoaderClassPath(PublicURLClassLoader.systemclassloader)); pool.appendClassPath(new LoaderClassPath(classLoader)); CtClass s1 = pool.get("java.lang.ClassLoader"); CtMethod m11 = s1.getDeclaredMethod("getSystemClassLoader"); // Находим метод, который нам нужно заменить - CtClass s2 = pool.get(LauncherClassLoader.class.getName()); + CtClass s2 = pool.get(PublicURLClassLoader.class.getName()); CtMethod m21 = s2.getDeclaredMethod("getSystemClassLoader"); // Находим метод, на который мы будем заменять CodeConverter cc = new CodeConverter(); cc.redirectMethodCall(m11, m21); // Указываем что на что нам нужно заменить diff --git a/libLauncher/src/main/java/ru/gravit/launcher/LauncherClassLoader.java b/libLauncher/src/main/java/ru/gravit/utils/PublicURLClassLoader.java similarity index 91% rename from libLauncher/src/main/java/ru/gravit/launcher/LauncherClassLoader.java rename to libLauncher/src/main/java/ru/gravit/utils/PublicURLClassLoader.java index 3bbd16d4..ad220655 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/LauncherClassLoader.java +++ b/libLauncher/src/main/java/ru/gravit/utils/PublicURLClassLoader.java @@ -1,17 +1,17 @@ -package ru.gravit.launcher; +package ru.gravit.utils; import java.net.URL; import java.net.URLClassLoader; +import ru.gravit.launcher.LauncherAPI; import ru.gravit.utils.helper.LogHelper; -public class LauncherClassLoader extends URLClassLoader { +public class PublicURLClassLoader extends URLClassLoader { @LauncherAPI public static ClassLoader systemclassloader = ClassLoader.getSystemClassLoader(); @LauncherAPI public static ClassLoader getSystemClassLoader() { - LogHelper.debug("Used FAKECLASSLOADER!!!!!!!!!"); return systemclassloader; } @@ -35,7 +35,7 @@ public static ClassLoader getSystemClassLoader() * @throws NullPointerException if {@code urls} is {@code null}. * @see SecurityManager#checkCreateClassLoader */ - public LauncherClassLoader(URL[] urls) { + public PublicURLClassLoader(URL[] urls) { super(urls); } /** @@ -59,7 +59,7 @@ public LauncherClassLoader(URL[] urls) { * @throws NullPointerException if {@code urls} is {@code null}. * @see SecurityManager#checkCreateClassLoader */ - public LauncherClassLoader(URL[] urls, ClassLoader parent) { + public PublicURLClassLoader(URL[] urls, ClassLoader parent) { super(urls, parent); } @Override diff --git a/libLauncher/src/main/java/ru/gravit/launcher/LauncherVersion.java b/libLauncher/src/main/java/ru/gravit/utils/Version.java similarity index 69% rename from libLauncher/src/main/java/ru/gravit/launcher/LauncherVersion.java rename to libLauncher/src/main/java/ru/gravit/utils/Version.java index 153e4f84..184ca218 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/LauncherVersion.java +++ b/libLauncher/src/main/java/ru/gravit/utils/Version.java @@ -1,51 +1,38 @@ -package ru.gravit.launcher; +package ru.gravit.utils; -import java.io.IOException; import java.util.Objects; -import ru.gravit.utils.helper.IOHelper; +import ru.gravit.launcher.LauncherAPI; -public class LauncherVersion { - public static int MAJOR = 4; - public static int MINOR = 0; - public static int PATCH = 0; - public static int BUILD = readBuildNumber(); - public static Type RELEASE = Type.DEV; - - public static LauncherVersion getVersion() { - return new LauncherVersion(MAJOR,MINOR,PATCH,BUILD,RELEASE); - } - static int readBuildNumber() { - try { - return Integer.valueOf(IOHelper.request(IOHelper.getResourceURL("buildnumber"))); - } catch (IOException ignored) { - return 0; // Maybe dev env? - } - } +public class Version { + @LauncherAPI public final int major; + @LauncherAPI public final int minor; - + @LauncherAPI public final int patch; - + @LauncherAPI public final int build; + @LauncherAPI public final Type release; - - public LauncherVersion(int major, int minor, int patch) { + @LauncherAPI + public Version(int major, int minor, int patch) { this.major = major; this.minor = minor; this.patch = patch; build = 0; release = Type.UNKNOWN; } - - public LauncherVersion(int major, int minor, int patch,int build) { + @LauncherAPI + public Version(int major, int minor, int patch, int build) { this.major = major; this.minor = minor; this.patch = patch; this.build = build; release = Type.UNKNOWN; } - public LauncherVersion(int major, int minor, int patch,int build,Type release) { + @LauncherAPI + public Version(int major, int minor, int patch, int build, Type release) { this.major = major; this.minor = minor; this.patch = patch; @@ -54,24 +41,27 @@ public LauncherVersion(int major, int minor, int patch,int build,Type release) { } @Override + @LauncherAPI public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; - LauncherVersion that = (LauncherVersion) o; + Version that = (Version) o; return major == that.major && minor == that.minor && patch == that.patch && build == that.build; } - + @LauncherAPI public String getVersionString() { return String.format("%d.%d.%d", major, minor, patch); } @Override + @LauncherAPI public int hashCode() { return Objects.hash(major, minor, patch, build); } + @LauncherAPI public String getReleaseStatus() { String result; @@ -104,9 +94,11 @@ public String getReleaseStatus() return result; } @Override + @LauncherAPI public String toString() { return String.format("%d.%d.%d-%d %s", major, minor, patch, build,getReleaseStatus()); } + @LauncherAPI public enum Type { LTS, diff --git a/libLauncher/src/main/java/ru/gravit/utils/helper/CommonHelper.java b/libLauncher/src/main/java/ru/gravit/utils/helper/CommonHelper.java index c924fd71..1afe84d9 100644 --- a/libLauncher/src/main/java/ru/gravit/utils/helper/CommonHelper.java +++ b/libLauncher/src/main/java/ru/gravit/utils/helper/CommonHelper.java @@ -9,7 +9,6 @@ import javax.script.ScriptEngineManager; import ru.gravit.launcher.LauncherAPI; -import ru.gravit.launcher.LauncherVersion; public final class CommonHelper { @LauncherAPI diff --git a/libLauncher/src/main/java/ru/gravit/utils/helper/LogHelper.java b/libLauncher/src/main/java/ru/gravit/utils/helper/LogHelper.java index 591c30b6..ed277c6b 100644 --- a/libLauncher/src/main/java/ru/gravit/utils/helper/LogHelper.java +++ b/libLauncher/src/main/java/ru/gravit/utils/helper/LogHelper.java @@ -20,8 +20,8 @@ import org.fusesource.jansi.AnsiConsole; import org.fusesource.jansi.AnsiOutputStream; +import ru.gravit.launcher.Launcher; import ru.gravit.launcher.LauncherAPI; -import ru.gravit.launcher.LauncherVersion; public final class LogHelper { @LauncherAPI @@ -234,8 +234,8 @@ private static String ansiFormatVersion(String product) { return new Ansi().bold(). // Setup fgBright(Color.MAGENTA).a("sashok724's "). // sashok724's fgBright(Color.CYAN).a(product). // Product - fgBright(Color.WHITE).a(" v").fgBright(Color.BLUE).a(LauncherVersion.getVersion().toString()). // Version - fgBright(Color.WHITE).a(" (build #").fgBright(Color.RED).a(LauncherVersion.getVersion().build).fgBright(Color.WHITE).a(')'). // Build# + fgBright(Color.WHITE).a(" v").fgBright(Color.BLUE).a(Launcher.getVersion().toString()). // Version + fgBright(Color.WHITE).a(" (build #").fgBright(Color.RED).a(Launcher.getVersion().build).fgBright(Color.WHITE).a(')'). // Build# reset().toString(); // To string } @@ -247,7 +247,7 @@ private static String formatLog(Level level, String message, String dateTime, bo } private static String formatVersion(String product) { - return String.format("sashok724's %s v%s", product, LauncherVersion.getVersion().toString()); + return String.format("sashok724's %s v%s", product, Launcher.getVersion().toString()); } static {