- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我有一个具有以下结构的应用程序:
my-application
+- pom.xml
+- app
| +- scripts
| | +- app.js
| | +- **/*.js
| +- 3rd-party-libs
+- build
+- node_modules
+- test
我创建了 pom.xml
只是为了运行 SonarQube 分析。否则,所有任务都由 Grunt 运行(测试使用 Karma 运行)。
pom.xml
的内容如下:
<properties>
<sonar.language>js</sonar.language>
<sonar.sourceEncoding>UTF-8</sonar.sourceEncoding>
<sonar.javascript.coveragePlugin>lcov</sonar.javascript.coveragePlugin>
<sonar.javascript.lcov.reportPath>build/karma/coverage/lcov.info</sonar.javascript.lcov.reportPath>
<sonar.exclusions>app/3rd-party-libs/**,node_modules/**</sonar.exclusions>
<sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
</properties>
<build>
<sourceDirectory>app/scripts</sourceDirectory>
<testSourceDirectory>test</testSourceDirectory>
</build>
当我运行 grunt test
时,它会创建一个包含以下信息的 build/karma/coverage/lcov.info
:
TN:
SF:./app/scripts/app.js
FN:16,(anonymous_1)
FN:26,(anonymous_2)
FNF:2
...
在 SonarQube 分析之后,仪表板显示代码覆盖率为 0%。
我怀疑 SF:
中的路径是错误的来源。因此,我更改了 sonar.javascript.lcov.reportPath
属性以使用另一个 lcov.info
来测试不同的值:app.js
, ./app.js
, app/scripts/app.js
, ./app/scripts/app.js
, 但都没有用,将覆盖率保持在 0%。
我错过了什么?
以防万一,我在我的 karma.conf.js
中有以下配置:
coverageReporter: {
reporters: [
{
type: 'lcov',
dir: 'build/karma/coverage',
subdir: '.'
}
]
},
ps:Sonar的版本是3.7.2,我也试过4.3的,结果一样。。。
编辑:我已经更新了配置以直接使用 Sonar-runner,我使用的是最新版本的 Sonar (5.0.1) 和 JS 插件 (2.3)。我还手动修改了 lcov.info
以具有“良好”格式(至少一种与 Sonar repo 示例匹配的格式):
SF:./app/scripts/app.js
DA:2,1
DA:20,1
DA:29,1
DA:34,1
end_of_record
SF:./app/scripts/services/exampleService.js
DA:1,1
DA:11,1
DA:12,0
end_of_record
sonar-project.properties
看起来像:
sonar.projectKey=xxx
sonar.projectName=xxx
sonar.projectVersion=xxx
sonar.sourceEncoding=UTF-8
sonar.sources=app/scripts
sonar.tests=test
sonar.exclusions=app/3rd-party-libs/**,node_modules/**
sonar.dynamicAnalysis=reuseReports
sonar.language=js
sonar.projectBaseDir=.
sonar.javascript.coveragePlugin=lcov
sonar.javascript.lcov.reportPath=build/karma/coverage/lcov.info
而且仍然是 0% 的覆盖率 :(
最佳答案
我一无所知,所以我决定修改 JavaScript plugin添加更多日志。我终于找到了错误,这是一个...区分大小写的恶性问题!
让我解释一下。让我们考虑 CoverageSensor.java
的 saveMeasureFromLCOVFile
方法:
protected void saveMeasureFromLCOVFile(SensorContext context) {
String providedPath = settings.getString(JavaScriptPlugin.LCOV_REPORT_PATH);
File lcovFile = getIOFile(fileSystem.baseDir(), providedPath);
...
LOG.info("Analysing {}", lcovFile);
LCOVParser parser = new LCOVParser(fileSystem.baseDir());
Map<String, CoverageMeasuresBuilder> coveredFiles = parser.parseFile(lcovFile);
for (InputFile inputFile : fileSystem.inputFiles(mainFilePredicate)) {
try {
CoverageMeasuresBuilder fileCoverage = coveredFiles.get(inputFile.file().getAbsolutePath());
org.sonar.api.resources.File resource = org.sonar.api.resources.File.create(inputFile.relativePath());
if (fileCoverage != null) {
for (Measure measure : fileCoverage.createMeasures()) {
context.saveMeasure(resource, measure);
}
} else {
// colour all lines as not executed
LOG.debug("Default value of zero will be saved for file: {}", resource.getPath());
LOG.debug("Because: either was not present in LCOV report either was not able to retrieve associated SonarQube resource");
saveZeroValueForResource(resource, context);
}
} catch (Exception e) {
LOG.error("Problem while calculating coverage for " + inputFile.absolutePath(), e);
}
}
}
首先,它读取给定的 lcov.info
文件以了解我们拥有哪些文件的覆盖率数据(通过解析文件检索,使用 LCOVParser
类完成)。之后,它从 coveredFiles
映射中获取相同的文件来进行指标和代码之间的匹配。如果找不到文件(if (fileCoverage != null) {
的 else
部分),则代码覆盖率将强制为 0。
这就是我的项目中发生的事情。
那么为什么会这样呢?仅仅是因为在我的环境中,inputFile
等于 d:\dev\my-application\app\scripts\app.js
而在 coveredFiles
map ,我有 D:\dev\my-application\app\scripts\app.js
。请注意驱动器号中大小写的区别(d:
与 D:
)。由于 map.get(...)
区分大小写,fileCoverage
为 null
,因此不计算覆盖率。
现在,我必须研究如何强制路径具有正确的大小写...
经过更多调查,我发现对插件代码的修改有效(至少对我而言,我没有考虑所有可能的影响)。在 LCOVParser
, filePath = CoverageSensor.getIOFile(moduleBaseDir, filePath).getCanonicalPath();
可以修改为 filePath = CoverageSensor.getIOFile(moduleBaseDir, filePath).getAbsolutePath();
,因为第一个返回类似 D:\...
的路径,而第二个将返回 d:\...
。
事实上,我什至不知道在 Windows 上使用什么是首选。以下代码:
public static void main(String[] args) throws IOException {
System.out.println("PATH 1 : " + new File(".").getAbsolutePath());
System.out.println("PATH 2 : " + new File(".").getCanonicalPath());
}
将返回:
PATH 1 : D:\dev\preclosing\preclosing-eme\.
PATH 2 : D:\dev\preclosing\preclosing-eme
无论如何,我暂时被卡住了,我什至不确定如何在不等待 JS 插件修复的情况下解决我的问题(因为我的“官方”Sonar 目前有点旧并且只支持JS 插件到 v2.1)。
关于javascript - Sonarqube 不从 LCOV 检索我的 JavaScript 覆盖率,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28702990/
我找到了 Using SonarQube in Eclipse 并将提出一个针对 Python 的单独问题。但在这里我想更一般地询问如何在提交之前处理单个源文件时,如何使用 SonarQube 作为
我们之前在现已关闭的 SonarQube Users mailing list 上讨论过这个问题. 通过优化Postgre DB换了半周左右问题解决,然后又出现问题。 我们正在使用 Jenkins 1
自从更新到5.x以来,由于“权限不足”问题,我们的许多构建作业现在都失败了。如here中所述,应该在SonarQube 5.1中解决该问题,但实际上它没有得到解决,或者存在另一个与我们当前运行Sona
我已经有一段时间没有看过 SonarQube 了。最新版本看起来很有趣。 上次我查看这个产品时,他们有一个网站,他们通过 SonarQube 进程推送了各种流行的开源库(如 Tomcat、Active
在 SonarQube (5.6.4 LTS) 中有一个后台(项目分析)任务可视化的 View :(管理/项目/后台任务)。似乎任务是按顺序运行的(一次一个)。有些任务可能需要 40 分钟,这意味着其
今天我正在用 mysqldump 备份 MySQL,但我不确定是否需要从/opt/sonar 保存一些文件。请你能帮我一些指示吗? 除了 MySQL,我还需要在 Sonar 中备份什么? 最佳答案 我
我们希望每个用户都能收到一封关于他们在此分析中引入的新问题的电子邮件。 我在这里找到了这个请求,说它应该已经成为可能: http://jira.sonarsource.com/browse/SONAR
是否可以从一个项目导出代码覆盖率和 sonarqube 问题的排除项并导入到其他项目? 最佳答案 排除项是项目属性,因此您可以使用 /api/properties Web 服务自动从一个项目获取这些属
当 Sonar 抛出一个特定的编码规则违规时,开发人员(或就此而言任何授权用户)如何忽略它?假设弹出一条规则“不遵循文件命名约定”,有没有办法可以将其声明为误报并单击某个按钮以确保不会显示该编码规则违
我希望更改规则“左花括号应位于代码行的末尾”,因为我们使用了不同的约定。 提前致谢! 最佳答案 由于 Sonarqube 打算在规则上提供尽可能少的配置:您应该使用 key squid:LeftCur
我正在寻找一种在 SonarQube 中组织项目的方法,并发现我必须为此付费:http://www.sonarqube.org/bring-a-new-dimension-to-sonar-with-
SonarQube Server 5.1.2, Sonar-Runner 2.4 正如 Multi-moduleProject 中提供的那样我创建了一个项目结构 Accounts | ->invoic
在 SonarQube 的 Web UI 中,您可以根据多个条件过滤问题。但似乎没有一个是可以否定的。 我喜欢找出所有关键问题,即 不是 规则xyz。我目前从 Web UI 中只能看到选择我喜欢看的东
我已经设置了一个 jenkins-sonarqube-github 集成工作流程,其中 git 存储库中的拉取请求会触发一个 webhook,该 webhook 会启动一个 jenkins 作业,该作
有没有人设法让 SonarQube 与 Upsource 合作?我已经为 SonarQube 下载了 upsource-sonar-plugin-0.1-SNAPSHOT.jar 插件,并在我通过/s
我正在使用JaCoCo进行代码覆盖。单元测试报告是使用junit创建的,并且已正确导入,因此可以正确显示单元测试信息。 问题是,我收到错误消息: 没有有关每次测试的覆盖率的信息。 ,代码覆盖率显示单元
我有一个 Sonarcloud 帐户,我正在尝试使用 SonarQube.Scanner.MSBuild.exe 分析 Visual Studio 解决方案。我创建了一个 token 并将其作为 So
似乎有最新版本的新规则可用。 我有几个问题报告为“应正确使用 Printf 样式的格式字符串 (squid:S3457)” 我不明白 my case 中的描述和错误是什么: LOGGER.info("
这个问题我看了很多帖子,但是没找到答案所以才问。我将 Sonarqube 从 4.5 升级到 5.6,它工作正常,但质量配置文件是空的。我尝试使用备份/恢复选项恢复一个,但规则被忽略: image .
我实现了 SonarQube在服务器上,我做了大部分配置 远程 .因此,无论何时安装插件,都会重新启动 SonarQube是必需的,每次我都必须显式(手动)重启 SonarQube服务器 . 有没有办
我是一名优秀的程序员,十分优秀!