本文整理汇总了Java中org.sonar.wsclient.Sonar.findAll方法的典型用法代码示例。如果您正苦于以下问题:Java Sonar.findAll方法的具体用法?Java Sonar.findAll怎么用?Java Sonar.findAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.sonar.wsclient.Sonar
的用法示例。
在下文中一共展示了Sonar.findAll方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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);
}
示例3: 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;
}
示例4: 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;
}
示例5: 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;
}
示例6: 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;
}
示例7: 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()));
}
}