]> source.dussan.org Git - sonarqube.git/commitdiff
Try to fix handling of BOM on Windows
authorJulien HENRY <julien.henry@sonarsource.com>
Fri, 21 Nov 2014 16:50:49 +0000 (17:50 +0100)
committerJulien HENRY <julien.henry@sonarsource.com>
Fri, 21 Nov 2014 16:50:49 +0000 (17:50 +0100)
sonar-batch/src/main/java/org/sonar/batch/source/CodeColorizers.java
sonar-batch/src/main/java/org/sonar/batch/source/HighlightingCodeBuilder.java

index 1bc0f315b6f2be608a9996c99a55674f1b9e34a2..e3c5e8387a88f137af0bdf706e9fcd2e1628c80d 100644 (file)
@@ -21,6 +21,7 @@ package org.sonar.batch.source;
 
 import com.google.common.collect.Lists;
 import org.apache.commons.io.IOUtils;
+import org.apache.commons.io.input.BOMInputStream;
 import org.apache.commons.lang.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -76,7 +77,7 @@ public class CodeColorizers implements BatchComponent {
     }
     Reader reader = null;
     try {
-      reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), encoding));
+      reader = new BufferedReader(new InputStreamReader(new BOMInputStream(new FileInputStream(file)), encoding));
       return new HighlightingRenderer().render(reader, tokenizers);
     } catch (Exception e) {
       throw new IllegalStateException("Unable to read source file for colorization", e);
index 1f52c21d793fca6cbec494185a9474d0d9dcc54c..7698a54eff4774a6e0b94d67fa3e7e85535feb75 100644 (file)
@@ -33,8 +33,6 @@ public class HighlightingCodeBuilder extends HtmlCodeBuilder {
 
   private static final Logger LOG = LoggerFactory.getLogger(HighlightingCodeBuilder.class);
 
-  private static final char BOM = '\uFEFF';
-
   private SyntaxHighlightingDataBuilder highlightingBuilder = new SyntaxHighlightingDataBuilder();
   private int currentOffset = 0;
   private static final Pattern START_TAG_PATTERN = Pattern.compile("<span class=\"(.+)\">");
@@ -52,9 +50,7 @@ public class HighlightingCodeBuilder extends HtmlCodeBuilder {
 
   @Override
   public Appendable append(char c) {
-    if (c != BOM) {
-      currentOffset++;
-    }
+    currentOffset++;
     return this;
   }