Tag: sonarqube

声纳定义常数的方法

我使用Sonarqube 5.1并尝试使用“Sonar way”Java质量配置文件。 工作很简单:我想为缺少的媒体类型定义一个全局 String常量: public interface Utf8MediaType { String APPLICATION_JSON = “application/json;charset=UTF-8”; } 然而,Sonarqube告诉我这在规则squid中是不好的做法:S1214 – 不应在接口中定义常量 。 长篇文章讨论了实现这个接口,我并不打算这样做,但我放弃并创建了一个类: public class Utf8MediaType { public static final String APPLICATION_JSON = “application/json;charset=UTF-8”; } 但是,这被认为是规则鱿鱼中的一个主要设计问题:S1118 – 实用程序类不应该有公共构造函数 。 所以它敦促我添加一个私有构造函数。 当然,这个构造函数首先不要违反规则squid中的约定:S1213 – 接口声明或类的成员应该以预定义的顺序出现 。 我想在那之后我甚至可能会得到common-java:InsufficientBranchCoverage,因为私有构造函数不在测试中。 这些是默认规则,我觉得它们组合起来有点傻。 我有更多的例子,其中默认值对我们不起作用(缺少TestNG支持)。 我该怎么办? 您有什么推荐的吗? 让它成为一个类,添加一个私有构造函数,在unit testing中使用内省。 使代码大十倍。 对于String常量。 创建例外列表。 但是为每个项目执行此操作可能会导致长列表,并邀请人们添加例外,即使是重要的事情。 停用规则。 现在我不想篡改默认配置文件,因为这可能意味着Sonarqube升级的很多工作。 创建一个inheritance自默认值并覆盖事物的配置文件。 事实certificate,当您从配置文件inheritance时,您无法停用规则。 […]

从Scala实现具有Raw类型的Java接口

我正在尝试使用Scala为Sonar构建扩展。 我需要扩展以下Java接口: public interface Decorator extends BatchExtension, CheckProject { void decorate(Resource resource, DecoratorContext context); } 但资源类型实际上定义如下: public abstract class Resource 我知道我可以解决创建Java原始超类的问题。 我想坚持Scala-only,也知道我是否缺少一个解决方案,以及是否有一个改进我可以向SonarSource人员建议他们(使用原始类型)。 我已经阅读过这方面存在的问题,以及某些情况下的一些解决方法,但似乎没有适用于此处( 一种解决方法 , 一张明显固定的机票 ,还有2091的机票…)

IntelliJ中的SonarQube本地脚本找不到mvn(IOException / No such directory)

我的maven构建在IntelliJ IDEA中运行良好。 这不是问题。 该问题与SonarQube社区插件有关。 ERROR 17:08:38.358 > java.io.IOException: Cannot run program “mvn” (in directory “/Users/chrismanning/Projects/Registry/registry/idea-files”): error=2, No such file or directory 本地分析脚本: mvn sonar:sonar -DskipTests=true -Dsonar.analysis.mode=issues -Dsonar.scm.enabled=false -Dsonar.scm-stats.enabled=false -Dissueassignplugin.enabled=false -Dsonar.preview.excludePlugins=emailnotifications,issueassign -Dsonar.report.export.path=sonar-report.json 我绝对安装了maven并且在我的路上。 (它在/ usr / local / bin中符号链接) chrismanning@Chriss-MacBook-Pro:~/Projects/Registry/registry/idea-files$ mvn -version Apache Maven 3.2.5 (12a6b3acb947671f09b81f49094c53f426d8cea1; 2014-12-14T12:29:23-05:00) Maven home: /Users/chrismanning/apache-maven-3.2.5 Java version: 1.8.0_40, vendor: Oracle Corporation […]

返回“数据”可能会暴露内部arrays?

