-
-
Notifications
You must be signed in to change notification settings - Fork 69
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
Support xml and html reports at once #114
Comments
I can say it works fine. :-) tasks.withType(SpotBugsTask) {
reports {
xml.withMessages true
html.stylesheet resources.text.fromArchiveEntry(configurations.spotbugsStylesheets, 'fancy-hist.xsl')
}
task "${it.name}HtmlReport" {
def input = reports.xml.destination
inputs.file reports.html.stylesheet.asFile() withPropertyName 'spotbugsStylesheet' withPathSensitivity NONE
inputs.files fileTree(input) withPropertyName 'input' withPathSensitivity NONE skipWhenEmpty()
def output = file(input.absolutePath.replaceFirst(/\.xml$/, '.html'))
outputs.file output withPropertyName 'output'
doLast {
def factory = TransformerFactory.newInstance('net.sf.saxon.TransformerFactoryImpl', getClass().classLoader)
def transformer = factory.newTransformer(new StreamSource(reports.html.stylesheet.asFile()));
transformer.transform(new StreamSource(input), new StreamResult(output))
}
}
it.finalizedBy "${it.name}HtmlReport"
} It cannot be a |
duplicates spotbugs/spotbugs#857 |
I'd not exactly name it a duplicate, especially as I mentioned that issue, just not linked it. |
@Vampire can you share a full gradle file? I tried using your example and first got errors about StreamSource not known and now I'm getting errors about |
I'm on mobile right now, the posted part was only the essential part. In your case, you are missing the configuration |
The missing parts should be import com.github.spotbugs.SpotBugsTask
import javax.xml.transform.TransformerFactory
import javax.xml.transform.stream.StreamResult
import javax.xml.transform.stream.StreamSource
import static org.gradle.api.tasks.PathSensitivity.NONE
plugins {
id 'com.github.spotbugs' version '1.6.9'
}
spotbugs {
toolVersion '3.1.11'
}
configurations {
spotbugsStylesheets { transitive false }
}
dependencies {
spotbugsStylesheets "com.github.spotbugs:spotbugs:$spotbugs.toolVersion"
} |
Thanks, that helps a lot. Although now I'm getting
|
Nevermind, I just removed the reference and I don't get anymore errors. However the report output doesn't look like the output that is normally produced by the HTML version. It just has counts, no details. I found that changing 'fancy-hist.xsl' to 'default.xsl' I get what I'm expecting. |
Better add the missing buildscript dependency on Saxon. |
I added buildscript {
dependencies {
classpath group: 'net.sf.saxon', name: 'Saxon-HE', version: '9.4'
}
} And switched back to the saxon transformer and now I get the following output >./gradlew spotbugsMain
Starting a Gradle Daemon (subsequent builds will be faster)
> Configure project :
POM relocation to an other version number is not fully supported in Gradle : xml-apis:xml-apis:2.0.2 relocated to xml-api
s:xml-apis:1.0.b2.
Please update your dependency to directly use the correct version 'xml-apis:xml-apis:1.0.b2'.
Resolution will only pick dependencies of the relocated element. Artifacts and other metadata will be ignored.
> Task :spotbugsMainHtmlReport FAILED
Warning: at xsl:variable on line 348 column 56 of default.xsl:
SXWN9001: A variable with no following sibling instructions has no effect
Warning: at xsl:variable on line 351 column 59 of default.xsl:
SXWN9001: A variable with no following sibling instructions has no effect
Error on line 71 of default.xsl:
SEPM0009: Values of 'standalone' and 'omit-xml-declaration' conflict
FAILURE: Build failed with an exception.
* Where:
Build file '/home/jpschewe/projects/fll-sw/working-dir/build.gradle' line: 396
* What went wrong:
Execution failed for task ':spotbugsMainHtmlReport'.
> net.sf.saxon.trans.XPathException: Values of 'standalone' and 'omit-xml-declaration' conflict
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with -
-scan to get full insights.
* Get more help at https://help.gradle.org
Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/5.3/userguide/command_line_interface.html#sec:command_line_warnings
BUILD FAILED in 1m 2s
5 actionable tasks: 3 executed, 2 up-to-date I tried adding configurations.classpath {
resolutionStrategy {
force 'xml-apis:xml-apis:1.4.01'
}
} to the buildscript section and the error about switching versions of the xml-apis went away, but I still got the xsl errors. |
Maybe try not using an ancient version? 9.4 is from 2012, try 9.9.1-2 instead. |
Ah, no, while you still should, |
Not sure why I found the ancient version to start with. I just tried 9.9.1-2 and got the same error. So is default.xsl really a 1.0 XSLT and I should just go back to the default transformer? It seems to work and I don't mind it being slow. |
You should anyway open an issue about it. |
The main reason for this switch is that the default stylesheet doesn't support XSLT 2.0 like it says it does and saxon errors out. I was originally not using saxon, however when switching to java 11, this broke. See the following issues for details * spotbugs/spotbugs-gradle-plugin#114 * spotbugs/spotbugs#958 Issue #648
PR opened to fix main error message in stylesheet: spotbugs/spotbugs#1000 |
https://github.com/Fernal73/LearnJava/blob/master/spotbugs Any particular reason why this script isn't generating XML output? Am I missing something obvious? EDIT: Removed sortByClass flag. That fixes the output. The documentation needs to be updated. |
@Fernal73 Please so not abuse foreign issues to post absolutely unrelated questions. The question is not even in the correct project, as it is about spotbugs itself, not about the Gradle plugin. |
@Vampire Where do I post it? What's the best way to go about it? Create an issue that may be a non-issue? Can these posts not be deleted or marked as outdated? |
@Fernal73 These are not "posts" but comments to an issue, that's the whole point, because this is not a forum. You pollute the issue with unrelated information and may hide important information, you send notification emails to all involved people that are interested in this issue, but not in your question. Of course some admin could delete the comments, but they usually have more important things to do, like actually fixing bugs. You can also delete your comments yourself. But whether it is possible to delete or not, it is rude and impolite and totally not helpful to wildly post at wing places. It disturbs others and it makes it much less likely you will get an answer. Posting to a totally unrelated issue is like going to a statistics class and asking how top draw a triangle. You might get a answer, but the question is totally out of place and you mainly disturb anyone present. And posting to the wrong project like you did additionally is like asking in a physics class (where physicians use math) how to draw a triangle. Next time, a good head start, us to look at the website, where most projects tell you where to get support. In this case it is even right on the startpage: https://spotbugs.github.io/#support-or-contact There both, the correct issue tracker and the mailing list for questions are linked. And yes, posting an own issue that maybe is just a question is always better than abusing an existing issue that is not at all related. Only comments or questions related to the issue should go to that issue. |
@Vampire ok. Done. Hmm, I didn't notice that you'd converted a Github repo into a general purpose mailing list. Btw, are you really telling me that an email or two pertaining to a matter that is just slightly tangential to the issue you're discussing is so very disturbing? Or you didn't like my response to your 'Please'? Frankly , if the documentation had been correct , I wouldn't have to post anything at all. |
I'm attempting to do this from an external script. Currently it looks something like this:
Then spotbugs.gradle:
So now I'm getting the dreaded |
Indeed, it does appear to be related. If I make my build.gradle ext block, like so:
then in my spotbugs.gradle, I can replace:
with
and it works. This isn't as clean as I was hoping for, but it does work. |
@mandrachek why don't you add Saxon to the build script class path of the script where you want to use it? If you add it to the class path of one script and want to use it on another, it is quite understandable, that it is not present. |
Actually, I'm converting it to a plugin, so I will have the plugin in the classpath, and saxon will be an implementation dependency of the plugin. |
Using 4.0.5, SpotBugs seems to generate both xml and html report by default. |
@daanschipper can you share the configuration that you are using? I have applied the spotbugs 4.0.5 plugin and I get a main.xml, but I don't get an HTML file. |
Sorry my bad, the html report was of a previous run :( |
I propose another workaround built upon the saxon transformation idea by @Vampire. I use org.myire.munge Gradle plugin to parse the xml report generated by spotbugs to html. Tested with Gradle 6.4.1.
Usage: |
@henrpe thanks for the alternate solution. This seems a little cleaner than what I've been using. I have made it generic for any number of spotbugs tasks import org.myire.munge.TransformTask configurations { dependencies { spotbugs {
} tasks.withType(SpotBugsTask) {
}
|
@jpschewe, that's an excellent point that transformation should work on multiple sourceSets (main/test atleast). Another way to achieve this would be by
|
@henrpe you need to be careful to handle files with multiple dots in them. I think this will be more robust. This still has the assumption that the output directory of the spotbugs task hasn't changed. That's where it may be good to create the task inside the
|
So any update? Can the plugin integrate this feature? |
@UkonnRa Pull requests are always welcome. But I believe the long term fix is spotbugs/spotbugs#857 |
🎉 This issue has been resolved in version 4.8.0 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
I know that SpotBugs currently only supports one report at a time and that there is an open improvement request to change this, but I don't really expect this to happen anytime soon.
But as far as I have seen from a quick look, the HTML reporter just gets the same XML structure the XML reporter is generating and storing to a file (with messages enabled and minimal XML disabled) and then applies the configured XSL script to get the HTML report.
Knowing this, the Gradle plugin could either "if xml and html is enabled" forward the xml setting to SpotBugs and then apply the XSL itself to the XML report and "if xml is disabled but html enabled" either imlicitly enable the XML report with the tempdir as target and do the same to get the same result in both cases or in this case forward the HTML setting to SpotBugs itself.
This way you could generate a human readable report and a machine readable report in one go without having to do the very same thing manually in your build script.
The text was updated successfully, but these errors were encountered: