SonarQube
  1. SonarQube
  2. SONAR-2477

Allow to use FindBugs filter-files with exclusions

    Details

    • Type: New Feature New Feature
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.8
    • Fix Version/s: 2.10
    • Component/s: None
    • Labels:
      None
    • Number of attachments :
      1

      Description

      It is not possible to utilise a Findbugs excludes filter file when performing analysis of projects. This functionality would have existed in previous versions of Sonar, but was removed as you discussed here - http://old.nabble.com/Sonar-2.5-is-not-honoring-FindBugs-exclussions-filter-defined-in-pom.xml-td30947735.html

      Would it be possible to alter the current Findbugs plugin (specifically the FindbugsConfiguration.saveExcludeConfigXml() method) to allow the user to specify an excludes file in the configuration to offer a degree of backwards compatibility?

      An example (but untested) fix follows:

        public File saveExcludeConfigXml() throws IOException {
      	  
      	// Example fix follows:
      	try {
      		String excludesFileLocation = project.getConfiguration().getString("sonar.findbugs.includesFilter");
      		if (excludesFileLocation != null && !excludesFileLocation.isEmpty()) {
      			File filter = new File(excludesFileLocation);
      			if (filter.exists()) {
      				return filter;
      			}
      		}
      	} catch (NoSuchElementException e) {
      		// log the exception here and proceed as before...
      	}
      	// End of example fix.
      	  
          FindBugsFilter findBugsFilter = new FindBugsFilter();
          if (project.getExclusionPatterns() != null) {
            for (String exclusion : project.getExclusionPatterns()) {
              ClassFilter classFilter = new ClassFilter(FindbugsAntConverter.antToJavaRegexpConvertor(exclusion));
              findBugsFilter.addMatch(new Match(classFilter));
            }
          }
          return project.getFileSystem().writeToWorkingDirectory(findBugsFilter.toXml(), "findbugs-exclude.xml");
        }
      

        Activity

        Hide
        Freddy Mallet added a comment -

        We could imagine two provide two features :

        • Ability to set the XML content directly through the Sonar interface (for the overall Sonar instance, by project and by module)
        • Ability to work with the findbugs-exclude.xml file defined in the pom.xml file
        Show
        Freddy Mallet added a comment - We could imagine two provide two features : Ability to set the XML content directly through the Sonar interface (for the overall Sonar instance, by project and by module) Ability to work with the findbugs-exclude.xml file defined in the pom.xml file
        Hide
        Simon Brandhof added a comment -

        A third option is to configure the path to findbugs file. It allows to support all environments (ant, standalone runner and maven).

        Show
        Simon Brandhof added a comment - A third option is to configure the path to findbugs file. It allows to support all environments (ant, standalone runner and maven).
        Hide
        Evgeny Mandrikov added a comment -

        Implemented in https://github.com/SonarSource/sonar/commit/0be3ce80890e26db3d0d94fd9242a230d8ec1747.
        Also note that filters would be applied in addition to Sonar filters.

        Show
        Evgeny Mandrikov added a comment - Implemented in https://github.com/SonarSource/sonar/commit/0be3ce80890e26db3d0d94fd9242a230d8ec1747 . Also note that filters would be applied in addition to Sonar filters.
        Hide
        Freddy Mallet added a comment -

        Tested but the exclusion file doesn't seem to be really used by the Findbugs library.

        Show
        Freddy Mallet added a comment - Tested but the exclusion file doesn't seem to be really used by the Findbugs library.
        Hide
        Evgeny Mandrikov added a comment -

        Hi Freddy,
        I've attached example project with file with exclusions for FindBugs , which works perfectly for me. You can check this by commenting property in pom.xml - 1 violation would be detected and 0 otherwise.

        Show
        Evgeny Mandrikov added a comment - Hi Freddy, I've attached example project with file with exclusions for FindBugs , which works perfectly for me. You can check this by commenting property in pom.xml - 1 violation would be detected and 0 otherwise.
        Hide
        Freddy Mallet added a comment -

        Works well Evgeny, thanks !

        Show
        Freddy Mallet added a comment - Works well Evgeny, thanks !

          People

          • Assignee:
            Evgeny Mandrikov
            Reporter:
            Michael Crawford
          • Votes:
            9 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: