3 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file.
7 """Runs findbugs, and returns an error code if there are new warnings.
10 --only-analyze used to only analyze the class you are interested.
11 --relase-build analyze the classes in out/Release directory.
12 --findbugs-args used to passin other findbugs's options.
15 $CHROMIUM_SRC/third_party/findbugs/bin/findbugs -textui for details.
23 from devil
.utils
import run_tests_helper
24 from pylib
import constants
25 from pylib
.utils
import findbugs
27 _DEFAULT_BASE_DIR
= os
.path
.join(
28 constants
.DIR_SOURCE_ROOT
, 'build', 'android', 'findbugs_filter')
31 os
.path
.join(constants
.DIR_SOURCE_ROOT
, 'build', 'android', 'gyp'))
32 from util
import build_utils
# pylint: disable=import-error
36 parser
= argparse
.ArgumentParser()
39 '-v', '--verbose', action
='count', help='Enable verbose logging.')
41 '-a', '--auxclasspath', default
=None, dest
='auxclasspath',
42 help='Set aux classpath for analysis.')
44 '--auxclasspath-gyp', dest
='auxclasspath_gyp',
45 help='A gyp list containing the aux classpath for analysis')
47 '-o', '--only-analyze', default
=None,
48 dest
='only_analyze', help='Only analyze the given classes and packages.')
50 '-e', '--exclude', default
=None, dest
='exclude',
51 help='Exclude bugs matching given filter.')
53 '-l', '--release-build', action
='store_true', dest
='release_build',
54 help='Analyze release build instead of debug.')
56 '-f', '--findbug-args', default
=None, dest
='findbug_args',
57 help='Additional findbug arguments.')
59 '-b', '--base-dir', default
=_DEFAULT_BASE_DIR
,
60 dest
='base_dir', help='Base directory for configuration file.')
62 '--output-file', dest
='output_file',
63 help='Path to save the output to.')
65 '--stamp', help='Path to touch on success.')
67 '--depfile', help='Path to the depfile. This must be specified as the '
68 "action's first output.")
71 'jar_paths', metavar
='JAR_PATH', nargs
='+',
72 help='JAR file to analyze')
74 args
= parser
.parse_args(build_utils
.ExpandFileArgs(sys
.argv
[1:]))
76 run_tests_helper
.SetLogLevel(args
.verbose
)
79 args
.auxclasspath
= args
.auxclasspath
.split(':')
80 elif args
.auxclasspath_gyp
:
81 args
.auxclasspath
= build_utils
.ParseGypList(args
.auxclasspath_gyp
)
85 args
.exclude
= os
.path
.join(args
.base_dir
, 'findbugs_exclude.xml')
87 findbugs_command
, findbugs_warnings
= findbugs
.Run(
88 args
.exclude
, args
.only_analyze
, args
.auxclasspath
,
89 args
.output_file
, args
.findbug_args
, args
.jar_paths
)
94 print 'FindBugs run via:'
95 print findbugs_command
97 print 'FindBugs reported the following issues:'
98 for warning
in sorted(findbugs_warnings
):
104 build_utils
.WriteDepfile(
106 build_utils
.GetPythonDependencies() + args
.auxclasspath
109 build_utils
.Touch(args
.stamp
)
111 return len(findbugs_warnings
)
114 if __name__
== '__main__':