--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2019 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.ce.task.projectanalysis.measure;
+
+import java.util.EnumMap;
+import org.sonar.server.measure.Rating;
+
+import static org.sonar.ce.task.projectanalysis.measure.Measure.newMeasureBuilder;
+
+public class RatingMeasures {
+ private static final EnumMap<Rating, Measure> ratingMeasureCache;
+
+ static {
+ ratingMeasureCache = new EnumMap<>(Rating.class);
+ for (Rating r : Rating.values()) {
+ ratingMeasureCache.put(r, newMeasureBuilder().create(r.getIndex(), r.name()));
+ }
+ }
+
+ private RatingMeasures() {
+ // static only
+ }
+
+ public static Measure get(Rating rating) {
+ return ratingMeasureCache.get(rating);
+ }
+}
import org.sonar.ce.task.projectanalysis.formula.counter.RatingValue;
import org.sonar.ce.task.projectanalysis.measure.Measure;
import org.sonar.ce.task.projectanalysis.measure.MeasureRepository;
+import org.sonar.ce.task.projectanalysis.measure.RatingMeasures;
import org.sonar.ce.task.projectanalysis.metric.Metric;
import org.sonar.ce.task.projectanalysis.metric.MetricRepository;
import org.sonar.server.measure.Rating;
private void addMaintainabilityRatingMeasure(Component component, double density) {
Rating rating = ratingSettings.getDebtRatingGrid().getRatingForDensity(density);
- measureRepository.add(component, maintainabilityRatingMetric, newMeasureBuilder().create(rating.getIndex(), rating.name()));
+ measureRepository.add(component, maintainabilityRatingMetric, RatingMeasures.get(rating));
}
private void addEffortToMaintainabilityRatingAMeasure(Component component, Path<Counter> path) {
package org.sonar.ce.task.projectanalysis.qualitymodel;
import com.google.common.collect.ImmutableMap;
+import java.util.EnumMap;
+import java.util.HashMap;
import java.util.Map;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.ce.task.projectanalysis.component.Component;
import org.sonar.ce.task.projectanalysis.component.PathAwareVisitorAdapter;
import org.sonar.ce.task.projectanalysis.formula.counter.RatingValue;
import org.sonar.ce.task.projectanalysis.issue.ComponentIssuesRepository;
+import org.sonar.ce.task.projectanalysis.measure.Measure;
import org.sonar.ce.task.projectanalysis.measure.MeasureRepository;
+import org.sonar.ce.task.projectanalysis.measure.RatingMeasures;
import org.sonar.ce.task.projectanalysis.metric.Metric;
import org.sonar.ce.task.projectanalysis.metric.MetricRepository;
import org.sonar.server.measure.Rating;
processIssues(component, path);
path.current().ratingValueByMetric.forEach((key, value) -> {
Rating rating = value.getValue();
- measureRepository.add(component, metricsByKey.get(key), newMeasureBuilder().create(rating.getIndex(), rating.name()));
+ measureRepository.add(component, metricsByKey.get(key), RatingMeasures.get(rating));
});
if (!path.isRoot()) {
path.parent().add(path.current());
import org.sonar.ce.task.projectanalysis.component.TypeAwareVisitorAdapter;
import org.sonar.ce.task.projectanalysis.measure.Measure;
import org.sonar.ce.task.projectanalysis.measure.MeasureRepository;
+import org.sonar.ce.task.projectanalysis.measure.RatingMeasures;
import org.sonar.ce.task.projectanalysis.metric.Metric;
import org.sonar.ce.task.projectanalysis.metric.MetricRepository;
import org.sonar.server.measure.Rating;
int ncloc = nclocMeasure.get().getIntValue();
int securityHotspots = securityHostspotsMeasure.get().getIntValue();
Rating rating = SecurityReviewRating.compute(ncloc, securityHotspots);
- measureRepository.add(component, securityReviewRatingMetric, newMeasureBuilder().create(rating.getIndex(), rating.name()));
+ measureRepository.add(component, securityReviewRatingMetric, RatingMeasures.get(rating));
}
}