本文整理汇总了Java中org.sonar.wsclient.Sonar类的典型用法代码示例。如果您正苦于以下问题:Java Sonar类的具体用法?Java Sonar怎么用?Java Sonar使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Sonar类属于org.sonar.wsclient包,在下文中一共展示了Sonar类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getStoreCurrentValue
import org.sonar.wsclient.Sonar; //导入依赖的package包/类
/**
* Retrieves a single value by a Sonar request.
* @param host Sonar host
* @param resourceKey the "project" to analyse
* @param metricKey the metric to retrieve
* @param stats
* @return true if metric value found and put to stats
*/
public static boolean getStoreCurrentValue(String host, String resourceKey, String metricKey, SonarStatistics stats){
Sonar sonar = Sonar.create(host);
ResourceQuery query = ResourceQuery.createForMetrics(resourceKey, metricKey);
Resource resource = null;
try {
resource = sonar.find(query);
} catch (org.sonar.wsclient.connectors.ConnectionException e) {
System.err.println("ConnectionException: Not able to connect to server "+host);
}
Measure measure;
if (resource != null) {
if ((measure = resource.getMeasure(metricKey)) != null) {
// System.out.println(measure);
stats.singleValues.put(metricKey, measure.getValue());
return true;
// return measure.getValue();
}
}
System.err.println("Warning[getCurrentValue]: Measure \""+ metricKey +"\" is empty." );
return false; //return 0.0;
}
开发者ID:RISCOSS,项目名称:riscoss-data-collector,代码行数:30,代码来源:RetrieveStats.java
示例2: getValuesPerClass
import org.sonar.wsclient.Sonar; //导入依赖的package包/类
/**
* Get Sonar values for a project, per class
*
* @param host Sonar host
* @param resourceKey the "project" to analyse
* @param metricKey the metric to retrieve
*/
public static ArrayList<Double> getValuesPerClass(String host, String resourceKey, String metricKey)
{
ArrayList<Double> values = new ArrayList<Double>();
Sonar sonar = Sonar.create(host);
ResourceQuery query = new ResourceQuery(resourceKey);
query.setMetrics(metricKey.trim());
query.setScopes("FIL");
query.setDepth(-1);
for (Resource resource : sonar.findAll(query)) {
Measure m = resource.getMeasure(metricKey);
if (m != null) {
values.add(m.getValue());
}
}
return values;
}
开发者ID:rbenjacob,项目名称:riscoss-platform,代码行数:24,代码来源:RetrieveStats.java
示例3: getStoreCurrentValue
import org.sonar.wsclient.Sonar; //导入依赖的package包/类
/**
* Retrieves a single value by a Sonar request.
*
* @param host Sonar host
* @param resourceKey the "project" to analyse
* @param metricKey the metric to retrieve
* @return true if metric value found and put to stats
*/
public static boolean getStoreCurrentValue(String host, String resourceKey, String metricKey, SonarStatistics stats)
{
Sonar sonar = Sonar.create(host);
ResourceQuery query = ResourceQuery.createForMetrics(resourceKey, metricKey);
Resource resource = null;
try {
resource = sonar.find(query);
} catch (org.sonar.wsclient.connectors.ConnectionException e) {
System.err.println("ConnectionException: Not able to connect to server " + host);
}
Measure measure;
if (resource != null) {
if ((measure = resource.getMeasure(metricKey)) != null) {
// System.out.println(measure);
stats.singleValues.put(metricKey, measure.getValue());
return true;
// return measure.getValue();
}
}
System.err.println("Warning[getCurrentValue]: Measure \"" + metricKey + "\" is empty.");
return false; //return 0.0;
}
开发者ID:rbenjacob,项目名称:riscoss-platform,代码行数:31,代码来源:RetrieveStats.java
示例4: getAllProjectsMetrics
import org.sonar.wsclient.Sonar; //导入依赖的package包/类
@Override
public List<ProjectStatsBean> getAllProjectsMetrics(String[] metrics, Date prevDate) {
LOG.info("Enter getAppProjects to get all the projects by calling the sonar client ");
Sonar sonar = Sonar.create(getSonarServerUrl(),
SonarUtils.getSonarServerUserName(),
SonarUtils.getSonarServerPassword());
List<Resource> resources = sonar.findAll(new ResourceQuery()
.setMetrics(metrics));
if (resources != null) {
LOG.debug("list of resouces returned are " + resources.size());
}
LOG.debug("Resources returned are " + resources);
return populateSonarServiceResponse(resources,prevDate,metrics);
}
开发者ID:pradeepruhil85,项目名称:Sonar-Email-Reports,代码行数:19,代码来源:SonarServiceImpl.java
示例5: collectMetricForResource
import org.sonar.wsclient.Sonar; //导入依赖的package包/类
public double collectMetricForResource(SonarConnectionSettings connectionSettings, String resourceKey, String metricIdentifier) throws ResourceNotFoundException {
if (!connectionSettings.hasProject()) {
throw new IllegalArgumentException("you can only collect metric value for a resource with connection settings that has a project");
}
Sonar sonar = new Sonar(new HttpClient4Connector(connectionSettings.asHostObject()));
Resource resource = sonar.find(ResourceQuery.create(resourceKey).setMetrics(metricIdentifier));
if (resource == null) {
log.debug("Could not find measurement for metric {} at resource {}", metricIdentifier, resourceKey);
return DEFAULT_VALUE;
}
Double metricValue = resource.getMeasureValue(metricIdentifier);
if (metricValue == null) {
log.error("Metric identifier " + metricIdentifier + " is not supported by the given Sonar server at " + connectionSettings.toString());
throw new ResourceNotFoundException("Could not find metric with identifier: " + metricIdentifier);
}
log.debug("{} = {} for {}", metricIdentifier, metricValue, resourceKey);
return metricValue;
}
开发者ID:CodeQInvest,项目名称:codeq-invest,代码行数:19,代码来源:MetricCollectorService.java
示例6: getValuesPerClass
import org.sonar.wsclient.Sonar; //导入依赖的package包/类
/**
* Get Sonar values for a project, per class
* @param host Sonar host
* @param resourceKey the "project" to analyse
* @param metricKey the metric to retrieve
* @return
*/
public static ArrayList<Double> getValuesPerClass(String host, String resourceKey, String metricKey){
ArrayList<Double> values = new ArrayList<Double>();
Sonar sonar = Sonar.create(host);
ResourceQuery query = new ResourceQuery(resourceKey);
query.setMetrics(metricKey.trim());
query.setScopes("FIL");
query.setDepth(-1);
for (Resource resource : sonar.findAll(query)){
Measure m =resource.getMeasure(metricKey);
if(m!=null) values.add(m.getValue());
}
return values;
}
开发者ID:RISCOSS,项目名称:riscoss-data-collector,代码行数:21,代码来源:RetrieveStats.java
示例7: getStatisticsPerClass
import org.sonar.wsclient.Sonar; //导入依赖的package包/类
/**
* Obtains the list of all classes of a project (or module) with their metrics per class.
*
* @param resourceKey the project or module to analyse.
* @return the list of classes of such project or module with their metrics, -1 if metric value not found.
*/
public static ArrayList<ClassInfo> getStatisticsPerClass(String host, String resourceKey, String[] metricNames)
{
ArrayList<ClassInfo> list = new ArrayList<ClassInfo>();
Sonar sonar = Sonar.create(host);
ResourceQuery query = new ResourceQuery(resourceKey);
query.setMetrics(metricNames);
query.setScopes("FIL");
query.setDepth(-1);
//**************************************************put above and control!
for (Resource resource : sonar.findAll(query)) {
ClassInfo classInfo = new ClassInfo();
classInfo.setClassName(resource.getName());
for (String metricName : metricNames) {
Measure measure = resource.getMeasure(metricName);
// System.err.println(measure);
if (measure != null) {
classInfo.setMetric(metricName, measure.getValue());
} else {
System.err.print("Warning[getClassInfos]: " + metricName + " of " + resource.getName()
+ " is empty. ");
classInfo.setMetric(metricName, new Double(-1.0));
}
}
list.add(classInfo);
}
System.err.println();
return list;
}
开发者ID:RISCOSS,项目名称:riscoss-data-collector,代码行数:36,代码来源:ClassInfoManager.java
示例8: fetchData
import org.sonar.wsclient.Sonar; //导入依赖的package包/类
@Override
public SonarData fetchData(String host, String resourceId)
throws ServiceUnavailableException, ResourceNotFoundException {
Sonar sonar = Sonar.create(host);
SonarData result = null;
try {
ResourceQuery query = ResourceQuery.createForMetrics(resourceId,
SONAR_METRIC_KEY_TESTS, SONAR_METRIC_KEY_TEST_ERRORS,
SONAR_METRIC_KEY_TEST_FAILURES,
SONAR_METRIC_KEY_TEST_SUCCESS_DENSITY,
SONAR_METRIC_KEY_TEST_EXECUTION_TIME,
SONAR_METRIC_KEY_TEST_SKIPPED);
query.setTimeoutMilliseconds(SONAR_TIMEOUT_IN_SECONDS * 1000);
Resource resource = sonar.find(query);
if (resource == null) {
throw new ResourceNotFoundException("No resource '"
+ resourceId + "' found on Sonar @ " + host);
} else {
result = new SonarData(resource);
}
} catch (RuntimeException /*
* org.sonar.wsclient.connectors.ConnectionException
*/e) {
throw new ServiceUnavailableException(
"Runtime exception occured while retrieving information from Sonar @ "
+ host + ", root cause: " + e.getMessage(), e);
}
return result;
}
开发者ID:baloise,项目名称:dashboard-plus,代码行数:33,代码来源:SonarService.java
示例9: collectAllResourcesForProject
import org.sonar.wsclient.Sonar; //导入依赖的package包/类
public Collection<Resource> collectAllResourcesForProject(SonarConnectionSettings connectionSettings) {
if (!connectionSettings.hasProject()) {
throw new IllegalArgumentException("you can only collect resources with connection settings that has a project");
}
log.info("Start collecting all classes for project {} at Sonar server", connectionSettings.getProject());
Sonar sonar = new Sonar(new HttpClient4Connector(connectionSettings.asHostObject()));
List<Resource> resources = sonar.findAll(ResourceQuery.create(connectionSettings.getProject())
.setAllDepths()
.setScopes("FIL")
.setQualifiers("FIL"));
log.info("Found {} classes for project {}", resources.size(), connectionSettings.getProject());
return resources;
}
开发者ID:CodeQInvest,项目名称:codeq-invest,代码行数:14,代码来源:ResourcesCollectorService.java
示例10: collectAllProjects
import org.sonar.wsclient.Sonar; //导入依赖的package包/类
/**
* Collects all Java projects of the specified Sonar server.
*/
public Set<ProjectInformation> collectAllProjects(SonarConnectionSettings connectionSettings) {
Sonar sonar = new Sonar(new HttpClient4Connector(connectionSettings.asHostObject()));
List<Resource> projectResources = sonar.findAll(new ResourceQuery());
Set<ProjectInformation> projects = new TreeSet<ProjectInformation>();
for (Resource resource : projectResources) {
projects.add(new ProjectInformation(resource.getName(), resource.getKey()));
}
return projects;
}
开发者ID:CodeQInvest,项目名称:codeq-invest,代码行数:13,代码来源:ProjectsCollectorService.java
示例11: analyse
import org.sonar.wsclient.Sonar; //导入依赖的package包/类
@Override
public void analyse(Project aProject, SensorContext aSensorContext) {
LOGGER.info("Collecting metrics before analysis");
String theSonarHostUrl = settings.getString(Constants.SONAR_HOST_URL);
if (theSonarHostUrl.endsWith("/")) {
theSonarHostUrl = theSonarHostUrl.substring(0, theSonarHostUrl.length() - 1);
}
String theUsername = settings.getString(Constants.SONAR_USERNAME);
String thePassword = settings.getString(Constants.SONAR_PASSWORD);
LOGGER.info("Connecting to {} with username = {}", theSonarHostUrl, theUsername);
Sonar theSonar = Sonar.create(theSonarHostUrl, theUsername, thePassword);
ResourceQuery theQuery = ResourceQuery.create(aProject.getKey());
theQuery.setDepth(0);
Resource theResource = theSonar.find(theQuery);
persister.logAnalysisStart(new Date());
if (theResource != null) {
LOGGER.info("Data found for project key {}", aProject.getKey());
persister.logLastAnalysis(theResource.getDate());
Set<String> theMetricsKey = new HashSet<>();
Map<String, String> theMetricsToDescription = new HashMap<>();
MetricQuery theCollectMetricKeysQuery = MetricQuery.all();
for (Metric theMetric : theSonar.findAll(theCollectMetricKeysQuery)) {
theMetricsToDescription.put(theMetric.getKey(), theMetric.getDescription());
theMetricsKey.add(theMetric.getKey());
}
ResourceQuery theMetricsQuery = ResourceQuery
.createForMetrics(aProject.getKey(), theMetricsKey.toArray(new String[theMetricsKey.size()]));
Resource theMetrics = theSonar.find(theMetricsQuery);
for (Measure theMeasure : theMetrics.getMeasures()) {
String theMetricKey = theMeasure.getMetricKey();
persister.registerMetricKeyWithDescription(theMetricKey, theMetricsToDescription.get(theMetricKey));
LOGGER.debug("Found historic data for metric {}", theMetricKey);
Double theValue = theMeasure.getValue();
persister.logBeforeAnalysis(theMetricKey, theValue);
}
} else {
// We need a last Analysis Date in any case. This happens during the first analyis of a project.
persister.logLastAnalysis(new Timestamp(System.currentTimeMillis()));
}
}
开发者ID:mirkosertic,项目名称:sonardeltareport,代码行数:58,代码来源:BeforeAnalysisSensor.java
注:本文中的org.sonar.wsclient.Sonar类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论