Counting files with specific extension

127 views
Skip to first unread message

Nader Mirzadeh

unread,
Apr 3, 2018, 1:44:35 PM4/3/18
to SonarQube
Hi,
I'm trying to create a plugin which would count files with specific extension (e.g.  *.md) in any project. I've tried to use Java plugin, but that plugin ignores files at root of the project (except pom.xml), and it checks files from target directory. I appreciate any help on doing it correctly.

Regards,
-nader

G. Ann Campbell

unread,
Apr 3, 2018, 2:47:44 PM4/3/18
to SonarQube
Hi nader,

Since you're already writing a plugin, then it may just be easiest to declare the Markdown language, claim the .md file extension, and make your count as part of the basic metrics calculation.

That said, since you appear to be analyzing with Maven, you'll still face the problem of how to find .md files in project root. For that, you'll need to override the value of sonar.sources, which Maven automatically sets for you, I believe to src/main. 

For that matter, you could override sonar.sources (-Dsonar.sources=... on the command line) while pursuing your current route, but declaring a new language is probably the more "correct" (though costlier) way to go about it.


HTH,
Ann

Nader Mirzadeh

unread,
Apr 3, 2018, 2:58:14 PM4/3/18
to SonarQube
Thanks Ann for your reply. I've already tried defining  md as a new language (extending AbstractLanguague), but I got an error that I'd to define a base language (e.g. Java, PHP etc). I'll give it another try. I'll also try the passing the sonar.sources property.

Regards,
-nader
--

G. Ann Campbell

unread,
Apr 3, 2018, 3:07:47 PM4/3/18
to SonarQube
Hi,

It's probably easiest to start from another plugin. Here's where the Lua analyzer declares the language: https://github.com/SonarQubeCommunity/sonar-lua/blob/master/sonar-lua-plugin/src/main/java/org/sonar/plugins/lua/core/Lua.java


Ann

nicolas...@sonarsource.com

unread,
Apr 4, 2018, 6:27:06 AM4/4/18
to SonarQube
H Nader,

I have to say that I do not understand why you're considering SonarQube for the use-case of 'count files with specific extension'. SonarQube as a tool is designed for providing continuous code quality via detection of bugs/vulnerabilities/code_smells (and related measures). Its APIs are also designed with that prime goal in mind.

Counting the number of files with a specific extension sounds like something you could pull off in a couple of commands (bash, or other scripting language), independently from SonarQube. I would understand the interest in SonarQube if you intend to actually analyze md files (and reports issues on them), otherwise for just counting files I would recommend you skip the cost (short-term for development, and long-term for maintenance) of writing a SonarQube plugin altogether.

Best regards,
Nicolas

Nader Mirzadeh

unread,
Apr 5, 2018, 8:06:28 AM4/5/18
to SonarQube
Hi Nicolas,
thanks for sharing your point of view. The reason for having the report is that SonarQube provides quality checks, and reports. We considered the documentation as another part of quality check, and show it along other Sonar reports.  

The issue I have is I can't get an easy way to check any documentation files (e.g *.rst, or uml) at the project level. For instance, in a Java project, the project is scanned from src and test directories as well as pom.xml at project level. I need to list another type of files at project level. I really appreciate if you can give a hint how to do it easily .

Regards,
-nader
-
Reply all
Reply to author
Forward
0 new messages