本文整理汇总了Java中org.sonar.api.measures.Metric类的典型用法代码示例。如果您正苦于以下问题:Java Metric类的具体用法?Java Metric怎么用?Java Metric使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Metric类属于org.sonar.api.measures包,在下文中一共展示了Metric类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: extractMeasure
import org.sonar.api.measures.Metric; //导入依赖的package包/类
protected static <G extends Serializable> Optional<String> extractMeasure(JsonObject apiResult, Metric<G> metric) {
JsonObject component = apiResult.getMap("component");
if (component == null) {
return Optional.empty();
}
JsonArray measures = component.getCollection("measures");
if (measures == null) {
return Optional.empty();
}
return measures.stream()
.map(o -> (JsonObject) o)
.filter(o ->
metric.getKey().equals(o.getString("metric"))
)
.map(o ->
o.getString("value")
)
.findFirst();
}
示例2: XanitizerMetrics
import org.sonar.api.measures.Metric; //导入依赖的package包/类
/**
* Create all metrics
*/
public XanitizerMetrics() {
metrics = new ArrayList<>();
metrics.add(ALL_XAN_FINDINGS_METRIC);
metrics.add(NEW_FINDINGS_METRIC);
metrics.add(BLOCKER_FINDINGS_METRIC);
metrics.add(CRITICAL_FINDINGS_METRIC);
metrics.add(MAJOR_FINDINGS_METRIC);
metrics.add(MINOR_FINDINGS_METRIC);
metrics.add(INFO_FINDINGS_METRIC);
for (final GeneratedProblemType problemType : GeneratedProblemType.values()) {
final Metric metricOrNull = mkMetricForProblemType(problemType);
if (metricOrNull != null) {
metrics.add(metricOrNull);
}
}
}
示例3: getMetricForSeverity
import org.sonar.api.measures.Metric; //导入依赖的package包/类
/**
* Returns the metric object counting the Xanitizer findings of the given
* severity
*
* @param severity
* @return
*/
public static Metric<Serializable> getMetricForSeverity(final Severity severity) {
switch (severity) {
case BLOCKER:
return BLOCKER_FINDINGS_METRIC;
case CRITICAL:
return CRITICAL_FINDINGS_METRIC;
case MAJOR:
return MAJOR_FINDINGS_METRIC;
case MINOR:
return MINOR_FINDINGS_METRIC;
case INFO:
return INFO_FINDINGS_METRIC;
default:
return null;
}
}
示例4: incrementMetrics
import org.sonar.api.measures.Metric; //导入依赖的package包/类
private void incrementMetrics(final XMLReportFinding xanFinding,
final Map<Metric<Serializable>, Map<InputComponent, Integer>> metricValuesAccu,
final DefaultInputModule project, final InputFile inputFile) {
final Severity severity = SensorUtil.mkSeverity(xanFinding);
final List<Metric<Serializable>> metrics = mkMetrics(xanFinding.getProblemType());
for (final Metric<Serializable> metric : metrics) {
incrementValueForFileAndProject(metric, inputFile, project, metricValuesAccu);
}
final String matchCode = xanFinding.getMatchCode();
if ("NOT".equals(matchCode)) {
incrementValueForFileAndProject(XanitizerMetrics.getMetricForNewXanFindings(),
inputFile, project, metricValuesAccu);
}
final Metric<Serializable> metricForSeverity = XanitizerMetrics
.getMetricForSeverity(severity);
if (metricForSeverity != null) {
incrementValueForFileAndProject(metricForSeverity, inputFile, project,
metricValuesAccu);
}
}
示例5: MeasureHolder
import org.sonar.api.measures.Metric; //导入依赖的package包/类
/**
* Constructs a MeasureHolder from a Measure object.
*
* @param measure used to retrieve the metric name for which the MeasureHolder is built
*/
@SuppressWarnings("unchecked")
public MeasureHolder(final Measure measure) {
final Metric<Serializable> metric = CoreMetrics.getMetric(measure.getMetric());
this.metricName = metric.getName()
.replace(" (%)", "")
.toLowerCase();
String tempValue = null;
if (!measure.hasValue()) {
if (measure.hasPeriods()) {
final PeriodsValue periods = measure.getPeriods();
final PeriodValue periodValue = periods.getPeriodsValue(0);
tempValue = periodValue.getValue();
}
} else {
tempValue = measure.getValue();
}
this.value = tempValue == null ? NA : tempValue + (metric.isPercentageType() ? "%" : "");
}
示例6: Aggregator
import org.sonar.api.measures.Metric; //导入依赖的package包/类
/**
* {@link Aggregator} contructor.
*
* @param context {@link MeasureComputerContext} to which aggregated result has to be saved.
* @param metricKey key of the {@link Metric} for which {@link Measure}s are aggregated.
*/
public Aggregator(final MeasureComputerContext context, final String metricKey) {
this.context = context;
this.metricKey = metricKey;
final Metric<Serializable> metric = SmellMetrics.metricFor(metricKey);
this.valueType = Preconditions.checkNotNull(metric, "No Metric could be found for metric key '{}'", metricKey)
.getType();
switch (this.valueType) {
case INT:
this.value = Integer.valueOf(0);
break;
case WORK_DUR:
this.value = Long.valueOf(0);
break;
default:
throw new UnsupportedOperationException();
}
}
开发者ID:QualInsight,项目名称:qualinsight-plugins-sonarqube-smell,代码行数:24,代码来源:AbstractSmellMeasureComputer.java
示例7: getMetrics_should_return_correctlyConfiguredMetrics
import org.sonar.api.measures.Metric; //导入依赖的package包/类
@Test
@Parameters
public void getMetrics_should_return_correctlyConfiguredMetrics(final Metric<Integer> metric, final String expectedKey, final String expectedName, final ValueType expectedValueType,
final Double expectedBestValue, final String expectedDescription, final Integer expectedDirection, final String expectedDomain) {
final SoftAssertions softly = new SoftAssertions();
softly.assertThat(metric.getKey())
.isEqualTo(expectedKey);
softly.assertThat(metric.getName())
.isEqualTo(expectedName);
softly.assertThat(metric.getType())
.isEqualTo(expectedValueType);
softly.assertThat(metric.getBestValue())
.isEqualTo(expectedBestValue);
softly.assertThat(metric.getDescription())
.isEqualTo(expectedDescription);
softly.assertThat(metric.getDirection())
.isEqualTo(expectedDirection);
softly.assertThat(metric.getDomain())
.isEqualTo(expectedDomain);
softly.assertAll();
}
示例8: decorate_should_saveExpectedMeasureTotal_when_usingAnyMetric
import org.sonar.api.measures.Metric; //导入依赖的package包/类
@Test
@Parameters
public void decorate_should_saveExpectedMeasureTotal_when_usingAnyMetric(final Metric<Integer> metric, final Collection<Measure> measures) {
Mockito.when(this.context.getComponent())
.thenReturn(this.component);
Mockito.when(this.component.getType())
.thenReturn(Type.PROJECT);
Mockito.when(this.context.getChildrenMeasures(Matchers.eq(metric.getKey())))
.thenReturn(measures);
Mockito.when(this.context.getChildrenMeasures(AdditionalMatchers.not(Matchers.eq(metric.getKey()))))
.thenReturn(null);
final AbstractSmellMeasureComputer sut = sut();
sut.compute(this.context);
Mockito.verify(this.context, Mockito.times(1))
.getComponent();
Mockito.verify(this.context, Mockito.times(1))
.getChildrenMeasures(Matchers.eq(metric.getKey()));
Mockito.verify(this.context, Mockito.times(1))
.addMeasure(Matchers.eq(metric.getKey()), Matchers.eq(3));
Mockito.verify(this.context, Mockito.times(sut.getInputMetricsKeys()
.size() - 1))
.addMeasure(AdditionalMatchers.not(Matchers.eq(metric.getKey())), Matchers.eq(0));
}
开发者ID:QualInsight,项目名称:qualinsight-plugins-sonarqube-smell,代码行数:24,代码来源:SmellCountByTypeMeasuresComputerTest.java
示例9: decorate
import org.sonar.api.measures.Metric; //导入依赖的package包/类
@SuppressWarnings({"unchecked", "rawtypes"})
@Override
public void decorate(Resource resource, DecoratorContext context) {
if (resource.getScope().equals(Scopes.FILE)) {
Map lineHits = new HashMap<Integer, Integer>();
context.saveMeasure(CoreMetrics.LINES_TO_COVER, context.getMeasure(CoreMetrics.LINES).getValue());
context.saveMeasure(CoreMetrics.UNCOVERED_LINES, 0.0);
for (int i = 1; i <= context.getMeasure(CoreMetrics.LINES).getIntValue(); i++) {
lineHits.put(i, 1);
}
context.saveMeasure(new Measure(CoreMetrics.COVERAGE_LINE_HITS_DATA).setData(KeyValueFormat.format(lineHits)).setPersistenceMode(PersistenceMode.DATABASE));
}
for (Metric[] entry : CONV) {
applyAndSaveMeasure(entry, context, resource);
}
}
示例10: parse
import org.sonar.api.measures.Metric; //导入依赖的package包/类
/**
* Parses out a {@link Criterion} from the criterionString. If the
* criterionString does not have fields for amount and days, then only the
* metric is set, and the Criterion Type is set to BEST.
*
* @see {@link Parser#parse()}
* @see {@link Criterion#Criterion(Metric)}
* @see {@link Criterion.Type}
*/
@Override
public Criterion parse() {
Criterion criterion;
Metric metric = parseMetric();
double amount = 0;
int days = 0;
try {
amount = parseAmount();
days = parseDays();
criterion = new Criterion(metric, amount, days);
} catch (IndexOutOfBoundsException e) {
criterion = (metric != null) ? new Criterion(metric): null;
}
return criterion;
}
示例11: better
import org.sonar.api.measures.Metric; //导入依赖的package包/类
/**
* Given the two ScoreProjects and the Metric, figures out which one has the
* better Metric value in its latest snapshot.
*
* @param project1
* @param project2
* @param metric
* @return the project that has the better metric value.
*/
protected ScoreProject better(ScoreProject project1, ScoreProject project2,
Metric metric) {
logger.info("Which project is better?");
ScoreProject projectToReturn;
double value1 = currentValue(project1, metric);
double value2 = currentValue(project2, metric);
if (isBetter(value1, value2, metric)) {
projectToReturn = project1;
} else {
projectToReturn = project2;
}
logger.info(project1.getName() + " has " + value1 + ", "
+ project2.getName() + " has " + value2 + ", so:");
logger.info(projectToReturn.getName() + " is better.");
return projectToReturn;
}
示例12: currentValue
import org.sonar.api.measures.Metric; //导入依赖的package包/类
/**
* Given the ScoreProject, finds its current value for the given Metric.
* @param thisProject
* @param metric
* @return the latest value for the metric attained by the ScoreProject.
*/
private double currentValue(ScoreProject thisProject, Metric metric) {
logger.info("Current Value");
SnapShotDao helper = new SnapShotDao(session, thisProject);
List<SnapshotValue> history = helper.getMeasureCollection(metric
.getName());
Collections.sort(history);
SnapshotValue lastSnapshot = (history.size() > 0) ? history.get(history
.size() - 1) : null;
logger.info("Last Snapshot for " + thisProject.getName() + " = "
+ lastSnapshot);
double value = (lastSnapshot != null) ? lastSnapshot.getMeasureValue()
.doubleValue() : 0;
logger.info("current value = " + value);
return value;
}
示例13: testCriteriaNotMetNextMeasureValue
import org.sonar.api.measures.Metric; //导入依赖的package包/类
/**
* Testing that when the criteriaMet returns false when the next measure value for a metric with a direction of -1
* does not meet the criteria
*/
@Test
public void testCriteriaNotMetNextMeasureValue(){
BigDecimal bd20= new BigDecimal (25);
BigDecimal bd21= new BigDecimal (100);
Date date20 = new Date(1370464358000l); //6/5/2013
Date date21 = new Date(1367785958000l);//5/5/2013
SnapshotValue sh20 = new SnapshotValue(bd20,date20);
SnapshotValue sh21 = new SnapshotValue(bd21,date21);
List<SnapshotValue> info = new ArrayList<SnapshotValue>();
info.add(sh20);
info.add(sh21);
when(mockSession.getSingleResult(Metric.class, "name",violationsName, "enabled", true)).thenReturn(violationsMetric);
assertFalse(trophiesHelper.criteriaMet(info, requiredAmount, 1, violationsName, mockSession));
}
示例14: testCriteriaMetWhenNextMeasureValueIsTheLastIndex
import org.sonar.api.measures.Metric; //导入依赖的package包/类
/** Testing that criteriaMet returns true when the last snapshot criteria is met and it is the next
* measure value */
@Test
public void testCriteriaMetWhenNextMeasureValueIsTheLastIndex(){
BigDecimal bd20= new BigDecimal (25);
BigDecimal bd21= new BigDecimal (24);
Date date20 = new Date(1370464358000l); //6/5/2013
Date date21 = new Date(1367785958000l);//5/5/2013
SnapshotValue sh20 = new SnapshotValue(bd20,date20);
SnapshotValue sh21 = new SnapshotValue(bd21,date21);
SnapshotValue sh22 = new SnapshotValue(bd22,date22);
List<SnapshotValue> info = new ArrayList<SnapshotValue>();
info.add(sh20);
info.add(sh21);
int day = 1;
when(mockSession.getSingleResult(Metric.class, "name",violationsName, "enabled", true)).thenReturn(violationsMetric);
assertTrue(trophiesHelper.criteriaMet(info, requiredAmount, day, violationsName, mockSession));
}
示例15: testCriteriaMetWhenGoodMeasureValuesInMiddleAndLastMeasureValueEqualsRequiredAmount
import org.sonar.api.measures.Metric; //导入依赖的package包/类
/**
* Testing that criteriaMet returns true when criteria is met between measure values that do not
* meet the criteria and the last measure value equals the required amount
*/
@Test
public void testCriteriaMetWhenGoodMeasureValuesInMiddleAndLastMeasureValueEqualsRequiredAmount(){
BigDecimal bd20= new BigDecimal (50);
BigDecimal bd21= new BigDecimal (25);
BigDecimal bd22= new BigDecimal (25);
BigDecimal bd23= new BigDecimal (50);
Date date20 = new Date(1370464358000l); //6/5/2013
Date date21 = new Date(1367785958000l);//5/5/2013
Date date22 = new Date(1360099958000l);//2/5/2013
Date date23 = new Date(1360099958000l);//2/5/2013
SnapshotValue sh20 = new SnapshotValue(bd20,date20);
SnapshotValue sh21 = new SnapshotValue(bd21,date21);
SnapshotValue sh22 = new SnapshotValue(bd22,date22);
SnapshotValue sh23 = new SnapshotValue(bd23,date23);
List<SnapshotValue> info = new ArrayList<SnapshotValue>();
info.add(sh20);
info.add(sh21);
info.add(sh22);
info.add(sh23);
int day = 30;
when(mockSession.getSingleResult(Metric.class, "name",violationsName, "enabled", true)).thenReturn(violationsMetric);
assertTrue(trophiesHelper.criteriaMet(info, requiredAmount, day, violationsName, mockSession));
}