Linux uses sonar to get the number of violations and lines of code

  
                

In Linux, sonar is mainly used to manage code quality, and two important parameters are the number of violations and the number of lines of code. This article will introduce the way that Linux uses sonar to get the number of violations and the number of lines of code.

demo follows:

public class SonarDemo {

static String host = & ldquo; http: //xxx: 9000 & rdquo ;;

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(“#.##”);

//Create Sonar

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

//Execute resource request

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

query.setIncludeTrends(true);

Resource resource = sonar.find(query);

//Loop traversal gets “violations”, “lines”

List "Measure" allMeasures = resource.getMeasures();

for (Measure measure : allMeasures) {

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

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

}

}

} Previous 12 Next Total 2 Pages

Copyright © Windows knowledge All Rights Reserved