Skip to content

Commit 3a56f5a

Browse files
committed
Use the native encoding for reading the file written by a native process (forked compiler).
Avoid too verbatim verifications of locale-sensitive compiler messages. apache#327
1 parent 1271c85 commit 3a56f5a

File tree

4 files changed

+33
-5
lines changed

4 files changed

+33
-5
lines changed

src/it/MCOMPILER-346/verify.groovy

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,14 @@ def logFile = new File( basedir, 'build.log' )
2121
assert logFile.exists()
2222
content = logFile.text
2323

24-
assert content.contains( 'package org.jenkinsci.test.acceptance.controller does not exist' )
25-
assert content.contains( 'package org.jenkinsci.test.acceptance.log does not exist' )
24+
/*
25+
* The messages expected by this test were:
26+
*
27+
* - package org.jenkinsci.test.acceptance.controller does not exist
28+
* - package org.jenkinsci.test.acceptance.log does not exist
29+
*
30+
* But we cannot test the full messages as shown above because they may be localized.
31+
* Test only the package name on the assumption that they will be present in all locales.
32+
*/
33+
assert content.contains( 'org.jenkinsci.test.acceptance.controller' )
34+
assert content.contains( 'org.jenkinsci.test.acceptance.log' )

src/it/mcompiler-120/verify.groovy

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@ def logFile = new File( basedir, 'build.log' )
2020
assert logFile.exists()
2121
content = logFile.text
2222

23+
/*
24+
* The message expected by this test was "unchecked call to add(E) as a member of the raw type List".
25+
* But we cannot test that message because it is locale-dependent. Check only a few keywords instead.
26+
*/
27+
assert content.contains( 'add(E)' )
28+
assert content.contains( 'List' ) // May be `List` or `java.util.List`.
2329
assert content.contains( 'COMPILATION ERROR:' )
2430
assert content.contains( 'CompilationFailureException' ) // In debug level logs.
2531
assert !content.contains( 'invalid flag' )
26-
assert content.contains( 'unchecked call to add(E) as a member of the raw type ' ) // List or java.util.List

src/it/mcompiler-179/verify.groovy

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ def logFile = new File( basedir, 'build.log' )
2121
assert logFile.exists()
2222
content = logFile.text
2323

24-
assert content.contains( '[WARNING] unchecked call' )
24+
/*
25+
* The message expected by this test was "[WARNING] unchecked call" (the full message
26+
* is actually "unchecked call to add(E) as a member of the raw type java.util.List").
27+
* But we cannot test that message because it is locale-dependent.
28+
* Check only a few keywords instead.
29+
*/
30+
assert content.contains( '[WARNING]' )
31+
assert content.contains( 'add(E)' )
32+
assert content.contains( 'List' ) // May be `List` or `java.util.List`.
2533
assert content.contains( 'COMPILATION ERROR:' )
2634
assert content.contains( 'CompilationFailureException' ) // In debug level logs.

src/main/java/org/apache/maven/plugin/compiler/ForkedTool.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,13 @@ final boolean run(
164164
builder.redirectOutput(dest);
165165
return start(builder, out) == 0;
166166
} finally {
167-
out.append(Files.readString(output.toPath()));
167+
/*
168+
* Need to use the native encoding because it is the encoding used by the native process.
169+
* This is not necessarily the default encoding of the JVM, which is "file.encoding".
170+
* This property is available since Java 17.
171+
*/
172+
String cs = System.getProperty("native.encoding");
173+
out.append(Files.readString(output.toPath(), Charset.forName(cs)));
168174
output.delete();
169175
}
170176
}

0 commit comments

Comments
 (0)