Move LauncherVersion and LauncherClassLoader

This commit is contained in:
Gravit 2018-09-22 21:22:39 +07:00
parent d14564f54e
commit 78766d0c5c
19 changed files with 88 additions and 94 deletions

View file

@ -29,8 +29,8 @@
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import java.util.zip.CRC32; import java.util.zip.CRC32;
import ru.gravit.launcher.Launcher;
import ru.gravit.launcher.LauncherAPI; import ru.gravit.launcher.LauncherAPI;
import ru.gravit.launcher.LauncherVersion;
import ru.gravit.launcher.hasher.HashedDir; import ru.gravit.launcher.hasher.HashedDir;
import ru.gravit.utils.helper.CommonHelper; import ru.gravit.utils.helper.CommonHelper;
import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.IOHelper;
@ -196,9 +196,9 @@ private ExeConf(BlockConfigEntry block) {
trademarks = block.hasEntry("trademarks") ? block.getEntryValue("trademarks", StringConfigEntry.class) trademarks = block.hasEntry("trademarks") ? block.getEntryValue("trademarks", StringConfigEntry.class)
: "This product is licensed under MIT License"; : "This product is licensed under MIT License";
txtFileVersion = block.hasEntry("txtFileVersion") ? block.getEntryValue("txtFileVersion", StringConfigEntry.class) 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) 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<Path> { private final class ProfilesFileVisitor extends SimpleFileVisitor<Path> {

View file

@ -3,9 +3,8 @@
import java.io.IOException; import java.io.IOException;
import java.nio.file.Path; import java.nio.file.Path;
import ru.gravit.launcher.Launcher;
import ru.gravit.launcher.LauncherAPI; 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.IOHelper;
import ru.gravit.utils.helper.LogHelper; import ru.gravit.utils.helper.LogHelper;
import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.LaunchServer;
@ -114,8 +113,8 @@ private void setConfig() {
// Return prepared config // Return prepared config
ConfigPersister.getInstance().setAntConfig(config, null); ConfigPersister.getInstance().setAntConfig(config, null);
} }
private static String VERSION = LauncherVersion.getVersion().getVersionString(); private static String VERSION = Launcher.getVersion().getVersionString();
private static int BUILD = LauncherVersion.getVersion().build; private static int BUILD = Launcher.getVersion().build;
public static String formatVars(String mask) public static String formatVars(String mask)
{ {
return String.format(mask, VERSION, BUILD); return String.format(mask, VERSION, BUILD);

View file

@ -1,6 +1,6 @@
package ru.gravit.launchserver.command.basic; 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.utils.helper.LogHelper;
import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.LaunchServer;
import ru.gravit.launchserver.command.Command; import ru.gravit.launchserver.command.Command;
@ -22,6 +22,6 @@ public String getUsageDescription() {
@Override @Override
public void invoke(String... args) { 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);
} }
} }

View file

