Skip to content

Commit

Permalink
- Removing metric definitions from this project
Browse files Browse the repository at this point in the history
- Adding reference to sonar-opencommunity-metrics
- Changing all code to reference metrics defined in sonar-opencommunity-metrics, which now is responsible for the aggregated numbers.
  • Loading branch information
ericlemes committed Apr 26, 2018
1 parent be40c96 commit 008fd89
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 249 deletions.
5 changes: 5 additions & 0 deletions cxx-sensors/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,10 @@
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.sonar.opencommunity.metrics</groupId>
<artifactId>sonar-opencommunity-metrics</artifactId>
<version>0.9.9</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.sonar.cxx.parser.CxxGrammarImpl;
import static org.sonar.cxx.sensors.clangtidy.CxxClangTidySensor.REPORT_PATH_KEY;
import org.sonar.cxx.sensors.squid.SquidSensor;
import org.sonar.opencommunity.metrics.OpenCommunityMetrics;
import org.sonar.squidbridge.SquidAstVisitor;
import org.sonar.squidbridge.api.SourceFile;
import org.sonar.squidbridge.api.SourceFunction;
Expand Down Expand Up @@ -138,13 +139,13 @@ private void publishComplexFunctionMetricsForFile(InputFile inputFile, SourceFil
}

context.<Integer>newMeasure()
.forMetric(FunctionComplexityMetrics.COMPLEX_FUNCTIONS)
.forMetric(OpenCommunityMetrics.COMPLEX_FUNCTIONS)
.on(inputFile)
.withValue((int)c.countOverThreshold)
.save();

context.<Double>newMeasure()
.forMetric(FunctionComplexityMetrics.PERC_COMPLEX_FUNCTIONS)
.forMetric(OpenCommunityMetrics.COMPLEX_FUNCTIONS_PERC)
.on(inputFile)
.withValue(calculatePercentual((int)c.countOverThreshold, (int)c.countBelowThreshold))
.save();
Expand All @@ -160,47 +161,46 @@ private void publishLocInComplexFunctionMetricsForFile(InputFile inputFile, Sour
}

context.<Integer>newMeasure()
.forMetric(FunctionComplexityMetrics.LOC_IN_COMPLEX_FUNCTIONS)
.forMetric(OpenCommunityMetrics.COMPLEX_FUNCTIONS_LOC)
.on(inputFile)
.withValue(locCount.countOverThreshold)
.save();

context.<Double>newMeasure()
.forMetric(FunctionComplexityMetrics.PERC_LOC_IN_COMPLEX_FUNCTIONS)
.forMetric(OpenCommunityMetrics.COMPLEX_FUNCTIONS_LOC_PERC)
.on(inputFile)
.withValue(calculatePercentual((int)locCount.countOverThreshold, (int)locCount.countBelowThreshold))
.save();
}

@Override
public void publishMeasureForProject(InputModule module, SensorContext context) {
publishComplexFunctionMetrics(module, context);
publishLinesOfCodeInComplexFunctionMetrics(module, context);

}

private void publishComplexFunctionMetrics(InputModule module, SensorContext context){
context.<Integer>newMeasure()
.forMetric(FunctionComplexityMetrics.COMPLEX_FUNCTIONS)
.forMetric(OpenCommunityMetrics.COMPLEX_FUNCTIONS)
.on(module)
.withValue(functionsOverThreshold)
.save();

context.<Double>newMeasure()
.forMetric(FunctionComplexityMetrics.PERC_COMPLEX_FUNCTIONS)
.forMetric(OpenCommunityMetrics.COMPLEX_FUNCTIONS_PERC)
.on(module)
.withValue(calculatePercentual(functionsOverThreshold, functionsBelowThreshold))
.save();
}

