Mercurial > hg > graal-jvmci-8
comparison mx/mx_graal.py @ 14772:c929a4a3b6c5
added checkheaders command for checking Java source headers without relying on Checkstyle
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Wed, 26 Mar 2014 21:08:00 +0100 |
parents | 141d570b397c |
children | 78343531acc7 |
comparison
equal
deleted
inserted
replaced
14771:f87c23fd304d | 14772:c929a4a3b6c5 |
---|---|
1710 with open(findbugsResults) as fp: | 1710 with open(findbugsResults) as fp: |
1711 mx.log(fp.read()) | 1711 mx.log(fp.read()) |
1712 os.unlink(findbugsResults) | 1712 os.unlink(findbugsResults) |
1713 return exitcode | 1713 return exitcode |
1714 | 1714 |
1715 def checkheaders(args): | |
1716 """check Java source headers against any required pattern""" | |
1717 failures = {} | |
1718 for p in mx.projects(): | |
1719 if p.native: | |
1720 continue | |
1721 | |
1722 csConfig = join(mx.project(p.checkstyleProj).dir, '.checkstyle_checks.xml') | |
1723 dom = xml.dom.minidom.parse(csConfig) | |
1724 for module in dom.getElementsByTagName('module'): | |
1725 if module.getAttribute('name') == 'RegexpHeader': | |
1726 for prop in module.getElementsByTagName('property'): | |
1727 if prop.getAttribute('name') == 'header': | |
1728 value = prop.getAttribute('value') | |
1729 matcher = re.compile(value, re.MULTILINE) | |
1730 for sourceDir in p.source_dirs(): | |
1731 for root, _, files in os.walk(sourceDir): | |
1732 for name in files: | |
1733 if name.endswith('.java') and name != 'package-info.java': | |
1734 f = join(root, name) | |
1735 with open(f) as fp: | |
1736 content = fp.read() | |
1737 if not matcher.match(content): | |
1738 failures[f] = csConfig | |
1739 for n, v in failures.iteritems(): | |
1740 mx.log('{}: header does not match RegexpHeader defined in {}'.format(n, v)) | |
1741 return len(failures) | |
1742 | |
1715 def mx_init(suite): | 1743 def mx_init(suite): |
1716 commands = { | 1744 commands = { |
1717 'build': [build, ''], | 1745 'build': [build, ''], |
1718 'buildvars': [buildvars, ''], | 1746 'buildvars': [buildvars, ''], |
1719 'buildvms': [buildvms, '[-options]'], | 1747 'buildvms': [buildvms, '[-options]'], |
1720 'c1visualizer' : [c1visualizer, ''], | 1748 'c1visualizer' : [c1visualizer, ''], |
1749 'checkheaders': [checkheaders, ''], | |
1721 'clean': [clean, ''], | 1750 'clean': [clean, ''], |
1722 'findbugs': [findbugs, ''], | 1751 'findbugs': [findbugs, ''], |
1723 'generateZshCompletion' : [generateZshCompletion, ''], | 1752 'generateZshCompletion' : [generateZshCompletion, ''], |
1724 'hsdis': [hsdis, '[att]'], | 1753 'hsdis': [hsdis, '[att]'], |
1725 'hcfdis': [hcfdis, ''], | 1754 'hcfdis': [hcfdis, ''], |