Remove guava dependency (#1776)

Signed-off-by: Marinov Avgustin <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2024-07-17 15:48:24 +03:00
committed by GitHub
parent a021de5829
commit bb288eab6b
6 changed files with 62 additions and 76 deletions

View File

@@ -78,6 +78,11 @@
</dependency>
<!-- TEST -->
<dependency>
<groupId>io.github.classgraph</groupId>
<artifactId>classgraph</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-junit5</artifactId>

View File

@@ -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<Class<?>> 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<? extends Class<?>> 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<Class<?>> 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);

View File

@@ -54,6 +54,11 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.github.classgraph</groupId>
<artifactId>classgraph</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>

View File

@@ -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<? extends Class<?>> matchingClasses = scanResult.getAllClasses()
.stream()
.filter(classInPackage -> classInPackage.getSimpleName().endsWith("Test") || classInPackage.isEnum())
.map(ClassInfo::loadClass)
.toList();
final Set<ClassPath.ClassInfo> 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();
});
}
}
}
}

View File

@@ -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.
*/

48
pom.xml
View File

@@ -60,12 +60,12 @@
<jaxb-api.version>2.3.1</jaxb-api.version>
<javax.el-api.version>3.0.0</javax.el-api.version>
<rsql-parser.version>2.1.0</rsql-parser.version>
<guava.version>33.2.1-jre</guava.version>
<commons-io.version>2.16.1</commons-io.version>
<commons-collections4.version>4.4</commons-collections4.version>
<io-protostuff.version>1.8.0</io-protostuff.version>
<!-- test -->
<rabbitmq.http-client.version>5.2.0</rabbitmq.http-client.version>
<classgraph.version>4.8.174</classgraph.version>
<allure.version>2.27.0</allure.version>
<awaitility.version>4.2.1</awaitility.version>
<!-- Misc libraries versions - END -->
@@ -765,10 +765,12 @@
<artifactId>commons-collections4</artifactId>
<version>${commons-collections4.version}</version>
</dependency>
<!-- Test -->
<dependency>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-junit5</artifactId>
<version>${allure.version}</version>
<groupId>io.github.classgraph</groupId>
<artifactId>classgraph</artifactId>
<version>${classgraph.version}</version>
<scope>test</scope>
</dependency>
<dependency>
@@ -783,6 +785,12 @@
<version>${spring-amqp.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-junit5</artifactId>
<version>${allure.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
@@ -797,37 +805,5 @@
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
<!-- https://github.com/google/guava/issues/2824 -->
<exclusions>
<exclusion>
<groupId>com.google.j2objc</groupId>
<artifactId>j2objc-annotations</artifactId>
</exclusion>
<exclusion>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
</exclusion>
<exclusion>
<groupId>org.checkerframework</groupId>
<artifactId>checker-compat-qual</artifactId>
</exclusion>
<exclusion>
<groupId>com.google.errorprone</groupId>
<artifactId>error_prone_annotations</artifactId>
</exclusion>
<exclusion>
<groupId>com.google.j2objc</groupId>
<artifactId>j2objc-annotations</artifactId>
</exclusion>
<exclusion>
<groupId>org.codehaus.mojo</groupId>
<artifactId>animal-sniffer-annotations</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</project>