diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2017-05-09 12:31:20 +0200 |
---|---|---|
committer | Julien HENRY <henryju@yahoo.fr> | 2017-05-09 18:02:07 +0200 |
commit | 53caac9fa3f2c97ca67936fe9d11ae47ae55c6ca (patch) | |
tree | 3d2042b8062f49ae33077d14765183185e4ee196 /plugins | |
parent | 72e45fffdea16673f257cb80b40269e73ccffaba (diff) | |
download | sonarqube-53caac9fa3f2c97ca67936fe9d11ae47ae55c6ca.tar.gz sonarqube-53caac9fa3f2c97ca67936fe9d11ae47ae55c6ca.zip |
SONAR-9199 InputFile::content() and InputFile::inputStream() should filter BOM
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/HasTagSensor.java | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/HasTagSensor.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/HasTagSensor.java index 32244809ef5..cd6d2576756 100644 --- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/HasTagSensor.java +++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/HasTagSensor.java @@ -19,8 +19,9 @@ */ package org.sonar.xoo.rule; +import java.io.BufferedReader; import java.io.IOException; -import java.nio.file.Files; +import java.io.InputStreamReader; import org.sonar.api.batch.fs.FileSystem; import org.sonar.api.batch.fs.InputFile; import org.sonar.api.batch.rule.ActiveRules; @@ -58,20 +59,23 @@ public class HasTagSensor extends AbstractXooRuleSensor { } try { int[] lineCounter = {1}; - Files.lines(inputFile.path(), inputFile.charset()).forEachOrdered(lineStr -> { - int startIndex = -1; - while ((startIndex = lineStr.indexOf(tag, startIndex + 1)) != -1) { - NewIssue newIssue = context.newIssue(); - newIssue - .forRule(ruleKey) - .gap(context.settings().getDouble(EFFORT_TO_FIX_PROPERTY)) - .at(newIssue.newLocation() - .on(inputFile) - .at(inputFile.newRange(lineCounter[0], startIndex, lineCounter[0], startIndex + tag.length()))) - .save(); - } - lineCounter[0]++; - }); + try (InputStreamReader isr = new InputStreamReader(inputFile.inputStream(), inputFile.charset()); + BufferedReader reader = new BufferedReader(isr)) { + reader.lines().forEachOrdered(lineStr -> { + int startIndex = -1; + while ((startIndex = lineStr.indexOf(tag, startIndex + 1)) != -1) { + NewIssue newIssue = context.newIssue(); + newIssue + .forRule(ruleKey) + .gap(context.settings().getDouble(EFFORT_TO_FIX_PROPERTY)) + .at(newIssue.newLocation() + .on(inputFile) + .at(inputFile.newRange(lineCounter[0], startIndex, lineCounter[0], startIndex + tag.length()))) + .save(); + } + lineCounter[0]++; + }); + } } catch (IOException e) { throw new IllegalStateException("Fail to process " + inputFile, e); } |