How to get fileName relative to project in a Check?

18 views
Skip to first unread message

Michael Vorburger

unread,
May 25, 2016, 7:26:34 AM5/25/16
to checkstyle-devel
Hello,

I'm writing a custom Check which is more of a sort of reporting tool than a real Check; it will create a list of all slf4j logger message used in a class, for external publication, but never call AbstractCheck's log.

In that check, I want to get the name of the file being analysed, in order to say write that into a text file. I've found getFileContents().getFileName(), but that gives the absolute path, which is not ideal.

Is there some handstand with Checkstyle's existing API that I could use to obtain the file under check's path relative to the project? After all, the Checkstyle report also shows relative paths. I can make them relative within my custom Check, with some heuristic to find the base path (e.g. where there is a pom.xml ..), but that seems brittle, and I'm hoping there is a better way.

If this is impossible as-is, then would an enhancement suggestion to have a getRelativeFileName() on FileContents be sensible?

Thank you,
Michael

Roman Ivanov

unread,
May 26, 2016, 9:51:01 AM5/26/16
to Michael Vorburger, checkstyle-devel
I'm writing a custom Check which is more of a sort of reporting tool than a real Check;

you can call it Module and do what ever you want.


Is there some handstand with Checkstyle's existing API that I could use to obtain the file under check's path relative to the project?



If this is impossible as-is, then would an enhancement suggestion to have a getRelativeFileName() on FileContents be sensible?

I would rather not, as your request too specific . Something who launch checkstyle should know "root"/"base" path. Chekcstyle give you full path to file, so you can do relative path in your application (I do believe there already ready to use implementations)


--
You received this message because you are subscribed to the Google Groups "checkstyle-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to checkstyle-dev...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages