Commands fixes.

This commit is contained in:
zaxar163 2018-12-17 19:22:04 +03:00 committed by Gravit
parent 52213d7c55
commit 1aba7624a1
3 changed files with 17 additions and 1 deletions

View file

@ -59,6 +59,7 @@ public void invoke(String... args) throws IOException, CommandException {
} }
client.setTitle(dirName); client.setTitle(dirName);
client.block.getEntry("dir", StringConfigEntry.class).setValue(dirName); client.block.getEntry("dir", StringConfigEntry.class).setValue(dirName);
client.block.getEntry("title", StringConfigEntry.class).setValue(dirName);
try (BufferedWriter writer = IOHelper.newWriter(IOHelper.resolveIncremental(server.profilesDir, try (BufferedWriter writer = IOHelper.newWriter(IOHelper.resolveIncremental(server.profilesDir,
dirName, "cfg"))) { dirName, "cfg"))) {
TextConfigWriter.write(client.block, writer, true); TextConfigWriter.write(client.block, writer, true);

View file

@ -25,6 +25,6 @@ public String getUsageDescription() {
public void invoke(String... args) throws Exception { public void invoke(String... args) throws Exception {
verifyArgs(args, 1); verifyArgs(args, 1);
URI uri = Paths.get(args[0]).toUri(); URI uri = Paths.get(args[0]).toUri();
server.modulesManager.loadModule(uri.toURL(), false); server.modulesManager.loadModuleFull(uri.toURL());
} }
} }

View file

@ -105,6 +105,21 @@ public void loadModule(URL jarpath, boolean preload) throws ClassNotFoundExcepti
f.close(); 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();
}
@Override @Override
public void loadModule(URL jarpath, String classname, boolean preload) throws ClassNotFoundException, IllegalAccessException, InstantiationException { public void loadModule(URL jarpath, String classname, boolean preload) throws ClassNotFoundException, IllegalAccessException, InstantiationException {