Skip to content
This repository has been archived by the owner on Feb 11, 2022. It is now read-only.

PT-427: Make Findbugs to honour the exclude filters #20

Merged
merged 11 commits into from Feb 8, 2017

Conversation

mr-archano
Copy link
Contributor

Tracked by PT-427

Scope of the PR

Findbugs is currently ignoring the exclude filters specified as part of the plugin configuration.
The issue is related to the fact the tool is working against class files while the exclude filters are applied only to sources. To solve the problem we need to filter out the classes produced from source files excluded in the config.

Considerations and implementation

We decided to create include patterns for the classes property of the Findbugs task evaluating the filtered set of source files specified via source (and after the exclude filters from the plugin extension have been applied), for instance:

  • original source file: com.novoda.test.HighPriorityViolator.java
  • generated include pattern: com/novoda/test/HighPriorityViolator*

Note that the * at the end will allow to catch inner classes as well.
Incidentally the internals of *Configurator classes have been refactored to expose a clean configuration point for Java projects via configureJavaProject().

Test(s) added

FindbugsIntegrationTest is now testing the case where we provide an exclude filter to skip one specific file from the sources as opposed to the entire source set as before. The source file used in the test is also now using a proper package and contains an inner class, to make the test more significative.

Copy link
Contributor

@devisnik devisnik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just some minor questions.

/**
* The simple "classes = sourceSet.output" may lead to non-existing resources directory
* being passed to FindBugs Ant task, resulting in an error
* */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is above comment still applicable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, we are not changing the default behaviour here, instead we stack filters upon the default implementation: this method has been copied (and groovyfied) from the original FindbugsPlugin#L189-L191. Should we reference the source?

createIncludePatterns(includedSourceFiles, sourceDirs.collect { it.toPath() })
}

private static List<String> createIncludePatterns(List<Path> includedSourceFiles, List<Path> sourceDirs) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: Here it's ...Include..., in the method name above ...Includes....

}
}
pmd.mustRunAfter variant.javaCompile
sourceFilter.applyTo(task)
task.mustRunAfter variant.javaCompile
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the mustRunAfter still needed here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be to ensure the compiler fails first, even before the codestyle checks run, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm actually not sure this mustRunAfter is correct here to be honest - like we briefly discussed last week, I reckon we should consider the use of dependsOn instead.

.withPenalty('''{
maxErrors = 0
maxWarnings = 10
}''')
.withFindbugs('findbugs { exclude "HighPriorityViolator.java" }')
.withFindbugs('findbugs { exclude "com/novoda/test/HighPriorityViolator.java" }')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link

@xrigau xrigau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 seems legit - but I'm not confident enough with the project codebase to give significant feedback

@devisnik devisnik merged commit 7955a71 into master Feb 8, 2017
@devisnik devisnik deleted the feature/PT-427_filter_out_classes branch February 8, 2017 11:23
@mr-archano mr-archano mentioned this pull request Feb 8, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants