Branch: refs/heads/master
  Home:   https://github.com/pmd/pmd
  Commit: c853e8caa9eab5d9c87116b5cd733a15dd16882d
      https://github.com/pmd/pmd/commit/c853e8caa9eab5d9c87116b5cd733a15dd16882d
  Author: pyxide <[email protected]>
  Date:   2016-12-17 (Sat, 17 Dec 2016)

  Changed paths:
    M pmd-core/src/main/java/net/sourceforge/pmd/ant/Formatter.java

  Log Message:
  -----------
  Ant Task Formatter encoding issue with XMLRenderer

Hi,

The writers in the Ant task's formatter uses the default platform's encoding 
(for instance cp1252 on Western Windows) and the XMLRenderer sets the default 
XML encoding to UTF-8. This may lead to incorrect XML encoding, detected for 
instance when the XML file is sent to a XSLT task.
This goes undetected as long as the characters in the XML file are in the ASCII 
subset, which is frequently the case with code, usually in plain Latin 
language. In my case, the issue was raised because of the localized formatting 
of some line numbers greater than 999, due to localized thousand separator 
0xA0, which is out of the ASCII subset.

I modified the Formatter class to always use a charset for writers. When no 
encoding is specified, UTF-8 is used instead of the default platform's encoding.

I strongly recommend to *always set the encoding parameter* of the formatter 
element. It should be reflected as so in the Ant Task documentation.

```xml
<pmd encoding="cp1252"> <!-- source encoding -->
  <formatter type="xml" toFile="pmd.xml">
    <param name="encoding" value="UTF-8" /> <!-- report encoding -->
  </formatter>
  <fileset dir="src/main/java">
    <include name="**/*.java"/>
  </fileset>
</pmd>
```
Note: when digging into sourceforge issues for similar bugs, I found [Bug 877: 
Output with encoding CP1252](https://sourceforge.net/p/pmd/bugs/877/) . Not the 
same task, but the same symptoms, probably the same cause ?


  Commit: 6c2f61bb9728594038989e889800021f2835d146
      https://github.com/pmd/pmd/commit/6c2f61bb9728594038989e889800021f2835d146
  Author: pyxide <[email protected]>
  Date:   2016-12-17 (Sat, 17 Dec 2016)

  Changed paths:
    M pmd-core/src/main/java/net/sourceforge/pmd/ant/Formatter.java

  Log Message:
  -----------
  Update Formatter.java


  Commit: 10fd174b294f7ff8cdaa70d6706b89aae66297f4
      https://github.com/pmd/pmd/commit/10fd174b294f7ff8cdaa70d6706b89aae66297f4
  Author: pyxide <[email protected]>
  Date:   2016-12-17 (Sat, 17 Dec 2016)

  Changed paths:
    M pmd-core/src/main/java/net/sourceforge/pmd/ant/Formatter.java

  Log Message:
  -----------
  checkstyle fixes


  Commit: 36afd5dfc600435e61adcc8584c7af3bfd31c88d
      https://github.com/pmd/pmd/commit/36afd5dfc600435e61adcc8584c7af3bfd31c88d
  Author: pyxide <[email protected]>
  Date:   2017-01-07 (Sat, 07 Jan 2017)

  Changed paths:
    M pmd-core/src/main/java/net/sourceforge/pmd/ant/Formatter.java

  Log Message:
  -----------
  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


  Commit: 7cbb06f6e3e0e6efa65e3ed4d4b68133b548f867
      https://github.com/pmd/pmd/commit/7cbb06f6e3e0e6efa65e3ed4d4b68133b548f867
  Author: pyxide <[email protected]>
  Date:   2017-01-07 (Sat, 07 Jan 2017)

  Changed paths:
    M pmd-core/src/main/java/net/sourceforge/pmd/ant/Formatter.java

  Log Message:
  -----------
  checkstyle fixes


  Commit: 2643f5a3d013d038f1c29d51fc7639555f81b304
      https://github.com/pmd/pmd/commit/2643f5a3d013d038f1c29d51fc7639555f81b304
  Author: pyxide <[email protected]>
  Date:   2017-01-09 (Mon, 09 Jan 2017)

  Changed paths:
    M pmd-core/src/main/java/net/sourceforge/pmd/ant/Formatter.java

  Log Message:
  -----------
  Reflection detection code for console encoding

Note: calling the static native method `String Console.encoding()` returns the 
current console encoding, even if `System.console()` is null because the 
console is not interactive (pipe or redirection).


  Commit: b5d931f1c9d683ecd0b51d9a69228941a4a88282
      https://github.com/pmd/pmd/commit/b5d931f1c9d683ecd0b51d9a69228941a4a88282
  Author: pyxide <[email protected]>
  Date:   2017-01-09 (Mon, 09 Jan 2017)

  Changed paths:
    M pmd-core/src/main/java/net/sourceforge/pmd/ant/Formatter.java

  Log Message:
  -----------
  checkstyle fixes


  Commit: 185df84fa4f22ba6511a0130d50f8c19e597ae04
      https://github.com/pmd/pmd/commit/185df84fa4f22ba6511a0130d50f8c19e597ae04
  Author: pyxide <[email protected]>
  Date:   2017-01-09 (Mon, 09 Jan 2017)

  Changed paths:
    M pmd-core/src/main/java/net/sourceforge/pmd/ant/Formatter.java

  Log Message:
  -----------
  Console encoding only when interactive


  Commit: 74583d003a841af280e7fea8f3ae3521dfcbb89b
      https://github.com/pmd/pmd/commit/74583d003a841af280e7fea8f3ae3521dfcbb89b
  Author: pyxide <[email protected]>
  Date:   2017-01-10 (Tue, 10 Jan 2017)

  Changed paths:
    M pmd-core/src/main/java/net/sourceforge/pmd/ant/Formatter.java

  Log Message:
  -----------
  Ant Task Formatter encoding issue with XMLRenderer

Hi,

The writers in the Ant task's formatter uses the default platform's encoding 
(for instance cp1252 on Western Windows) and the XMLRenderer sets the default 
XML encoding to UTF-8. This may lead to incorrect XML encoding, detected for 
instance when the XML file is sent to a XSLT task.
This goes undetected as long as the characters in the XML file are in the ASCII 
subset, which is frequently the case with code, usually in plain Latin 
language. In my case, the issue was raised because of the localized formatting 
of some line numbers greater than 999, due to localized thousand separator 
0xA0, which is out of the ASCII subset.

I modified the Formatter class to always use a charset for writers. When no 
encoding is specified, UTF-8 is used instead of the default platform's encoding.

I strongly recommend to *always set the encoding parameter* of the formatter 
element. It should be reflected as so in the Ant Task documentation.

```xml
<pmd encoding="cp1252"> <!-- source encoding -->
  <formatter type="xml" toFile="pmd.xml">
    <param name="encoding" value="UTF-8" /> <!-- report encoding -->
  </formatter>
  <fileset dir="src/main/java">
    <include name="**/*.java"/>
  </fileset>
</pmd>
```
Note: when digging into sourceforge issues for similar bugs, I found [Bug 877: 
Output with encoding CP1252](https://sourceforge.net/p/pmd/bugs/877/) . Not the 
same task, but the same symptoms, probably the same cause ?


  Commit: 368313fd8f246300b6f38159029f217b1eedaef0
      https://github.com/pmd/pmd/commit/368313fd8f246300b6f38159029f217b1eedaef0
  Author: pyxide <[email protected]>
  Date:   2017-01-10 (Tue, 10 Jan 2017)

  Changed paths:
    M pmd-core/src/main/java/net/sourceforge/pmd/ant/Formatter.java

  Log Message:
  -----------
  Update Formatter.java


  Commit: 4c71b0da4ad11049d01aa5c2e10292711cf7b5dc
      https://github.com/pmd/pmd/commit/4c71b0da4ad11049d01aa5c2e10292711cf7b5dc
  Author: pyxide <[email protected]>
  Date:   2017-01-10 (Tue, 10 Jan 2017)

  Changed paths:
    M pmd-core/src/main/java/net/sourceforge/pmd/ant/Formatter.java

  Log Message:
  -----------
  checkstyle fixes


  Commit: abf65acb63522a6332020821efef7c275bec275c
      https://github.com/pmd/pmd/commit/abf65acb63522a6332020821efef7c275bec275c
  Author: pyxide <[email protected]>
  Date:   2017-01-10 (Tue, 10 Jan 2017)

  Changed paths:
    M pmd-core/src/main/java/net/sourceforge/pmd/ant/Formatter.java

  Log Message:
  -----------
  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


  Commit: 89600bfcc4e7d75f67bfbeb77dc04865c8355921
      https://github.com/pmd/pmd/commit/89600bfcc4e7d75f67bfbeb77dc04865c8355921
  Author: pyxide <[email protected]>
  Date:   2017-01-10 (Tue, 10 Jan 2017)

  Changed paths:
    M pmd-core/src/main/java/net/sourceforge/pmd/ant/Formatter.java

  Log Message:
  -----------
  checkstyle fixes


  Commit: 958f8df5f557a381e556818f156bc03b981dfed8
      https://github.com/pmd/pmd/commit/958f8df5f557a381e556818f156bc03b981dfed8
  Author: pyxide <[email protected]>
  Date:   2017-01-10 (Tue, 10 Jan 2017)

  Changed paths:
    M pmd-core/src/main/java/net/sourceforge/pmd/ant/Formatter.java

  Log Message:
  -----------
  Reflection detection code for console encoding

Note: calling the static native method `String Console.encoding()` returns the 
current console encoding, even if `System.console()` is null because the 
console is not interactive (pipe or redirection).


  Commit: d7c503bee4209ac3ae4359c45c1d8db2ee8694db
      https://github.com/pmd/pmd/commit/d7c503bee4209ac3ae4359c45c1d8db2ee8694db
  Author: pyxide <[email protected]>
  Date:   2017-01-10 (Tue, 10 Jan 2017)

  Changed paths:
    M pmd-core/src/main/java/net/sourceforge/pmd/ant/Formatter.java

  Log Message:
  -----------
  checkstyle fixes


  Commit: 43a38d314433e6f4f1345d793cb418157849765c
      https://github.com/pmd/pmd/commit/43a38d314433e6f4f1345d793cb418157849765c
  Author: pyxide <[email protected]>
  Date:   2017-01-10 (Tue, 10 Jan 2017)

  Changed paths:
    M pmd-core/src/main/java/net/sourceforge/pmd/ant/Formatter.java

  Log Message:
  -----------
  Console encoding only when interactive


  Commit: 552bb7eabf3830a8ae7b29a391ceadc32553f00e
      https://github.com/pmd/pmd/commit/552bb7eabf3830a8ae7b29a391ceadc32553f00e
  Author: Juan Martín Sotuyo Dodero <[email protected]>
  Date:   2017-01-10 (Tue, 10 Jan 2017)

  Changed paths:
    M pmd-core/src/main/java/net/sourceforge/pmd/ant/Formatter.java

  Log Message:
  -----------
  Merge branch 'pr-170'


  Commit: eae56033bdd20b9226be55c5a6f7a3eea4ebe47c
      https://github.com/pmd/pmd/commit/eae56033bdd20b9226be55c5a6f7a3eea4ebe47c
  Author: Juan Martín Sotuyo Dodero <[email protected]>
  Date:   2017-01-10 (Tue, 10 Jan 2017)

  Log Message:
  -----------
  Merge branch 'patch-1' of https://github.com/pyxide/pmd


Compare: https://github.com/pmd/pmd/compare/056554c4e3e3...eae56033bdd2
------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today. http://sdm.link/xeonphi
_______________________________________________
Pmd-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pmd-commits

Reply via email to