From bb288eab6b7ad8be514acc7dcb24ecd68074735c Mon Sep 17 00:00:00 2001 From: Avgustin Marinov Date: Wed, 17 Jul 2024 15:48:24 +0300 Subject: [PATCH] Remove guava dependency (#1776) Signed-off-by: Marinov Avgustin --- .../hawkbit-repository-api/pom.xml | 5 ++ ...gementMethodPreAuthorizeAnnotatedTest.java | 31 ++++++------ hawkbit-rest/hawkbit-ddi-api/pom.xml | 5 ++ .../JsonIgnorePropertiesAnnotationTest.java | 47 ++++++++++-------- .../mgmt/json/model/MgmtPollStatus.java | 2 - pom.xml | 48 +++++-------------- 6 files changed, 62 insertions(+), 76 deletions(-) diff --git a/hawkbit-repository/hawkbit-repository-api/pom.xml b/hawkbit-repository/hawkbit-repository-api/pom.xml index ee322f4d7..6bfbee10f 100644 --- a/hawkbit-repository/hawkbit-repository-api/pom.xml +++ b/hawkbit-repository/hawkbit-repository-api/pom.xml @@ -78,6 +78,11 @@ + + io.github.classgraph + classgraph + test + io.qameta.allure allure-junit5 diff --git a/hawkbit-repository/hawkbit-repository-api/src/test/java/org/eclipse/hawkbit/repository/RepositoryManagementMethodPreAuthorizeAnnotatedTest.java b/hawkbit-repository/hawkbit-repository-api/src/test/java/org/eclipse/hawkbit/repository/RepositoryManagementMethodPreAuthorizeAnnotatedTest.java index e5ac71040..5ea105fe5 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/test/java/org/eclipse/hawkbit/repository/RepositoryManagementMethodPreAuthorizeAnnotatedTest.java +++ b/hawkbit-repository/hawkbit-repository-api/src/test/java/org/eclipse/hawkbit/repository/RepositoryManagementMethodPreAuthorizeAnnotatedTest.java @@ -11,16 +11,15 @@ package org.eclipse.hawkbit.repository; import static org.assertj.core.api.Assertions.assertThat; -import java.io.IOException; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.HashSet; import java.util.List; import java.util.Set; -import java.util.regex.Pattern; -import java.util.stream.Collectors; -import com.google.common.reflect.ClassPath; +import io.github.classgraph.ClassGraph; +import io.github.classgraph.ClassInfo; +import io.github.classgraph.ScanResult; import org.junit.jupiter.api.Test; import org.springframework.security.access.prepost.PreAuthorize; @@ -40,13 +39,17 @@ public class RepositoryManagementMethodPreAuthorizeAnnotatedTest { @Test @Description("Verifies that repository methods are @PreAuthorize annotated") - public void repositoryManagementMethodsArePreAuthorizedAnnotated() throws IOException { - final List> findInterfacesInPackage = findInterfacesInPackage(getClass().getPackage(), - Pattern.compile(".*Management")); - - assertThat(findInterfacesInPackage).isNotEmpty(); - for (final Class interfaceToCheck : findInterfacesInPackage) { - assertDeclaredMethodsContainsPreAuthorizeAnnotations(interfaceToCheck); + public void repositoryManagementMethodsArePreAuthorizedAnnotated() { + final String packageName = getClass().getPackage().getName(); + try (final ScanResult scanResult = new ClassGraph().acceptPackages(packageName).scan()) { + final List> matchingClasses = scanResult.getAllClasses() + .stream() + .filter(classInPackage -> classInPackage.getSimpleName().endsWith("Management") && classInPackage.isInterface()) + .map(ClassInfo::loadClass) + .toList(); + assertThat(matchingClasses).isNotEmpty(); + matchingClasses.forEach( + RepositoryManagementMethodPreAuthorizeAnnotatedTest::assertDeclaredMethodsContainsPreAuthorizeAnnotations); } // all exclusion should be used, otherwise the method exclusion should be @@ -78,12 +81,6 @@ public class RepositoryManagementMethodPreAuthorizeAnnotatedTest { } } - private List> findInterfacesInPackage(final Package p, final Pattern includeFilter) throws IOException { - return ClassPath.from(Thread.currentThread().getContextClassLoader()).getTopLevelClasses(p.getName()).stream() - .filter(clazzInfo -> includeFilter.matcher(clazzInfo.getSimpleName()).matches()) - .map(clazzInfo -> clazzInfo.load()).filter(clazz -> clazz.isInterface()).collect(Collectors.toList()); - } - private static Method getMethod(final Class clazz, final String methodName, final Class... parameterTypes) { try { return clazz.getMethod(methodName, parameterTypes); diff --git a/hawkbit-rest/hawkbit-ddi-api/pom.xml b/hawkbit-rest/hawkbit-ddi-api/pom.xml index 306245f4c..baa4d6e76 100644 --- a/hawkbit-rest/hawkbit-ddi-api/pom.xml +++ b/hawkbit-rest/hawkbit-ddi-api/pom.xml @@ -54,6 +54,11 @@ spring-boot-starter-test test + + io.github.classgraph + classgraph + test + org.assertj assertj-core diff --git a/hawkbit-rest/hawkbit-ddi-api/src/test/java/org/eclipse/hawkbit/ddi/json/model/JsonIgnorePropertiesAnnotationTest.java b/hawkbit-rest/hawkbit-ddi-api/src/test/java/org/eclipse/hawkbit/ddi/json/model/JsonIgnorePropertiesAnnotationTest.java index 700cb873e..9be307497 100644 --- a/hawkbit-rest/hawkbit-ddi-api/src/test/java/org/eclipse/hawkbit/ddi/json/model/JsonIgnorePropertiesAnnotationTest.java +++ b/hawkbit-rest/hawkbit-ddi-api/src/test/java/org/eclipse/hawkbit/ddi/json/model/JsonIgnorePropertiesAnnotationTest.java @@ -12,18 +12,19 @@ package org.eclipse.hawkbit.ddi.json.model; import static org.assertj.core.api.Assertions.assertThat; -import java.io.IOException; -import java.util.Set; - +import io.github.classgraph.ClassGraph; +import io.github.classgraph.ClassInfo; +import io.github.classgraph.ScanResult; import org.junit.jupiter.api.Test; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.google.common.reflect.ClassPath; import io.qameta.allure.Description; import io.qameta.allure.Feature; import io.qameta.allure.Story; +import java.util.List; + /** * Check DDI api model classes for '@JsonIgnoreProperties' annotation */ @@ -33,23 +34,27 @@ public class JsonIgnorePropertiesAnnotationTest { @Test @Description("This test verifies that all model classes within the 'org.eclipse.hawkbit.ddi.json.model' package are annotated with '@JsonIgnoreProperties(ignoreUnknown = true)'") - public void shouldCheckAnnotationsForAllModelClasses() throws IOException { - final ClassLoader loader = Thread.currentThread().getContextClassLoader(); - final String packageName = this.getClass().getPackage().getName(); + public void shouldCheckAnnotationsForAllModelClasses() { + final String packageName = getClass().getPackage().getName(); + try (final ScanResult scanResult = new ClassGraph().acceptPackages(packageName).scan()) { + final List> matchingClasses = scanResult.getAllClasses() + .stream() + .filter(classInPackage -> classInPackage.getSimpleName().endsWith("Test") || classInPackage.isEnum()) + .map(ClassInfo::loadClass) + .toList(); - final Set topLevelClasses = ClassPath.from(loader) - .getTopLevelClasses(packageName); - for (final ClassPath.ClassInfo classInfo : topLevelClasses) { - final Class modelClass = classInfo.load(); - if (modelClass.getSimpleName().contains("Test") || modelClass.isEnum()) { - continue; - } - final JsonIgnoreProperties annotation = modelClass.getAnnotation(JsonIgnoreProperties.class); - assertThat(annotation) - .describedAs( - "Annotation 'JsonIgnoreProperties' is missing for class: " + modelClass.getSimpleName()) - .isNotNull(); - assertThat(annotation.ignoreUnknown()).isTrue(); + assertThat(matchingClasses).isNotEmpty(); + matchingClasses.forEach(modelClass -> { + if (modelClass.getSimpleName().contains("Test") || modelClass.isEnum()) { + return; + } + final JsonIgnoreProperties annotation = modelClass.getAnnotation(JsonIgnoreProperties.class); + assertThat(annotation) + .describedAs( + "Annotation 'JsonIgnoreProperties' is missing for class: " + modelClass.getSimpleName()) + .isNotNull(); + assertThat(annotation.ignoreUnknown()).isTrue(); + }); } } -} +} \ No newline at end of file diff --git a/hawkbit-rest/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/json/model/MgmtPollStatus.java b/hawkbit-rest/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/json/model/MgmtPollStatus.java index 34da3ff30..2d4de8b1a 100644 --- a/hawkbit-rest/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/json/model/MgmtPollStatus.java +++ b/hawkbit-rest/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/json/model/MgmtPollStatus.java @@ -18,8 +18,6 @@ import lombok.Data; import lombok.ToString; import lombok.experimental.Accessors; -import static org.checkerframework.checker.units.qual.Prefix.exa; - /** * A json annotated rest model for PollStatus to RESTful API representation. */ diff --git a/pom.xml b/pom.xml index d891d8f54..3aa25c53a 100644 --- a/pom.xml +++ b/pom.xml @@ -60,12 +60,12 @@ 2.3.1 3.0.0 2.1.0 - 33.2.1-jre 2.16.1 4.4 1.8.0 5.2.0 + 4.8.174 2.27.0 4.2.1 @@ -765,10 +765,12 @@ commons-collections4 ${commons-collections4.version} + + - io.qameta.allure - allure-junit5 - ${allure.version} + io.github.classgraph + classgraph + ${classgraph.version} test @@ -783,6 +785,12 @@ ${spring-amqp.version} test + + io.qameta.allure + allure-junit5 + ${allure.version} + test + org.awaitility awaitility @@ -797,37 +805,5 @@ lombok true - - com.google.guava - guava - ${guava.version} - - - - com.google.j2objc - j2objc-annotations - - - com.google.code.findbugs - jsr305 - - - org.checkerframework - checker-compat-qual - - - com.google.errorprone - error_prone_annotations - - - com.google.j2objc - j2objc-annotations - - - org.codehaus.mojo - animal-sniffer-annotations - - -