This repository has been archived by the owner on Jun 24, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
add the support of findbugs (not really tested)
- Loading branch information
Sylvestre Ledru
committed
Oct 27, 2013
1 parent
d2d26e8
commit c9bba8e
Showing
3 changed files
with
162 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| # Copyright (c) 2012-2013 Paul Tagliamonte <paultag@debian.org> | ||
| # Copyright (c) 2013 Leo Cavaille <leo@cavaille.net> | ||
| # Copyright (c) 2013 Sylvestre Ledru <sylvestre@debian.org> | ||
| # | ||
| # Permission is hereby granted, free of charge, to any person obtaining a | ||
| # copy of this software and associated documentation files (the "Software"), | ||
| # to deal in the Software without restriction, including without limitation | ||
| # the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
| # and/or sell copies of the Software, and to permit persons to whom the | ||
| # Software is furnished to do so, subject to the following conditions: | ||
| # | ||
| # The above copyright notice and this permission notice shall be included in | ||
| # all copies or substantial portions of the Software. | ||
| # | ||
| # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
| # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
| # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
| # DEALINGS IN THE SOFTWARE. | ||
|
|
||
| from debile.slave.runners.findbugs import findbugs, version | ||
|
|
||
|
|
||
| def run(dsc, package, job, firehose): | ||
| return findbugs(dsc, firehose) | ||
|
|
||
|
|
||
| def get_version(): | ||
| return version() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| # Copyright (c) 2012-2013 Paul Tagliamonte <paultag@debian.org> | ||
| # Copyright (c) 2013 Leo Cavaille <leo@cavaille.net> | ||
| # Copyright (c) 2013 Sylvestre Ledru <sylvestre@debian.org> | ||
| # | ||
| # Permission is hereby granted, free of charge, to any person obtaining a | ||
| # copy of this software and associated documentation files (the "Software"), | ||
| # to deal in the Software without restriction, including without limitation | ||
| # the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
| # and/or sell copies of the Software, and to permit persons to whom the | ||
| # Software is furnished to do so, subject to the following conditions: | ||
| # | ||
| # The above copyright notice and this permission notice shall be included in | ||
| # all copies or substantial portions of the Software. | ||
| # | ||
| # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
| # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
| # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
| # DEALINGS IN THE SOFTWARE. | ||
|
|
||
| from debile.slave.wrappers.findbugs import parse_findbugs | ||
| from debile.slave.utils import run_command, cd | ||
|
|
||
|
|
||
| def findbugs(deb, analysis): | ||
| run_command(["dpkg", "-x", deb, "binary"]) | ||
| with cd('binary'): | ||
| out, err, ret = run_command([ | ||
| 'fb', 'analyze', '-effort:max', '-xml:withMessages', '.' | ||
| ]) | ||
|
|
||
| xmlbytes = out.encode("utf-8") | ||
|
|
||
| failed = False | ||
| # if err.strip() == '': | ||
| # return (analysis, err, failed) | ||
|
|
||
| for issue in parse_findbugs(xmlbytes): | ||
| analysis.results.append(issue) | ||
| if not failed and issue.severity in [ | ||
| 'performance', 'portability', 'error', 'warning' | ||
| ]: | ||
| failed = True | ||
|
|
||
| return (analysis, err, failed, None) | ||
|
|
||
|
|
||
| def version(): | ||
| out, err, ret = run_command([ | ||
| 'fb', '-version' | ||
| ]) | ||
| if ret != 0: | ||
| raise Exception("findbugs is not installed") | ||
| name, version = out.split(" ") | ||
| return (name, version.strip()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| # Copyright (c) 2012-2013 Paul Tagliamonte <paultag@debian.org> | ||
| # Copyright (c) 2013 Leo Cavaille <leo@cavaille.net> | ||
| # Copyright (c) 2013 Sylvestre Ledru <sylvestre@debian.org> | ||
| # | ||
| # Permission is hereby granted, free of charge, to any person obtaining a | ||
| # copy of this software and associated documentation files (the "Software"), | ||
| # to deal in the Software without restriction, including without limitation | ||
| # the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
| # and/or sell copies of the Software, and to permit persons to whom the | ||
| # Software is furnished to do so, subject to the following conditions: | ||
| # | ||
| # The above copyright notice and this permission notice shall be included in | ||
| # all copies or substantial portions of the Software. | ||
| # | ||
| # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
| # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
| # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
| # DEALINGS IN THE SOFTWARE. | ||
|
|
||
| from firehose.model import Issue, Message, File, Location, Point | ||
| import lxml.etree | ||
|
|
||
| # We require: | ||
| # findbugs TODO | ||
| # --enable=all . --xml 1>/dev/null ( stderr ) | ||
|
|
||
|
|
||
| def parse_findbugs(payload): | ||
| tree = lxml.etree.fromstring(payload) | ||
| for result in tree.xpath("//BugCollection/BugInstance/Class/SourceLine"): | ||
| keys = result.keys() | ||
|
|
||
| p = None | ||
| # Start is not always defined | ||
| if 'start' in keys: | ||
| line = result.attrib['start'] | ||
| p = Point(int(line), 0) | ||
|
|
||
| if 'end' in keys: | ||
| lineEnd = result.attrib['end'] | ||
| p = Point(int(line), int(lineEnd)) | ||
|
|
||
| if 'sourcepath' in keys: | ||
| path = result.attrib['sourcepath'] | ||
| else: | ||
| path = "unknown" | ||
|
|
||
| message, = result.xpath("../../LongMessage") | ||
| message = message.text | ||
| testid = result.getparent().getparent().attrib['instanceHash'] | ||
| rank = result.getparent().getparent().attrib['rank'] | ||
| if rank <= 4: | ||
| severity = "scariest" | ||
| elif rank <= 9: | ||
| severity = "scary" | ||
| elif rank <= 14: | ||
| severity = "troubling" | ||
| else: | ||
| severity = "concern" | ||
|
|
||
|
|
||
| yield Issue(cwe=None, | ||
| testid=testid, | ||
| location=Location( | ||
| file=File(path, None), | ||
| function=None, | ||
| point=p), | ||
| severity=severity, | ||
| message=Message(text=message), | ||
| notes=None, | ||
| trace=None) |