BuildContext

This commit is contained in:
Gravit 2018-09-19 20:14:50 +07:00
parent 4bdf6a2cbf
commit 75cc2156a0
7 changed files with 63 additions and 19 deletions

View file

@ -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();
}
}
}

View file

@ -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<String, byte[]> outputM1 = new HashMap<>();
server.buildHookManager.preHook(outputM1);
for (Entry<String, byte[]> 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<String, byte[]> 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);
}

View file

@ -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<String, byte[]> output);
void build(BuildContext context);
}
@FunctionalInterface
public interface PreBuildHook
{
void build(Map<String, byte[]> 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<String, byte[]> 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<String, byte[]> 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)
{

View file

@ -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;
}
}

View file

@ -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;
}
}

View file

@ -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;
}
}

View file

@ -5,4 +5,5 @@ enum Type {
SERVER,CLIENT,LAUNCHSERVER
}
Type getType();
ModulesManagerInterface getModulesManager();
}