系统城装机大师 - 固镇县祥瑞电脑科技销售部宣传站!

当前位置:首页 > 系统教程 > Linux教程 > 详细页面

Linux用sonar获取违规数和代码行数的方法

时间:2017-08-17来源:系统城装机大师作者:zhijie

  在Linux系统中sonar主要是用于管理代码质量,而其中两个重要的参数就是违规数和代码行数了。本文就来介绍一下,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())));

  }

  }

  }

上一页12 
分享到:

相关信息

  • linux定时关机设置教程

    当linux在运作时不能直接关闭电源容易将档案系统损毁,因此需要用shutdown以安全的方式关闭,那么这个操作该怎么实现呢?下面就为大家带来了详细教程。...

    2022-11-07

  • linux强制删除文件教程

    由于linux系统和我们常用的windows系统是不一样的,所以如果是初学者,可能会不知道linux怎么强制删除文件,其实我们只要打开终端,使用命令就可以删除了。...

    2022-11-03

系统教程栏目

栏目热门教程

人气教程排行

站长推荐

热门系统下载