Mercurial > hg > truffle
comparison mxtool/mx.py @ 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 | 0f4ae7bbe062 |
children | 931f9ced42ad |
comparison
equal
deleted
inserted
replaced
9825:81d5d8089cda | 9826:cff647969dfa |
---|---|
131 | 131 |
132 Property values can use environment variables with Bash syntax (e.g. ${HOME}). | 132 Property values can use environment variables with Bash syntax (e.g. ${HOME}). |
133 """ | 133 """ |
134 | 134 |
135 import sys, os, errno, time, subprocess, shlex, types, urllib2, contextlib, StringIO, zipfile, signal, xml.sax.saxutils, tempfile | 135 import sys, os, errno, time, subprocess, shlex, types, urllib2, contextlib, StringIO, zipfile, signal, xml.sax.saxutils, tempfile |
136 import xml.parsers.expat | |
136 import shutil, re, xml.dom.minidom | 137 import shutil, re, xml.dom.minidom |
137 from collections import Callable | 138 from collections import Callable |
138 from threading import Thread | 139 from threading import Thread |
139 from argparse import ArgumentParser, REMAINDER | 140 from argparse import ArgumentParser, REMAINDER |
140 from os.path import join, basename, dirname, exists, getmtime, isabs, expandvars, isdir, isfile | 141 from os.path import join, basename, dirname, exists, getmtime, isabs, expandvars, isdir, isfile |
1906 break | 1907 break |
1907 | 1908 |
1908 batch = javafilelist[:i] | 1909 batch = javafilelist[:i] |
1909 javafilelist = javafilelist[i:] | 1910 javafilelist = javafilelist[i:] |
1910 try: | 1911 try: |
1911 run_java(['-Xmx1g', '-jar', library('CHECKSTYLE').get_path(True), '-c', config, '-o', auditfileName] + batch) | 1912 run_java(['-Xmx1g', '-jar', library('CHECKSTYLE').get_path(True), '-f', 'xml', '-c', config, '-o', auditfileName] + batch) |
1912 finally: | 1913 finally: |
1913 if exists(auditfileName): | 1914 if exists(auditfileName): |
1914 with open(auditfileName) as f: | 1915 errors = [] |
1915 warnings = [line.strip() for line in f if 'warning:' in line] | 1916 source = None |
1916 if len(warnings) != 0: | 1917 def start_element(name, attrs): |
1917 map(log, warnings) | 1918 if name == 'file': |
1918 return 1 | 1919 global source |
1920 source = attrs['name'] | |
1921 elif name == 'error': | |
1922 errors.append('{}:{}: {}'.format(source, attrs['line'], attrs['message'])) | |
1923 | |
1924 p = xml.parsers.expat.ParserCreate() | |
1925 p.StartElementHandler = start_element | |
1926 with open(auditfileName) as fp: | |
1927 p.ParseFile(fp) | |
1928 if len(errors) != 0: | |
1929 map(log, errors) | |
1930 return len(errors) | |
1931 else: | |
1932 if exists(timestampFile): | |
1933 os.utime(timestampFile, None) | |
1919 else: | 1934 else: |
1920 if exists(timestampFile): | 1935 file(timestampFile, 'a') |
1921 os.utime(timestampFile, None) | |
1922 else: | |
1923 file(timestampFile, 'a') | |
1924 finally: | 1936 finally: |
1925 if exists(auditfileName): | 1937 if exists(auditfileName): |
1926 os.unlink(auditfileName) | 1938 os.unlink(auditfileName) |
1927 return 0 | 1939 return 0 |
1928 | 1940 |