简体   繁体   English

Jenkins 声纳扫描仪显示警告

[英]Jenkins sonarscanner shows enconding warnings

I've just deployed a CI system based on jenkins plus sonarqube.我刚刚部署了一个基于 jenkins 和 sonarqube 的 CI 系统。 Once Jenkins Sonnarscanner starts his part of the Pipeline I can see a lot of messages such as the following:一旦 Jenkins Sonnarscanner 启动他的管道部分,我可以看到很多消息,如下所示:

WARN: Invalid character encountered in file /var/jenkins_home/workspace/Pipeline Test/code/..../CodigoSitioDAO.java at line 3 for encoding UTF-8. Please fix file content or configure the encoding to be used using property 'sonar.sourceEncoding'.

Well, my sonarqube calling line is:那么,我的 sonarqube 呼叫线路是:

                                sh "${scannerHome}/bin/sonar-scanner \
                                -Dsonar.sourceEnconding=UTF-8 \
                                -Dsonar.projectKey=My_Project\
                                -Dsonar.sources=. \
                                -Dsonar.java.binaries=. \
                                -Dsonar.nodejs.executable=. \
                                -Dsonar.login=c9bb378b2380af844c7465424933b942d10f5d18 \
                                -Dsonar.host.url=http://sonarqube:9000"
                            }

So, once I've check the mentioned file, what I can see in line 3 is something that I think does not have to do with the warning messages: import java.sql.Connection;因此,一旦我检查了上述文件,我在第 3 行看到的内容与警告消息import java.sql.Connection;

Having also configured -Dsonar.sourceEncoding=UTF-8 , I have to say that I don't know what is happenig.还配置-Dsonar.sourceEncoding=UTF-8 ,我不得不说我不知道发生了什么。

Could anyone of you help me?你们中的任何人都可以帮助我吗?

It looks to me like the file is not in UTF-8.在我看来,该文件不在 UTF-8 中。 It's quite possible (especially if you used Windows editor) that the file is saved in some platform-specific encoding and its contents does not make sense for UTF-8.很有可能(特别是如果您使用 Windows 编辑器)文件以某些特定于平台的编码保存,并且其内容对于 UTF-8 没有意义。 Consider the following:考虑以下:

Clase de implementación del DAO de los códigos

The same contents has been saved as ANSI and UTF-8 (explicitly selected upon save).相同的内容已保存为 ANSI 和 UTF-8(保存时明确选择)。 Now if you compare byte contents, these are not the same:现在,如果您比较字节内容,它们是不一样的:

$ hexdump -C test-ansi.txt
00000000  43 6c 61 73 65 20 64 65  20 69 6d 70 6c 65 6d 65  |Clase de impleme|
00000010  6e 74 61 63 69 f3 6e 20  64 65 6c 20 44 41 4f 20  |ntaci.n del DAO |
00000020  64 65 20 6c 6f 73 20 63  f3 64 69 67 6f 73        |de los c.digos|
0000002e

$ hexdump -C test-utf8.txt
00000000  43 6c 61 73 65 20 64 65  20 69 6d 70 6c 65 6d 65  |Clase de impleme|
00000010  6e 74 61 63 69 c3 b3 6e  20 64 65 6c 20 44 41 4f  |ntaci..n del DAO|
00000020  20 64 65 20 6c 6f 73 20  63 c3 b3 64 69 67 6f 73  | de los c..digos|
00000030

Note that the same character ó is encoded as f3 in ANSI and as c3 b3 in UTF-8.请注意,相同的字符ó在 ANSI 中编码为f3 ,在 UTF-8 中编码为c3 b3 I believe this is what your message is about: declared encoding is UTF-8 (possibly default), but the character contents f3 is invalid under this encoding.我相信这就是您的消息的内容:声明的编码为 UTF-8(可能是默认值),但在此编码下字符内容f3无效。 Please double check your encoding with the hex editor.请使用十六进制编辑器仔细检查您的编码。

Side note: if you copied and pasted your line directly from your file, please note that Stack Overflow was not able to decode it as well, confirming it's not UTF-8-encoded.旁注:如果您直接从文件中复制并粘贴您的行,请注意 Stack Overflow 也无法对其进行解码,确认它不是 UTF-8 编码的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM