Check Whether particular file present in the project or application directory

  • versions used (SonarQube 6.7.6)

  • Description: I am trying to check whether file present in the directory or not.

Eg:- when i run the custom rule i need to scan all the files present in the project and check whether settings.gradle is there or not.

  • What i am looking, is there any way to scan the project location and get all the files ?

hello @AnuragSanagapalli,

I assume you are developing custom plugin. Please have a look at SensorContext#fileSystem() method and FilePredicates class

Thanks @saberduck. I have tried using that but I will explore more on it.

I am writing custom rules to check the required file. So, When i write Junit to test, how to pass current project directory as input to Junit without Hard-coding ?

For Example,

I am wiriting Junit as below,

JavaCheckVerifier.verify("src/main/resources/", new PomFileIsMandatoryRule());

The highlighted one was the input, I am testing against one custom rule.

For my scenario to check file exits or not, How can I pass current directory or folder as input to test against custom rule(developed to check file existence).

@AnuragSanagapalli you will probably want to raise issue on project level then, you can use this method to test your rule

You can see the way it is used in implementation of PackageInfoCheck

A post was split to a new topic: Exporting custom rule setting