考虑一下 public class Data { private final SomeField[] fields; ….. public SomeField[] getFields() { return map == null ? null : map.clone(); } 安全性 – 方法返回内部数组 直接公开内部数组允许用户修改一些可能至关重要的代码。 返回数组副本更安全。 我知道我们不应该使用clone()来复制对象,而是使用copy constructor复制对象。 但是仍然会复制作为引用的内部对象。 有什么建议的方法可以避免上面的clone() ? 谢谢

声纳违规:“方法可能无法关闭exception”

我有这个方法: private void unZipElementsTo(String inputZipFileName, String destPath) throws FileNotFoundException, IOException { OutputStream out = null; InputStream in = null; ZipFile zf = null; try { zf = new ZipFile(inputZipFileName); for (Enumeration em = zf.entries(); em.hasMoreElements();) { ZipEntry entry = em.nextElement(); String targetFile = destPath + FILE_SEPARATOR + entry.toString().replace(“/”, FILE_SEPARATOR); File temp = new File(targetFile); if […]

运行sonarrunner时发现类错误

我正在上课找不到错误。 无法通过类加载器访问该类,并且从gradle运行sonarrunner时会出现错误提示。 这些类在gradle中编译时包含在依赖项中,gradle构建工作正常。 如何将这些类包含在声纳中? 14:53:24.322 INFO – Load module settings 14:53:24.335 INFO – Base dir: /Users/srao1/Documents/GradleTest/lds_warehouse/lds_warehouse_base 14:53:24.335 INFO – Working dir: /Users/srao1/Documents/GradleTest/lds_warehouse/build/sonar/lds_warehouse_lds_warehouse_base 14:53:24.336 INFO – Source paths: src 14:53:24.336 INFO – Test paths: test 14:53:24.336 INFO – Binary dirs: build/classes/main 14:53:24.336 INFO – Source encoding: UTF-8, default locale: en_US 14:53:24.336 INFO – Index files 14:53:24.444 […]

使用Travis,Maven和github的Sonarcloud失败

我工作的项目( 日食/扫描 )使用Travis和Sonar进行持续集成和代码分析。 上周,我注意到构建在声纳步骤失败了: ERROR: Error during SonarQube Scanner execution org.sonar.squidbridge.api.AnalysisException: Please provide compiled classes of your project with sonar.java.binaries property 经过一些研究,我想我已经通过更新addons: 修复这个问题 addons: section( sonarqube to sonarcloud )并切换到使用sonarcloud – mvn -q sonar:sonar而不是- sonar-scanner在script: .travis.yml部分文件。 现在,在声纳步骤中出于不同原因,外部拉动请求(来自叉子)使其通过集成测试失败了: $ mvn -q sonar:sonar … [ERROR] SonarQube server [http://localhost:9000] can not be reached [ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.3.0.603:sonar […]

SonarJava-71使用javax.annotation.Generated进行批注时排除生成代码的问题

我看到这个https://jira.sonarsource.com/browse/SONARJAVA-71改进,当前状态已关闭。 我被要求在这里提出我的问题。 我想知道如何实现修复,因为我试图使用最新的SonarJava 4.10.0.10260,但它仍然报告带有@generated注释的类/方法的问题。 请告知如何实施此修复程序。 包含哪个版本的SonarJava版本此修复程序。 谢谢!

声纳:如何使用try-with-resources关闭FileOutputStream

声纳正在给出一个错误,即应关闭此FileOutputStream 。 我需要修改以下代码以使用try-with-resources 。 我该怎么做呢? public void archivingTheFile(String zipFile){ byte[] buffer = new byte[1024]; try{ FileOutputStream fos = new FileOutputStream(zipFile); ZipOutputStream zos = new ZipOutputStream(fos); for(String file : this.fileList){ ZipEntry ze= new ZipEntry(file); zos.putNextEntry(ze); FileInputStream in = new FileInputStream(SOURCE_FOLDER + File.separator + file); int len; while ((len = in.read(buffer)) > 0) { zos.write(buffer, 0, len); […]

Sonar Lint与服务器规则不同步

Sonar Lint 2.0,它连接到我自己的Sonar Qube服务器,插件没有报告任何问题。 问题是它与我的服务器规则不同步。 找到了Java文档中提到的那些,但它们似乎也不是全部。 我想知道这些java规则列表是否仅在未连接到任何服务器时使用。 使用远程服务器时是否限制使用或同步的规则? 如果可能的话,我们究竟能做些什么来使它同步。 Plateform: Java SonarQube Server: Version 5.6+ Sonar Lint: Version 2.0