mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-11-15 11:39:11 +03:00
[FEATURE] Try recursive LauncherModule configuration
This commit is contained in:
parent
fb00adb129
commit
73fcf4aae4
2 changed files with 41 additions and 9 deletions
|
@ -175,6 +175,18 @@ private static InsnList serializeValue(Object value) {
|
||||||
value.getClass()));
|
value.getClass()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isSerializableValue(Object value)
|
||||||
|
{
|
||||||
|
if(value == null) return true;
|
||||||
|
if (primitiveLDCClasses.contains(value.getClass())) return true;
|
||||||
|
for (Map.Entry<Class<?>, Serializer<?>> serializerEntry : serializers.entrySet()) {
|
||||||
|
if (serializerEntry.getKey().isInstance(value)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void transform(ClassNode classNode, String className, BuildContext context) {
|
public void transform(ClassNode classNode, String className, BuildContext context) {
|
||||||
visit(classNode, values);
|
visit(classNode, values);
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
import pro.gravit.launcher.Launcher;
|
import pro.gravit.launcher.Launcher;
|
||||||
import pro.gravit.launchserver.LaunchServer;
|
import pro.gravit.launchserver.LaunchServer;
|
||||||
|
import pro.gravit.launchserver.asm.InjectClassAcceptor;
|
||||||
import pro.gravit.launchserver.binary.tasks.MainBuildTask;
|
import pro.gravit.launchserver.binary.tasks.MainBuildTask;
|
||||||
import pro.gravit.utils.helper.IOHelper;
|
import pro.gravit.utils.helper.IOHelper;
|
||||||
import pro.gravit.utils.helper.LogHelper;
|
import pro.gravit.utils.helper.LogHelper;
|
||||||
|
@ -120,15 +121,17 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
|
||||||
targetConfig = Launcher.gsonManager.configGson.fromJson(reader, clazz);
|
targetConfig = Launcher.gsonManager.configGson.fromJson(reader, clazz);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Field[] fields = clazz.getFields();
|
//Field[] fields = clazz.getFields();
|
||||||
for (Field field : fields) {
|
//for (Field field : fields) {
|
||||||
if ((field.getModifiers() & Modifier.STATIC) != 0) continue;
|
// if ((field.getModifiers() & Modifier.STATIC) != 0) continue;
|
||||||
Object obj = field.get(targetConfig);
|
// Object obj = field.get(targetConfig);
|
||||||
String configPropertyName = "modules.".concat(entity.moduleConfigName.toLowerCase()).concat(".").concat(field.getName().toLowerCase());
|
// String configPropertyName = "modules.".concat(entity.moduleConfigName.toLowerCase()).concat(".").concat(field.getName().toLowerCase());
|
||||||
|
// if (entity.propertyMap == null) entity.propertyMap = new HashMap<>();
|
||||||
|
// LogHelper.dev("Property name %s", configPropertyName);
|
||||||
|
// entity.propertyMap.put(configPropertyName, obj);
|
||||||
|
//}
|
||||||
if (entity.propertyMap == null) entity.propertyMap = new HashMap<>();
|
if (entity.propertyMap == null) entity.propertyMap = new HashMap<>();
|
||||||
LogHelper.dev("Property name %s", configPropertyName);
|
addClassFieldsToProperties(entity.propertyMap, "modules.".concat(entity.moduleConfigName.toLowerCase()), targetConfig, clazz);
|
||||||
entity.propertyMap.put(configPropertyName, obj);
|
|
||||||
}
|
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
LogHelper.error(e);
|
LogHelper.error(e);
|
||||||
}
|
}
|
||||||
|
@ -140,4 +143,21 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
|
||||||
return super.visitFile(file, attrs);
|
return super.visitFile(file, attrs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public void addClassFieldsToProperties(Map<String, Object> propertyMap, String prefix, Object object, Class<?> classOfObject) throws IllegalAccessException {
|
||||||
|
Field[] fields = classOfObject.getFields();
|
||||||
|
for (Field field : fields) {
|
||||||
|
if ((field.getModifiers() & Modifier.STATIC) != 0) continue;
|
||||||
|
Object obj = field.get(object);
|
||||||
|
String propertyName = prefix.concat(".").concat(field.getName());
|
||||||
|
if(InjectClassAcceptor.isSerializableValue(obj))
|
||||||
|
{
|
||||||
|
propertyMap.put(propertyName, obj);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//Try recursive add fields
|
||||||
|
addClassFieldsToProperties(propertyMap, propertyName, obj, obj.getClass());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue