SonarQube
  1. SonarQube
  2. SONAR-2760

Ability to exclude source folders from source code analysis (the same way it's possible to exclude some packages for instance)

    Details

    • Number of attachments :
      0

      Description

      With the raise of Tycho (http://www.eclipse.org/tycho/) to build OSGI/Eclipse apps and since many eclipse based plugins have multiple source directory (such as
      xtext based plugins, to diferenciate manual (src directory) and generated (src-gen directory) code), it would be great to have the ability to exclude source directories rather than packages.

      Regards,

      Xavier

        Issue Links

          Activity

          Freddy Mallet made changes -
          Field Original Value New Value
          Component/s Exclusions [ 14074 ]
          Component/s Maven Plugin [ 13194 ]
          Hide
          Daniel Warzecha added a comment -

          I wouldn't say "rather", but an additional ability to exclude root source folders would be greatly appreciated.

          Most of our project's modules have separate "gensrc" and "src" root source folders. We can't use the package exclusion method because the packages in both of the source folders are named the same to reflect their affiliation to each other.

          Show
          Daniel Warzecha added a comment - I wouldn't say "rather", but an additional ability to exclude root source folders would be greatly appreciated. Most of our project's modules have separate "gensrc" and "src" root source folders. We can't use the package exclusion method because the packages in both of the source folders are named the same to reflect their affiliation to each other.
          Hide
          Bob Lorain added a comment -

          I am having an issue where I have code in /src/test/java that has an issue but I can't exclude the code using sonar exclusions. This is the standard Maven source directory for test code. In order to support analysis on Maven projects that follow the standards it seems to me this issue must be addressed.

          Show
          Bob Lorain added a comment - I am having an issue where I have code in /src/test/java that has an issue but I can't exclude the code using sonar exclusions. This is the standard Maven source directory for test code. In order to support analysis on Maven projects that follow the standards it seems to me this issue must be addressed.
          Freddy Mallet made changes -
          Summary Ability to exclude source folders rather than packages from source code analysis. Ability to exclude source folders from source code analysis (the same way it's possible to exclude some packages for instance)
          Freddy Mallet made changes -
          Link This issue depends upon SONAR-3754 [ SONAR-3754 ]
          Hide
          Michael Wenig added a comment -

          Indeed this is a must-have on our site. We have big amounts of generated code which normally does not meet any rules. As these violations are reported the "real" problems are not really visible. As the code is generated via Maven (and placed in target/generated-sources) it should be easily possible for the sonar-plugin to detect them and auto-generate and apply the according exclusions.

          Afaik sonar is only able to exclude based on package/classname patterns because PMD and other tools are working on bytecode. On the other hand which class is generated and which is not is not readable out of the bytecode (even if the @generated-annotation is used - it is not a runtime annotation).

          As a solution I could think of the following:

          • The maven-plugin knows about the source-folders
          • from all source-folders which are in target (or other configured name) (or as a positive list: which are in some named directories, defaults src/**) a list of classes (files) is made and used to build an exclusion-list
          • This exclusion list gets merged with some eventually existing exclusions
          • The exclusions are used when analyzing

          I think this would at least lead to a 99% solution

          Regards Michael

          Show
          Michael Wenig added a comment - Indeed this is a must-have on our site. We have big amounts of generated code which normally does not meet any rules. As these violations are reported the "real" problems are not really visible. As the code is generated via Maven (and placed in target/generated-sources) it should be easily possible for the sonar-plugin to detect them and auto-generate and apply the according exclusions. Afaik sonar is only able to exclude based on package/classname patterns because PMD and other tools are working on bytecode. On the other hand which class is generated and which is not is not readable out of the bytecode (even if the @generated-annotation is used - it is not a runtime annotation). As a solution I could think of the following: The maven-plugin knows about the source-folders from all source-folders which are in target (or other configured name) (or as a positive list: which are in some named directories, defaults src/**) a list of classes (files) is made and used to build an exclusion-list This exclusion list gets merged with some eventually existing exclusions The exclusions are used when analyzing I think this would at least lead to a 99% solution Regards Michael
          Freddy Mallet made changes -
          Fix Version/s 3.5 [ 18825 ]
          Hide
          Mickael Istria added a comment -

          Can we hope a sonar.excludeSourceFolder in a next release?

          Show
          Mickael Istria added a comment - Can we hope a sonar.excludeSourceFolder in a next release?
          Hide
          Freddy Mallet added a comment -

          Sorry Mickael, this is not planned for Sonar 3.4 but already for Sonar 3.5.

          Show
          Freddy Mallet added a comment - Sorry Mickael, this is not planned for Sonar 3.4 but already for Sonar 3.5.
          Hide
          Mickael Istria added a comment -

          > Sorry Mickael, this is not planned for Sonar 3.4 but already for Sonar 3.5.

          I'm glad to here this is planned! Thanks.

          Show
          Mickael Istria added a comment - > Sorry Mickael, this is not planned for Sonar 3.4 but already for Sonar 3.5. I'm glad to here this is planned! Thanks.
          Hide
          Michael Keppler added a comment -

          Are you aware of the regex based file filter plugin over at https://github.com/Obeo/fr.obeo.sonar.plugin.regexfilefilter
          It provides a solution to exclude generated code by looking at the content of the file (not the source folder name).

          Show
          Michael Keppler added a comment - Are you aware of the regex based file filter plugin over at https://github.com/Obeo/fr.obeo.sonar.plugin.regexfilefilter It provides a solution to exclude generated code by looking at the content of the file (not the source folder name).
          Simon Brandhof made changes -
          Assignee Simon Brandhof [ simon.brandhof ]
          Hide
          Simon Brandhof added a comment -

          Most of users will still use the standard inclusion/exclusion patterns. To prevent from misunderstanding of a new property, we're going to improve the format of existing exclusion properties. If they start with "file:", then the exclusions will relate to absolute path. A typical usage could be "file:*/src-gen//".

          Show
          Simon Brandhof added a comment - Most of users will still use the standard inclusion/exclusion patterns. To prevent from misunderstanding of a new property, we're going to improve the format of existing exclusion properties. If they start with "file:", then the exclusions will relate to absolute path. A typical usage could be "file:* /src-gen/ / ".
          Hide
          Simon Brandhof added a comment -

          @Michael Keppler, this plugin is a good candidate for the plugin forge !

          Show
          Simon Brandhof added a comment - @Michael Keppler, this plugin is a good candidate for the plugin forge !
          Simon Brandhof made changes -
          Resolution Fixed [ 1 ]
          Status Open [ 1 ] Resolved [ 5 ]
          Assignee Simon Brandhof [ simon.brandhof ] Freddy Mallet [ freddy.mallet ]
          Freddy Mallet made changes -
          Link This issue depends upon SONAR-1896 [ SONAR-1896 ]
          Hide
          Freddy Mallet added a comment -

          The exclusion of files based on absolut paths works well with "exclusion patterns" but not with "inclusion patterns".

          Moreover the following items must be added to the "Wilcards" documentation :

          • In "Following rules are applied":
            • file: to define a pattern based on the absolut path
          • In "Examples:":
            • org/mycompany/* matches all files in the org/mycompany directory. ex: org/mycompany/Foo.java, org/mycompany/Bar.cs
            • org/*Model matches all files with Model in filename and in the org directory. ex: org/Model.java, org/FirstModel.php, org/ModelTest.cs
            • org/*/.cs matches all .cs files underneath the org directory . ex : org/Foo.cs, org/foo/Bar.cs, org/foo/bar/Baz.cs
            • file:**/generated/** matches all files whose one parent directory is 'generated'. ex: /../my_project/tmp/generated/org/castor/Model.java
          Show
          Freddy Mallet added a comment - The exclusion of files based on absolut paths works well with "exclusion patterns" but not with "inclusion patterns". Moreover the following items must be added to the "Wilcards" documentation : In "Following rules are applied": file: to define a pattern based on the absolut path In "Examples:": org/mycompany/* matches all files in the org/mycompany directory. ex: org/mycompany/Foo.java, org/mycompany/Bar.cs org/*Model matches all files with Model in filename and in the org directory. ex: org/Model.java, org/FirstModel.php, org/ModelTest.cs org/* / .cs matches all .cs files underneath the org directory . ex : org/Foo.cs, org/foo/Bar.cs, org/foo/bar/Baz.cs file:**/generated/** matches all files whose one parent directory is 'generated'. ex: /../my_project/tmp/generated/org/castor/Model.java
          Freddy Mallet made changes -
          Resolution Fixed [ 1 ]
          Status Resolved [ 5 ] Reopened [ 4 ]
          Assignee Freddy Mallet [ freddy.mallet ] Simon Brandhof [ simon.brandhof ]
          Simon Brandhof made changes -
          Status Reopened [ 4 ] Resolved [ 5 ]
          Assignee Simon Brandhof [ simon.brandhof ] Freddy Mallet [ freddy.mallet ]
          Resolution Fixed [ 1 ]
          Freddy Mallet made changes -
          Assignee Freddy Mallet [ freddy.mallet ] Evgeny Mandrikov [ godin ]
          Freddy Mallet made changes -
          Comment [ Well done Evgeny, this is no extra fast even with big program files. ]
          Freddy Mallet made changes -
          Assignee Evgeny Mandrikov [ godin ] Freddy Mallet [ freddy.mallet ]
          Hide
          Xavier Seignard added a comment -

          Thanks for correcting that!

          A shame I'm not developing Eclipse based stuff anymore

          Keep up the good work guys!

          Show
          Xavier Seignard added a comment - Thanks for correcting that! A shame I'm not developing Eclipse based stuff anymore Keep up the good work guys!
          Freddy Mallet made changes -
          Assignee Freddy Mallet [ freddy.mallet ] Simon Brandhof [ simon.brandhof ]
          Simon Brandhof made changes -
          Status Resolved [ 5 ] Closed [ 6 ]
          Hide
          Daniel Warzecha added a comment -

          Thanks, I hope that will work...

          Show
          Daniel Warzecha added a comment - Thanks, I hope that will work...
          Freddy Mallet made changes -
          Link This issue is duplicated by SONAR-3784 [ SONAR-3784 ]

            People

            • Assignee:
              Simon Brandhof
              Reporter:
              Xavier Seignard
            • Votes:
              14 Vote for this issue
              Watchers:
              17 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: