comparison mx/commands.py @ 5706:6f2ccb483d96

added overview.html for each project and integrated it into the generated 'mx site' command
author Doug Simon <doug.simon@oracle.com>
date Wed, 27 Jun 2012 18:06:03 +0200
parents 12a34d1bcaa2
children e149c0e252e0
comparison
equal deleted inserted replaced
5705:f96e7b39e9fe 5706:6f2ccb483d96
999 out = args[0] 999 out = args[0]
1000 elif len(args) > 1: 1000 elif len(args) > 1:
1001 mx.abort('jacocoreport takes only one argument : an output directory') 1001 mx.abort('jacocoreport takes only one argument : an output directory')
1002 mx.run_java(['-jar', jacocoreport.get_path(True), '-in', 'jacoco.exec', '-g', join(_graal_home, 'graal'), out]) 1002 mx.run_java(['-jar', jacocoreport.get_path(True), '-in', 'jacoco.exec', '-g', join(_graal_home, 'graal'), out])
1003 1003
1004 def _fix_overview_summary(path, topLink):
1005 """
1006 Processes an "overview-summary.html" generated by javadoc to put the complete
1007 summary text above the Packages table.
1008 """
1009
1010 # This uses scraping and so will break if the relevant content produced by javadoc changes in any way!
1011 orig = path + '.orig'
1012 if exists(orig):
1013 with open(orig) as fp:
1014 content = fp.read()
1015 else:
1016 with open(path) as fp:
1017 content = fp.read()
1018 with open(orig, 'w') as fp:
1019 fp.write(content)
1020
1021 class Chunk:
1022 def __init__(self, content, ldelim, rdelim):
1023 lindex = content.find(ldelim)
1024 rindex = content.find(rdelim)
1025 self.ldelim = ldelim
1026 self.rdelim = rdelim
1027 if lindex != -1 and rindex != -1 and rindex > lindex:
1028 self.text = content[lindex + len(ldelim):rindex]
1029 else:
1030 self.text = None
1031
1032 def replace(self, content, repl):
1033 lindex = content.find(self.ldelim)
1034 rindex = content.find(self.rdelim)
1035 old = content[lindex:rindex + len(self.rdelim)]
1036 return content.replace(old, repl)
1037
1038 chunk1 = Chunk(content, """<div class="header">
1039 <div class="subTitle">
1040 <div class="block">""", """</div>
1041 </div>
1042 <p>See: <a href="#overview_description">Description</a></p>
1043 </div>""")
1044
1045 chunk2 = Chunk(content, """<div class="footer"><a name="overview_description">
1046 <!-- -->
1047 </a>
1048 <div class="subTitle">
1049 <div class="block">""", """</div>
1050 </div>
1051 </div>
1052 <!-- ======= START OF BOTTOM NAVBAR ====== -->""")
1053
1054 if not chunk1.text:
1055 mx.log('Could not find header section in ' + path)
1056 return
1057
1058 if not chunk2.text:
1059 mx.log('Could not find footer section in ' + path)
1060 return
1061
1062 content = chunk1.replace(content, '<div class="header"><div class="subTitle"><div class="block">' + chunk2.text + topLink +'</div></div></div>')
1063 content = chunk2.replace(content, '')
1064
1065 with open(path, 'w') as fp:
1066 fp.write(content)
1067
1004 def site(args): 1068 def site(args):
1005 """creates a website containing javadoc and the project dependency graph""" 1069 """creates a website containing javadoc and the project dependency graph"""
1006 1070
1007 parser = ArgumentParser(prog='site') 1071 parser = ArgumentParser(prog='site')
1008 parser.add_argument('-d', '--base', action='store', help='directory for generated site', required=True, metavar='<dir>') 1072 parser.add_argument('-d', '--base', action='store', help='directory for generated site', required=True, metavar='<dir>')
1009 parser.add_argument('-c', '--clean', action='store_true', help='remove existing site in <dir>') 1073 parser.add_argument('-c', '--clean', action='store_true', help='remove existing site in <dir>')
1074 parser.add_argument('-t', '--test', action='store_true', help='omit the Javadoc execution (useful for testing)')
1010 1075
1011 args = parser.parse_args(args) 1076 args = parser.parse_args(args)
1012 1077
1013 args.base = os.path.abspath(args.base) 1078 args.base = os.path.abspath(args.base)
1014 1079
1016 os.mkdir(args.base) 1081 os.mkdir(args.base)
1017 elif args.clean: 1082 elif args.clean:
1018 shutil.rmtree(args.base) 1083 shutil.rmtree(args.base)
1019 os.mkdir(args.base) 1084 os.mkdir(args.base)
1020 1085
1021 mx.javadoc(['--base', args.base])
1022
1023 unified = join(args.base, 'all') 1086 unified = join(args.base, 'all')
1024 if exists(unified): 1087
1025 shutil.rmtree(unified) 1088 if not args.test:
1026 mx.javadoc(['--base', args.base, '--unified', '--arg', '@-overview', '--arg', '@' + join(_graal_home, 'graal', 'overview.html')]) 1089 # Create javadoc for each project
1027 os.rename(join(args.base, 'javadoc'), unified) 1090 mx.javadoc(['--base', args.base])
1028 1091
1092 # Create unified javadoc for all projects
1093 if exists(unified):
1094 shutil.rmtree(unified)
1095 mx.javadoc(['--base', args.base,
1096 '--unified',
1097 '--arg', '@-windowtitle', '--arg', '@Unified Graal Javadoc',
1098 '--arg', '@-doctitle', '--arg', '@Unified Graal Javadoc',
1099 '--arg', '@-overview', '--arg', '@' + join(_graal_home, 'graal', 'overview.html')])
1100 os.rename(join(args.base, 'javadoc'), unified)
1101
1102 # Generate dependency graph with Graphviz
1029 _, tmp = tempfile.mkstemp() 1103 _, tmp = tempfile.mkstemp()
1030 try: 1104 try:
1031 svg = join(args.base, 'all', 'modules.svg') 1105 svg = join(args.base, 'all', 'modules.svg')
1032 with open(tmp, 'w') as fp: 1106 with open(tmp, 'w') as fp:
1033 print >> fp, 'digraph projects {' 1107 print >> fp, 'digraph projects {'
1048 print >> fp, '{ rank = same; "' + '"; "'.join(names) + '"; }' 1122 print >> fp, '{ rank = same; "' + '"; "'.join(names) + '"; }'
1049 print >> fp, '}' 1123 print >> fp, '}'
1050 1124
1051 mx.run(['dot', '-Tsvg', '-o' + svg, tmp]) 1125 mx.run(['dot', '-Tsvg', '-o' + svg, tmp])
1052 1126
1053 # Post-process generated SVG to remove unified title elements which most browsers
1054 # render as redundant (and annoying) tooltips.
1055 with open(svg, 'r') as fp:
1056 content = fp.read()
1057 content = re.sub('<title>.*</title>', '', content)
1058 content = re.sub('xlink:title="[^"]*"', '', content)
1059 with open(svg, 'w') as fp:
1060 fp.write(content)
1061
1062 print 'Created website - root is ' + join(unified, 'index.html')
1063 finally: 1127 finally:
1064 os.remove(tmp) 1128 os.remove(tmp)
1129
1130 # Post-process generated SVG to remove title elements which most browsers
1131 # render as redundant (and annoying) tooltips.
1132 with open(svg, 'r') as fp:
1133 content = fp.read()
1134 content = re.sub('<title>.*</title>', '', content)
1135 content = re.sub('xlink:title="[^"]*"', '', content)
1136 with open(svg, 'w') as fp:
1137 fp.write(content)
1138
1139 # Post-process generated overview-summary.html files
1140 top = join(args.base, 'all', 'overview-summary.html')
1141 for root, _, files in os.walk(args.base):
1142 for f in files:
1143 if f == 'overview-summary.html':
1144 path = join(root, f)
1145 topLink = ''
1146 if top != path:
1147 link = os.path.relpath(join(args.base, 'all', 'index.html'), dirname(path))
1148 topLink = '<p><a href="' + link + '", target="_top">[return to the unified Graal javadoc]</a></p>'
1149 _fix_overview_summary(path, topLink)
1150
1151 print 'Created website - root is ' + join(unified, 'index.html')
1065 1152
1066 def mx_init(): 1153 def mx_init():
1067 _vmbuild = 'product' 1154 _vmbuild = 'product'
1068 commands = { 1155 commands = {
1069 'build': [build, '[-options]'], 1156 'build': [build, '[-options]'],