Sonar C#插件。无法使用BOM解析文件UTF-8

时间:2015-03-31 12:20:36

标签: c# sonarqube sonarqube-4.5

我有安装了C#插件的sonarqube 4.5.4,它无法以UTF-8 BOM编码解析文件。

[15:08:01][Step 1/8] 16:07:06.847 ERROR - Unable to parse file: E:\BuildAgent\work\daac5e6d39eee3cb\Source\GraphVizGraph.cs
[15:08:01][Step 1/8] 16:07:06.847 ERROR - Parse error at line 1 column 0:
[15:08:01][Step 1/8]
[15:08:01][Step 1/8] --> п»їusing System;

有人有这个问题吗?

2 个答案:

答案 0 :(得分:2)

我必须浏览我的文件并使用Notepad ++从utf-8更改其编码。 "编码"菜单在顶部的菜单栏中将有能力做到这一点。

答案 1 :(得分:0)

当我们使用Teamcity时,我们发现了一个删除BOM From文件的python脚本。 我们在结账后和声纳步骤之前运行此脚本。它从文件中删除bom,声纳工作正常。

import os, re, sys

"""
    UTF-BOM Remover
    Usage: python bom.py [dir]
"""

bom = r"^\xEF\xBB\xBF"
pattern = r"^(.*)\.(php|js|css|txt|inc|conf|tpl|html|htm|cs|cpp|h|c|cxx)$"
cleaned_files = total_files = 0

if len(sys.argv) == 2:
    rundir = sys.argv[1]
else:
    rundir = '.'

if os.path.isdir(rundir):
    for root, dirs, files in os.walk(rundir):
        for name in files:
            if re.match(pattern, name):
                filename = os.path.abspath(os.path.join(root, name))
                buffer = open(filename, 'rb').read()
                file = re.search(bom, buffer)
                if file:
                    print "Remove BOM-marker from %s" % name
                    cleaned_files+= 1
                    open(filename, 'wb').write(buffer[:file.start()] + buffer[file.end():])
        total_files+= len(files)
    print "There are was %d files with BOM in %d files" % (cleaned_files, total_files)
else:
    print "Error: You must set a valid directory."