All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.devsecops.engine.domain.sonar.api.SonarMeasuresApi Maven / Gradle / Ivy

There is a newer version: 3.4.0
Show newest version
package io.github.devsecops.engine.domain.sonar.api;

import com.google.common.collect.ImmutableMap;
import io.github.devsecops.engine.domain.sonar.model.Metric;
import io.github.devsecops.engine.domain.sonar.utils.SonarMeasureMapper;
import org.sonar.wsclient.SonarClient;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import static java.lang.String.join;
import static java.util.Arrays.asList;

public class SonarMeasuresApi {

    private static final String METRIC_REST_ENDPOINT = "api/measures/component";

    private final SonarClient sonarClient;
    private final SonarMeasureMapper mapper;

    public SonarMeasuresApi(SonarClient sonarClient) {
        this.sonarClient = sonarClient;
        this.mapper = new SonarMeasureMapper();
    }

    public Map calculate(final String component) {
        final List metrics = asList(Metric.values()).stream().map(Metric::getName).collect(Collectors.toList());
        final Map params = ImmutableMap.of(
                "component", component,
                "metricKeys", join(",", metrics)
        );
        final String response = sonarClient.get(METRIC_REST_ENDPOINT, params);
        return mapper.toMeasures(response);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy