import org.sonar.ce.task.step.ComputationStep;
import static org.sonar.api.measures.CoreMetrics.CLASSES_KEY;
-import static org.sonar.api.measures.CoreMetrics.DIRECTORIES_KEY;
import static org.sonar.api.measures.CoreMetrics.FILES_KEY;
import static org.sonar.api.measures.CoreMetrics.FUNCTIONS_KEY;
import static org.sonar.api.measures.CoreMetrics.GENERATED_LINES_KEY;
@Override
public void execute(ComputationStep.Context context) {
new PathAwareCrawler<>(new FileAndDirectoryMeasureVisitor(
- metricRepository.getByKey(DIRECTORIES_KEY),
metricRepository.getByKey(FILES_KEY),
metricRepository.getByKey(LINES_KEY)))
.visit(treeRootHolder.getRoot());
}
private class FileAndDirectoryMeasureVisitor extends PathAwareVisitorAdapter<Counter> {
- private final Metric directoryMetric;
private final Metric fileMetric;
private final Metric linesMetric;
- public FileAndDirectoryMeasureVisitor(Metric directoryMetric, Metric fileMetric, Metric linesMetric) {
+ public FileAndDirectoryMeasureVisitor(Metric fileMetric, Metric linesMetric) {
super(CrawlerDepthLimit.LEAVES, POST_ORDER, COUNTER_STACK_ELEMENT_FACTORY);
- this.directoryMetric = directoryMetric;
this.fileMetric = fileMetric;
this.linesMetric = linesMetric;
}
@Override
public void visitDirectory(Component directory, Path<Counter> path) {
int mainfileCount = path.current().files;
- path.parent().directories += path.current().directories;
- if (mainfileCount > 0 || path.current().directories > 0) {
- path.parent().directories += 1;
- }
if (mainfileCount > 0) {
measureRepository.add(directory, fileMetric, newMeasureBuilder().create(mainfileCount));
measureRepository.add(directory, linesMetric, newMeasureBuilder().create(path.current().lines));
path.parent().files += mainfileCount;
path.parent().lines += path.current().lines;
}
- int mainDirectoryCount = path.current().directories;
- if (mainDirectoryCount > 0) {
- measureRepository.add(directory, directoryMetric, newMeasureBuilder().create(mainDirectoryCount));
- }
}
private void createMeasures(Component directory, Counter counter) {
if (counter.files > 0) {
- measureRepository.add(directory, directoryMetric, newMeasureBuilder().create(counter.directories));
measureRepository.add(directory, fileMetric, newMeasureBuilder().create(counter.files));
measureRepository.add(directory, linesMetric, newMeasureBuilder().create(counter.lines));
}
@Override
public void visitProjectView(Component projectView, Path<Counter> path) {
- path.parent().directories += getIntValue(projectView, this.directoryMetric);
path.parent().files += getIntValue(projectView, this.fileMetric);
path.parent().lines += getIntValue(projectView, this.linesMetric);
}
private static class Counter {
private int lines = 0;
private int files = 0;
- private int directories = 0;
void aggregate(Counter counter) {
- directories += counter.directories;
files += counter.files;
lines += counter.lines;
}
import static java.util.Arrays.asList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.sonar.api.measures.CoreMetrics.CLASSES_KEY;
-import static org.sonar.api.measures.CoreMetrics.DIRECTORIES_KEY;
import static org.sonar.api.measures.CoreMetrics.FILES_KEY;
import static org.sonar.api.measures.CoreMetrics.FUNCTIONS_KEY;
import static org.sonar.api.measures.CoreMetrics.GENERATED_LINES_KEY;
MeasureRepoEntry[] measureRepoEntries = concatIntoArray(
otherMeasures,
linesCount == null ? null : entryOf(LINES_KEY, newMeasureBuilder().create(linesCount)),
- fileCount == null ? null : entryOf(FILES_KEY, newMeasureBuilder().create(fileCount)),
- directoryCount == null ? null : entryOf(DIRECTORIES_KEY, newMeasureBuilder().create(directoryCount)));
+ fileCount == null ? null : entryOf(FILES_KEY, newMeasureBuilder().create(fileCount)));
assertThat(toEntries(measureRepository.getAddedRawMeasures(componentRef)))
.containsOnly(measureRepoEntries);
}
import static org.sonar.api.measures.CoreMetrics.CLASSES;
import static org.sonar.api.measures.CoreMetrics.CLASSES_KEY;
import static org.sonar.api.measures.CoreMetrics.DIRECTORIES;
-import static org.sonar.api.measures.CoreMetrics.DIRECTORIES_KEY;
import static org.sonar.api.measures.CoreMetrics.FILES;
import static org.sonar.api.measures.CoreMetrics.FILES_KEY;
import static org.sonar.api.measures.CoreMetrics.FUNCTIONS;
.addRawMeasure(PROJECTVIEW_2_REF, FILES_KEY, newMeasureBuilder().create(2))
.addRawMeasure(PROJECTVIEW_3_REF, FILES_KEY, newMeasureBuilder().create(3))
// PROJECTVIEW_4_REF has no file metric
- .addRawMeasure(PROJECTVIEW_5_REF, FILES_KEY, newMeasureBuilder().create(5))
- .addRawMeasure(PROJECTVIEW_1_REF, DIRECTORIES_KEY, newMeasureBuilder().create(1))
- .addRawMeasure(PROJECTVIEW_2_REF, DIRECTORIES_KEY, newMeasureBuilder().create(2))
- // PROJECTVIEW_3_REF has no directory metric
- .addRawMeasure(PROJECTVIEW_4_REF, DIRECTORIES_KEY, newMeasureBuilder().create(4))
- .addRawMeasure(PROJECTVIEW_5_REF, DIRECTORIES_KEY, newMeasureBuilder().create(5));
+ .addRawMeasure(PROJECTVIEW_5_REF, FILES_KEY, newMeasureBuilder().create(5));
+ // PROJECTVIEW_3_REF has no directory metric
private SizeMeasuresStep underTest = new SizeMeasuresStep(treeRootHolder, metricRepository, measureRepository);
private static MeasureRepoEntry[] createFileAndDirectoryEntries(@Nullable Integer linesCount, @Nullable Integer fileCount, @Nullable Integer directoryCount) {
return new MeasureRepoEntry[] {
linesCount == null ? null : entryOf(LINES_KEY, newMeasureBuilder().create(linesCount)),
- fileCount == null ? null : entryOf(FILES_KEY, newMeasureBuilder().create(fileCount)),
- directoryCount == null ? null : entryOf(DIRECTORIES_KEY, newMeasureBuilder().create(directoryCount))
+ fileCount == null ? null : entryOf(FILES_KEY, newMeasureBuilder().create(fileCount))
};
}
return from(concat(
asList(otherMeasures),
from(asList(measureRepoEntries)).filter(notNull())))
- .toArray(MeasureRepoEntry.class);
+ .toArray(MeasureRepoEntry.class);
}
private void verifyNoMeasure(int componentRef) {
.setDomain(DOMAIN_SIZE)
.create();
+ /**
+ * @deprecated since 7.7 - no longer computed
+ */
+ @Deprecated
public static final String DIRECTORIES_KEY = "directories";
+
/**
- * Computed by the platform.
+ * @deprecated since 7.7 - no longer computed
*/
+ @Deprecated
public static final Metric<Integer> DIRECTORIES = new Metric.Builder(DIRECTORIES_KEY, "Directories", Metric.ValueType.INT)
.setDescription("Directories")
.setDirection(Metric.DIRECTION_WORST)
.setDomain(DOMAIN_SIZE)
.create();
+ /**
+ * Computed by the platform.
+ */
public static final String FUNCTIONS_KEY = "functions";
public static final Metric<Integer> FUNCTIONS = new Metric.Builder(FUNCTIONS_KEY, "Functions", Metric.ValueType.INT)
.setDescription("Functions")