From 1bf46b1a4ac4b19bafb591f56810133bfa313b88 Mon Sep 17 00:00:00 2001 From: Siphalor Date: Sat, 2 Nov 2024 21:48:05 +0100 Subject: [PATCH] [*] Logging via SLF4J --- build.gradle.kts | 31 ++++++++++++-- gradle.properties | 3 ++ .../impl/weaving/PojoClassIntrospector.java | 42 ++++++++++++++++--- 3 files changed, 68 insertions(+), 8 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index ebee5e2..f163643 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,13 +1,18 @@ plugins { id("java") + id("maven-publish") } -group = "de.siphalor" -version = "1.0-SNAPSHOT" +group = "de.siphalor.tweed5" +version = properties["version"]!! allprojects { apply(plugin = "java") apply(plugin = "java-library") + apply(plugin = "maven-publish") + + group = rootProject.group + version = properties["version"]!! java { sourceCompatibility = JavaVersion.VERSION_1_8 @@ -18,7 +23,12 @@ allprojects { mavenCentral() } - dependencies { + val localRuntimeOnly = configurations.create("localRuntimeOnly") + sourceSets.main.get().runtimeClasspath += localRuntimeOnly + + sourceSets.test.get().runtimeClasspath += sourceSets.main.get().runtimeClasspath + + dependencies { val lombok = "org.projectlombok:lombok:${properties["lombok.version"]}" compileOnly(lombok) annotationProcessor(lombok) @@ -34,6 +44,9 @@ allprojects { implementation("org.jetbrains:annotations:${properties["jetbrains_annotations.version"]}") + implementation("org.slf4j:slf4j-api:${properties["slf4j.version"]}") + localRuntimeOnly("org.slf4j:slf4j-simple:${properties["slf4j.version"]}") + testImplementation(platform("org.junit:junit-bom:${properties["junit.version"]}")) testImplementation("org.junit.jupiter:junit-jupiter") testImplementation("org.mockito:mockito-core:${properties["mockito.version"]}") @@ -48,4 +61,16 @@ allprojects { "junit.jupiter.execution.timeout.thread.mode.default" to "SEPARATE_THREAD", ) } + + publishing { + publications { + create("maven") { + groupId = project.group.toString() + artifactId = project.name + version = project.version.toString() + + from(components["java"]) + } + } + } } diff --git a/gradle.properties b/gradle.properties index c9c1735..e04b261 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,7 +1,10 @@ +version = 0.1.0 + asm.version = 9.7 jetbrains_annotations.version = 26.0.1 lombok.version = 1.18.34 auto_service.version = 1.1.1 +slf4j.version = 2.0.16 junit.version = 5.11.2 mockito.version = 5.14.2 diff --git a/tweed5-weaver-pojo/src/main/java/de/siphalor/tweed5/weaver/pojo/impl/weaving/PojoClassIntrospector.java b/tweed5-weaver-pojo/src/main/java/de/siphalor/tweed5/weaver/pojo/impl/weaving/PojoClassIntrospector.java index 1960312..c7df317 100644 --- a/tweed5-weaver-pojo/src/main/java/de/siphalor/tweed5/weaver/pojo/impl/weaving/PojoClassIntrospector.java +++ b/tweed5-weaver-pojo/src/main/java/de/siphalor/tweed5/weaver/pojo/impl/weaving/PojoClassIntrospector.java @@ -4,6 +4,7 @@ import lombok.AccessLevel; import lombok.Builder; import lombok.RequiredArgsConstructor; import lombok.Value; +import lombok.extern.slf4j.Slf4j; import org.jetbrains.annotations.Nullable; import java.lang.invoke.MethodHandle; @@ -16,6 +17,7 @@ import java.util.Collections; import java.util.HashMap; import java.util.Map; +@Slf4j @RequiredArgsConstructor(access = AccessLevel.PRIVATE) public class PojoClassIntrospector { private final Class clazz; @@ -67,11 +69,23 @@ public class PojoClassIntrospector { Property property = introspectProperty(field); properties.put(property.field.getName(), property); } else { - // TODO: logging + Property existingProperty = properties.get(field.getName()); + log.error( + "Duplicate property \"{}\" detected in hierarchy of {} in classes: {} and {}", + field.getName(), + clazz.getName(), + existingProperty.field().getDeclaringClass().getName(), + targetClass.getName() + ); } } } catch (Exception e) { - // TODO: logging + log.error( + "Got unexpected error introspecting the properties of class {} (in hierarchy of {})", + targetClass.getName(), + clazz.getName(), + e + ); } } @@ -178,7 +192,13 @@ public class PojoClassIntrospector { } catch (NoSuchMethodException e) { return null; } catch (IllegalAccessException e) { - // TODO: logging + log.warn( + "Failed to access method \"{}\" of class {} in hierarchy of {}", + methodDescriptor, + targetClass.getName(), + clazz.getName(), + e + ); return null; } } @@ -190,7 +210,13 @@ public class PojoClassIntrospector { } catch (NoSuchFieldException e) { return null; } catch (IllegalAccessException e) { - // TODO: logging + log.warn( + "Failed to access getter for field \"{}\" of class {} in hierarchy of {}", + field.getName(), + field.getDeclaringClass().getName(), + clazz.getName(), + e + ); return null; } } @@ -202,7 +228,13 @@ public class PojoClassIntrospector { } catch (NoSuchFieldException e) { return null; } catch (IllegalAccessException e) { - // TODO: logging + log.warn( + "Failed to access setter for field \"{}\" of class {} in hierarchy of {}", + field.getName(), + field.getDeclaringClass().getName(), + clazz.getName(), + e + ); return null; } }