Mercurial > hg > graal-jvmci-8
annotate mxtool/mx_findbugs.py @ 22041:56c50504d60d
mx: removed JVMCI code from Distribution.make_archive
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Sat, 20 Jun 2015 12:37:01 +0200 |
parents | 434fbaaf53d7 |
children | 0defcb691fe2 |
rev | line source |
---|---|
22031
434fbaaf53d7
moved findbugs support from mx_graal.py to mx_findbugs.py
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1 #!/usr/bin/env python2.7 |
434fbaaf53d7
moved findbugs support from mx_graal.py to mx_findbugs.py
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
2 # |
434fbaaf53d7
moved findbugs support from mx_graal.py to mx_findbugs.py
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
3 # ---------------------------------------------------------------------------------------------------- |
434fbaaf53d7
moved findbugs support from mx_graal.py to mx_findbugs.py
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
4 # |
434fbaaf53d7
moved findbugs support from mx_graal.py to mx_findbugs.py
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
5 # Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved. |
434fbaaf53d7
moved findbugs support from mx_graal.py to mx_findbugs.py
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
6 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
434fbaaf53d7
moved findbugs support from mx_graal.py to mx_findbugs.py
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
7 # |
434fbaaf53d7
moved findbugs support from mx_graal.py to mx_findbugs.py
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
8 # This code is free software; you can redistribute it and/or modify it |
434fbaaf53d7
moved findbugs support from mx_graal.py to mx_findbugs.py
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
9 # under the terms of the GNU General Public License version 2 only, as |
434fbaaf53d7
moved findbugs support from mx_graal.py to mx_findbugs.py
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
10 # published by the Free Software Foundation. |
434fbaaf53d7
moved findbugs support from mx_graal.py to mx_findbugs.py
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
11 # |
434fbaaf53d7
moved findbugs support from mx_graal.py to mx_findbugs.py
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
12 # This code is distributed in the hope that it will be useful, but WITHOUT |
434fbaaf53d7
moved findbugs support from mx_graal.py to mx_findbugs.py
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
13 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
434fbaaf53d7
moved findbugs support from mx_graal.py to mx_findbugs.py
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
14 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
434fbaaf53d7
moved findbugs support from mx_graal.py to mx_findbugs.py
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
15 # version 2 for more details (a copy is included in the LICENSE file that |
434fbaaf53d7
moved findbugs support from mx_graal.py to mx_findbugs.py
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
16 # accompanied this code). |
434fbaaf53d7
moved findbugs support from mx_graal.py to mx_findbugs.py
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
17 # |
434fbaaf53d7
moved findbugs support from mx_graal.py to mx_findbugs.py
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
18 # You should have received a copy of the GNU General Public License version |
434fbaaf53d7
moved findbugs support from mx_graal.py to mx_findbugs.py
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
19 # 2 along with this work; if not, write to the Free Software Foundation, |
434fbaaf53d7
moved findbugs support from mx_graal.py to mx_findbugs.py
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
20 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
434fbaaf53d7
moved findbugs support from mx_graal.py to mx_findbugs.py
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
21 # |
434fbaaf53d7
moved findbugs support from mx_graal.py to mx_findbugs.py
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
22 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
434fbaaf53d7
moved findbugs support from mx_graal.py to mx_findbugs.py
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
23 # or visit www.oracle.com if you need additional information or have any |
434fbaaf53d7
moved findbugs support from mx_graal.py to mx_findbugs.py
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
24 # questions. |
434fbaaf53d7
moved findbugs support from mx_graal.py to mx_findbugs.py
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
25 # |
434fbaaf53d7
moved findbugs support from mx_graal.py to mx_findbugs.py
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
26 # ---------------------------------------------------------------------------------------------------- |
434fbaaf53d7
moved findbugs support from mx_graal.py to mx_findbugs.py
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
27 # |
434fbaaf53d7
moved findbugs support from mx_graal.py to mx_findbugs.py
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
28 |
434fbaaf53d7
moved findbugs support from mx_graal.py to mx_findbugs.py
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
29 import mx |
434fbaaf53d7
moved findbugs support from mx_graal.py to mx_findbugs.py
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
30 import os |
434fbaaf53d7
moved findbugs support from mx_graal.py to mx_findbugs.py
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
31 import tempfile |
434fbaaf53d7
moved findbugs support from mx_graal.py to mx_findbugs.py
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
32 import zipfile |
434fbaaf53d7
moved findbugs support from mx_graal.py to mx_findbugs.py
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
33 import shutil |
434fbaaf53d7
moved findbugs support from mx_graal.py to mx_findbugs.py
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
34 from os.path import join, exists |
434fbaaf53d7
moved findbugs support from mx_graal.py to mx_findbugs.py
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
35 |
434fbaaf53d7
moved findbugs support from mx_graal.py to mx_findbugs.py
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
36 def defaultFindbugsArgs(): |
434fbaaf53d7
moved findbugs support from mx_graal.py to mx_findbugs.py
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
37 args = ['-textui', '-low', '-maxRank', '15'] |
434fbaaf53d7
moved findbugs support from mx_graal.py to mx_findbugs.py
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
38 if mx.is_interactive(): |
434fbaaf53d7
moved findbugs support from mx_graal.py to mx_findbugs.py
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
39 args.append('-progress') |
434fbaaf53d7
moved findbugs support from mx_graal.py to mx_findbugs.py
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
40 return args |
434fbaaf53d7
moved findbugs support from mx_graal.py to mx_findbugs.py
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
41 |
434fbaaf53d7
moved findbugs support from mx_graal.py to mx_findbugs.py
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
42 def findbugs(args, fbArgs=None, suite=None, projects=None): |
434fbaaf53d7
moved findbugs support from mx_graal.py to mx_findbugs.py
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
43 """run FindBugs against non-test Java projects""" |
434fbaaf53d7
moved findbugs support from mx_graal.py to mx_findbugs.py
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
44 findBugsHome = mx.get_env('FINDBUGS_HOME', None) |
434fbaaf53d7
moved findbugs support from mx_graal.py to mx_findbugs.py
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
45 if suite is None: |
434fbaaf53d7
moved findbugs support from mx_graal.py to mx_findbugs.py
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
46 suite = mx._primary_suite |
434fbaaf53d7
moved findbugs support from mx_graal.py to mx_findbugs.py
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
47 if findBugsHome: |
434fbaaf53d7
moved findbugs support from mx_graal.py to mx_findbugs.py
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
48 findbugsJar = join(findBugsHome, 'lib', 'findbugs.jar') |
434fbaaf53d7
moved findbugs support from mx_graal.py to mx_findbugs.py
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
49 else: |
434fbaaf53d7
moved findbugs support from mx_graal.py to mx_findbugs.py
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
50 findbugsLib = join(mx._mx_suite.dir, 'lib', 'findbugs-3.0.0') |
434fbaaf53d7
moved findbugs support from mx_graal.py to mx_findbugs.py
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
51 if not exists(findbugsLib): |
434fbaaf53d7
moved findbugs support from mx_graal.py to mx_findbugs.py
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
52 tmp = tempfile.mkdtemp(prefix='findbugs-download-tmp', dir=mx._mx_suite.dir) |
434fbaaf53d7
moved findbugs support from mx_graal.py to mx_findbugs.py
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
53 try: |
434fbaaf53d7
moved findbugs support from mx_graal.py to mx_findbugs.py
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
54 findbugsDist = mx.library('MX_FINDBUGS_DIST').get_path(resolve=True) |
434fbaaf53d7
moved findbugs support from mx_graal.py to mx_findbugs.py
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
55 with zipfile.ZipFile(findbugsDist) as zf: |
434fbaaf53d7
moved findbugs support from mx_graal.py to mx_findbugs.py
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
56 candidates = [e for e in zf.namelist() if e.endswith('/lib/findbugs.jar')] |
434fbaaf53d7
moved findbugs support from mx_graal.py to mx_findbugs.py
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
57 assert len(candidates) == 1, candidates |
434fbaaf53d7
moved findbugs support from mx_graal.py to mx_findbugs.py
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
58 libDirInZip = os.path.dirname(candidates[0]) |
434fbaaf53d7
moved findbugs support from mx_graal.py to mx_findbugs.py
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
59 zf.extractall(tmp) |
434fbaaf53d7
moved findbugs support from mx_graal.py to mx_findbugs.py
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
60 shutil.copytree(join(tmp, libDirInZip), findbugsLib) |
434fbaaf53d7
moved findbugs support from mx_graal.py to mx_findbugs.py
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
61 finally: |
434fbaaf53d7
moved findbugs support from mx_graal.py to mx_findbugs.py
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
62 shutil.rmtree(tmp) |
434fbaaf53d7
moved findbugs support from mx_graal.py to mx_findbugs.py
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
63 findbugsJar = join(findbugsLib, 'findbugs.jar') |
434fbaaf53d7
moved findbugs support from mx_graal.py to mx_findbugs.py
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
64 assert exists(findbugsJar) |
434fbaaf53d7
moved findbugs support from mx_graal.py to mx_findbugs.py
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
65 nonTestProjects = [p for p in mx.projects() if not p.name.endswith('.test') and not p.name.endswith('.jtt')] |
434fbaaf53d7
moved findbugs support from mx_graal.py to mx_findbugs.py
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
66 outputDirs = map(mx._cygpathU2W, [p.output_dir() for p in nonTestProjects]) |
434fbaaf53d7
moved findbugs support from mx_graal.py to mx_findbugs.py
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
67 javaCompliance = max([p.javaCompliance for p in nonTestProjects]) |
434fbaaf53d7
moved findbugs support from mx_graal.py to mx_findbugs.py
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
68 findbugsResults = join(suite.dir, 'findbugs.results') |
434fbaaf53d7
moved findbugs support from mx_graal.py to mx_findbugs.py
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
69 |
434fbaaf53d7
moved findbugs support from mx_graal.py to mx_findbugs.py
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
70 if fbArgs is None: |
434fbaaf53d7
moved findbugs support from mx_graal.py to mx_findbugs.py
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
71 fbArgs = defaultFindbugsArgs() |
434fbaaf53d7
moved findbugs support from mx_graal.py to mx_findbugs.py
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
72 cmd = ['-jar', mx._cygpathU2W(findbugsJar)] + fbArgs |
434fbaaf53d7
moved findbugs support from mx_graal.py to mx_findbugs.py
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
73 cmd = cmd + ['-auxclasspath', mx._separatedCygpathU2W(mx.classpath([p.name for p in nonTestProjects])), '-output', mx._cygpathU2W(findbugsResults), '-exitcode'] + args + outputDirs |
434fbaaf53d7
moved findbugs support from mx_graal.py to mx_findbugs.py
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
74 exitcode = mx.run_java(cmd, nonZeroIsFatal=False, javaConfig=mx.java(javaCompliance)) |
434fbaaf53d7
moved findbugs support from mx_graal.py to mx_findbugs.py
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
75 if exitcode != 0: |
434fbaaf53d7
moved findbugs support from mx_graal.py to mx_findbugs.py
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
76 with open(findbugsResults) as fp: |
434fbaaf53d7
moved findbugs support from mx_graal.py to mx_findbugs.py
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
77 mx.log(fp.read()) |
434fbaaf53d7
moved findbugs support from mx_graal.py to mx_findbugs.py
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
78 os.unlink(findbugsResults) |
434fbaaf53d7
moved findbugs support from mx_graal.py to mx_findbugs.py
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
79 return exitcode |