Skip to content

Commit

Permalink
fix console output on windows (remove special unicode separator chara…
Browse files Browse the repository at this point in the history
…cters, appearing incorrectly)
  • Loading branch information
xvik committed Apr 29, 2021
1 parent ba2c32d commit a802366
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 21 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
* Fix gradle 7 compatibility (for checkstyle plugin)
* Fix console output on windows (remove special unicode separator characters, appearing incorrectly)
* Update checkstyle 8.39 -> 8.42
* Update checkstyle config:
- Add [RecordComponentName](https://checkstyle.sourceforge.io/config_naming.html#RecordComponentName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class CheckstyleReporter implements Reporter<Checkstyle> {
int cnt = result.file.error.size()
if (cnt > 0) {
int filesCnt = result.file.findAll { it.error.size() > 0 }.size()
task.logger.error "$NO_TRIM$NL$cnt Checkstyle rule violations were found in $filesCnt files$NL$NO_TRIM"
task.logger.error "$NL$cnt Checkstyle rule violations were found in $filesCnt files$NL"

result.file.each { file ->
String filePath = file.@name
Expand All @@ -47,7 +47,7 @@ class CheckstyleReporter implements Reporter<Checkstyle> {
// part in braces recognized by intellij IDEA and shown as link
task.logger.error "[${group.capitalize()} | $check] $name.($sourceFile:$srcPointer)" +
"$NL ${it.@message}" +
"$NL http://checkstyle.sourceforge.io/config_${group}.html#$check$NL$NO_TRIM"
"$NL http://checkstyle.sourceforge.io/config_${group}.html#$check$NL"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ class CodeNarcReporter implements Reporter<CodeNarc> {
Integer p2 = summary.@priority2 as Integer
Integer p3 = summary.@priority3 as Integer
Integer count = p1 + p2 + p3
task.logger.error "$NO_TRIM$NL$count ($p1 / $p2 / $p3) CodeNarc violations were found in ${fileCnt} " +
"files$NL$NO_TRIM"
task.logger.error "$NL$count ($p1 / $p2 / $p3) CodeNarc violations were found in ${fileCnt} " +
"files$NL"

Map<String, String> desc = [:]
result.Rules.Rule.each {
Expand All @@ -59,7 +59,7 @@ class CodeNarcReporter implements Reporter<CodeNarc> {
"$NL ${message}" +
"$NL ${desc[rule]}" +
"$NL https://codenarc.github.io/CodeNarc/codenarc-rules-" +
"${group.toLowerCase()}.html#${rule.toLowerCase()}-rule$NL$NO_TRIM"
"${group.toLowerCase()}.html#${rule.toLowerCase()}-rule$NL"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class CpdReporter implements Reporter<SourceTask>, HtmlReportGenerator<SourceTas
Node result = new XmlParser().parse(reportFile)
int cnt = result.duplication.size()
if (cnt > 0) {
task.logger.error "$NO_TRIM$NL$cnt ${task.language} duplicates were found by CPD$NL$NO_TRIM"
task.logger.error "$NL$cnt ${task.language} duplicates were found by CPD$NL"
result.duplication.each { dupl ->
int lines = dupl.@lines as Integer
int start = 0
Expand Down Expand Up @@ -63,7 +63,7 @@ class CpdReporter implements Reporter<SourceTask>, HtmlReportGenerator<SourceTas
msg << "${String.format(nbFmt, codePos++)}$CODE_INDENT $it$NL"
}

task.logger.error "$msg$NL$NO_TRIM"
task.logger.error "$msg$NL"
}
// html report will be generated before console reporting
String htmlReportUrl = ReportUtils.toConsoleLink(task.project
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class PmdReporter implements Reporter<Pmd> {
Node result = new XmlParser().parse(reportFile)
int cnt = result.file.violation.size()
if (cnt > 0) {
task.logger.error "$NO_TRIM$NL$cnt PMD rule violations were found in ${result.file.size()} files$NL$NO_TRIM"
task.logger.error "$NL$cnt PMD rule violations were found in ${result.file.size()} files$NL"

result.file.each { file ->
String filePath = file.@name
Expand All @@ -34,7 +34,7 @@ class PmdReporter implements Reporter<Pmd> {
// part in braces recognized by intellij IDEA and shown as link
task.logger.error "[${violation.@ruleset} | ${violation.@rule}] $name.($sourceFile:${srcPos})" +
"$NL ${violation.text().trim()}" +
"$NL ${violation.@externalInfoUrl}$NL$NO_TRIM"
"$NL ${violation.@externalInfoUrl}$NL"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@ interface Reporter<T extends Task> {
*/
String NL = String.format('%n')

/**
* Special invisible symbol (ZERO WIDTH SPACE) to prevent removing of empty separator lines in IDEA output.
* Should be used before NL at the beginning and after last NL.
*/
String NO_TRIM = '\u200B'

/**
* Called after quality tool task to report violations.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ class SpotbugsReporter implements Reporter<SpotBugsTask>, HtmlReportGenerator<Sp
int p1 = summary.@priority_1 == null ? 0 : summary.@priority_1 as Integer
int p2 = summary.@priority_2 == null ? 0 : summary.@priority_2 as Integer
int p3 = summary.@priority_3 == null ? 0 : summary.@priority_3 as Integer
task.logger.error "$NO_TRIM$NL$cnt ($p1 / $p2 / $p3) SpotBugs violations were found in ${fileCnt} " +
"files$NL$NO_TRIM"
task.logger.error "$NL$cnt ($p1 / $p2 / $p3) SpotBugs violations were found in ${fileCnt} " +
"files$NL"

Map<String, String> desc = buildDescription(result)
Map<String, String> cat = buildCategories(result)
Expand All @@ -60,7 +60,7 @@ class SpotbugsReporter implements Reporter<SpotBugsTask>, HtmlReportGenerator<Sp
task.logger.error "[${plugin}${cat[bug.@category]} | ${bugType}] $pkg(${cls}:${srcPosition}) " +
"[priority ${bug.@priority} / rank ${bug.@rank}]" +
"$NL\t>> ${msg.text()}" +
"$NL ${description}$NL$NO_TRIM"
"$NL ${description}$NL"
}
// html report will be generated before console reporting
String htmlReportUrl = ReportUtils.toConsoleLink(task.project
Expand Down Expand Up @@ -97,7 +97,7 @@ class SpotbugsReporter implements Reporter<SpotBugsTask>, HtmlReportGenerator<Sp
//remove html tags
.replaceAll('<(.|\n)*?>', '')
// remove empty lines after tags remove (only one separator line remain)
.replaceAll('([ \t]*\n){3,}', "$NL$NO_TRIM$NL")
.replaceAll('([ \t]*\n){3,}', "$NL$NL")
// reduce left indents
.replaceAll('\n\t+', "$NL ").replaceAll(' {2,}', ' ')
// indent all not indented lines
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,5 @@ abstract class AbstractKitTest extends Specification {
return input
// cleanup win line break for simpler comparisons
.replaceAll("\r", '')
// remove invisible symbols to simplify comparison
.replaceAll(Reporter.NO_TRIM, '')
}
}

0 comments on commit a802366

Please sign in to comment.