added Logging for InteractionChecks
Some checks failed
github-mirror / push-github (push) Successful in 4s
Build / Gradle-Build (push) Successful in 33s
Test / Gradle-Test (push) Failing after 40s

This commit is contained in:
Tueem 2024-12-19 21:07:42 +01:00
parent 7249c99b69
commit 404f221ccf
Signed by: tueem
GPG Key ID: F2CE0513D231AD7A
2 changed files with 15 additions and 2 deletions

View File

@ -5,9 +5,14 @@ import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.Arrays; import java.util.Arrays;
import org.apache.logging.log4j.Logger;
import net.tomatentum.marinara.util.LoggerUtil;
import net.tomatentum.marinara.util.ReflectionUtil; import net.tomatentum.marinara.util.ReflectionUtil;
public record AppliedCheck(InteractionCheck<?> check, Annotation annotation) { public record AppliedCheck(InteractionCheck<?> check, Annotation annotation) {
private static Logger logger = LoggerUtil.getLogger(AppliedCheck.class);
public boolean pre(Object context) { public boolean pre(Object context) {
Method[] methods = Arrays.stream(check.getClass().getMethods()) Method[] methods = Arrays.stream(check.getClass().getMethods())
@ -17,9 +22,10 @@ public record AppliedCheck(InteractionCheck<?> check, Annotation annotation) {
Method method = ReflectionUtil.getMostSpecificMethod(methods, context.getClass(), annotation.annotationType()); Method method = ReflectionUtil.getMostSpecificMethod(methods, context.getClass(), annotation.annotationType());
method.setAccessible(true); method.setAccessible(true);
try { try {
logger.debug("Executing pre check {} with context {}", check.getClass().getName(), context.toString());
return (boolean) method.invoke(check, context, annotation); return (boolean) method.invoke(check, context, annotation);
} catch (IllegalAccessException | InvocationTargetException | SecurityException e) { } catch (IllegalAccessException | InvocationTargetException | SecurityException e) {
e.printStackTrace(); logger.fatal(e);
return false; return false;
} }
} }
@ -32,9 +38,10 @@ public record AppliedCheck(InteractionCheck<?> check, Annotation annotation) {
Method method = ReflectionUtil.getMostSpecificMethod(methods, context.getClass(), annotation.annotationType()); Method method = ReflectionUtil.getMostSpecificMethod(methods, context.getClass(), annotation.annotationType());
method.setAccessible(true); method.setAccessible(true);
try { try {
logger.debug("Executing pre check {} with context {}", check.getClass().getName(), context.toString());
method.invoke(check, context, annotation); method.invoke(check, context, annotation);
} catch (IllegalAccessException | InvocationTargetException | SecurityException e) { } catch (IllegalAccessException | InvocationTargetException | SecurityException e) {
e.printStackTrace(); logger.fatal(e);
} }
} }

View File

@ -6,19 +6,25 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import org.apache.logging.log4j.Logger;
import io.leangen.geantyref.GenericTypeReflector; import io.leangen.geantyref.GenericTypeReflector;
import net.tomatentum.marinara.checks.InteractionCheck; import net.tomatentum.marinara.checks.InteractionCheck;
import net.tomatentum.marinara.util.LoggerUtil;
public class InteractionCheckRegistry { public class InteractionCheckRegistry {
private List<InteractionCheck<?>> checks; private List<InteractionCheck<?>> checks;
private Logger logger = LoggerUtil.getLogger(getClass());
public InteractionCheckRegistry() { public InteractionCheckRegistry() {
this.checks = new ArrayList<>(); this.checks = new ArrayList<>();
} }
public void addCheck(InteractionCheck<?> check) { public void addCheck(InteractionCheck<?> check) {
checks.add(check); checks.add(check);
logger.info("Registered Check {}", check.getClass().getName());
} }
public Optional<InteractionCheck<?>> getCheckFromAnnotation(Type annotation) { public Optional<InteractionCheck<?>> getCheckFromAnnotation(Type annotation) {