Skip to content
Open
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
97 changes: 94 additions & 3 deletions log4j-samples-jlink/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
~ See the License for the specific language governing permissions and
~ 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">
<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://www.w3.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.apache.logging.log4j.samples</groupId>
<artifactId>log4j-samples</artifactId>
Expand All @@ -30,6 +32,12 @@
<properties>
<!-- Plugin version -->
<maven-jlink-plugin.version>3.2.0</maven-jlink-plugin.version>

<!-- OS-specific launcher suffix -->
<launcher.suffix />

<!-- Optional readability improvement -->
<jlink.launcher.path>${project.build.directory}/maven-jlink/default/bin/${project.artifactId}${launcher.suffix}</jlink.launcher.path>
</properties>

<dependencies>
Expand All @@ -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>
Expand All @@ -52,9 +58,77 @@
<scope>runtime</scope>
</dependency>

<!-- TEST -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</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>

<!-- ✅ FIXED HERE -->
<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>
Expand All @@ -64,6 +138,23 @@
<launcher>log4j-samples-jlink=org.apache.logging.log4j.samples.jlink/org.apache.logging.log4j.samples.jlink.Main</launcher>
</configuration>
</plugin>

</plugins>
</build>

<!-- ✅ Windows profile -->
<profiles>
<profile>
<id>windows</id>
<activation>
<os>
<family>Windows</family>
</os>
</activation>
<properties>
<launcher.suffix>.exe</launcher.suffix>
</properties>
</profile>
</profiles>

</project>
Original file line number Diff line number Diff line change
@@ -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.Assert;
import org.junit.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");

Assert.assertTrue("Log file does not exist", Files.exists(logFile));
Assert.assertTrue("Log file is empty", Files.size(logFile) > 0);

final List<String> lines = Files.readAllLines(logFile, StandardCharsets.UTF_8);

Assert.assertEquals(2, lines.size());
Assert.assertTrue(lines.get(0)
.matches("XML: .* INFO\\s+\\[main] o\\.a\\.l\\.l\\.s\\.j\\.Main Starting Log4j JLink Sample\\.\\.\\."));
Assert.assertTrue(
lines.get(1)
.matches(
"XML: .* WARN\\s+\\[main] o\\.a\\.l\\.l\\.s\\.j\\.Main Please add your name as command line parameter\\."));
}
}