diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java index 5a4e2849..596cd766 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java @@ -38,7 +38,6 @@ import java.io.IOException; import java.lang.ProcessBuilder.Redirect; import java.net.InetSocketAddress; -import java.net.MalformedURLException; import java.net.SocketAddress; import java.nio.file.*; import java.nio.file.attribute.BasicFileAttributes; diff --git a/Launcher/src/main/java/ru/gravit/launcher/client/ClientModuleManager.java b/Launcher/src/main/java/ru/gravit/launcher/client/ClientModuleManager.java index f41cda42..56e0a98d 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/client/ClientModuleManager.java +++ b/Launcher/src/main/java/ru/gravit/launcher/client/ClientModuleManager.java @@ -13,12 +13,7 @@ public ClientModuleManager(LauncherEngine engine) { } @Override - public void loadModule(URL jarpath, boolean preload) { - throw new SecurityException("Custom JAR's load not allowed here"); - } - - @Override - public void loadModule(URL jarpath, String classname, boolean preload) { + public void loadModule(URL jarpath, String classname) { throw new SecurityException("Custom JAR's load not allowed here"); } } diff --git a/libLauncher/src/main/java/ru/gravit/launcher/Launcher.java b/libLauncher/src/main/java/ru/gravit/launcher/Launcher.java index fe399fbf..c6db3d48 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/Launcher.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/Launcher.java @@ -7,7 +7,6 @@ import ru.gravit.launcher.serialize.HInput; import ru.gravit.utils.Version; import ru.gravit.utils.helper.IOHelper; -import ru.gravit.utils.helper.JVMHelper; import ru.gravit.utils.helper.LogHelper; import ru.gravit.utils.helper.SecurityHelper; @@ -126,12 +125,6 @@ public static Version getVersion() { return new Version(MAJOR, MINOR, PATCH, BUILD, RELEASE); } - public static final boolean useAvanguard = true; - - public static boolean isUsingAvanguard() { - return JVMHelper.OS_TYPE == JVMHelper.OS.MUSTDIE && useAvanguard; - } - public static void applyLauncherEnv(LauncherConfig.LauncherEnvironment env) { switch (env) diff --git a/libLauncher/src/main/java/ru/gravit/launcher/LauncherAgent.java b/libLauncher/src/main/java/ru/gravit/launcher/LauncherAgent.java index 19b6794e..8c94c604 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/LauncherAgent.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/LauncherAgent.java @@ -20,10 +20,6 @@ public boolean isAgentStarted() { return isAgentStarted; } - public static long getObjSize(Object obj) { - return inst.getObjectSize(obj); - } - public static void premain(String agentArgument, Instrumentation instrumentation) { System.out.println("Launcher Agent"); inst = instrumentation; diff --git a/libLauncher/src/main/java/ru/gravit/launcher/managers/SimpleModuleManager.java b/libLauncher/src/main/java/ru/gravit/launcher/managers/SimpleModuleManager.java index 40898330..fcf9e0e1 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/managers/SimpleModuleManager.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/managers/SimpleModuleManager.java @@ -14,26 +14,20 @@ import java.nio.file.attribute.BasicFileAttributes; import java.util.ArrayList; import java.util.jar.JarFile; -import java.util.jar.Manifest; -public class SimpleModuleManager implements ModulesManagerInterface, AutoCloseable { +public class SimpleModuleManager implements ModulesManagerInterface { protected final class ModulesVisitor extends SimpleFileVisitor { private ModulesVisitor() { } @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { - try { - JarFile f = new JarFile(file.toString()); - Manifest m = f.getManifest(); - String mainclass = m.getMainAttributes().getValue("Main-Class"); - loadModule(file.toUri().toURL(), mainclass, true); - f.close(); - } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { - e.printStackTrace(); - } - - // Return result + if (file.toFile().getName().endsWith(".jar")) + try (JarFile f = new JarFile(file.toFile())) { + loadModule(file.toUri().toURL(), f.getManifest().getMainAttributes().getValue("Main-Class")); + } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { + LogHelper.error(e); + } return super.visitFile(file, attrs); } } @@ -72,7 +66,6 @@ public void close() { } @Override - public void initModules() { for (Module m : modules) { m.init(context); @@ -81,53 +74,34 @@ public void initModules() { } @Override - public void load(Module module) { modules.add(module); } - @Override - - public void load(Module module, boolean preload) { - load(module); - if (!preload) module.init(context); - } - - - @Override - - public void loadModule(URL jarpath, boolean preload) throws ClassNotFoundException, IllegalAccessException, InstantiationException, URISyntaxException, IOException { - JarFile f = new JarFile(Paths.get(jarpath.toURI()).toString()); - Manifest m = f.getManifest(); - String mainclass = m.getMainAttributes().getValue("Main-Class"); - loadModule(jarpath, mainclass, preload); - f.close(); - } - public void loadModuleFull(URL jarpath) throws ClassNotFoundException, IllegalAccessException, InstantiationException, URISyntaxException, IOException { - JarFile f = new JarFile(Paths.get(jarpath.toURI()).toString()); - Manifest m = f.getManifest(); - String mainclass = m.getMainAttributes().getValue("Main-Class"); - classloader.addURL(jarpath); - Class moduleclass = Class.forName(mainclass, true, classloader); - Module module = (Module) moduleclass.newInstance(); - modules.add(module); - module.preInit(context); - module.init(context); - module.postInit(context); - LogHelper.info("Module %s version: %s loaded", module.getName(), module.getVersion()); - f.close(); + try (JarFile f = new JarFile(Paths.get(jarpath.toURI()).toFile())) { + classloader.addURL(jarpath); + Module module = (Module) Class.forName(f.getManifest().getMainAttributes().getValue("Main-Class"), true, classloader).newInstance(); + modules.add(module); + module.preInit(context); + module.init(context); + module.postInit(context); + LogHelper.info("Module %s version: %s loaded", module.getName(), module.getVersion()); + } } - @Override + @Override + public void loadModule(URL jarpath) throws Exception { + try (JarFile f = new JarFile(Paths.get(jarpath.toURI()).toFile())) { + loadModule(jarpath, f.getManifest().getMainAttributes().getValue("Main-Class")); + } + } - public void loadModule(URL jarpath, String classname, boolean preload) throws ClassNotFoundException, IllegalAccessException, InstantiationException { + @Override + public void loadModule(URL jarpath, String classname) throws ClassNotFoundException, IllegalAccessException, InstantiationException { classloader.addURL(jarpath); - Class moduleclass = Class.forName(classname, true, classloader); - Module module = (Module) moduleclass.newInstance(); + Module module = (Module) Class.forName(classname, true, classloader).newInstance(); modules.add(module); - module.preInit(context); - if (!preload) module.init(context); LogHelper.info("Module %s version: %s loaded", module.getName(), module.getVersion()); } @@ -141,7 +115,6 @@ public void postInitModules() { @Override - public void preInitModules() { for (Module m : modules) { m.preInit(context); @@ -150,7 +123,6 @@ public void preInitModules() { } @Override - public void printModules() { for (Module m : modules) LogHelper.info("Module %s version: %s", m.getName(), m.getVersion()); @@ -158,9 +130,8 @@ public void printModules() { } @Override - - public void registerModule(Module module, boolean preload) { - load(module, preload); + public void registerModule(Module module) { + load(module); LogHelper.info("Module %s version: %s registered", module.getName(), module.getVersion()); } } diff --git a/libLauncher/src/main/java/ru/gravit/launcher/modules/ModulesManagerInterface.java b/libLauncher/src/main/java/ru/gravit/launcher/modules/ModulesManagerInterface.java index 87e7eb22..78eceb76 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/modules/ModulesManagerInterface.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/modules/ModulesManagerInterface.java @@ -2,16 +2,14 @@ import java.net.URL; -public interface ModulesManagerInterface { +public interface ModulesManagerInterface extends AutoCloseable { void initModules(); void load(Module module); - void load(Module module, boolean preload); + void loadModule(URL jarpath) throws Exception; - void loadModule(URL jarpath, boolean preload) throws Exception; - - void loadModule(URL jarpath, String classname, boolean preload) throws Exception; + void loadModule(URL jarpath, String classname) throws Exception; void postInitModules(); @@ -21,5 +19,5 @@ public interface ModulesManagerInterface { void sort(); - void registerModule(Module module, boolean preload); + void registerModule(Module module); }