From abf65acb63522a6332020821efef7c275bec275c Mon Sep 17 00:00:00 2001 From: pyxide Date: Sat, 7 Jan 2017 03:11:59 +0100 Subject: [PATCH] Bug fix and enhanced console output encoding - due to some rewriting without testing, the encoding property was not added to the renderer properties. - better console encoding: use system property `sun.stdout.encoding` in interactive console, and `file.encoding` in piped or redirected output --- .../net/sourceforge/pmd/ant/Formatter.java | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/ant/Formatter.java b/pmd-core/src/main/java/net/sourceforge/pmd/ant/Formatter.java index 7d2a590eb8..efe3dae1d3 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/ant/Formatter.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/ant/Formatter.java @@ -70,9 +70,29 @@ public class Formatter { { String s = (String) properties.get("encoding"); if (null == s) { - charset = StandardCharsets.UTF_8; - properties.put("encoding", charset.name()); - } else { + + if (toConsole) { + if(null == System.console()) { + // pipe or redirect, no interactive console. + s = System.getProperty("file.encoding"); + } else { + s = System.getProperty("sun.stdout.encoding"); + } + } + + if (null == s) { + charset = StandardCharsets.UTF_8; + } else { + charset = Charset.forName(s); + } + + // Configures the encoding for the renderer. + final Parameter parameter = new Parameter(); + parameter.setName("encoding"); + parameter.setValue(charset.name()); + parameters.add(parameter); + } + else { charset = Charset.forName(s); } }