diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/BuildContext.java b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/BuildContext.java new file mode 100644 index 00000000..c336f051 --- /dev/null +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/BuildContext.java @@ -0,0 +1,32 @@ +package ru.gravit.launchserver.binary; + +import ru.gravit.utils.helper.IOHelper; + +import java.io.IOException; +import java.io.InputStream; +import java.util.jar.JarInputStream; +import java.util.zip.ZipEntry; +import java.util.zip.ZipOutputStream; + +public class BuildContext { + public final ZipOutputStream output; + public final JAConfigurator config; + + public BuildContext(ZipOutputStream output, JAConfigurator config) { + this.output = output; + this.config = config; + } + public void pushFile(String filename,InputStream inputStream) throws IOException { + ZipEntry zip = IOHelper.newZipEntry(filename); + output.putNextEntry(zip); + IOHelper.transfer(inputStream,output); + } + public void pushJarFile(JarInputStream input) throws IOException { + ZipEntry e = input.getNextEntry(); + while (e != null) { + output.putNextEntry(e); + IOHelper.transfer(input,output); + e = input.getNextEntry(); + } + } +} diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/JARLauncherBinary.java b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/JARLauncherBinary.java index d1d81184..f366a523 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/JARLauncherBinary.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/JARLauncherBinary.java @@ -130,13 +130,8 @@ private void signBuild() throws IOException { private void stdBuild() throws IOException { try (ZipOutputStream output = new ZipOutputStream(IOHelper.newOutput(binaryFile)); JAConfigurator jaConfigurator = new JAConfigurator(AutogenConfig.class)) { - Map outputM1 = new HashMap<>(); - server.buildHookManager.preHook(outputM1); - for (Entry e : outputM1.entrySet()) { - output.putNextEntry(newZipEntry(e.getKey())); - output.write(e.getValue()); - } - outputM1.clear(); + BuildContext context = new BuildContext(output, jaConfigurator); + server.buildHookManager.preHook(context); jaConfigurator.setAddress(server.config.getAddress()); jaConfigurator.setPort(server.config.port); server.buildHookManager.registerAllClientModuleClass(jaConfigurator); @@ -204,12 +199,7 @@ private void stdBuild() throws IOException { ZipEntry e = newZipEntry(jaConfigurator.getZipEntryPath()); output.putNextEntry(e); output.write(jaConfigurator.getBytecode()); - server.buildHookManager.postHook(outputM1); - for (Entry e1 : outputM1.entrySet()) { - output.putNextEntry(newZipEntry(e1.getKey())); - output.write(e1.getValue()); - } - outputM1.clear(); + server.buildHookManager.postHook(context); } catch (CannotCompileException | NotFoundException e) { LogHelper.error(e); } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/BuildHookManager.java b/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/BuildHookManager.java index 27407137..3b0b0339 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/BuildHookManager.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/BuildHookManager.java @@ -7,18 +7,19 @@ import ru.gravit.launcher.AutogenConfig; import ru.gravit.launcher.modules.TestClientModule; +import ru.gravit.launchserver.binary.BuildContext; import ru.gravit.launchserver.binary.JAConfigurator; public class BuildHookManager { @FunctionalInterface public interface PostBuildHook { - void build(Map output); + void build(BuildContext context); } @FunctionalInterface public interface PreBuildHook { - void build(Map output); + void build(BuildContext context); } @FunctionalInterface public interface Transformer @@ -69,13 +70,13 @@ public boolean isContainsBlacklist(String clazz) { return CLASS_BLACKLIST.contains(clazz); } - public void postHook(Map output) + public void postHook(BuildContext context) { - for(PostBuildHook hook : POST_HOOKS) hook.build(output); + for(PostBuildHook hook : POST_HOOKS) hook.build(context); } - public void preHook(Map output) + public void preHook(BuildContext context) { - for(PreBuildHook hook : PRE_HOOKS) hook.build(output); + for(PreBuildHook hook : PRE_HOOKS) hook.build(context); } public void registerAllClientModuleClass(JAConfigurator cfg) { 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 330e90d2..d1162039 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/modules/LaunchServerModuleContext.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/modules/LaunchServerModuleContext.java @@ -2,6 +2,7 @@ import ru.gravit.launcher.LauncherClassLoader; import ru.gravit.launcher.modules.ModuleContext; +import ru.gravit.launcher.modules.ModulesManagerInterface; import ru.gravit.launchserver.LaunchServer; public class LaunchServerModuleContext implements ModuleContext { @@ -16,4 +17,9 @@ public LaunchServerModuleContext(LaunchServer server, LauncherClassLoader classl public Type getType() { return Type.LAUNCHSERVER; } + + @Override + public ModulesManagerInterface getModulesManager() { + return launchServer.modulesManager; + } } diff --git a/Launcher/src/main/java/ru/gravit/launcher/client/ClientModuleContext.java b/Launcher/src/main/java/ru/gravit/launcher/client/ClientModuleContext.java index 1953515c..66f17ec8 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/client/ClientModuleContext.java +++ b/Launcher/src/main/java/ru/gravit/launcher/client/ClientModuleContext.java @@ -1,7 +1,9 @@ package ru.gravit.launcher.client; +import ru.gravit.launcher.Launcher; import ru.gravit.launcher.LauncherEngine; import ru.gravit.launcher.modules.ModuleContext; +import ru.gravit.launcher.modules.ModulesManagerInterface; public class ClientModuleContext implements ModuleContext { public final LauncherEngine engine; @@ -13,4 +15,9 @@ public class ClientModuleContext implements ModuleContext { public Type getType() { return Type.CLIENT; } + + @Override + public ModulesManagerInterface getModulesManager() { + return Launcher.modulesManager; + } } 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 e1df3b88..a112b54e 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/server/ServerModuleContext.java +++ b/Launcher/src/main/java/ru/gravit/launcher/server/ServerModuleContext.java @@ -1,7 +1,9 @@ package ru.gravit.launcher.server; +import ru.gravit.launcher.Launcher; import ru.gravit.launcher.LauncherClassLoader; import ru.gravit.launcher.modules.ModuleContext; +import ru.gravit.launcher.modules.ModulesManagerInterface; public class ServerModuleContext implements ModuleContext { public final LauncherClassLoader classLoader; @@ -16,4 +18,9 @@ public ServerModuleContext(ServerWrapper wrapper, LauncherClassLoader classLoade public Type getType() { return Type.SERVER; } + + @Override + public ModulesManagerInterface getModulesManager() { + return Launcher.modulesManager; + } } diff --git a/libLauncher/src/main/java/ru/gravit/launcher/modules/ModuleContext.java b/libLauncher/src/main/java/ru/gravit/launcher/modules/ModuleContext.java index edb55e44..e3059d89 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/modules/ModuleContext.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/modules/ModuleContext.java @@ -5,4 +5,5 @@ enum Type { SERVER,CLIENT,LAUNCHSERVER } Type getType(); + ModulesManagerInterface getModulesManager(); }