Skip to content

Commit

Permalink
Add charset configuration
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Widdis <[email protected]>
  • Loading branch information
dbwiddis committed Dec 8, 2023
1 parent b9bbccb commit 80ba114
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 1 deletion.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,16 @@ Duration between output and error log file sizes during execution (JAVA executio
</configuration>
```

### Log Charset

Charset format for the output and error log files. Defaults to `Charset.defaultCharset()` for JDK 17 and lower, `System.getProperty("native.encoding")` for JDK 18 and higher.

```xml
<configuration>
<charset>UTF-8</charset>
</configuration>
```

### Isolation Level

`ClassLoader` hierarchy configuration.
Expand Down
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@
<!--<pomInclude>multiple-engines-*</pomInclude>-->
<!--<pomInclude>timeout</pomInclude>-->
<!--<pomInclude>executionProgress</pomInclude>-->
<!--<pomInclude>charset</pomInclude>-->
</pomIncludes>
<pomExcludes>
<!-- None, B. -->
Expand Down
2 changes: 2 additions & 0 deletions src/it/charset/invoker.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

invoker.buildResult=failure
37 changes: 37 additions & 0 deletions src/it/charset/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<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>it</groupId>
<artifactId>setup</artifactId>
<version>0</version>
</parent>

<artifactId>execution-progress</artifactId>

<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>@project.groupId@</groupId>
<artifactId>@project.artifactId@</artifactId>
<configuration>
<executor>JAVA</executor>
<charset>ISO-8859-1</charset>
<timeout>3</timeout>
</configuration>
</plugin>
</plugins>
</build>

</project>
9 changes: 9 additions & 0 deletions src/it/charset/src/test/java/CharsetTests.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import org.junit.jupiter.api.Test;

class CharsetTests {

@Test
void outputSomething() throws Exception {
System.out.println("UTF-8 degree sign is °");
}
}
28 changes: 28 additions & 0 deletions src/it/charset/verify.bsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import it.Verifier;

Verifier verifier = new Verifier(basedir.toPath());

// verifier.verifyBadLines(); // warning and error lines are expected

verifier.verifyReadable(new String[] {
"pom.xml",
"src/test/java/CharsetTests.java",
"target/test-classes/CharsetTests.class"
});

verifier.verifyNotExists(new String[] {
"target/classes",
"target/surefire-reports"
});

verifier.verifyLogMatches(new String[] {
">> BEGIN >>",
"[INFO] Launching JUnit Platform " + junitPlatformVersion + "...",
">> Platform executes tests...>>",
"\\Q[INFO]\\E UTF-8 degree sign is °",
">> Platform executes tests...>>",
"[INFO] BUILD SUCCESS",
">> END. >>"
});

return verifier.isOk();
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ public class JUnitPlatformMojo extends AbstractMavenLifecycleParticipant impleme
@Parameter(defaultValue = "300")
private long timeout = 300L;

/** Charset for log files. */
@Parameter(defaultValue = "")
private String charset = null;

/** Execution progress update duration in seconds. */
@Parameter(defaultValue = "60")
private long executionProgress = 60;
Expand Down Expand Up @@ -508,6 +512,10 @@ long getTimeout() {
return timeout;
}

String getCharset() {
return charset;
}

long getExecutionProgress() {
return executionProgress;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,10 @@ int evaluate(Configuration configuration) {
}
int exitValue = process.exitValue();
if (captureIO) {
String encoding = System.getProperty("native.encoding"); // Populated on Java 18 and later
String encoding = mojo.getCharset();
if (encoding == null) {
encoding = System.getProperty("native.encoding"); // Populated on Java 18 and later
}
Charset charset = encoding != null ? Charset.forName(encoding) : Charset.defaultCharset();
try (Stream<String> stdoutput = Files.lines(outputPath, charset);
Stream<String> erroutput = Files.lines(errorPath, charset)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ void checkDefaultPropertyValues() {
assertEquals(Isolation.NONE, mojo.getIsolation());
assertEquals(300L, mojo.getTimeout());
assertEquals(60L, mojo.getExecutionProgress());
assertNull(mojo.getCharset());

assertNotNull(mojo.getLog());
assertNull(mojo.getMavenProject());
Expand Down

0 comments on commit 80ba114

Please sign in to comment.