@ -3,7 +3,7 @@
import java.net.URL; import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import ru.gravit.launcher.LauncherClassLoader; import ru.gravit.utils.PublicURLClassLoader;
import ru.gravit.launcher.modules.SimpleModuleManager; import ru.gravit.launcher.modules.SimpleModuleManager;
import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.LaunchServer;
import ru.gravit.launchserver.modules.CoreModule; import ru.gravit.launchserver.modules.CoreModule;
@ -12,7 +12,7 @@
public class ModulesManager extends SimpleModuleManager { public class ModulesManager extends SimpleModuleManager {
public ModulesManager(LaunchServer lsrv) { public ModulesManager(LaunchServer lsrv) {
modules = new ArrayList<>(1); 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); context = new LaunchServerModuleContext(lsrv, classloader);
} }
private void registerCoreModule() { private void registerCoreModule() {

View file

@ -1,6 +1,7 @@
package ru.gravit.launchserver.modules; 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.Module;
import ru.gravit.launcher.modules.ModuleContext; import ru.gravit.launcher.modules.ModuleContext;
@ -16,8 +17,8 @@ public String getName() {
} }
@Override @Override
public LauncherVersion getVersion() { public Version getVersion() {
return LauncherVersion.getVersion(); return Launcher.getVersion();
} }
@Override @Override

View file

@ -1,14 +1,14 @@
package ru.gravit.launchserver.modules; 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.ModuleContext;
import ru.gravit.launcher.modules.ModulesManagerInterface; import ru.gravit.launcher.modules.ModulesManagerInterface;
import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.LaunchServer;
public class LaunchServerModuleContext implements ModuleContext { public class LaunchServerModuleContext implements ModuleContext {
public final LaunchServer launchServer; public final LaunchServer launchServer;
public final LauncherClassLoader classloader; public final PublicURLClassLoader classloader;
public LaunchServerModuleContext(LaunchServer server, LauncherClassLoader classloader) public LaunchServerModuleContext(LaunchServer server, PublicURLClassLoader classloader)
{ {
launchServer = server; launchServer = server;
this.classloader = classloader; this.classloader = classloader;

View file

@ -1,6 +1,6 @@
package ru.gravit.launchserver.modules; 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.Module;
import ru.gravit.launcher.modules.ModuleContext; import ru.gravit.launcher.modules.ModuleContext;
@ -16,8 +16,8 @@ public String getName() {
} }
@Override @Override
public LauncherVersion getVersion() { public Version getVersion() {
return new LauncherVersion(1,0,0,0, LauncherVersion.Type.UNKNOWN); return new Version(1,0,0,0, Version.Type.UNKNOWN);
} }
@Override @Override

View file

@ -33,6 +33,7 @@
import ru.gravit.launcher.hasher.DirWatcher; import ru.gravit.launcher.hasher.DirWatcher;
import ru.gravit.launcher.hasher.FileNameMatcher; import ru.gravit.launcher.hasher.FileNameMatcher;
import ru.gravit.launcher.hasher.HashedDir; import ru.gravit.launcher.hasher.HashedDir;
import ru.gravit.utils.PublicURLClassLoader;
import ru.gravit.utils.helper.CommonHelper; import ru.gravit.utils.helper.CommonHelper;
import ru.gravit.utils.helper.EnvHelper; import ru.gravit.utils.helper.EnvHelper;
import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.IOHelper;
@ -161,7 +162,7 @@ public void write(HOutput output) throws IOException {
// Constants // Constants
private static final Path NATIVES_DIR = IOHelper.toPath("natives"); private static final Path NATIVES_DIR = IOHelper.toPath("natives");
private static final Path RESOURCEPACKS_DIR = IOHelper.toPath("resourcepacks"); private static final Path RESOURCEPACKS_DIR = IOHelper.toPath("resourcepacks");
private static LauncherClassLoader classLoader; private static PublicURLClassLoader classLoader;
// Authlib constants // Authlib constants
@LauncherAPI @LauncherAPI
public static final String SKIN_URL_PROPERTY = "skinURL"; public static final String SKIN_URL_PROPERTY = "skinURL";
@ -222,7 +223,7 @@ private static void addClientArgs(Collection<String> args, ClientProfile profile
Collections.addAll(args, "--assetsDir", params.assetDir.toString()); Collections.addAll(args, "--assetsDir", params.assetDir.toString());
Collections.addAll(args, "--resourcePackDir", params.clientDir.resolve(RESOURCEPACKS_DIR).toString()); Collections.addAll(args, "--resourcePackDir", params.clientDir.resolve(RESOURCEPACKS_DIR).toString());
if (version.compareTo(ClientProfile.Version.MC194) >= 0) 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 // Add server args
if (params.autoEnter) { if (params.autoEnter) {
@ -451,9 +452,9 @@ public static void main(String... args) throws Throwable {
LauncherAgent.addJVMClassPath(classpathURL.toAbsolutePath().toString()); LauncherAgent.addJVMClassPath(classpathURL.toAbsolutePath().toString());
} }
URL[] classpathurls = resolveClassPath(params.clientDir, profile.object.getClassPath()); URL[] classpathurls = resolveClassPath(params.clientDir, profile.object.getClassPath());
classLoader = new LauncherClassLoader(classpathurls, ClassLoader.getSystemClassLoader()); classLoader = new PublicURLClassLoader(classpathurls, ClassLoader.getSystemClassLoader());
Thread.currentThread().setContextClassLoader(classLoader); Thread.currentThread().setContextClassLoader(classLoader);
LauncherClassLoader.systemclassloader = classLoader; PublicURLClassLoader.systemclassloader = classLoader;
// Start client with WatchService monitoring // Start client with WatchService monitoring
boolean digest = !profile.object.isUpdateFastCheck(); boolean digest = !profile.object.isUpdateFastCheck();
LogHelper.debug("Starting JVM and client WatchService"); LogHelper.debug("Starting JVM and client WatchService");

View file

@ -3,13 +3,13 @@
import java.net.URL; import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import ru.gravit.launcher.LauncherClassLoader; import ru.gravit.utils.PublicURLClassLoader;
import ru.gravit.launcher.modules.SimpleModuleManager; import ru.gravit.launcher.modules.SimpleModuleManager;
public class ModulesManager extends SimpleModuleManager { public class ModulesManager extends SimpleModuleManager {
public ModulesManager(ServerWrapper wrapper) { public ModulesManager(ServerWrapper wrapper) {
modules = new ArrayList<>(); modules = new ArrayList<>();
classloader = new LauncherClassLoader(new URL[0], ClassLoader.getSystemClassLoader()); classloader = new PublicURLClassLoader(new URL[0], ClassLoader.getSystemClassLoader());
context = new ServerModuleContext(wrapper, classloader); context = new ServerModuleContext(wrapper, classloader);
} }
} }

View file

@ -1,15 +1,15 @@
package ru.gravit.launcher.server; package ru.gravit.launcher.server;
import ru.gravit.launcher.Launcher; 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.ModuleContext;
import ru.gravit.launcher.modules.ModulesManagerInterface; import ru.gravit.launcher.modules.ModulesManagerInterface;
public class ServerModuleContext implements ModuleContext { public class ServerModuleContext implements ModuleContext {
public final LauncherClassLoader classLoader; public final PublicURLClassLoader classLoader;
public final ServerWrapper wrapper; public final ServerWrapper wrapper;
public ServerModuleContext(ServerWrapper wrapper, LauncherClassLoader classLoader) { public ServerModuleContext(ServerWrapper wrapper, PublicURLClassLoader classLoader) {
this.classLoader = classLoader; this.classLoader = classLoader;
this.wrapper = wrapper; this.wrapper = wrapper;
} }

View file

@ -9,23 +9,22 @@
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import ru.gravit.utils.Version;
import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.IOHelper;
import ru.gravit.utils.helper.SecurityHelper; import ru.gravit.utils.helper.SecurityHelper;
import ru.gravit.launcher.modules.ModulesManagerInterface; import ru.gravit.launcher.modules.ModulesManagerInterface;
import ru.gravit.launcher.serialize.HInput; import ru.gravit.launcher.serialize.HInput;
public final class Launcher { 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<LauncherConfig> CONFIG = new AtomicReference<>(); private static final AtomicReference<LauncherConfig> 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 @LauncherAPI
public static ModulesManagerInterface modulesManager = null; public static ModulesManagerInterface modulesManager = null;
@LauncherAPI @LauncherAPI
@ -44,6 +43,11 @@ public final class Launcher {
public static final String API_SCRIPT_FILE = "engine/api.js"; public static final String API_SCRIPT_FILE = "engine/api.js";
private static final Pattern UUID_PATTERN = Pattern.compile("-", Pattern.LITERAL); 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 @LauncherAPI
public static LauncherConfig getConfig() { public static LauncherConfig getConfig() {
@ -75,15 +79,12 @@ public static URL getResourceURL(String name) throws IOException {
return url; return url;
} }
@LauncherAPI
@SuppressWarnings({"SameReturnValue", "MethodReturnAlwaysConstant"})
public static String getVersion() {
return LauncherVersion.getVersion().toString(); // Because Java constants are known at compile-time
}
@LauncherAPI @LauncherAPI
public static String toHash(UUID uuid) { public static String toHash(UUID uuid) {
return UUID_PATTERN.matcher(uuid.toString()).replaceAll(""); return UUID_PATTERN.matcher(uuid.toString()).replaceAll("");
} }
public static Version getVersion() {
return new Version(MAJOR,MINOR,PATCH,BUILD,RELEASE);
}
} }

View file

@ -1,12 +1,12 @@
package ru.gravit.launcher.modules; package ru.gravit.launcher.modules;
import ru.gravit.launcher.LauncherVersion; import ru.gravit.utils.Version;
public interface Module extends AutoCloseable { public interface Module extends AutoCloseable {
String getName(); String getName();
LauncherVersion getVersion(); Version getVersion();
int getPriority(); int getPriority();
void init(ModuleContext context); void init(ModuleContext context);

View file

@ -1,7 +1,7 @@
package ru.gravit.launcher.modules; package ru.gravit.launcher.modules;
import ru.gravit.launcher.LauncherAPI; 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.IOHelper;
import ru.gravit.utils.helper.LogHelper; import ru.gravit.utils.helper.LogHelper;
@ -36,7 +36,7 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
} }
} }
public ArrayList<Module> modules; public ArrayList<Module> modules;
public LauncherClassLoader classloader; public PublicURLClassLoader classloader;
protected ModuleContext context; protected ModuleContext context;
@LauncherAPI @LauncherAPI

View file

@ -1,7 +1,8 @@
package ru.gravit.launcher.modules; 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 { public class TestClientModule implements Module {
@Override @Override
@ -15,8 +16,8 @@ public String getName() {
} }
@Override @Override
public LauncherVersion getVersion() { public Version getVersion() {
return LauncherVersion.getVersion(); return Launcher.getVersion();
} }
@Override @Override

View file

@ -11,7 +11,7 @@
import javassist.CtConstructor; import javassist.CtConstructor;
import javassist.CtMethod; import javassist.CtMethod;
import javassist.LoaderClassPath; import javassist.LoaderClassPath;
import ru.gravit.launcher.LauncherClassLoader; import ru.gravit.utils.PublicURLClassLoader;
public class SystemClassLoaderTransformer implements ClassFileTransformer { public class SystemClassLoaderTransformer implements ClassFileTransformer {
@Override @Override
@ -24,11 +24,11 @@ public byte[] transform(ClassLoader classLoader, String classname, Class<?> aCla
if(classname.startsWith("jdk/")) return bytes; if(classname.startsWith("jdk/")) return bytes;
try { try {
ClassPool pool = ClassPool.getDefault(); ClassPool pool = ClassPool.getDefault();
pool.appendClassPath(new LoaderClassPath(LauncherClassLoader.systemclassloader)); pool.appendClassPath(new LoaderClassPath(PublicURLClassLoader.systemclassloader));
pool.appendClassPath(new LoaderClassPath(classLoader)); pool.appendClassPath(new LoaderClassPath(classLoader));
CtClass s1 = pool.get("java.lang.ClassLoader"); CtClass s1 = pool.get("java.lang.ClassLoader");
CtMethod m11 = s1.getDeclaredMethod("getSystemClassLoader"); // Находим метод, который нам нужно заменить CtMethod m11 = s1.getDeclaredMethod("getSystemClassLoader"); // Находим метод, который нам нужно заменить
CtClass s2 = pool.get(LauncherClassLoader.class.getName()); CtClass s2 = pool.get(PublicURLClassLoader.class.getName());
CtMethod m21 = s2.getDeclaredMethod("getSystemClassLoader"); // Находим метод, на который мы будем заменять CtMethod m21 = s2.getDeclaredMethod("getSystemClassLoader"); // Находим метод, на который мы будем заменять
CodeConverter cc = new CodeConverter(); CodeConverter cc = new CodeConverter();
cc.redirectMethodCall(m11, m21); // Указываем что на что нам нужно заменить cc.redirectMethodCall(m11, m21); // Указываем что на что нам нужно заменить

View file

@ -1,17 +1,17 @@
package ru.gravit.launcher; package ru.gravit.utils;
import java.net.URL; import java.net.URL;
import java.net.URLClassLoader; import java.net.URLClassLoader;
import ru.gravit.launcher.LauncherAPI;
import ru.gravit.utils.helper.LogHelper; import ru.gravit.utils.helper.LogHelper;
public class LauncherClassLoader extends URLClassLoader { public class PublicURLClassLoader extends URLClassLoader {
@LauncherAPI @LauncherAPI
public static ClassLoader systemclassloader = ClassLoader.getSystemClassLoader(); public static ClassLoader systemclassloader = ClassLoader.getSystemClassLoader();
@LauncherAPI @LauncherAPI
public static ClassLoader getSystemClassLoader() public static ClassLoader getSystemClassLoader()
{ {
LogHelper.debug("Used FAKECLASSLOADER!!!!!!!!!");
return systemclassloader; return systemclassloader;
} }
@ -35,7 +35,7 @@ public static ClassLoader getSystemClassLoader()
* @throws NullPointerException if {@code urls} is {@code null}. * @throws NullPointerException if {@code urls} is {@code null}.
* @see SecurityManager#checkCreateClassLoader * @see SecurityManager#checkCreateClassLoader
*/ */
public LauncherClassLoader(URL[] urls) { public PublicURLClassLoader(URL[] urls) {
super(urls); super(urls);
} }
/** /**
@ -59,7 +59,7 @@ public LauncherClassLoader(URL[] urls) {
* @throws NullPointerException if {@code urls} is {@code null}. * @throws NullPointerException if {@code urls} is {@code null}.
* @see SecurityManager#checkCreateClassLoader * @see SecurityManager#checkCreateClassLoader
*/ */
public LauncherClassLoader(URL[] urls, ClassLoader parent) { public PublicURLClassLoader(URL[] urls, ClassLoader parent) {
super(urls, parent); super(urls, parent);
} }
@Override @Override

View file

@ -1,51 +1,38 @@
package ru.gravit.launcher; package ru.gravit.utils;
import java.io.IOException;
import java.util.Objects; import java.util.Objects;
import ru.gravit.utils.helper.IOHelper; import ru.gravit.launcher.LauncherAPI;
public class LauncherVersion { public class Version {
public static int MAJOR = 4; @LauncherAPI
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 final int major; public final int major;
@LauncherAPI
public final int minor; public final int minor;
@LauncherAPI
public final int patch; public final int patch;
@LauncherAPI
public final int build; public final int build;
@LauncherAPI
public final Type release; public final Type release;
@LauncherAPI
public LauncherVersion(int major, int minor, int patch) { public Version(int major, int minor, int patch) {
this.major = major; this.major = major;
this.minor = minor; this.minor = minor;
this.patch = patch; this.patch = patch;
build = 0; build = 0;
release = Type.UNKNOWN; release = Type.UNKNOWN;
} }
@LauncherAPI
public LauncherVersion(int major, int minor, int patch,int build) { public Version(int major, int minor, int patch, int build) {
this.major = major; this.major = major;
this.minor = minor; this.minor = minor;
this.patch = patch; this.patch = patch;
this.build = build; this.build = build;
release = Type.UNKNOWN; 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.major = major;
this.minor = minor; this.minor = minor;
this.patch = patch; this.patch = patch;
@ -54,24 +41,27 @@ public LauncherVersion(int major, int minor, int patch,int build,Type release) {
} }
@Override @Override
@LauncherAPI
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false; if (o == null || getClass() != o.getClass()) return false;
LauncherVersion that = (LauncherVersion) o; Version that = (Version) o;
return major == that.major && return major == that.major &&
minor == that.minor && minor == that.minor &&
patch == that.patch && patch == that.patch &&
build == that.build; build == that.build;
} }
@LauncherAPI
public String getVersionString() { public String getVersionString() {
return String.format("%d.%d.%d", major, minor, patch); return String.format("%d.%d.%d", major, minor, patch);
} }
@Override @Override
@LauncherAPI
public int hashCode() { public int hashCode() {
return Objects.hash(major, minor, patch, build); return Objects.hash(major, minor, patch, build);
} }
@LauncherAPI
public String getReleaseStatus() public String getReleaseStatus()
{ {
String result; String result;
@ -104,9 +94,11 @@ public String getReleaseStatus()
return result; return result;
} }
@Override @Override
@LauncherAPI
public String toString() { public String toString() {
return String.format("%d.%d.%d-%d %s", major, minor, patch, build,getReleaseStatus()); return String.format("%d.%d.%d-%d %s", major, minor, patch, build,getReleaseStatus());
} }
@LauncherAPI
public enum Type public enum Type
{ {
LTS, LTS,

View file

@ -9,7 +9,6 @@
import javax.script.ScriptEngineManager; import javax.script.ScriptEngineManager;
import ru.gravit.launcher.LauncherAPI; import ru.gravit.launcher.LauncherAPI;
import ru.gravit.launcher.LauncherVersion;
public final class CommonHelper { public final class CommonHelper {
@LauncherAPI @LauncherAPI

View file

@ -20,8 +20,8 @@
import org.fusesource.jansi.AnsiConsole; import org.fusesource.jansi.AnsiConsole;
import org.fusesource.jansi.AnsiOutputStream; import org.fusesource.jansi.AnsiOutputStream;
import ru.gravit.launcher.Launcher;
import ru.gravit.launcher.LauncherAPI; import ru.gravit.launcher.LauncherAPI;
import ru.gravit.launcher.LauncherVersion;
public final class LogHelper { public final class LogHelper {
@LauncherAPI @LauncherAPI
@ -234,8 +234,8 @@ private static String ansiFormatVersion(String product) {
return new Ansi().bold(). // Setup return new Ansi().bold(). // Setup
fgBright(Color.MAGENTA).a("sashok724's "). // sashok724's fgBright(Color.MAGENTA).a("sashok724's "). // sashok724's
fgBright(Color.CYAN).a(product). // Product fgBright(Color.CYAN).a(product). // Product
fgBright(Color.WHITE).a(" v").fgBright(Color.BLUE).a(LauncherVersion.getVersion().toString()). // Version fgBright(Color.WHITE).a(" v").fgBright(Color.BLUE).a(Launcher.getVersion().toString()). // Version
fgBright(Color.WHITE).a(" (build #").fgBright(Color.RED).a(LauncherVersion.getVersion().build).fgBright(Color.WHITE).a(')'). // Build# fgBright(Color.WHITE).a(" (build #").fgBright(Color.RED).a(Launcher.getVersion().build).fgBright(Color.WHITE).a(')'). // Build#
reset().toString(); // To string 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) { 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 { static {