private void publishLinesOfCodeInComplexFunctionMetrics(InputModule module, SensorContext context){
context.<Integer>newMeasure()
.forMetric(FunctionComplexityMetrics.LOC_IN_COMPLEX_FUNCTIONS)
.forMetric(OpenCommunityMetrics.COMPLEX_FUNCTIONS_LOC)
.on(module)
.withValue(linesOfCodeOverThreshold)
.save();

context.<Double>newMeasure()
.forMetric(FunctionComplexityMetrics.PERC_LOC_IN_COMPLEX_FUNCTIONS)
.forMetric(OpenCommunityMetrics.COMPLEX_FUNCTIONS_LOC_PERC)
.on(module)
.withValue(calculatePercentual(linesOfCodeOverThreshold, linesOfCodeBelowThreshold))
.save();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@
import org.sonar.cxx.CxxLanguage;
import static org.sonar.cxx.checks.TooManyLinesOfCodeInFunctionCheck.getNumberOfLine;
import org.sonar.cxx.parser.CxxGrammarImpl;
import org.sonar.cxx.sensors.functioncomplexity.FunctionComplexityMetrics;
import org.sonar.cxx.sensors.functioncomplexity.FunctionCount;
import org.sonar.cxx.sensors.functioncomplexity.FunctionScore;
import org.sonar.cxx.sensors.functioncomplexity.FunctionScoreComparator;
import org.sonar.cxx.sensors.squid.SquidSensor;
import org.sonar.opencommunity.metrics.OpenCommunityMetrics;
import org.sonar.squidbridge.SquidAstVisitor;
import org.sonar.squidbridge.api.SourceFile;
import org.sonar.squidbridge.api.SourceFunction;
Expand Down Expand Up @@ -128,39 +128,32 @@ public void publishMeasureForFile(InputFile inputFile, SourceFile squidFile, Sen

@Override
public void publishMeasureForProject(InputModule module, SensorContext context) {
publishBigFunctionCountForProject(module, context);
publishLocInBigFunctionForProject(module, context);

}

private void publishBigFunctionCountForProject(InputModule module, SensorContext context){
context.<Integer>newMeasure()
.forMetric(FunctionSizeMetrics.BIG_FUNCTIONS)
.forMetric(OpenCommunityMetrics.BIG_FUNCTIONS)
.on(module)
.withValue(functionsOverThreshold)
.save();

context.<Double>newMeasure()
.forMetric(FunctionSizeMetrics.PERC_BIG_FUNCTIONS)
.forMetric(OpenCommunityMetrics.BIG_FUNCTIONS_PERC)
.on(module)
.withValue(calculatePercentual(functionsOverThreshold, functionsBelowThreshold))
.save();
}

private void publishLocInBigFunctionForProject(InputModule module, SensorContext context){
context.<Integer>newMeasure()
.forMetric(FunctionSizeMetrics.LOC_IN_FUNCTIONS)
.on(module)
.withValue(locOverThreshold + locBelowThreshold)
.save();

private void publishLocInBigFunctionForProject(InputModule module, SensorContext context){
context.<Integer>newMeasure()
.forMetric(FunctionSizeMetrics.LOC_IN_BIG_FUNCTIONS)
.forMetric(OpenCommunityMetrics.BIG_FUNCTIONS_LOC)
.on(module)
.withValue(locOverThreshold)
.save();

context.<Double>newMeasure()
.forMetric(FunctionSizeMetrics.PERC_LOC_IN_BIG_FUNCTIONS)
.forMetric(OpenCommunityMetrics.BIG_FUNCTIONS_LOC_PERC)
.on(module)
.withValue(calculatePercentual(locOverThreshold, locBelowThreshold))
.save();
Expand All @@ -183,13 +176,13 @@ private void publishBigFunctionMetrics(InputFile inputFile, SourceFile squidFile
}

context.<Integer>newMeasure()
.forMetric(FunctionSizeMetrics.BIG_FUNCTIONS)
.forMetric(OpenCommunityMetrics.BIG_FUNCTIONS)
.on(inputFile)
.withValue((int)c.countOverThreshold)
.save();

context.<Double>newMeasure()
.forMetric(FunctionSizeMetrics.PERC_BIG_FUNCTIONS)
.forMetric(OpenCommunityMetrics.BIG_FUNCTIONS_PERC)
.on(inputFile)
.withValue(calculatePercentual(c.countOverThreshold, c.countBelowThreshold))
.save();
Expand All @@ -204,19 +197,19 @@ private void publishLocInBigFunctionMetrics(InputFile inputFile, SourceFile squi
}

context.<Integer>newMeasure()
.forMetric(FunctionSizeMetrics.LOC_IN_FUNCTIONS)
.forMetric(OpenCommunityMetrics.LOC_IN_FUNCTIONS)
.on(inputFile)
.withValue(c.countOverThreshold + c.countBelowThreshold)
.save();

context.<Integer>newMeasure()
.forMetric(FunctionSizeMetrics.LOC_IN_BIG_FUNCTIONS)
.forMetric(OpenCommunityMetrics.BIG_FUNCTIONS_LOC)
.on(inputFile)
.withValue(c.countOverThreshold)
.save();

context.<Double>newMeasure()
.forMetric(FunctionSizeMetrics.PERC_LOC_IN_BIG_FUNCTIONS)
.forMetric(OpenCommunityMetrics.BIG_FUNCTIONS_LOC_PERC)
.on(inputFile)
.withValue(calculatePercentual(c.countOverThreshold, c.countBelowThreshold))
.save();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,9 @@ public CxxSquidSensor(CxxLanguage language,
registerSquidSensors();
}

protected void registerSquidSensors(){
if (this.language.getKey() == "c++"){
this.squidSensors.add(new CxxFunctionComplexitySquidSensor(this.language));
this.squidSensors.add(new CxxFunctionSizeSquidSensor(this.language));
}
protected void registerSquidSensors(){
this.squidSensors.add(new CxxFunctionComplexitySquidSensor(this.language));
this.squidSensors.add(new CxxFunctionSizeSquidSensor(this.language));
}

@Override
Expand Down
Loading

0 comments on commit 008fd89

Please sign in to comment.