mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-12-23 00:51:01 +03:00
[FEATURE] Print launcher modules in modules
command
This commit is contained in:
parent
ae82964a24
commit
f188378fd6
3 changed files with 59 additions and 5 deletions
|
@ -1,9 +1,20 @@
|
|||
package pro.gravit.launchserver.command.modules;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import pro.gravit.launcher.LauncherTrustManager;
|
||||
import pro.gravit.launcher.modules.LauncherModule;
|
||||
import pro.gravit.launcher.modules.LauncherModuleInfo;
|
||||
import pro.gravit.launchserver.LaunchServer;
|
||||
import pro.gravit.launchserver.command.Command;
|
||||
import pro.gravit.launchserver.launchermodules.LauncherModuleLoader;
|
||||
import pro.gravit.utils.helper.LogHelper;
|
||||
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class ModulesCommand extends Command {
|
||||
private transient Logger logger = LogManager.getLogger();
|
||||
public ModulesCommand(LaunchServer server) {
|
||||
super(server);
|
||||
}
|
||||
|
@ -20,6 +31,27 @@ public String getUsageDescription() {
|
|||
|
||||
@Override
|
||||
public void invoke(String... args) {
|
||||
server.modulesManager.printModulesInfo();
|
||||
for (LauncherModule module : server.modulesManager.getModules()) {
|
||||
LauncherModuleInfo info = module.getModuleInfo();
|
||||
LauncherTrustManager.CheckClassResult checkStatus = module.getCheckResult();
|
||||
logger.info("[MODULE] {} v: {} p: {} deps: {} sig: {}", info.name, info.version.getVersionString(), info.priority, Arrays.toString(info.dependencies), checkStatus == null ? "null" : checkStatus.type);
|
||||
printCheckStatusInfo(checkStatus);
|
||||
}
|
||||
for(LauncherModuleLoader.ModuleEntity entity : server.launcherModuleLoader.launcherModules) {
|
||||
LauncherTrustManager.CheckClassResult checkStatus = entity.checkResult;
|
||||
logger.info("[LAUNCHER MODULE] {} sig: {}", entity.path.getFileName().toString(), checkStatus == null ? "null" : checkStatus.type);
|
||||
printCheckStatusInfo(checkStatus);
|
||||
}
|
||||
}
|
||||
|
||||
private void printCheckStatusInfo(LauncherTrustManager.CheckClassResult checkStatus) {
|
||||
if (checkStatus != null && checkStatus.endCertificate != null) {
|
||||
X509Certificate cert = checkStatus.endCertificate;
|
||||
logger.info("[MODULE CERT] Module signer: {}", cert.getSubjectDN().getName());
|
||||
}
|
||||
if (checkStatus != null && checkStatus.rootCertificate != null) {
|
||||
X509Certificate cert = checkStatus.rootCertificate;
|
||||
logger.info("[MODULE CERT] Module signer CA: {}", cert.getSubjectDN().getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package pro.gravit.launchserver.launchermodules;
|
||||
|
||||
import pro.gravit.launcher.Launcher;
|
||||
import pro.gravit.launcher.LauncherTrustManager;
|
||||
import pro.gravit.launcher.modules.LauncherModule;
|
||||
import pro.gravit.launchserver.LaunchServer;
|
||||
import pro.gravit.launchserver.asm.InjectClassAcceptor;
|
||||
import pro.gravit.launchserver.binary.tasks.MainBuildTask;
|
||||
|
@ -84,8 +86,9 @@ public void addClassFieldsToProperties(Map<String, Object> propertyMap, String p
|
|||
}
|
||||
}
|
||||
|
||||
static class ModuleEntity {
|
||||
public static class ModuleEntity {
|
||||
public Path path;
|
||||
public LauncherTrustManager.CheckClassResult checkResult;
|
||||
public String moduleMainClass;
|
||||
public String moduleConfigClass;
|
||||
public String moduleConfigName;
|
||||
|
@ -99,6 +102,7 @@ private ModulesVisitor() {
|
|||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
|
||||
if (file.toFile().getName().endsWith(".jar"))
|
||||
try (JarFile f = new JarFile(file.toFile())) {
|
||||
|
@ -107,9 +111,23 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
|
|||
if (mainClass == null) {
|
||||
LogHelper.error("In module %s MainClass not found", file.toString());
|
||||
} else {
|
||||
if (classLoader == null)
|
||||
classLoader = new LauncherModuleClassLoader(server.modulesManager.getModuleClassLoader());
|
||||
classLoader.addURL(file.toUri().toURL());
|
||||
ModuleEntity entity = new ModuleEntity();
|
||||
entity.path = file;
|
||||
entity.moduleMainClass = mainClass;
|
||||
try {
|
||||
Class<? extends LauncherModule> mainClazz = (Class<? extends LauncherModule>) classLoader.loadClass(entity.moduleMainClass);
|
||||
entity.checkResult = server.modulesManager.checkModuleClass(mainClazz);
|
||||
} catch (Throwable e) {
|
||||
if(e instanceof ClassNotFoundException || e instanceof NoClassDefFoundError) {
|
||||
LogHelper.error("Module-MainClass in module %s incorrect", file.toString());
|
||||
} else {
|
||||
LogHelper.error(e);
|
||||
}
|
||||
return super.visitFile(file, attrs);
|
||||
}
|
||||
entity.moduleConfigClass = attributes.getValue("Module-Config-Class");
|
||||
if (entity.moduleConfigClass != null) {
|
||||
entity.moduleConfigName = attributes.getValue("Module-Config-Name");
|
||||
|
@ -117,9 +135,6 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
|
|||
LogHelper.warning("Module-Config-Name in module %s null. Module not configured", file.toString());
|
||||
} else {
|
||||
try {
|
||||
if (classLoader == null)
|
||||
classLoader = new LauncherModuleClassLoader(server.modulesManager.getModuleClassLoader());
|
||||
classLoader.addURL(file.toUri().toURL());
|
||||
Class<?> clazz = classLoader.loadClass(entity.moduleConfigClass);
|
||||
Path configPath = server.modulesManager.getConfigManager().getModuleConfig(entity.moduleConfigName);
|
||||
Object defaultConfig = MethodHandles.publicLookup().findStatic(clazz, "getDefault", MethodType.methodType(Object.class)).invoke();
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
import java.nio.file.Path;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class LaunchServerModulesManager extends SimpleModuleManager {
|
||||
public final LaunchServerCoreModule coreModule;
|
||||
|
@ -24,6 +26,7 @@ public void fullInitializedLaunchServer(LaunchServer server) {
|
|||
initContext = new LaunchServerInitContext(server);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void printModulesInfo() {
|
||||
for (LauncherModule module : modules) {
|
||||
LauncherModuleInfo info = module.getModuleInfo();
|
||||
|
@ -40,6 +43,10 @@ public void printModulesInfo() {
|
|||
}
|
||||
}
|
||||
|
||||
public List<LauncherModule> getModules() {
|
||||
return Collections.unmodifiableList(modules);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean verifyClassCheckResult(LauncherTrustManager.CheckClassResult result) {
|
||||
return true;
|
||||
|
|
Loading…
Reference in a new issue