系統(tǒng)之家 - 系統(tǒng)光盤下載網(wǎng)站!

當(dāng)前位置:系統(tǒng)之家 > 系統(tǒng)教程 > Linux用sonar獲取違規(guī)數(shù)和代碼行數(shù)

Linux用sonar獲取違規(guī)數(shù)和代碼行數(shù)的方法

時(shí)間:2015-07-22 13:59:10 作者:zhijie 來源:系統(tǒng)之家 1. 掃描二維碼隨時(shí)看資訊 2. 請使用手機(jī)瀏覽器訪問: https://m.xitongzhijia.net/xtjc/20150722/53510.html 手機(jī)查看 評(píng)論

  在Linux系統(tǒng)中sonar主要是用于管理代碼質(zhì)量,而其中兩個(gè)重要的參數(shù)就是違規(guī)數(shù)和代碼行數(shù)了。本文就來介紹一下,Linux用sonar取得違規(guī)數(shù)和代碼行數(shù)的方法。

Linux用sonar獲取違規(guī)數(shù)和代碼行數(shù)的方法

  demo如下:

  public class SonarDemo {

  static String host = “https://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(“#.##”);

  //創(chuàng)建Sonar

  Sonar sonar = new Sonar(new HttpClient4Connector(new Host(host, username, password)));

  //執(zhí)行資源請求

  ResourceQuery query = ResourceQuery.createForMetrics(resourceKey, MEASURES_TO_GET);

  query.setIncludeTrends(true);

  Resource resource = sonar.find(query);

  // 循環(huán)遍歷獲取“violations”, “lines”

  List《Measure》 allMeasures = resource.getMeasures();

  for (Measure measure : allMeasures) {

  System.out.println((measure.getMetricKey() + “: ” +

  df.format(measure.getValue())));

  }

  }

  }

發(fā)表評(píng)論

0

沒有更多評(píng)論了

評(píng)論就這些咯,讓大家也知道你的獨(dú)特見解

立即評(píng)論

以上留言僅代表用戶個(gè)人觀點(diǎn),不代表系統(tǒng)之家立場

其他版本軟件

熱門教程

人氣教程排行

Linux系統(tǒng)推薦

掃碼關(guān)注
掃碼關(guān)注

掃碼關(guān)注 官方交流群 軟件收錄