有声纳违规:
声纳违规:安全 - 数组直接存储
public void setMyArray(String[] myArray) {
this.myArray = myArray;
}
Run Code Online (Sandbox Code Playgroud)
解:
public void setMyArray(String[] newMyArray) {
if(newMyArray == null) {
this.myArray = new String[0];
} else {
this.myArray = Arrays.copyOf(newMyArray, newMyArray.length);
}
}
Run Code Online (Sandbox Code Playgroud)
但我想知道为什么?
我在Scala中看到了关于静态分析的StackOverflow问题,但是在2009年得到了回答.如您所知,Scala工具正在快速变化.
因此,我想知道熟悉Scala中当前静态分析工具状态的人是否可以告诉我,例如,Scala的Findbugs等价物是否存在.我发现Findbugs为Scala发出了许多不必要的警告,可能与"对象"单例编译成字节码的方式有关,由于特征等等.我听说Scalastyle不仅是Java的CheckStyle的Scala版本,它也是包括Findbugs和PMD.但是,如果它没有实现所有Findbugs和/或PMD,那么还有其他工具可以补充吗?或者,Scalastyle不仅适用于样式检查,还有助于提高代码质量吗?
另外,Scala与Sonar的整合怎么样?Scala Sonar插件(适用于Scalastyle)是否可靠?
我真的有一个"溢出"试图使这些东西一起工作.我按照这里的指示:http://docs.sonarqube.org/display/PLUG/Android+Lint+Plugin,最后得到一个安装了Android Lint插件1.1的SonarQube 5.1.1服务器.然后我配置了我的多模块Gradle构建以使用SonarQube插件:请参阅下面的root配置中的代码片段.
plugins {
id 'org.sonarqube' version '1.0'
}
sonarqube {
properties {
property 'sonar.host.url', 'sonarqube-server:9000'
property 'sonar.jdbc.url', 'jdbc:mysql://sonarqube-db:3306/sonar?useUnicode=true&characterEncoding=utf8'
property 'sonar.jdbc.driverClassName', 'com.mysql.jdbc.Driver'
property 'sonar.jdbc.username', 'sonar'
property 'sonar.jdbc.password', 'sonar'
property 'sonar.sourceEncoding', 'UTF-8'
property 'sonar.login', 'admin'
property 'sonar.password', 'admin'
property 'sonar.profile', 'Android Lint'
property 'sonar.import_unknown_files', true
property 'sonar.android.lint.report', 'build/outputs/lint-results.xml'
}
}
Run Code Online (Sandbox Code Playgroud)
之后我运行lint sonarqube任务来执行分析.因此,我得到了关于'retrolambda'项目(java.lang.UnsupportedOperationException: Unknown ASTNode child: LambdaExpression)的大量Lint错误,这是非常正常的,并且lint-results.xml(每个模块附带HTML版本)文件包含所发现问题的描述.该报告说,发现了8个错误和434个警告.但是当sonarqube插件试图将结果上传到SonarQube服务器时出现问题.日志中充满了"无法找到文件"和"无法找到规则"消息.当处理结束时,我的SonarQube服务器项目没有报告任何问题.
我想知道,出了什么问题?我检查了路径,所有文件都在那里.我浏览了所有可以达到的讨论,似乎我的配置是正确的,我做的一切都是正确的.有没有人有任何线索,我错过了什么,需要检查什么?欢迎任何建议或想法.
如果有一种方法可以使用外部SonarQube Runner导入lint数据,我也会很高兴,因为这个工具似乎比Gradle插件更可预测和更稳定.
我正在收听声纳获取jacoco分析报告的问题.然而,詹金斯能够拿起报告并显示结果.我的项目是由詹金斯建造的maven构建.jacoco报告由maven生成(在pom中配置).通过使用Jenkins插件执行声纳.
这就是我在SonarQube上看到的:

这是我在詹金斯看到的项目报告.

maven插件配置:
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.6.4.201312101107</version>
<executions>
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>default-report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>default-check</id>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
Jenkins Sonar插件配置

我的仓库中有一个Maven Web项目.
我是一个Maven noob,但我仍然理解有这样一个事实,即我们需要配置插件才能运行特定于插件的命令.
事实:
我在本地机器上的端口9000上运行了一个声纳服务器.
我没有在我的POM.xml中添加任何声纳特定插件
参考:
http://www.sonarsource.org/we-had-a-dream-mvn-sonarsonar/
观察:
但是当我从命令行运行mvn sonar:sonar我的项目时,它工作正常.
事实很重要的是我没有在我的POM.xml中配置声纳插件即使那时Maven正在拾取并理解"声纳:声纳"目标/命令?
问题/好奇心:
我不想要声纳本身的工作知识.我想知道为什么mvn sonar:sonar在没有在我的pom.xml中配置声纳插件的情况下工作
为什么以及如何?
我已经将Karma配置为报告我的JavaScript代码的覆盖范围.以下是karma.conf.js文件中配置的一部分:
coverageReporter: {
reporters: [
{
type: 'html',
dir: 'build/karma/coverage'
},
{
type: 'lcov',
dir: 'build/karma/coverage',
subdir: '.'
},
{
type: 'cobertura',
dir: 'build/karma/coverage'
}
]
},
Run Code Online (Sandbox Code Playgroud)
我的lcov.info文件格式如下:
TN:
SF:./app/scripts/app.js
FN:16,(anonymous_1)
FN:26,(anonymous_2)
FNF:2
FNH:1
FNDA:1,(anonymous_1)
FNDA:0,(anonymous_2)
DA:2,1
DA:20,1
DA:29,0
DA:34,0
LF:4
LH:2
BRF:0
BRH:0
end_of_record
Run Code Online (Sandbox Code Playgroud)
不幸的是,在Sonarqube JavaScript的插件,仅考虑与启动线SF:,DA:或BRDA:(CF LCOVParser).
因此,LCOV HTML报告(由伊斯坦布尔制作)使我在相同数据上的代码覆盖率高于Sonar.
有没有办法改变lcov.info生成的格式?
如果我查看伊斯坦布尔代码,我可以想象不同标签的含义:
BRF,BRH,BRDA是分支机构.FN,FNF …我在Maven有一个声纳配置文件.除代码覆盖率指标外,一切正常.我想让Sonar只为代码覆盖率指标忽略一些类.我有以下个人资料:
<profile>
<id>sonar</id>
<properties>
<sonar.exclusions>**/beans/jaxb/**</sonar.exclusions>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven.surefire.plugin.version}</version>
<configuration>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
<excludes>
<exclude>**/*Suite*.java</exclude>
<exclude>**/*RemoteTest.java</exclude>
<exclude>**/*SpringTest.java</exclude>
<exclude>**/*CamelTest.java</exclude>
<exclude>**/*FunctionalTest.java</exclude>
<exclude>**/*IntegrationTest.java</exclude>
<exclude>**/*DaoBeanTest.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
Run Code Online (Sandbox Code Playgroud)
请帮忙.我试着添加类似的东西
<exclude>com/qwerty/dw/publisher/Main.class</exclude>
Run Code Online (Sandbox Code Playgroud)
但它没有帮助
UPDATE
我有一个正确的Cobertura配置文件.我试图将它添加到Sonar配置文件中,但我仍然有53%而不是Cobertura配置文件中的95%
<profile>
<id>sonar</id>
<properties>
<sonar.exclusions>**/beans/jaxb/**</sonar.exclusions>
<sonar.core.codeCoveragePlugin>cobertura</sonar.core.codeCoveragePlugin>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven.surefire.plugin.version}</version>
<configuration>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
<excludes>
<exclude>**/*Suite*.java</exclude>
<exclude>**/*RemoteTest.java</exclude>
<exclude>**/*SpringTest.java</exclude>
<exclude>**/*CamelTest.java</exclude>
<exclude>**/*FunctionalTest.java</exclude>
<exclude>**/*IntegrationTest.java</exclude>
<exclude>**/*DaoBeanTest.java</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>${cobertura.maven.plugin.version}</version>
<configuration>
<instrumentation>
<excludes>
<exclude>com/qwerty/dw/dao/*</exclude>
<exclude>com/qwerty/dw/domain/*</exclude>
<exclude>com/qwerty/dw/beans/**/*</exclude>
<exclude>com/qwerty/dw/daemon/exception/*</exclude>
<exclude>com/qwerty/dw/daemon/Main.class</exclude>
<exclude>com/qwerty/dw/sink/Main.class</exclude>
<exclude>com/qwerty/dw/publisher/Main.class</exclude>
<exclude>com/qwerty/dw/publisher/dao/*</exclude>
<exclude>com/qwerty/dw/publisher/domain/*</exclude>
</excludes>
</instrumentation>
<formats>
<format>html</format>
</formats>
<aggregate>true</aggregate> …Run Code Online (Sandbox Code Playgroud) 我建立Sonar了我的项目,这是一个混合的一个Groovy和Java.我能够为这些语言中的任何一种单独配置项目,但不能一起配置.有没有办法做到这一点?我试过这个
sonar.language = java,grvy
但没有工作
学习如何使用SonarQube并从这里快速安装
一直到第5步.执行时我的构建失败:C:\ sonar-runner\bin\sonar-runner.bat
我收到以下错误:
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
Total time: 7.572s
Final Memory: 8M/223M
INFO: ------------------------------------------------------------------------
ERROR: Error during Sonar runner execution
ERROR: Unable to execute Sonar
ERROR: Caused by: You must define the following mandatory properties for 'Unknown': sonar.projectKey, sonar.projectName, sonar.projectVersion, sonar.sources
ERROR:
ERROR: To see the full stack trace of the errors, re-run SonarQube Runner with the -e switch.
ERROR: Re-run SonarQube Runner using the -X switch to enable full debug logging.
Run Code Online (Sandbox Code Playgroud)
有人遇到过类似的情况并解决了吗?
我想和詹金斯一起设置Sonar.但我不确定Sonar网站是否描述了两种不同的方法,或者是否有两个必要的步骤:
据我所知,它有两种不同的方式.如果是这种情况,有什么区别,有什么优点和缺点(声纳本身和声纳跑步者之间)?
sonarqube ×10
java ×5
maven ×3
jenkins ×2
sonar-runner ×2
android ×1
batch-file ×1
gradle ×1
groovy ×1
jacoco ×1
javascript ×1
karma-runner ×1
lcov ×1
maven-plugin ×1
scala ×1
scalastyle ×1