changeset 9826:cff647969dfa

fixed detection of Checkstyle errors in checkstyle command (GRAAL-293)
author Doug Simon <doug.simon@oracle.com>
date Sun, 26 May 2013 22:48:43 +0200
parents 81d5d8089cda
children 26a4433252a3
files mxtool/mx.py
diffstat 1 files changed, 22 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/mxtool/mx.py	Sun May 26 13:44:16 2013 -0400
+++ b/mxtool/mx.py	Sun May 26 22:48:43 2013 +0200
@@ -133,6 +133,7 @@
 """
 
 import sys, os, errno, time, subprocess, shlex, types, urllib2, contextlib, StringIO, zipfile, signal, xml.sax.saxutils, tempfile
+import xml.parsers.expat
 import shutil, re, xml.dom.minidom
 from collections import Callable
 from threading import Thread
@@ -1908,19 +1909,30 @@
                     batch = javafilelist[:i]
                     javafilelist = javafilelist[i:]
                     try:
-                        run_java(['-Xmx1g', '-jar', library('CHECKSTYLE').get_path(True), '-c', config, '-o', auditfileName] + batch)
+                        run_java(['-Xmx1g', '-jar', library('CHECKSTYLE').get_path(True), '-f', 'xml', '-c', config, '-o', auditfileName] + batch)
                     finally:
                         if exists(auditfileName):
-                            with open(auditfileName) as f:
-                                warnings = [line.strip() for line in f if 'warning:' in line]
-                                if len(warnings) != 0:
-                                    map(log, warnings)
-                                    return 1
+                            errors = []
+                            source = None
+                            def start_element(name, attrs):
+                                if name == 'file':
+                                    global source
+                                    source = attrs['name']
+                                elif name == 'error':
+                                    errors.append('{}:{}: {}'.format(source, attrs['line'], attrs['message']))
+
+                            p = xml.parsers.expat.ParserCreate()
+                            p.StartElementHandler = start_element
+                            with open(auditfileName) as fp:
+                                p.ParseFile(fp)
+                            if len(errors) != 0:
+                                map(log, errors)
+                                return len(errors)
+                            else:
+                                if exists(timestampFile):
+                                    os.utime(timestampFile, None)
                                 else:
-                                    if exists(timestampFile):
-                                        os.utime(timestampFile, None)
-                                    else:
-                                        file(timestampFile, 'a')
+                                    file(timestampFile, 'a')
             finally:
                 if exists(auditfileName):
                     os.unlink(auditfileName)