Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validation doesn't fail for project with test sources only #454

Closed
MetroMarv opened this issue Jul 18, 2022 · 1 comment · Fixed by #458
Closed

Validation doesn't fail for project with test sources only #454

MetroMarv opened this issue Jul 18, 2022 · 1 comment · Fixed by #458

Comments

@MetroMarv
Copy link

MetroMarv commented Jul 18, 2022

Steps to reproduce

  • create a new Maven repository with only sources in src/test/..
    • there should be no java classes in src/main/
  • create a file that violates any Spotbugs rule in src/test/
  • add the Spotbugs Maven plugin to the pom.xml file
    • set also the plugin's setting includeTests to true (includeTests)
  • execute Spotbugs by calling mvn package and mvn spotbugs:check

Observed behavior

No violation detected -> Build green

[INFO] --- spotbugs-maven-plugin:4.7.1.0:spotbugs (spotbugs) @ one-performance-tests ---
[INFO] Fork Value is true
[INFO] Done SpotBugs Analysis....

Expected behavior

Violation is printed and build fails.

Notes

  • the when using the option xmlOutput=true the XML file is correctly written and contains violations
  • in the class BaseViolationCheckMojo (L490) only executes the violation verification if there are class files in the projects output directory (usually target/classes), which is empty for projects only having test sources
  • when we add a class like src/main/Test.java to our project, Spotbugs prints the violations and fails the build
@hazendaz
Copy link
Member

hazendaz commented Jul 18, 2022 via email

MetroMarv pushed a commit to MetroMarv/spotbugs-maven-plugin that referenced this issue Jul 22, 2022
If you use this plugin in a project that only has test sources (source
files in the folder `src/test/`) and no source files in the main folder
(`src/main/`), then it'd not validate the report generated by spotbugs.
Instead it would only log 0 bugs.

Instead of verifying only the folder for class files (main folder), we
also check if there are test class files (only if the option
`includeTests` is enabled). If there are test files, validation of the
report takes place.

Fixes spotbugs#454
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants