Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use log4j2 and slf4j properly, add maven-dependency plugin #149

Merged
merged 1 commit into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 43 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
<maven.compiler.release>17</maven.compiler.release>

<fabric8.version>6.13.1</fabric8.version>
<log4j.version>2.17.2</log4j.version>
<log4j.version>2.23.1</log4j.version>
<slf4j.version>2.0.13</slf4j.version>

<!-- TEST dependencies -->
Expand All @@ -85,6 +85,7 @@
<spotbugs.version>4.8.6</spotbugs.version>
<maven.spotbugs.version>4.8.6.2</maven.spotbugs.version>
<maven.checkstyle.version>3.4.0</maven.checkstyle.version>
<maven.dependency.version>3.3.0</maven.dependency.version>

<maven.compile.plugin.version>3.13.0</maven.compile.plugin.version>
<maven.source.plugin.version>3.3.1</maven.source.plugin.version>
Expand Down Expand Up @@ -189,7 +190,7 @@
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<artifactId>log4j-slf4j2-impl</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
Expand Down Expand Up @@ -292,6 +293,45 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>${maven.dependency.version}</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>none</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<includeScope>runtime</includeScope>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<prependGroupId>true</prependGroupId>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
<execution>
<id>set-classpath</id>
<phase>none</phase>
<goals>
<goal>build-classpath</goal>
</goals>
<configuration>
<includeScope>runtime</includeScope>
<outputProperty>project.dist.classpath</outputProperty>
<attach>false</attach>
<prefix>lib</prefix>
<prependGroupId>true</prependGroupId>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-source-plugin</artifactId>
<version>${maven.source.plugin.version}</version>
Expand Down Expand Up @@ -474,4 +514,4 @@
</build>
</profile>
</profiles>
</project>
</project>
59 changes: 54 additions & 5 deletions test-frame-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,28 @@
</dependency>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>openshift-client</artifactId>
<artifactId>kubernetes-model-core</artifactId>
</dependency>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-client</artifactId>
<artifactId>kubernetes-model-extensions</artifactId>
</dependency>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-model</artifactId>
<artifactId>kubernetes-model-apps</artifactId>
</dependency>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>openshift-model-operatorhub</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-commons</artifactId>
</dependency>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-server-mock</artifactId>
Expand All @@ -94,18 +102,59 @@
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</dependency>
<!-- Logger -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<artifactId>log4j-slf4j2-impl</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>${maven.dependency.version}</version>
<executions>
<execution>
<id>analyze</id>
<goals>
<goal>analyze-only</goal>
</goals>
<configuration>
<failOnWarning>true</failOnWarning>
<ignoredUnusedDeclaredDependencies>
<!-- Needed for logging in tests used by test-frame (uses SLF4J) -->
<ignoredUnusedDeclaredDependency>org.apache.logging.log4j:log4j-slf4j2-impl</ignoredUnusedDeclaredDependency>
</ignoredUnusedDeclaredDependencies>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@
import io.skodjob.testframe.TestFrameConstants;
import io.skodjob.testframe.TestFrameEnv;
import io.skodjob.testframe.executor.Exec;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Provides functionality to interact with Kubernetes and OpenShift clusters.
* This includes creating clients, reading resources from files, and managing kubeconfig for authentication.
*/
public class KubeClient {
private static final Logger LOGGER = LogManager.getLogger(KubeClient.class);
private static final Logger LOGGER = LoggerFactory.getLogger(KubeClient.class);


private KubernetesClient client;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import io.skodjob.testframe.clients.KubeClusterException;
import io.skodjob.testframe.executor.Exec;
import io.skodjob.testframe.executor.ExecResult;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static java.lang.String.join;
import static java.util.Arrays.asList;
Expand All @@ -32,7 +32,7 @@
*/
public abstract class BaseCmdKubeClient<K extends BaseCmdKubeClient<K>> implements KubeCmdClient<K> {

private static final Logger LOGGER = LogManager.getLogger(BaseCmdKubeClient.class);
private static final Logger LOGGER = LoggerFactory.getLogger(BaseCmdKubeClient.class);

private static final String CREATE = "create";
private static final String APPLY = "apply";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import io.skodjob.testframe.utils.LoggerUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.IOException;
Expand All @@ -28,7 +28,7 @@
*/
public class TestEnvironmentVariables {

private static final Logger LOGGER = LogManager.getLogger(TestEnvironmentVariables.class);
private static final Logger LOGGER = LoggerFactory.getLogger(TestEnvironmentVariables.class);

/* test */ private final Map<String, String> envMap;
private Map<String, String> values = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@

import io.fabric8.kubernetes.api.model.EnvVar;
import io.skodjob.testframe.clients.KubeClusterException;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static java.lang.String.join;

Expand All @@ -40,7 +40,7 @@
*/
public class Exec {

private static final Logger LOGGER = LogManager.getLogger(Exec.class);
private static final Logger LOGGER = LoggerFactory.getLogger(Exec.class);

private static final Pattern ERROR_PATTERN = Pattern.compile("Error from server \\(([a-zA-Z0-9]+)\\):");
private static final Pattern INVALID_PATTERN = Pattern
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
package io.skodjob.testframe.listeners;

import io.skodjob.testframe.utils.LoggerUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.jupiter.api.extension.AfterEachCallback;
import org.junit.jupiter.api.extension.BeforeEachCallback;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* jUnit5 specific class which listening on test callbacks
*/
public class TestVisualSeparatorExtension implements BeforeEachCallback, AfterEachCallback {
private final Logger logger = LogManager.getLogger(TestVisualSeparatorExtension.class);
private final Logger logger = LoggerFactory.getLogger(TestVisualSeparatorExtension.class);

private TestVisualSeparatorExtension() {
// Private constructor to prevent instantiation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
import io.skodjob.testframe.interfaces.NamespacedResourceType;
import io.skodjob.testframe.interfaces.ResourceType;
import io.skodjob.testframe.wait.Wait;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.event.Level;

import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
Expand All @@ -45,7 +45,7 @@
* Manages Kubernetes resources for testing purposes.
*/
public class KubeResourceManager {
private static final Logger LOGGER = LogManager.getLogger(KubeResourceManager.class);
private static final Logger LOGGER = LoggerFactory.getLogger(KubeResourceManager.class);

private static KubeResourceManager instance;
private static KubeClient client;
Expand Down Expand Up @@ -197,12 +197,12 @@ public final <T extends HasMetadata> void pushToStack(T resource) {
/**
* Logs all managed resources across all test contexts with set log level
*
* @param logLevel log4j2 log level
* @param logLevel slf4j log level event
*/
public void printAllResources(Level logLevel) {
LOGGER.log(logLevel, "Printing all managed resources from all test contexts");
LOGGER.atLevel(logLevel).log("Printing all managed resources from all test contexts");
STORED_RESOURCES.forEach((testName, resources) -> {
LOGGER.log(logLevel, "Context: {}", testName);
LOGGER.atLevel(logLevel).log("Context: {}", testName);
resources.forEach(resourceItem -> {
if (resourceItem.resource() != null) {
LoggerUtils.logResource("Managed resource:", logLevel, resourceItem.resource());
Expand All @@ -214,10 +214,10 @@ public void printAllResources(Level logLevel) {
/**
* Logs all managed resources in current test context with set log level
*
* @param logLevel log4j2 log level
* @param logLevel slf4j log level event
*/
public void printCurrentResources(Level logLevel) {
LOGGER.log(logLevel, "Printing all managed resources from current test context");
LOGGER.atLevel(logLevel).log("Printing all managed resources from current test context");
STORED_RESOURCES.get(getTestContext().getDisplayName()).forEach(resourceItem -> {
if (resourceItem.resource() != null) {
LoggerUtils.logResource("Managed resource:", logLevel, resourceItem.resource());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*/
package io.skodjob.testframe.utils;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand All @@ -14,7 +14,7 @@
* Class containing methods for handling images
*/
public final class ImageUtils {
private static final Logger LOGGER = LogManager.getLogger(ImageUtils.class);
private static final Logger LOGGER = LoggerFactory.getLogger(ImageUtils.class);

private ImageUtils() {
// Private constructor to prevent instantiation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
import io.skodjob.testframe.TestFrameConstants;
import io.skodjob.testframe.resources.KubeResourceManager;
import io.skodjob.testframe.wait.Wait;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Utility methods for Kubernetes and Openshift clusters.
*/
public final class KubeUtils {

private static final Logger LOGGER = LogManager.getLogger(KubeUtils.class);
private static final Logger LOGGER = LoggerFactory.getLogger(KubeUtils.class);

private KubeUtils() {
// Private constructor to prevent instantiation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
import java.util.Collections;

import io.fabric8.kubernetes.api.model.HasMetadata;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.event.Level;

/**
* Utility methods for logging.
*/
public final class LoggerUtils {

private static final Logger LOGGER = LogManager.getLogger(LoggerUtils.class);
private static final Logger LOGGER = LoggerFactory.getLogger(LoggerUtils.class);
static final String SEPARATOR_CHAR = "#";

/**
Expand Down Expand Up @@ -71,11 +71,11 @@ public static <T extends HasMetadata> void logResource(String operation, T resou
*/
public static <T extends HasMetadata> void logResource(String operation, Level logLevel, T resource) {
if (resource.getMetadata().getNamespace() == null) {
LOGGER.log(logLevel, LoggerUtils.RESOURCE_LOGGER_PATTERN,
LOGGER.atLevel(logLevel).log(LoggerUtils.RESOURCE_LOGGER_PATTERN,
operation, resource.getKind(),
resource.getMetadata().getName());
} else {
LOGGER.log(logLevel, LoggerUtils.RESOURCE_WITH_NAMESPACE_LOGGER_PATTERN,
LOGGER.atLevel(logLevel).log(LoggerUtils.RESOURCE_WITH_NAMESPACE_LOGGER_PATTERN,
operation,
resource.getKind(), resource.getMetadata().getName(), resource.getMetadata().getNamespace());
}
Expand Down
Loading
Loading