This is an automated email from the ASF dual-hosted git repository.
vy pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/logging-log4j-samples.git
The following commit(s) were added to refs/heads/main by this push:
new dceda47 Add integration test for `log4j-samples-jlink` module (#393)
dceda47 is described below
commit dceda473f02ab4addfc88b22f4c6f407fb108ff7
Author: Ramanathan <[email protected]>
AuthorDate: Wed Apr 29 00:37:55 2026 +0530
Add integration test for `log4j-samples-jlink` module (#393)
Co-authored-by: Volkan Yazıcı <[email protected]>
---
log4j-samples-jlink/pom.xml | 93 +++++++++++++++++++++-
.../logging/log4j/samples/jlink/StandardIT.java | 48 +++++++++++
2 files changed, 139 insertions(+), 2 deletions(-)
diff --git a/log4j-samples-jlink/pom.xml b/log4j-samples-jlink/pom.xml
index 7019762..1b80b60 100644
--- a/log4j-samples-jlink/pom.xml
+++ b/log4j-samples-jlink/pom.xml
@@ -16,7 +16,9 @@
~ limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
<modelVersion>4.0.0</modelVersion>
+
<parent>
<groupId>org.apache.logging.log4j.samples</groupId>
<artifactId>log4j-samples</artifactId>
@@ -30,6 +32,12 @@
<properties>
<!-- Plugin version -->
<maven-jlink-plugin.version>3.2.0</maven-jlink-plugin.version>
+
+ <!-- OS-specific launcher suffix -->
+ <jlink.launcher.suffix />
+
+ <!-- Optional readability improvement -->
+
<jlink.launcher.path>${project.build.directory}/maven-jlink/default/bin/${project.artifactId}${jlink.launcher.suffix}</jlink.launcher.path>
</properties>
<dependencies>
@@ -39,11 +47,9 @@
<artifactId>log4j-api</artifactId>
</dependency>
- <!-- Runtime dependencies -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
- <scope>runtime</scope>
</dependency>
<dependency>
@@ -52,9 +58,76 @@
<scope>runtime</scope>
</dependency>
+ <!-- TEST -->
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter</artifactId>
+ <scope>test</scope>
+ </dependency>
+
</dependencies>
+
<build>
<plugins>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-antrun-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>prepare-integration-test-logs</id>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ <phase>pre-integration-test</phase>
+ <configuration>
+ <target>
+ <mkdir dir="${project.build.directory}/logs" />
+ <delete file="${project.build.directory}/logs/out.log" />
+ </target>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>exec-maven-plugin</artifactId>
+ <version>${exec-maven-plugin.version}</version>
+ <executions>
+ <execution>
+ <id>run-custom-jlink-launcher</id>
+ <goals>
+ <goal>exec</goal>
+ </goals>
+ <phase>integration-test</phase>
+ <configuration>
+ <executable>${jlink.launcher.path}</executable>
+ <outputFile>${project.build.directory}/logs/out.log</outputFile>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>integration-test</id>
+ <goals>
+ <goal>integration-test</goal>
+ <goal>verify</goal>
+ </goals>
+ <configuration>
+ <includes>
+ <include>**/StandardIT.class</include>
+ </includes>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jlink-plugin</artifactId>
@@ -64,6 +137,22 @@
<launcher>log4j-samples-jlink=org.apache.logging.log4j.samples.jlink/org.apache.logging.log4j.samples.jlink.Main</launcher>
</configuration>
</plugin>
+
</plugins>
</build>
+
+ <profiles>
+ <profile>
+ <id>windows</id>
+ <activation>
+ <os>
+ <family>Windows</family>
+ </os>
+ </activation>
+ <properties>
+ <jlink.launcher.suffix>.exe</jlink.launcher.suffix>
+ </properties>
+ </profile>
+ </profiles>
+
</project>
diff --git
a/log4j-samples-jlink/src/test/java/org/apache/logging/log4j/samples/jlink/StandardIT.java
b/log4j-samples-jlink/src/test/java/org/apache/logging/log4j/samples/jlink/StandardIT.java
new file mode 100644
index 0000000..ac82691
--- /dev/null
+++
b/log4j-samples-jlink/src/test/java/org/apache/logging/log4j/samples/jlink/StandardIT.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.logging.log4j.samples.jlink;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.List;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+public class StandardIT {
+
+ @Test
+ public void verifyStdOut() throws IOException {
+ final Path basePath = Paths.get(System.getProperty("basedir"),
"target", "logs");
+ final Path logFile = basePath.resolve("out.log");
+
+ Assertions.assertTrue(Files.exists(logFile), "Log file does not
exist");
+ Assertions.assertTrue(Files.size(logFile) > 0, "Log file is empty");
+
+ final List<String> lines = Files.readAllLines(logFile,
StandardCharsets.UTF_8);
+
+ Assertions.assertEquals(2, lines.size());
+ Assertions.assertTrue(lines.get(0)
+ .matches("XML: .* INFO\\s+\\[main]
o\\.a\\.l\\.l\\.s\\.j\\.Main Starting Log4j JLink Sample\\.\\.\\."));
+ Assertions.assertTrue(
+ lines.get(1)
+ .matches(
+ "XML: .* WARN\\s+\\[main]
o\\.a\\.l\\.l\\.s\\.j\\.Main Please add your name as command line
parameter\\."));
+ }
+}