private void processMeasure(FileLinesContext context, File measureFile, int lineNumber, String line) { try { String metricKey = StringUtils.substringBefore(line, ":"); String value = line.substring(metricKey.length() + 1); saveMeasure(context, metricKey, KeyValueFormat.parseIntInt(value)); } catch (Exception e) { LOG.error("Error processing line " + lineNumber + " of file " + measureFile.getAbsolutePath(), e); throw new IllegalStateException("Error processing line " + lineNumber + " of file " + measureFile.getAbsolutePath(), e); } }
private static Map<Integer, Integer> parseCountByLine(Optional<Measure> measure) { if (measure.isPresent() && measure.get().getValueType() != Measure.ValueType.NO_VALUE) { return KeyValueFormat.parseIntInt(measure.get().getStringValue()); } return Collections.emptyMap(); }
/** * Merge the two line coverage data measures. For lines hits use the sum, and for conditions * keep max value in case they both contains a value for the same line. */ static String mergeCoverageLineMetric(Metric<?> metric, String value1, String value2) { Map<Integer, Integer> data1 = KeyValueFormat.parseIntInt(value1); Map<Integer, Integer> data2 = KeyValueFormat.parseIntInt(value2); if (metric.key().equals(COVERAGE_LINE_HITS_DATA_KEY)) { return KeyValueFormat.format(Stream.of(data1, data2) .map(Map::entrySet) .flatMap(Collection::stream) .collect( Collectors.toMap( Map.Entry::getKey, Map.Entry::getValue, Integer::sum, TreeMap::new))); } else { return KeyValueFormat.format(Stream.of(data1, data2) .map(Map::entrySet) .flatMap(Collection::stream) .collect( Collectors.toMap( Map.Entry::getKey, Map.Entry::getValue, Integer::max, TreeMap::new))); } }
static void validateCoverageMeasure(String value, InputFile inputFile) { Map<Integer, Integer> m = KeyValueFormat.parseIntInt(value); validatePositiveLine(m, inputFile.toString()); validateMaxLine(m, inputFile); }
private static void storeZeroCoverageForEachExecutableLine(final SensorContext context, InputFile f, DefaultMeasure<String> execLines) { NewCoverage newCoverage = context.newCoverage().onFile(f); Map<Integer, Integer> lineMeasures = KeyValueFormat.parseIntInt((String) execLines.value()); for (Map.Entry<Integer, Integer> lineMeasure : lineMeasures.entrySet()) { int lineIdx = lineMeasure.getKey(); if (lineIdx <= f.lines() && lineMeasure.getValue() > 0) { newCoverage.lineHits(lineIdx, 0); } } newCoverage.save(); }
Map<Integer, Integer> lineHits = KeyValueFormat.parseIntInt(lineHitsMeasure.value()); measureCache.put(inputFile.key(), LINES_TO_COVER_KEY, new DefaultMeasure<Integer>().forMetric(LINES_TO_COVER).withValue(lineHits.keySet().size())); measureCache.put(inputFile.key(), UNCOVERED_LINES_KEY, DefaultMeasure<String> coveredConditionsMeasure = (DefaultMeasure<String>) measureCache.byMetric(inputFile.key(), CoreMetrics.COVERED_CONDITIONS_BY_LINE_KEY); if (conditionsMeasure != null) { Map<Integer, Integer> conditions = KeyValueFormat.parseIntInt(conditionsMeasure.value()); Map<Integer, Integer> coveredConditions = coveredConditionsMeasure != null ? KeyValueFormat.parseIntInt(coveredConditionsMeasure.value()) : Collections.emptyMap(); measureCache.put(inputFile.key(), CONDITIONS_TO_COVER_KEY, new DefaultMeasure<Integer>().forMetric(CONDITIONS_TO_COVER).withValue(conditions .values()
@Test public void helper_parse_methods() { assertThat(KeyValueFormat.parseIntDate("1=2014-01-15")).hasSize(1); assertThat(KeyValueFormat.parseIntDateTime("1=2014-01-15T15:50:45+0100")).hasSize(1); assertThat(KeyValueFormat.parseIntDouble("1=3.14")).hasSize(1); assertThat(KeyValueFormat.parseIntInt("1=10")).containsOnly(entry(1, 10)); assertThat(KeyValueFormat.parseIntString("1=one")).containsOnly(entry(1, "one")); assertThat(KeyValueFormat.parseIntString("1=\"escaped\"")).containsOnly(entry(1, "escaped")); assertThat(KeyValueFormat.parseStringInt("one=1")).containsOnly(entry("one", 1)); assertThat(KeyValueFormat.parseStringDouble("pi=3.14")).containsOnly(entry("pi", 3.14)); }
private void processMeasure(FileLinesContext context, File measureFile, int lineNumber, String line) { try { String metricKey = StringUtils.substringBefore(line, ":"); String value = line.substring(metricKey.length() + 1); saveMeasure(context, metricKey, KeyValueFormat.parseIntInt(value)); } catch (Exception e) { LOG.error("Error processing line " + lineNumber + " of file " + measureFile.getAbsolutePath(), e); throw new IllegalStateException("Error processing line " + lineNumber + " of file " + measureFile.getAbsolutePath(), e); } }
private static Map<Integer, Integer> parseCountByLine(Optional<Measure> measure) { if (measure.isPresent() && measure.get().getValueType() != Measure.ValueType.NO_VALUE) { return KeyValueFormat.parseIntInt(measure.get().getStringValue()); } return Collections.emptyMap(); }
private Map<Integer, Integer> parseCountByLine(@Nullable Measure measure) { if (measure != null && measure.hasData()) { return KeyValueFormat.parseIntInt(measure.getData()); } return Maps.newHashMap(); }
/** * Merge the two line coverage data measures. For lines hits use the sum, and for conditions * keep max value in case they both contains a value for the same line. */ static String mergeCoverageLineMetric(Metric<?> metric, String value1, String value2) { Map<Integer, Integer> data1 = KeyValueFormat.parseIntInt(value1); Map<Integer, Integer> data2 = KeyValueFormat.parseIntInt(value2); if (metric.key().equals(COVERAGE_LINE_HITS_DATA_KEY)) { return KeyValueFormat.format(Stream.of(data1, data2) .map(Map::entrySet) .flatMap(Collection::stream) .collect( Collectors.toMap( Map.Entry::getKey, Map.Entry::getValue, Integer::sum, TreeMap::new))); } else { return KeyValueFormat.format(Stream.of(data1, data2) .map(Map::entrySet) .flatMap(Collection::stream) .collect( Collectors.toMap( Map.Entry::getKey, Map.Entry::getValue, Integer::max, TreeMap::new))); } }
static void validateCoverageMeasure(String value, InputFile inputFile) { Map<Integer, Integer> m = KeyValueFormat.parseIntInt(value); validatePositiveLine(m, inputFile.toString()); validateMaxLine(m, inputFile); }
private static void storeZeroCoverageForEachExecutableLine(final SensorContext context, InputFile f, DefaultMeasure<String> execLines) { NewCoverage newCoverage = context.newCoverage().onFile(f); Map<Integer, Integer> lineMeasures = KeyValueFormat.parseIntInt((String) execLines.value()); for (Map.Entry<Integer, Integer> lineMeasure : lineMeasures.entrySet()) { int lineIdx = lineMeasure.getKey(); if (lineIdx <= f.lines() && lineMeasure.getValue() > 0) { newCoverage.lineHits(lineIdx, 0); } } newCoverage.save(); }
Map<Integer, Integer> lineHits = KeyValueFormat.parseIntInt(lineHitsMeasure.value()); measureCache.put(inputFile.key(), LINES_TO_COVER_KEY, new DefaultMeasure<Integer>().forMetric(LINES_TO_COVER).withValue(lineHits.keySet().size())); measureCache.put(inputFile.key(), UNCOVERED_LINES_KEY, DefaultMeasure<String> coveredConditionsMeasure = (DefaultMeasure<String>) measureCache.byMetric(inputFile.key(), CoreMetrics.COVERED_CONDITIONS_BY_LINE_KEY); if (conditionsMeasure != null) { Map<Integer, Integer> conditions = KeyValueFormat.parseIntInt(conditionsMeasure.value()); Map<Integer, Integer> coveredConditions = coveredConditionsMeasure != null ? KeyValueFormat.parseIntInt(coveredConditionsMeasure.value()) : Collections.emptyMap(); measureCache.put(inputFile.key(), CONDITIONS_TO_COVER_KEY, new DefaultMeasure<Integer>().forMetric(CONDITIONS_TO_COVER).withValue(conditions .values()
public void validate(Measure<?> measure, InputFile inputFile) { Metric<?> metric = measure.getMetric(); if (!isLineMetrics(metric)) { return; } Map<Integer, Integer> m = KeyValueFormat.parseIntInt(measure.getData()); validatePositiveLine(m, inputFile.absolutePath()); validateMaxLine(m, inputFile); }