use of org.sonar.api.batch.fs.InputComponent in project sonarqube by SonarSource.
the class IssueTransition method execute.
public void execute() {
if (localIssueTracking != null) {
localIssueTracking.init();
}
ScannerReportReader reader = new ScannerReportReader(reportPublisher.getReportDir());
int nbComponents = inputComponentStore.all().size();
if (nbComponents == 0) {
return;
}
ProgressReport progressReport = new ProgressReport("issue-tracking-report", TimeUnit.SECONDS.toMillis(10));
progressReport.start("Performing issue tracking");
int count = 0;
try {
for (InputComponent component : inputComponentStore.all()) {
trackIssues(reader, (DefaultInputComponent) component);
count++;
progressReport.message(count + "/" + nbComponents + " components tracked");
}
} finally {
progressReport.stop(count + "/" + nbComponents + " components tracked");
}
}
use of org.sonar.api.batch.fs.InputComponent in project sonarqube by SonarSource.
the class TestExecutionAndCoveragePublisher method publish.
@Override
public void publish(ScannerReportWriter writer) {
final ScannerReport.Test.Builder testBuilder = ScannerReport.Test.newBuilder();
final ScannerReport.CoverageDetail.Builder builder = ScannerReport.CoverageDetail.newBuilder();
final ScannerReport.CoverageDetail.CoveredFile.Builder coveredBuilder = ScannerReport.CoverageDetail.CoveredFile.newBuilder();
for (final InputComponent c : componentStore.all()) {
DefaultInputComponent component = (DefaultInputComponent) c;
final MutableTestPlan testPlan = testPlanBuilder.loadPerspective(MutableTestPlan.class, component);
if (testPlan == null || Iterables.isEmpty(testPlan.testCases())) {
continue;
}
final Set<String> testNamesWithCoverage = new HashSet<>();
writer.writeTests(component.batchId(), StreamSupport.stream(testPlan.testCases().spliterator(), false).map(testCase -> toProtobufTest(testBuilder, testNamesWithCoverage, testCase)).collect(toList()));
writer.writeCoverageDetails(component.batchId(), testNamesWithCoverage.stream().map(testName -> toProtobufCoverageDetails(builder, coveredBuilder, testPlan, testName)).collect(toList()));
}
}
use of org.sonar.api.batch.fs.InputComponent in project sonarqube by SonarSource.
the class TestExecutionPublisher method publish.
@Override
public void publish(ScannerReportWriter writer) {
for (final InputComponent c : componentStore.all()) {
DefaultInputComponent component = (DefaultInputComponent) c;
if (component.isFile()) {
DefaultInputFile file = (DefaultInputFile) component;
// Recompute test execution measures from MutableTestPlan to take into account the possible merge of several reports
updateTestExecutionFromTestPlan(file, writer);
}
}
}
use of org.sonar.api.batch.fs.InputComponent in project sonarqube by SonarSource.
the class DefaultSensorStorage method saveMeasure.
private void saveMeasure(InputComponent component, DefaultMeasure<?> measure) {
if (component.isFile()) {
DefaultInputFile defaultInputFile = (DefaultInputFile) component;
defaultInputFile.setPublished(true);
}
if (component instanceof InputDir || (component instanceof DefaultInputModule && ((DefaultInputModule) component).definition().getParent() != null)) {
logOnce(measure.metric().key(), "Storing measures on folders or modules is deprecated. Provided value of metric '{}' is ignored.", measure.metric().key());
return;
}
if (DEPRECATED_METRICS_KEYS.contains(measure.metric().key())) {
logOnce(measure.metric().key(), "Metric '{}' is deprecated. Provided value is ignored.", measure.metric().key());
return;
}
Metric metric = metricFinder.findByKey(measure.metric().key());
if (metric == null) {
throw new UnsupportedOperationException("Unknown metric: " + measure.metric().key());
}
if (!measure.isFromCore() && NEWLY_CORE_METRICS_KEYS.contains(measure.metric().key())) {
logOnce(measure.metric().key(), "Metric '{}' is an internal metric computed by SonarQube/SonarCloud. Provided value is ignored.", measure.metric().key());
return;
}
if (!scannerMetrics.getMetrics().contains(metric)) {
throw new UnsupportedOperationException("Metric '" + metric.key() + "' should not be computed by a Sensor");
}
if (((DefaultInputComponent) component).hasMeasureFor(metric)) {
throw new UnsupportedOperationException("Can not add the same measure twice on " + component + ": " + measure);
}
((DefaultInputComponent) component).setHasMeasureFor(metric);
if (metric.key().equals(CoreMetrics.EXECUTABLE_LINES_DATA_KEY)) {
if (component.isFile()) {
((DefaultInputFile) component).setExecutableLines(KeyValueFormat.parseIntInt((String) measure.value()).entrySet().stream().filter(e -> e.getValue() > 0).map(Map.Entry::getKey).collect(Collectors.toSet()));
} else {
throw new IllegalArgumentException("Executable lines can only be saved on files");
}
}
reportPublisher.getWriter().appendComponentMeasure(((DefaultInputComponent) component).scannerId(), toReportMeasure(measure));
}
use of org.sonar.api.batch.fs.InputComponent in project sonarqube by SonarSource.
the class DefaultIndex method addMeasure.
public Measure addMeasure(String key, Measure measure) {
InputComponent component = componentStore.getByKey(key);
if (component == null) {
throw new IllegalStateException("Invalid component key: " + key);
}
if (sensorStorage.isDeprecatedMetric(measure.getMetricKey())) {
// Ignore deprecated metrics
return measure;
}
org.sonar.api.batch.measure.Metric<?> metric = metricFinder.findByKey(measure.getMetricKey());
if (metric == null) {
throw new UnsupportedOperationException("Unknown metric: " + measure.getMetricKey());
}
DefaultMeasure<?> newMeasure;
if (Boolean.class.equals(metric.valueType())) {
newMeasure = new DefaultMeasure<Boolean>().forMetric((Metric<Boolean>) metric).withValue(measure.getValue() != 0.0);
} else if (Integer.class.equals(metric.valueType())) {
newMeasure = new DefaultMeasure<Integer>().forMetric((Metric<Integer>) metric).withValue(measure.getValue().intValue());
} else if (Double.class.equals(metric.valueType())) {
newMeasure = new DefaultMeasure<Double>().forMetric((Metric<Double>) metric).withValue(measure.getValue());
} else if (String.class.equals(metric.valueType())) {
newMeasure = new DefaultMeasure<String>().forMetric((Metric<String>) metric).withValue(measure.getData());
} else if (Long.class.equals(metric.valueType())) {
newMeasure = new DefaultMeasure<Long>().forMetric((Metric<Long>) metric).withValue(measure.getValue().longValue());
} else {
throw new UnsupportedOperationException("Unsupported type :" + metric.valueType());
}
sensorStorage.saveMeasure(component, newMeasure);
return measure;
}
Aggregations