3

I am trying to exclude files containing generated code in a sonar project.properties file. I have added the following to project.properties.

sonar.issue.ignore.allfile=.*generated.*,.*GeneratedCodeAttribute.*

I get the following error: ERROR: Caused by: Exclusions > Issues : Invalid format. The field does not define a regular expression: null

I have tried a lot of combinations. None of these work, same error.

sonar.issue.ignore.allfile=file:generated
sonar.issue.ignore.allfile=generated
sonar.issue.ignore.allfile=regex:generated

etc...

Any ideas on how to set this property in a project.properties file?
I am aware that this can be done in the user interface, I need the project file syntax for multiple exclusions. I have read the source code, but cannot figure out what's missing.

Jim
  • 14,952
  • 15
  • 80
  • 167

3 Answers3

6

You can configure the propertie sonar.issue.ignore.allfile to ignore all issues on file by setting the project.properties file as followed:

sonar.issue.ignore.allfile=r1
sonar.issue.ignore.allfile.r1.fileRegexp=GeneratedFile

As documented:
If this regular expression is found in a file, then the whole file is ignored.
means you'll need to set the regex, GeneratedFile for example, in the files that you want to be ignored.

Yuval Simhon
  • 1,439
  • 2
  • 19
  • 34
  • 2
    This is exactly what I need! Specifying the r1 is not in the documentation that I can see, do you by any chance know how to specify multiple conditions that can be used to match files? For example, how to specify /r1/ and /r2/? – Paul Wagland Aug 19 '16 at 23:22
5

Quoting the Documentation here (Emphasis is mine)

You can have SonarQube ignore issues on certain components and against certain coding rules. Go to Configuration > Settings > Exclusions > Issues. Note that the properties below can only be set through the web interface because they are multi-valued.

Tensibai
  • 15,557
  • 1
  • 37
  • 57
  • Is there another way to ignore files based on a property? Failing that is there a configuration file that can be edited programmatically? – Jim Jun 10 '15 at 12:15
  • @Jim I'm unsure on what you mean by property – Tensibai Jun 10 '15 at 12:24
  • I mean is there any way to add regular expressions to any kind of property in a project.properties file that will result in files containing generated code to be ignored – Jim Jun 10 '15 at 12:33
  • @Jim none I'm aware of. We're using an old version of Sonar so I can't test, but maybe adding the exclusions and having a look into the project file after can be of some help ? – Tensibai Jun 10 '15 at 12:51
  • You *can* ignore files based on a property. See @Techtwaddle's answer. – matt freake Jun 10 '15 at 16:04
  • 1
    @Disco3 I'm really unsure the answer works for the OP as he's looking to ignore files from their content, not their class or path. – Tensibai Jun 10 '15 at 16:06
  • You are right @Tensibai - I missed the word "contains". I thought they were actual filenames/paths – matt freake Jun 10 '15 at 16:30
2

Check the last section in the link given by @Tensibai. Using sonar.exclusions in the project-properties file should work.

# Exclude all classes ending by "Bean"
# Matches org/sonar.api/MyBean.java, org/sonar/util/MyOtherBean.java, org/sonar/util/MyDTO.java, etc.
sonar.exclusions=**/*Bean.java,**/*DTO.java

# Exclude all classes in the "src/main/java/org/sonar" directory
# Matches src/main/java/org/sonar/MyClass.java, src/main/java/org/sonar/MyOtherClass.java
# But does not match src/main/java/org/sonar/util/MyClassUtil.java
sonar.exclusions=src/main/java/org/sonar/*
kryger
  • 12,906
  • 8
  • 44
  • 65
Techtwaddle
  • 1,643
  • 1
  • 15
  • 11