本文整理了Java中org.sonar.api.measures.Metric.getName()
方法的一些代码示例,展示了Metric.getName()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Metric.getName()
方法的具体详情如下:
包路径:org.sonar.api.measures.Metric
类名称:Metric
方法名:getName
暂无
代码示例来源:origin: SonarSource/sonarqube
@Test
public void shouldCreateMetric() {
Metric metric = new Metric.Builder("foo", "Foo", Metric.ValueType.INT)
.setDomain("my domain")
.create();
assertThat(metric.getKey()).isEqualTo("foo");
assertThat(metric.getName()).isEqualTo("Foo");
assertThat(metric.getDomain()).isEqualTo("my domain");
}
代码示例来源:origin: SonarSource/sonarqube
@Test
public void all_core_metrics_are_in_core_bundle() {
List<Metric> coreMetrics = CoreMetrics.getMetrics();
List<String> incorrectMetricDefinitions = new ArrayList<>();
for (Metric metric : coreMetrics) {
if (metric.isHidden()) {
continue;
}
String metricNamePropertyKey = "metric." + metric.getKey() + ".name";
String l10nMetricName = underTest.message(Locale.ENGLISH, metricNamePropertyKey, null);
if (l10nMetricName == null) {
incorrectMetricDefinitions.add(metricNamePropertyKey + "=" + metric.getName());
} else if (!l10nMetricName.equals(metric.getName())) {
incorrectMetricDefinitions.add(metricNamePropertyKey + " is not consistent in core bundle and CoreMetrics");
}
String metricDescriptionPropertyKey = "metric." + metric.getKey() + ".description";
String l10nMetricDescription = underTest.message(Locale.ENGLISH, metricDescriptionPropertyKey, null);
if (l10nMetricDescription == null) {
incorrectMetricDefinitions.add(metricDescriptionPropertyKey + "=" + metric.getDescription());
} else if (!l10nMetricDescription.equals(metric.getDescription())) {
incorrectMetricDefinitions.add(metricDescriptionPropertyKey + " is not consistent in core bundle and CoreMetrics");
}
}
assertThat(incorrectMetricDefinitions).as("Metric definitions to fix in core bundle", incorrectMetricDefinitions.size()).isEmpty();
}
代码示例来源:origin: SonarSource/sonarqube
private static Metric from(int id, org.sonar.api.measures.Metric<?> coreMetric) {
return new MetricImpl(
id, coreMetric.getKey(), coreMetric.getName(),
convert(coreMetric.getType()),
coreMetric.getDecimalScale(),
coreMetric.getBestValue(), coreMetric.isOptimizedBestValue());
}
代码示例来源:origin: SonarSource/sonarqube
@Override
@Nonnull
public MetricDto apply(@Nonnull Metric metric) {
MetricDto dto = new MetricDto();
dto.setId(metric.getId());
dto.setKey(metric.getKey());
dto.setDescription(metric.getDescription());
dto.setShortName(metric.getName());
dto.setBestValue(metric.getBestValue());
dto.setDomain(metric.getDomain());
dto.setEnabled(metric.getEnabled());
dto.setDirection(metric.getDirection());
dto.setHidden(metric.isHidden());
dto.setQualitative(metric.getQualitative());
dto.setValueType(metric.getType().name());
dto.setOptimizedBestValue(metric.isOptimizedBestValue());
dto.setUserManaged(metric.getUserManaged());
dto.setWorstValue(metric.getWorstValue());
dto.setDeleteHistoricalData(metric.getDeleteHistoricalData());
dto.setDecimalScale(metric.getDecimalScale());
return dto;
}
}
代码示例来源:origin: QualInsight/qualinsight-plugins-sonarqube-badges
/**
* Constructs a MeasureHolder from a metric key.
*
* @param metricKey key used to retrieve the metric name for which the MeasureHolder is built
*/
public MeasureHolder(final String metricKey) {
try {
this.metricName = CoreMetrics.getMetric(metricKey)
.getName()
.replace(" (%)", "")
.toLowerCase();
} catch (final NoSuchElementException e) {
LOGGER.debug("Metric '{}' is not referenced in CoreMetrics.", metricKey, e);
this.metricName = metricKey;
}
this.value = NA;
}
代码示例来源:origin: gabrie-allaigre/sonar-gitlab-plugin
@VisibleForTesting
String getMetricName(String metricKey) {
try {
Metric metric = CoreMetrics.getMetric(metricKey);
return metric.getName();
} catch (NoSuchElementException e) {
LOG.trace("Using key as name for custom metric '{}' due to '{}'", metricKey, e);
}
return metricKey;
}
代码示例来源:origin: octo-technology/sonar-objective-c
private void saveMeasures(final CoverageMeasuresBuilder measureBuilder,
final org.sonar.api.resources.File objcfile) {
for (final Measure measure : measureBuilder.createMeasures()) {
LoggerFactory.getLogger(getClass()).debug("Measure {}",
measure.getMetric().getName());
context.saveMeasure(objcfile, measure);
}
}
代码示例来源:origin: org.codehaus.sonar-plugins/sonar-php-plugin
/**
* Saves on measure in the context. One value is associated with a metric and a resource.
*
* @param resource
* Can be a PhpFile or a PhpPackage
* @param metric
* the metric evaluated
* @param measure
* the corresponding value
*/
private void saveMeasure(PhpFile resource, Metric metric, Double measure) {
if (LOG.isDebugEnabled()) {
LOG.debug("Saving " + metric.getName() + " for resource " + resource.getKey() + " with value " + measure);
}
context.saveMeasure(resource, metric, measure);
}
代码示例来源:origin: SonarQubeCommunity/sonar-build-breaker
private static String getMetricName(String metricKey) {
try {
Metric metric = CoreMetrics.getMetric(metricKey);
return metric.getName();
} catch (NoSuchElementException e) {
LOGGER.trace("Using key as name for custom metric '{}' due to '{}'", metricKey, e);
}
return metricKey;
}
代码示例来源:origin: org.codehaus.sonar/sonar-batch
private String getAlertLabel(Resource project, ResolvedCondition condition, Metric.Level level) {
Integer alertPeriod = condition.period();
String metric = i18n.message(Locale.ENGLISH, "metric." + condition.metricKey() + ".name", condition.metric().getName());
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(metric);
if (alertPeriod != null && !condition.metricKey().startsWith(VARIATION_METRIC_PREFIX)) {
String variation = i18n.message(Locale.ENGLISH, VARIATION, VARIATION).toLowerCase();
stringBuilder.append(" ").append(variation);
}
stringBuilder
.append(" ").append(operatorLabel(condition.operator())).append(" ")
.append(alertValue(condition, level));
if (alertPeriod != null) {
Snapshot snapshot = resourceCache.get(project.getEffectiveKey()).snapshot();
stringBuilder.append(" ").append(periods.label(snapshot, alertPeriod));
}
return stringBuilder.toString();
}
代码示例来源:origin: org.codehaus.sonar/sonar-batch
private static Comparable getValueForComparison(Metric metric, String value) {
Comparable valueToCompare = null;
try {
if (isADouble(metric)) {
valueToCompare = Double.parseDouble(value);
} else if (isAInteger(metric)) {
valueToCompare = parseInteger(value);
} else if (isAString(metric)) {
valueToCompare = value;
} else if (isABoolean(metric)) {
valueToCompare = Integer.parseInt(value);
} else if (isAWorkDuration(metric)) {
valueToCompare = Long.parseLong(value);
} else {
throw new NotImplementedException(metric.getType().toString());
}
} catch (NumberFormatException badValueFormat) {
throw new IllegalArgumentException(String.format("Quality Gate: Unable to parse value '%s' to compare against %s", value, metric.getName()));
}
return valueToCompare;
}
代码示例来源:origin: QualInsight/qualinsight-plugins-sonarqube-badges
/**
* 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() ? "%" : "");
}
代码示例来源:origin: stackoverflow.com
start, end);
hqAssertSuccess(dataResponse);
assertTrue("No metric data found for " + m.getName(),
dataResponse.getMetricData().getDataPoint().size() > 0);
for (DataPoint d : dataResponse.getMetricData().getDataPoint()) {
代码示例来源:origin: org.codehaus.sonar/sonar-batch
public FakeGlobalRepositoriesLoader add(Metric metric) {
Boolean optimizedBestValue = metric.isOptimizedBestValue();
ref.metrics().add(new org.sonar.batch.protocol.input.Metric(metricId,
metric.key(),
metric.getType().name(),
metric.getDescription(),
metric.getDirection(),
metric.getName(),
metric.getQualitative(),
metric.getUserManaged(),
metric.getWorstValue(),
metric.getBestValue(),
optimizedBestValue != null ? optimizedBestValue : false));
metricId++;
return this;
}
}
代码示例来源:origin: org.sonarsource.sonarqube/sonar-server
@Override
@Nonnull
public MetricDto apply(@Nonnull Metric metric) {
MetricDto dto = new MetricDto();
dto.setId(metric.getId());
dto.setKey(metric.getKey());
dto.setDescription(metric.getDescription());
dto.setShortName(metric.getName());
dto.setBestValue(metric.getBestValue());
dto.setDomain(metric.getDomain());
dto.setEnabled(metric.getEnabled());
dto.setDirection(metric.getDirection());
dto.setHidden(metric.isHidden());
dto.setQualitative(metric.getQualitative());
dto.setValueType(metric.getType().name());
dto.setOptimizedBestValue(metric.isOptimizedBestValue());
dto.setUserManaged(metric.getUserManaged());
dto.setWorstValue(metric.getWorstValue());
dto.setDeleteHistoricalData(metric.getDeleteHistoricalData());
dto.setDecimalScale(metric.getDecimalScale());
return dto;
}
}
内容来源于网络,如有侵权,请联系作者删除!