CoreMetrics.FILE_COMPLEXITY is not saved to the database therefore does not appear

49 views
Skip to first unread message

xti...@gmail.com

unread,
Oct 3, 2016, 7:23:38 PM10/3/16
to SonarQube
I am developing a plugin for Typescript, using CCM.exe I am able to get the cyclomatic complexity of the functions in the TS files.

the code that saves the measure is this:



@Override

public void analyse(Project module, SensorContext context) {

String complexityResults = this.getExecutor().GenerateResults();

if(complexityResults != "")

{

HashMap<String, Double> complexityInfo = this.getParser().Parse(complexityResults);

if (complexityInfo != null)

{

for (InputFile file : moduleFileSystem.inputFiles(this.filePredicates.hasLanguage(TypeScriptLanguage.LANGUAGE_KEY)))

{

String fileName = file.file().getPath();

LOG.info("Complexity for: "+fileName);

Double complexityValue = 0.0;

for(Map.Entry<String, Double> entry :complexityInfo.entrySet())

{

if (fileName.contains(entry.getKey()))

{

complexityValue = entry.getValue();

break;

}

}

if( complexityValue != 0.0)

{

LOG.debug("Complexity for: "+file.file().getName() +" Value: "+complexityValue);

Measure<Double> fileComplexity = new Measure<Double>(CoreMetrics.FILE_COMPLEXITY, (double) complexityValue);

context.saveMeasure(file, fileComplexity );          

 

}

}

}    

}

}





when I run the sonar-runner it hits the LOG an does not throw any exception, e.g:

Lines1,013
Lines of Code779
Comments /
Complexity
Complexity / Function
                  
Classes 1
Files 1
Functions 68
Generated Lines 0
Generated Lines of Code 0
Lines 1,013
Lines of Code 779
Statements 546


do I miss something????





Elena Vilchik

unread,
Oct 6, 2016, 4:57:19 AM10/6/16
to SonarQube, xti...@gmail.com
Hello,

You posted one piece of code and one output which has nothing to do with that piece of code.
Could you describe your problem?


Elena VILCHIK | SonarSource
Language Team

xti...@gmail.com

unread,
Oct 6, 2016, 12:21:20 PM10/6/16
to SonarQube, xti...@gmail.com
the output that I collect was taken from the web interface in the SonarQube instance. I was hoping to be able to see the data, that I was pushing to the system, in the web interface

xti...@gmail.com

unread,
Oct 6, 2016, 12:33:35 PM10/6/16
to SonarQube, xti...@gmail.com
After digging in the SonarQube database I found that my code does no even send the information to the  database.

Frustrating hours came to me. Decided to understand the current data in the database, I discover that complexity measure were saved by other plugins using the ID = 20 and ID = 21. Checking the ID of the Complexity/File  in the database found that is 21, so it came to my mind that maybe I should try to save the data to Complexity (ID=20) so I change one line in my code

Measure<Double> fileComplexity = new Measure<Double>(CoreMetrics.COMPLEXITY, (double) complexityValue);        

Voila!!! it works, it saves in the database the data for complexity for both metrics (complexity and file complexity),.

Now in the web interface I am able to see the complexity of the files.

Seeing the result of my work, and sipping a coffee, the following questions come to my mind:

Why in the hell there is a metric that should be not setted (coreMetrics.File_Complexity) from code? How I am suppose to guess that?
Reply all
Reply to author
Forward
0 new messages