changeset 22031:434fbaaf53d7

moved findbugs support from mx_graal.py to mx_findbugs.py
author Doug Simon <doug.simon@oracle.com>
date Fri, 19 Jun 2015 17:41:45 +0200
parents 5b4a974d9ae6
children 3e7ab72bac96
files .hgignore mx.graal/mx_graal.py mx.graal/suite.py mxtool/mx.mx/suite.py mxtool/mx.py mxtool/mx_findbugs.py
diffstat 6 files changed, 98 insertions(+), 52 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Fri Jun 19 15:59:22 2015 +0200
+++ b/.hgignore	Fri Jun 19 17:41:45 2015 +0200
@@ -3,7 +3,6 @@
 ^build-nojvmci/
 ^dist/
 ^java/
-^lib/
 ^jdk1.(7|8).0
 ^java64/
 ^work/
@@ -62,6 +61,7 @@
 ^tags
 
 syntax: glob
+lib
 currentAnnotationProcessors
 ecj.jar
 jmh
--- a/mx.graal/mx_graal.py	Fri Jun 19 15:59:22 2015 +0200
+++ b/mx.graal/mx_graal.py	Fri Jun 19 17:41:45 2015 +0200
@@ -30,12 +30,14 @@
 from os.path import join, exists, dirname, basename
 from argparse import ArgumentParser, REMAINDER
 from outputparser import OutputParser, ValuesMatcher
-import mx
-import mx_unittest
 import xml.dom.minidom
 import sanitycheck
 import itertools
 import json, textwrap
+
+import mx
+import mx_unittest
+import mx_findbugs
 import mx_graal_makefile
 
 _suite = mx.suite('graal')
@@ -1523,7 +1525,7 @@
                 t.abort('Checkheaders warnings were found')
 
         with Task('FindBugs', tasks) as t:
-            if t and findbugs([]) != 0:
+            if t and mx_findbugs.findbugs([]) != 0:
                 t.abort('FindBugs warnings were found')
 
         if exists('jacoco.exec'):
@@ -2254,43 +2256,6 @@
     valueMap = parser.parse(output.getvalue())
     return valueMap
 
-def findbugs(args):
-    '''run FindBugs against non-test Java projects'''
-    findBugsHome = mx.get_env('FINDBUGS_HOME', None)
-    if findBugsHome:
-        findbugsJar = join(findBugsHome, 'lib', 'findbugs.jar')
-    else:
-        findbugsLib = join(_graal_home, 'lib', 'findbugs-3.0.0')
-        if not exists(findbugsLib):
-            tmp = tempfile.mkdtemp(prefix='findbugs-download-tmp', dir=_graal_home)
-            try:
-                findbugsDist = mx.library('FINDBUGS_DIST').get_path(resolve=True)
-                with zipfile.ZipFile(findbugsDist) as zf:
-                    candidates = [e for e in zf.namelist() if e.endswith('/lib/findbugs.jar')]
-                    assert len(candidates) == 1, candidates
-                    libDirInZip = os.path.dirname(candidates[0])
-                    zf.extractall(tmp)
-                shutil.copytree(join(tmp, libDirInZip), findbugsLib)
-            finally:
-                shutil.rmtree(tmp)
-        findbugsJar = join(findbugsLib, 'findbugs.jar')
-    assert exists(findbugsJar)
-    nonTestProjects = [p for p in mx.projects() if not p.name.endswith('.test') and not p.name.endswith('.jtt')]
-    outputDirs = map(mx._cygpathU2W, [p.output_dir() for p in nonTestProjects])
-    javaCompliance = max([p.javaCompliance for p in nonTestProjects])
-    findbugsResults = join(_graal_home, 'findbugs.results')
-
-    cmd = ['-jar', mx._cygpathU2W(findbugsJar), '-textui', '-low', '-maxRank', '15']
-    if mx.is_interactive():
-        cmd.append('-progress')
-    cmd = cmd + ['-auxclasspath', mx._separatedCygpathU2W(mx.classpath([d.name for d in _jdkDeployedDists] + [p.name for p in nonTestProjects])), '-output', mx._cygpathU2W(findbugsResults), '-exitcode'] + args + outputDirs
-    exitcode = mx.run_java(cmd, nonZeroIsFatal=False, javaConfig=mx.java(javaCompliance))
-    if exitcode != 0:
-        with open(findbugsResults) as fp:
-            mx.log(fp.read())
-    os.unlink(findbugsResults)
-    return exitcode
-
 def checkheaders(args):
     """check Java source headers against any required pattern"""
     failures = {}
@@ -2333,7 +2298,6 @@
         'clean': [clean, ''],
         'ctw': [ctw, '[-vmoptions|noinline|nocomplex|full]'],
         'export': [export, '[-options] [zipfile]'],
-        'findbugs': [findbugs, ''],
         'generateZshCompletion' : [generateZshCompletion, ''],
         'hsdis': [hsdis, '[att]'],
         'hcfdis': [hcfdis, ''],
--- a/mx.graal/suite.py	Fri Jun 19 15:59:22 2015 +0200
+++ b/mx.graal/suite.py	Fri Jun 19 17:41:45 2015 +0200
@@ -61,15 +61,6 @@
       "sha1" : "bc8b2253436485e9dbaf81771c259ccfa1a24c80",
     },
 
-    "FINDBUGS_DIST" : {
-      "path" : "lib/findbugs-dist-3.0.0.zip",
-      "urls" : [
-        "http://lafo.ssw.uni-linz.ac.at/graal-external-deps/findbugs-3.0.0.zip",
-        "http://sourceforge.net/projects/findbugs/files/findbugs/3.0.0/findbugs-3.0.0.zip/download",
-      ],
-      "sha1" : "6e56d67f238dbcd60acb88a81655749aa6419c5b",
-    },
-
     "C1VISUALIZER_DIST" : {
       "path" : "lib/c1visualizer_2014-04-22.zip",
       "urls" : ["https://java.net/downloads/c1visualizer/c1visualizer_2014-04-22.zip"],
--- a/mxtool/mx.mx/suite.py	Fri Jun 19 15:59:22 2015 +0200
+++ b/mxtool/mx.mx/suite.py	Fri Jun 19 17:41:45 2015 +0200
@@ -5,6 +5,15 @@
 
     # ------------- Libraries -------------
 
+    "MX_FINDBUGS_DIST" : {
+      "path" : "lib/findbugs-dist-3.0.0.zip",
+      "urls" : [
+        "http://lafo.ssw.uni-linz.ac.at/graal-external-deps/findbugs-3.0.0.zip",
+        "http://sourceforge.net/projects/findbugs/files/findbugs/3.0.0/findbugs-3.0.0.zip/download",
+      ],
+      "sha1" : "6e56d67f238dbcd60acb88a81655749aa6419c5b",
+    },
+
     "MX_JUNIT" : {
       "path" : "lib/junit-4.11.jar",
       "urls" : [
--- a/mxtool/mx.py	Fri Jun 19 15:59:22 2015 +0200
+++ b/mxtool/mx.py	Fri Jun 19 17:41:45 2015 +0200
@@ -47,12 +47,14 @@
 import shutil, re, xml.dom.minidom
 import pipes
 import difflib
-import mx_unittest
 from collections import Callable
 from threading import Thread
 from argparse import ArgumentParser, REMAINDER
 from os.path import join, basename, dirname, exists, getmtime, isabs, expandvars, isdir, isfile
 
+import mx_unittest
+import mx_findbugs
+
 try:
     # needed to work around https://bugs.python.org/issue1927
     import readline
@@ -5708,6 +5710,7 @@
     'eclipseinit': [eclipseinit, ''],
     'eclipseformat': [eclipseformat, ''],
     'exportlibs': [exportlibs, ''],
+    'findbugs': [mx_findbugs.findbugs, ''],
     'findclass': [findclass, ''],
     'fsckprojects': [fsckprojects, ''],
     'help': [help_, '[command]'],
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mxtool/mx_findbugs.py	Fri Jun 19 17:41:45 2015 +0200
@@ -0,0 +1,79 @@
+#!/usr/bin/env python2.7
+#
+# ----------------------------------------------------------------------------------------------------
+#
+# Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+# ----------------------------------------------------------------------------------------------------
+#
+
+import mx
+import os
+import tempfile
+import zipfile
+import shutil
+from os.path import join, exists
+
+def defaultFindbugsArgs():
+    args = ['-textui', '-low', '-maxRank', '15']
+    if mx.is_interactive():
+        args.append('-progress')
+    return args
+
+def findbugs(args, fbArgs=None, suite=None, projects=None):
+    """run FindBugs against non-test Java projects"""
+    findBugsHome = mx.get_env('FINDBUGS_HOME', None)
+    if suite is None:
+        suite = mx._primary_suite
+    if findBugsHome:
+        findbugsJar = join(findBugsHome, 'lib', 'findbugs.jar')
+    else:
+        findbugsLib = join(mx._mx_suite.dir, 'lib', 'findbugs-3.0.0')
+        if not exists(findbugsLib):
+            tmp = tempfile.mkdtemp(prefix='findbugs-download-tmp', dir=mx._mx_suite.dir)
+            try:
+                findbugsDist = mx.library('MX_FINDBUGS_DIST').get_path(resolve=True)
+                with zipfile.ZipFile(findbugsDist) as zf:
+                    candidates = [e for e in zf.namelist() if e.endswith('/lib/findbugs.jar')]
+                    assert len(candidates) == 1, candidates
+                    libDirInZip = os.path.dirname(candidates[0])
+                    zf.extractall(tmp)
+                shutil.copytree(join(tmp, libDirInZip), findbugsLib)
+            finally:
+                shutil.rmtree(tmp)
+        findbugsJar = join(findbugsLib, 'findbugs.jar')
+    assert exists(findbugsJar)
+    nonTestProjects = [p for p in mx.projects() if not p.name.endswith('.test') and not p.name.endswith('.jtt')]
+    outputDirs = map(mx._cygpathU2W, [p.output_dir() for p in nonTestProjects])
+    javaCompliance = max([p.javaCompliance for p in nonTestProjects])
+    findbugsResults = join(suite.dir, 'findbugs.results')
+
+    if fbArgs is None:
+        fbArgs = defaultFindbugsArgs()
+    cmd = ['-jar', mx._cygpathU2W(findbugsJar)] + fbArgs
+    cmd = cmd + ['-auxclasspath', mx._separatedCygpathU2W(mx.classpath([p.name for p in nonTestProjects])), '-output', mx._cygpathU2W(findbugsResults), '-exitcode'] + args + outputDirs
+    exitcode = mx.run_java(cmd, nonZeroIsFatal=False, javaConfig=mx.java(javaCompliance))
+    if exitcode != 0:
+        with open(findbugsResults) as fp:
+            mx.log(fp.read())
+    os.unlink(findbugsResults)
+    return exitcode