Skip to content

Commit

Permalink
deprecate *PUBLIC*API* metrics
Browse files Browse the repository at this point in the history
* `PUBLIC_API`, `PUBLIC_UNDOCUMENTED_API` and `PUBLIC_DOCUMENTED_API_DENSITY`
  were depricated since SQ 6.2 (https://jira.sonarsource.com/browse/SONAR-8328)
  but existed as custom sonar-cxx metrics

* the minimal supported SQ version now is 6.7

* moreover, it looks like there is a general problem in displaying
  custom metrics (see SonarOpenCommunity#1509)

* that means that nobody a) expects that the SQ plugin implements the
  deprectad metrics and b) nobody misses them (because they are just not
  visualized)

* the squid check `UndocumentedApiCheck` is not affected
  (it doesn't rely on the stored metric, but visits the AST
  by itself)

* BTW public API measurements belong to the obligatory AST Visitors
  and introduce the time overhead of ~6% (measured with SonarOpenCommunity#1507,
  6% means, that if there is no sensors activated at all
  the importing of C++ project will still cause a calculation
  of a bunch of metrics; summary overhead of this calculation
  considered as 100%)
  • Loading branch information
ivangalkin committed Jun 28, 2018
1 parent 72af628 commit ad0da49
Show file tree
Hide file tree
Showing 15 changed files with 2 additions and 902 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -256,24 +256,6 @@ private void saveMeasures(InputFile inputFile, SourceFile squidFile, SensorConte
.withValue(squidFile.getInt(CxxMetric.COMPLEXITY)).save();
context.<Integer>newMeasure().forMetric(CoreMetrics.COMMENT_LINES).on(inputFile)
.withValue(squidFile.getInt(CxxMetric.COMMENT_LINES)).save();
context.<Integer>newMeasure().forMetric(CoreMetrics.PUBLIC_API).on(inputFile)
.withValue(squidFile.getInt(CxxMetric.PUBLIC_API)).save();
context.<Integer>newMeasure().forMetric(CoreMetrics.PUBLIC_UNDOCUMENTED_API).on(inputFile)
.withValue(squidFile.getInt(CxxMetric.PUBLIC_UNDOCUMENTED_API)).save();

// Configuration properties for SQ 6.2++
// see https://jira.sonarsource.com/browse/SONAR-8328
if (!language.getMetricsCache().isEmpty()) {
int publicApi = squidFile.getInt(CxxMetric.PUBLIC_API);
int publicUndocumentedApi = squidFile.getInt(CxxMetric.PUBLIC_UNDOCUMENTED_API);
double densityOfPublicDocumentedApi = (publicApi > publicUndocumentedApi) ? ((publicApi - publicUndocumentedApi) / (double) publicApi * 100.0) : 0.0;
context.<Integer>newMeasure().forMetric(language.getMetric(CxxMetrics.PUBLIC_API_KEY))
.on(inputFile).withValue(publicApi).save();
context.<Integer>newMeasure().forMetric(language.getMetric(CxxMetrics.PUBLIC_UNDOCUMENTED_API_KEY)).on(inputFile)
.withValue(publicUndocumentedApi).save();
context.<Double>newMeasure().forMetric(language.getMetric(CxxMetrics.PUBLIC_DOCUMENTED_API_DENSITY_KEY))
.on(inputFile).withValue(densityOfPublicDocumentedApi).save();
}

for(SquidSensor sensor: squidSensors) {
sensor.publishMeasureForFile(inputFile, squidFile, context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,6 @@ public class CxxMetrics implements Metrics {
private final CxxLanguage language;
private final String domain;

// Introduce own documentation metrics, after they has been removed from SQ core
// see https://jira.sonarsource.com/browse/SONAR-8328
public static final String PUBLIC_API_KEY = "public_api";
public static final String PUBLIC_UNDOCUMENTED_API_KEY = "public_undocumented_api";
public static final String PUBLIC_DOCUMENTED_API_DENSITY_KEY = "public_documented_api_density";

/**
* CxxMetrics
*
Expand All @@ -61,36 +55,6 @@ public CxxMetrics(CxxLanguage language) {
this.language = language;
this.domain = language.getKey().toUpperCase(Locale.ENGLISH);

Metric<?> metric = new Metric.Builder(getKey(PUBLIC_API_KEY, language), "Public API", Metric.ValueType.INT)
.setDescription("Public API")
.setDirection(Metric.DIRECTION_WORST)
.setQualitative(Boolean.FALSE)
.setDomain(this.domain)
.create();
saveMetric(PUBLIC_API_KEY, metric);

metric = new Metric.Builder(getKey(PUBLIC_DOCUMENTED_API_DENSITY_KEY, language), "Public Documented API (%)", Metric.ValueType.PERCENT)
.setDescription("Public documented classes and functions balanced by ncloc")
.setDirection(Metric.DIRECTION_BETTER)
.setQualitative(Boolean.TRUE)
.setDomain(this.domain)
.setWorstValue(0.0)
.setBestValue(100.0)
.setOptimizedBestValue(true)
.create();
saveMetric(PUBLIC_DOCUMENTED_API_DENSITY_KEY, metric);

metric = new Metric.Builder(getKey(PUBLIC_UNDOCUMENTED_API_KEY, language), "Public Undocumented API", Metric.ValueType.INT)
.setDescription("Public undocumented classes, functions and variables")
.setDirection(Metric.DIRECTION_WORST)
.setQualitative(Boolean.TRUE)
.setDomain(this.domain)
.setBestValue(0.0)
.setDirection(Metric.DIRECTION_WORST)
.setOptimizedBestValue(true)
.create();
saveMetric(PUBLIC_UNDOCUMENTED_API_KEY, metric);

saveMetric(CxxCompilerSensor.KEY, buildReportMetric(CxxCompilerSensor.KEY, "Compiler issues"));
saveMetric(CxxCppCheckSensor.KEY, buildReportMetric(CxxCppCheckSensor.KEY, "CppCheck issues"));
saveMetric(CxxOtherSensor.KEY, buildReportMetric(CxxOtherSensor.KEY, "Other tools issues"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,4 @@ public void getMetricsTest() {
assertThat(list.size()).isEqualTo(14);
}

@Test
public void getMetricTest() {
Metric<?> metric = language.getMetric(CxxMetrics.PUBLIC_API_KEY);
assertThat(metric).isNotNull();

metric = language.getMetric(CxxMetrics.PUBLIC_UNDOCUMENTED_API_KEY);
assertThat(metric).isNotNull();

metric = language.getMetric(CxxMetrics.PUBLIC_DOCUMENTED_API_DENSITY_KEY);
assertThat(metric).isNotNull();
}
}
4 changes: 0 additions & 4 deletions cxx-squid/src/main/java/org/sonar/cxx/CxxAstScanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import org.sonar.cxx.visitors.CxxLinesOfCodeInFunctionBodyVisitor;
import org.sonar.cxx.visitors.CxxLinesOfCodeVisitor;
import org.sonar.cxx.visitors.CxxParseErrorLoggerVisitor;
import org.sonar.cxx.visitors.CxxPublicApiVisitor;
import org.sonar.squidbridge.AstScanner;
import org.sonar.squidbridge.CommentAnalyser;
import org.sonar.squidbridge.SourceCodeBuilderCallback;
Expand Down Expand Up @@ -201,9 +200,6 @@ public SourceCode createSourceCode(SourceCode parentSourceCode, AstNode astNode)
builder.withSquidAstVisitor(new LinesVisitor<>(CxxMetric.LINES));
builder.withSquidAstVisitor(new CxxLinesOfCodeVisitor<>(CxxMetric.LINES_OF_CODE));
builder.withSquidAstVisitor(new CxxLinesOfCodeInFunctionBodyVisitor<>());
builder.withSquidAstVisitor(new CxxPublicApiVisitor<>(CxxMetric.PUBLIC_API,
CxxMetric.PUBLIC_UNDOCUMENTED_API)
.withHeaderFileSuffixes(conf.getHeaderFileSuffixes()));

builder.withSquidAstVisitor(CommentsVisitor.<Grammar>builder().withCommentMetric(CxxMetric.COMMENT_LINES)
.withNoSonar(true)
Expand Down
4 changes: 1 addition & 3 deletions cxx-squid/src/main/java/org/sonar/cxx/api/CxxMetric.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ public enum CxxMetric implements MetricDef {
CLASSES,
COMPLEXITY,
COGNITIVE_COMPLEXITY,
COMMENT_LINES,
PUBLIC_API,
PUBLIC_UNDOCUMENTED_API;
COMMENT_LINES;

@Override
public String getName() {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class CxxMetricTest {
@Test
public void test() {
SoftAssertions softly = new SoftAssertions();
softly.assertThat(CxxMetric.values()).hasSize(12);
softly.assertThat(CxxMetric.values()).hasSize(10);

for (CxxMetric metric : CxxMetric.values()) {
softly.assertThat(metric.getName()).isEqualTo(metric.name());
Expand Down
Loading

0 comments on commit ad0da49

Please sign in to comment.