sonar java,从我的java程序中调用Sonar

I have installed sonar server on my localhost. And I am able to run and analyse the java project. Even i have installed sonar plugin on eclipse.

But I want to run sonar from my java project(like simple java class) and should retrieve the sonar results and able to save it in database. I searched for the tutorial but unable to find the answer for this. Please anyone can give sample code or resource where I can gain knowledge to overcome this task.

import javax.annotation.Resource;

import org.sonar.wsclient.Host;

import org.sonar.wsclient.Sonar;

import org.sonar.wsclient.connectors.HttpClient4Connector;

import org.sonar.wsclient.services.*;

public class SonarTask1{

public static void main(String[] args) {

//public void Hi(){

String url = "http://localhost:9000";

String login = "admin";

String password = "admin";

Sonar sonar = new Sonar(new HttpClient4Connector(new Host(url, login, password)));

String projectKey = "java-sonar-runner-simple";

String manualMetricKey = "burned_budget";

sonar.create(ManualMeasureCreateQuery.create(projectKey, manualMetricKey).setValue(50.0));

for (ManualMeasure manualMeasure : sonar.findAll(ManualMeasureQuery.create(projectKey))) {

System.out.println("Manual measure on project: " + manualMeasure);

}

}

}

解决方案

There are 2 things you can do from a Java program:

launch a Sonar analysis: look into the Sonar Ant Task (in method #launchAnalysis) to see how to do that very easily.

retrieve results from the Sonar server: check the Web API for that purpose

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值