mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-12-22 16:41:46 +03:00
BuildContext
This commit is contained in:
parent
4bdf6a2cbf
commit
75cc2156a0
7 changed files with 63 additions and 19 deletions
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -130,13 +130,8 @@ private void signBuild() throws IOException {
|
||||||
private void stdBuild() throws IOException {
|
private void stdBuild() throws IOException {
|
||||||
try (ZipOutputStream output = new ZipOutputStream(IOHelper.newOutput(binaryFile));
|
try (ZipOutputStream output = new ZipOutputStream(IOHelper.newOutput(binaryFile));
|
||||||
JAConfigurator jaConfigurator = new JAConfigurator(AutogenConfig.class)) {
|
JAConfigurator jaConfigurator = new JAConfigurator(AutogenConfig.class)) {
|
||||||
Map<String, byte[]> outputM1 = new HashMap<>();
|
BuildContext context = new BuildContext(output, jaConfigurator);
|
||||||
server.buildHookManager.preHook(outputM1);
|
server.buildHookManager.preHook(context);
|
||||||
for (Entry<String, byte[]> e : outputM1.entrySet()) {
|
|
||||||
output.putNextEntry(newZipEntry(e.getKey()));
|
|
||||||
output.write(e.getValue());
|
|
||||||
}
|
|
||||||
outputM1.clear();
|
|
||||||
jaConfigurator.setAddress(server.config.getAddress());
|
jaConfigurator.setAddress(server.config.getAddress());
|
||||||
jaConfigurator.setPort(server.config.port);
|
jaConfigurator.setPort(server.config.port);
|
||||||
server.buildHookManager.registerAllClientModuleClass(jaConfigurator);
|
server.buildHookManager.registerAllClientModuleClass(jaConfigurator);
|
||||||
|
@ -204,12 +199,7 @@ private void stdBuild() throws IOException {
|
||||||
ZipEntry e = newZipEntry(jaConfigurator.getZipEntryPath());
|
ZipEntry e = newZipEntry(jaConfigurator.getZipEntryPath());
|
||||||
output.putNextEntry(e);
|
output.putNextEntry(e);
|
||||||
output.write(jaConfigurator.getBytecode());
|
output.write(jaConfigurator.getBytecode());
|
||||||
server.buildHookManager.postHook(outputM1);
|
server.buildHookManager.postHook(context);
|
||||||
for (Entry<String, byte[]> e1 : outputM1.entrySet()) {
|
|
||||||
output.putNextEntry(newZipEntry(e1.getKey()));
|
|
||||||
output.write(e1.getValue());
|
|
||||||
}
|
|
||||||
outputM1.clear();
|
|
||||||
} catch (CannotCompileException | NotFoundException e) {
|
} catch (CannotCompileException | NotFoundException e) {
|
||||||
LogHelper.error(e);
|
LogHelper.error(e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,18 +7,19 @@
|
||||||
|
|
||||||
import ru.gravit.launcher.AutogenConfig;
|
import ru.gravit.launcher.AutogenConfig;
|
||||||
import ru.gravit.launcher.modules.TestClientModule;
|
import ru.gravit.launcher.modules.TestClientModule;
|
||||||
|
import ru.gravit.launchserver.binary.BuildContext;
|
||||||
import ru.gravit.launchserver.binary.JAConfigurator;
|
import ru.gravit.launchserver.binary.JAConfigurator;
|
||||||
|
|
||||||
public class BuildHookManager {
|
public class BuildHookManager {
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface PostBuildHook
|
public interface PostBuildHook
|
||||||
{
|
{
|
||||||
void build(Map<String, byte[]> output);
|
void build(BuildContext context);
|
||||||
}
|
}
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface PreBuildHook
|
public interface PreBuildHook
|
||||||
{
|
{
|
||||||
void build(Map<String, byte[]> output);
|
void build(BuildContext context);
|
||||||
}
|
}
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface Transformer
|
public interface Transformer
|
||||||
|
@ -69,13 +70,13 @@ public boolean isContainsBlacklist(String clazz)
|
||||||
{
|
{
|
||||||
return CLASS_BLACKLIST.contains(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)
|
public void registerAllClientModuleClass(JAConfigurator cfg)
|
||||||
{
|
{
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
import ru.gravit.launcher.LauncherClassLoader;
|
import ru.gravit.launcher.LauncherClassLoader;
|
||||||
import ru.gravit.launcher.modules.ModuleContext;
|
import ru.gravit.launcher.modules.ModuleContext;
|
||||||
|
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 {
|
||||||
|
@ -16,4 +17,9 @@ public LaunchServerModuleContext(LaunchServer server, LauncherClassLoader classl
|
||||||
public Type getType() {
|
public Type getType() {
|
||||||
return Type.LAUNCHSERVER;
|
return Type.LAUNCHSERVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ModulesManagerInterface getModulesManager() {
|
||||||
|
return launchServer.modulesManager;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package ru.gravit.launcher.client;
|
package ru.gravit.launcher.client;
|
||||||
|
|
||||||
|
import ru.gravit.launcher.Launcher;
|
||||||
import ru.gravit.launcher.LauncherEngine;
|
import ru.gravit.launcher.LauncherEngine;
|
||||||
import ru.gravit.launcher.modules.ModuleContext;
|
import ru.gravit.launcher.modules.ModuleContext;
|
||||||
|
import ru.gravit.launcher.modules.ModulesManagerInterface;
|
||||||
|
|
||||||
public class ClientModuleContext implements ModuleContext {
|
public class ClientModuleContext implements ModuleContext {
|
||||||
public final LauncherEngine engine;
|
public final LauncherEngine engine;
|
||||||
|
@ -13,4 +15,9 @@ public class ClientModuleContext implements ModuleContext {
|
||||||
public Type getType() {
|
public Type getType() {
|
||||||
return Type.CLIENT;
|
return Type.CLIENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ModulesManagerInterface getModulesManager() {
|
||||||
|
return Launcher.modulesManager;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package ru.gravit.launcher.server;
|
package ru.gravit.launcher.server;
|
||||||
|
|
||||||
|
import ru.gravit.launcher.Launcher;
|
||||||
import ru.gravit.launcher.LauncherClassLoader;
|
import ru.gravit.launcher.LauncherClassLoader;
|
||||||
import ru.gravit.launcher.modules.ModuleContext;
|
import ru.gravit.launcher.modules.ModuleContext;
|
||||||
|
import ru.gravit.launcher.modules.ModulesManagerInterface;
|
||||||
|
|
||||||
public class ServerModuleContext implements ModuleContext {
|
public class ServerModuleContext implements ModuleContext {
|
||||||
public final LauncherClassLoader classLoader;
|
public final LauncherClassLoader classLoader;
|
||||||
|
@ -16,4 +18,9 @@ public ServerModuleContext(ServerWrapper wrapper, LauncherClassLoader classLoade
|
||||||
public Type getType() {
|
public Type getType() {
|
||||||
return Type.SERVER;
|
return Type.SERVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ModulesManagerInterface getModulesManager() {
|
||||||
|
return Launcher.modulesManager;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,4 +5,5 @@ enum Type {
|
||||||
SERVER,CLIENT,LAUNCHSERVER
|
SERVER,CLIENT,LAUNCHSERVER
|
||||||
}
|
}
|
||||||
Type getType();
|
Type getType();
|
||||||
|
ModulesManagerInterface getModulesManager();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue