时间:2017-08-17来源:系统城装机大师作者:zhijie
在Linux系统中sonar主要是用于管理代码质量,而其中两个重要的参数就是违规数和代码行数了。本文就来介绍一下,Linux用sonar取得违规数和代码行数的方法。
demo如下:
public class SonarDemo {
static String host = “http://xxx:9000”;
static String username = “xxx”;
static String password = “xxx”;
static String resourceKey = “org.codehaus.sonar:sonar-ws-client”;
static String[] MEASURES_TO_GET = new String[] { “violations”, “lines” };
public static void main(String[] args) {
DecimalFormat df = new DecimalFormat(“#.##”);
//创建Sonar
Sonar sonar = new Sonar(new HttpClient4Connector(new Host(host, username, password)));
//执行资源请求
ResourceQuery query = ResourceQuery.createForMetrics(resourceKey, MEASURES_TO_GET);
query.setIncludeTrends(true);
Resource resource = sonar.find(query);
// 循环遍历获取“violations”, “lines”
List《Measure》 allMeasures = resource.getMeasures();
for (Measure measure : allMeasures) {
System.out.println((measure.getMetricKey() + “: ” +
df.format(measure.getValue())));
}
}
}
2023-02-28
解决linux不识别nfst格式u盘问题技巧 linux无法识别ntfs格式U盘怎么办?2023-02-28
linux扩容swap分区的技巧 linux怎么调整swap大小?2023-02-26
微软Linux资源库首次加入Edge浏览器稳定版当linux在运作时不能直接关闭电源容易将档案系统损毁,因此需要用shutdown以安全的方式关闭,那么这个操作该怎么实现呢?下面就为大家带来了详细教程。...
2022-11-07
由于linux系统和我们常用的windows系统是不一样的,所以如果是初学者,可能会不知道linux怎么强制删除文件,其实我们只要打开终端,使用命令就可以删除了。...
2022-11-03