public void visitFile(Component file, Path<QualityModelCounter> path) {
if (!file.getFileAttributes().isUnitTest()) {
path.current().addDevCosts(computeDevelopmentCost(file));
- for (Issue issue : componentIssuesRepository.getIssues(file)) {
- if (issue.resolution() == null) {
- path.current().addIssue(issue);
- }
- }
computeAndSaveMeasures(file, path);
}
}
}
private void computeAndSaveMeasures(Component component, Path<QualityModelCounter> path) {
+ addIssues(component, path);
addDevelopmentCostMeasure(component, path.current());
double density = computeDensity(component, path.current());
addToParent(path);
}
+ private void addIssues(Component component, Path<QualityModelCounter> path){
+ for (Issue issue : componentIssuesRepository.getIssues(component)) {
+ if (issue.resolution() == null) {
+ path.current().addIssue(issue);
+ }
+ }
+ }
+
private double computeDensity(Component component, QualityModelCounter developmentCost) {
Optional<Measure> measure = measureRepository.getRawMeasure(component, maintainabilityRemediationEffortMetric);
double maintainabilityRemediationEffort = measure.isPresent() ? measure.get().getLongValue() : 0L;
*/
package org.sonar.server.computation.issue;
+import java.util.Collections;
import java.util.List;
import javax.annotation.CheckForNull;
import org.junit.rules.ExternalResource;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static java.util.Objects.requireNonNull;
+import static org.sonar.server.computation.component.Component.Type.PROJECT_VIEW;
+import static org.sonar.server.computation.component.Component.Type.SUBVIEW;
+import static org.sonar.server.computation.component.Component.Type.VIEW;
public class ComponentIssuesRepositoryRule extends ExternalResource implements MutableComponentIssuesRepository, ComponentIssuesRepository {
@Override
public List<DefaultIssue> getIssues(Component component) {
checkNotNull(component, "component cannot be null");
+ // Views has no issues
+ if (component.getType().equals(PROJECT_VIEW)
+ || component.getType().equals(SUBVIEW)
+ || component.getType().equals(VIEW)) {
+ return Collections.emptyList();
+ }
return getIssues(component.getReportAttributes().getRef());
}
@Test
public void compute_reliability_rating() throws Exception {
treeRootHolder.setRoot(ROOT_PROJECT);
- fillComponentIssuesVisitorRule.setIssues(FILE_1_REF, newBugIssue(10L, BLOCKER), newBugIssue(1L, MAJOR),
+ fillComponentIssuesVisitorRule.setIssues(FILE_1_REF, newBugIssue(10L, MAJOR), newBugIssue(1L, MAJOR),
// Should not be taken into account
newVulnerabilityIssue(5L, MINOR)
);
// Should not be taken into account
newBugIssue(10L, BLOCKER).setResolution(RESOLUTION_FIXED)
);
+ fillComponentIssuesVisitorRule.setIssues(MODULE_REF, newBugIssue(7L, BLOCKER));
underTest.visit(ROOT_PROJECT);
- verifyAddedRawMeasure(FILE_1_REF, RELIABILITY_RATING_KEY, E);
+ verifyAddedRawMeasure(FILE_1_REF, RELIABILITY_RATING_KEY, C);
verifyAddedRawMeasure(FILE_2_REF, RELIABILITY_RATING_KEY, D);
- verifyAddedRawMeasure(DIRECTORY_REF, RELIABILITY_RATING_KEY, E);
+ verifyAddedRawMeasure(DIRECTORY_REF, RELIABILITY_RATING_KEY, D);
verifyAddedRawMeasure(MODULE_REF, RELIABILITY_RATING_KEY, E);
verifyAddedRawMeasure(PROJECT_REF, RELIABILITY_RATING_KEY, E);
}
@Test
public void compute_security_rating() throws Exception {
treeRootHolder.setRoot(ROOT_PROJECT);
- fillComponentIssuesVisitorRule.setIssues(FILE_1_REF, newVulnerabilityIssue(10L, BLOCKER), newVulnerabilityIssue(1L, MAJOR),
+ fillComponentIssuesVisitorRule.setIssues(FILE_1_REF, newVulnerabilityIssue(10L, MAJOR), newVulnerabilityIssue(1L, MAJOR),
// Should not be taken into account
newBugIssue(1L, MAJOR));
fillComponentIssuesVisitorRule.setIssues(FILE_2_REF, newVulnerabilityIssue(2L, CRITICAL), newVulnerabilityIssue(3L, MINOR),
// Should not be taken into account
newVulnerabilityIssue(10L, BLOCKER).setResolution(RESOLUTION_FIXED)
);
+ fillComponentIssuesVisitorRule.setIssues(MODULE_REF, newVulnerabilityIssue(7L, BLOCKER));
underTest.visit(ROOT_PROJECT);
- verifyAddedRawMeasure(FILE_1_REF, SECURITY_RATING_KEY, E);
+ verifyAddedRawMeasure(FILE_1_REF, SECURITY_RATING_KEY, C);
verifyAddedRawMeasure(FILE_2_REF, SECURITY_RATING_KEY, D);
- verifyAddedRawMeasure(DIRECTORY_REF, SECURITY_RATING_KEY, E);
+ verifyAddedRawMeasure(DIRECTORY_REF, SECURITY_RATING_KEY, D);
verifyAddedRawMeasure(MODULE_REF, SECURITY_RATING_KEY, E);
verifyAddedRawMeasure(PROJECT_REF, SECURITY_RATING_KEY, E);
}
import org.sonar.server.computation.component.ComponentVisitor;
import org.sonar.server.computation.component.ViewsComponent;
import org.sonar.server.computation.component.VisitorsCrawler;
+import org.sonar.server.computation.issue.ComponentIssuesRepositoryRule;
import org.sonar.server.computation.measure.Measure;
import org.sonar.server.computation.measure.MeasureRepositoryRule;
import org.sonar.server.computation.metric.MetricRepositoryRule;
@Rule
public MeasureRepositoryRule measureRepository = MeasureRepositoryRule.create(treeRootHolder, metricRepository);
+ @Rule
+ public ComponentIssuesRepositoryRule componentIssuesRepositoryRule = new ComponentIssuesRepositoryRule(treeRootHolder);
+
private RatingSettings ratingSettings = mock(RatingSettings.class);
private VisitorsCrawler underTest;
@Before
public void setUp() {
when(ratingSettings.getRatingGrid()).thenReturn(new RatingGrid(RATING_GRID));
- underTest = new VisitorsCrawler(Arrays.<ComponentVisitor>asList(new QualityModelMeasuresVisitor(metricRepository, measureRepository, ratingSettings, null)));
+ underTest = new VisitorsCrawler(Arrays.<ComponentVisitor>asList(new QualityModelMeasuresVisitor(metricRepository, measureRepository, ratingSettings, componentIssuesRepositoryRule)));
}
@Test