1

我有安装了 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;

有人有这个问题吗?

4

2 回答 2

3

我必须浏览我的文件并从 utf-8 更改它们的编码,而无需使用 Notepad++ 进行 bom。顶部菜单栏中的“编码”菜单可以执行此操作。

于 2015-04-03T20:03:29.117 回答
0

当我们使用 Teamcity 时,我们发现了一个从文件中删除 BOM 的 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."
于 2015-04-07T10:34:31.327 回答