Mercurial > hg > truffle
comparison mxtool/mx.py @ 15406:ca16edfcecd5
mx: fixed site command by removing brittle post-processing of javadoc output
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Mon, 28 Apr 2014 16:22:58 +0200 |
parents | a9df38ce8fb7 |
children | 7a5c34543493 |
comparison
equal
deleted
inserted
replaced
15405:21204413a6de | 15406:ca16edfcecd5 |
---|---|
3983 if stdDoclet: | 3983 if stdDoclet: |
3984 windowTitle = ['-windowtitle', p.name + ' javadoc'] | 3984 windowTitle = ['-windowtitle', p.name + ' javadoc'] |
3985 try: | 3985 try: |
3986 log('Generating {2} for {0} in {1}'.format(p.name, out, docDir)) | 3986 log('Generating {2} for {0} in {1}'.format(p.name, out, docDir)) |
3987 projectJava = java(p.javaCompliance) | 3987 projectJava = java(p.javaCompliance) |
3988 run([java().javadoc, memory, | 3988 run([projectJava.javadoc, memory, |
3989 '-XDignore.symbol.file', | 3989 '-XDignore.symbol.file', |
3990 '-classpath', cp, | 3990 '-classpath', cp, |
3991 '-quiet', | 3991 '-quiet', |
3992 '-d', out, | 3992 '-d', out, |
3993 '-overview', overviewFile, | 3993 '-overview', overviewFile, |
3994 '-sourcepath', sp, | 3994 '-sourcepath', sp, |
3995 '-source', str(projectJava.javaCompliance), | 3995 '-source', str(projectJava.javaCompliance), |
3996 '-bootclasspath', projectJava.bootclasspath(), | 3996 '-bootclasspath', projectJava.bootclasspath(), |
3997 '-extdirs', projectJava.extdirs()] + | 3997 '-extdirs', projectJava.extdirs()] + |
3998 ([] if java().javaCompliance < JavaCompliance('1.8') else ['-Xdoclint:none']) + | 3998 ([] if projectJava.javaCompliance < JavaCompliance('1.8') else ['-Xdoclint:none']) + |
3999 links + | 3999 links + |
4000 extraArgs + | 4000 extraArgs + |
4001 nowarnAPI + | 4001 nowarnAPI + |
4002 windowTitle + | 4002 windowTitle + |
4003 list(pkgs)) | 4003 list(pkgs)) |
4038 extraArgs + | 4038 extraArgs + |
4039 nowarnAPI + | 4039 nowarnAPI + |
4040 list(pkgs)) | 4040 list(pkgs)) |
4041 log('Generated {2} for {0} in {1}'.format(', '.join(names), out, docDir)) | 4041 log('Generated {2} for {0} in {1}'.format(', '.join(names), out, docDir)) |
4042 | 4042 |
4043 class Chunk: | |
4044 def __init__(self, content, ldelim, rdelim=None): | |
4045 lindex = content.find(ldelim) | |
4046 if rdelim is not None: | |
4047 rindex = content.find(rdelim) | |
4048 else: | |
4049 rindex = lindex + len(ldelim) | |
4050 self.ldelim = ldelim | |
4051 self.rdelim = rdelim | |
4052 if lindex != -1 and rindex != -1 and rindex > lindex: | |
4053 self.text = content[lindex + len(ldelim):rindex] | |
4054 else: | |
4055 self.text = None | |
4056 | |
4057 def replace(self, content, repl): | |
4058 lindex = content.find(self.ldelim) | |
4059 if self.rdelim is not None: | |
4060 rindex = content.find(self.rdelim) | |
4061 rdelimLen = len(self.rdelim) | |
4062 else: | |
4063 rindex = lindex + len(self.ldelim) | |
4064 rdelimLen = 0 | |
4065 old = content[lindex:rindex + rdelimLen] | |
4066 return content.replace(old, repl) | |
4067 | |
4068 # Post-process an overview-summary.html file to move the | |
4069 # complete overview to the top of the page | |
4070 def _fix_overview_summary(path, topLink): | |
4071 """ | |
4072 Processes an "overview-summary.html" generated by javadoc to put the complete | |
4073 summary text above the Packages table. | |
4074 """ | |
4075 | |
4076 # This uses scraping and so will break if the relevant content produced by javadoc changes in any way! | |
4077 with open(path) as fp: | |
4078 content = fp.read() | |
4079 | |
4080 chunk1 = Chunk(content, """<div class="header"> | |
4081 <div class="subTitle"> | |
4082 <div class="block">""", """</div> | |
4083 </div> | |
4084 <p>See: <a href="#overview.description">Description</a></p> | |
4085 </div>""") | |
4086 | |
4087 chunk2 = Chunk(content, """<div class="contentContainer"><a name="overview.description"> | |
4088 <!-- --> | |
4089 </a> | |
4090 <div class="block">""", """</div> | |
4091 </div> | |
4092 <!-- ======= START OF BOTTOM NAVBAR ====== -->""") | |
4093 | |
4094 assert chunk1.text, 'Could not find header section in ' + path | |
4095 assert chunk2.text, 'Could not find footer section in ' + path | |
4096 | |
4097 content = chunk1.replace(content, '<div class="header"><div class="subTitle"><div class="block">' + topLink + chunk2.text + '</div></div></div>') | |
4098 content = chunk2.replace(content, '') | |
4099 | |
4100 with open(path, 'w') as fp: | |
4101 fp.write(content) | |
4102 | |
4103 | |
4104 # Post-process a package-summary.html file to move the | |
4105 # complete package description to the top of the page | |
4106 def _fix_package_summary(path): | |
4107 """ | |
4108 Processes an "overview-summary.html" generated by javadoc to put the complete | |
4109 summary text above the Packages table. | |
4110 """ | |
4111 | |
4112 # This uses scraping and so will break if the relevant content produced by javadoc changes in any way! | |
4113 with open(path) as fp: | |
4114 content = fp.read() | |
4115 | |
4116 chunk1 = Chunk(content, """<div class="header"> | |
4117 <h1 title="Package" class="title">Package""", """<p>See: <a href="#package.description">Description</a></p> | |
4118 </div>""") | |
4119 | |
4120 chunk2 = Chunk(content, """<a name="package.description"> | |
4121 <!-- --> | |
4122 </a>""", """</div> | |
4123 </div> | |
4124 <!-- ======= START OF BOTTOM NAVBAR ====== -->""") | |
4125 | |
4126 if chunk1.text: | |
4127 if chunk2.text: | |
4128 repl = re.sub(r'<h2 title=(.*) Description</h2>', r'<h1 title=\1</h1>', chunk2.text, 1) | |
4129 content = chunk1.replace(content, '<div class="header">' + repl + '</div></div>') | |
4130 content = chunk2.replace(content, '') | |
4131 | |
4132 with open(path, 'w') as fp: | |
4133 fp.write(content) | |
4134 else: | |
4135 log('warning: Could not find package description detail section in ' + path) | |
4136 | |
4137 else: | |
4138 # no package description given | |
4139 pass | |
4140 | |
4141 def site(args): | 4043 def site(args): |
4142 """creates a website containing javadoc and the project dependency graph""" | 4044 """creates a website containing javadoc and the project dependency graph""" |
4143 | 4045 |
4144 parser = ArgumentParser(prog='site') | 4046 parser = ArgumentParser(prog='site') |
4145 parser.add_argument('-d', '--base', action='store', help='directory for generated site', required=True, metavar='<dir>') | 4047 parser.add_argument('-d', '--base', action='store', help='directory for generated site', required=True, metavar='<dir>') |
4048 parser.add_argument('--tmp', action='store', help='directory to use for intermediate results', metavar='<dir>') | |
4146 parser.add_argument('--name', action='store', help='name of overall documentation', required=True, metavar='<name>') | 4049 parser.add_argument('--name', action='store', help='name of overall documentation', required=True, metavar='<name>') |
4147 parser.add_argument('--overview', action='store', help='path to the overview content for overall documentation', required=True, metavar='<path>') | 4050 parser.add_argument('--overview', action='store', help='path to the overview content for overall documentation', required=True, metavar='<path>') |
4148 parser.add_argument('--projects', action='store', help='comma separated projects to process (omit to process all projects)') | 4051 parser.add_argument('--projects', action='store', help='comma separated projects to process (omit to process all projects)') |
4149 parser.add_argument('--jd', action='append', help='extra Javadoc arguments (e.g. --jd @-use)', metavar='@<arg>', default=[]) | 4052 parser.add_argument('--jd', action='append', help='extra Javadoc arguments (e.g. --jd @-use)', metavar='@<arg>', default=[]) |
4150 parser.add_argument('--exclude-packages', action='store', help='comma separated packages to exclude', metavar='<pkgs>') | 4053 parser.add_argument('--exclude-packages', action='store', help='comma separated packages to exclude', metavar='<pkgs>') |
4151 parser.add_argument('--dot-output-base', action='store', help='base file name (relative to <dir>/all) for project dependency graph .svg and .jpg files generated by dot (omit to disable dot generation)', metavar='<path>') | 4054 parser.add_argument('--dot-output-base', action='store', help='base file name (relative to <dir>/all) for project dependency graph .svg and .jpg files generated by dot (omit to disable dot generation)', metavar='<path>') |
4152 parser.add_argument('--title', action='store', help='value used for -windowtitle and -doctitle javadoc args for overall documentation (default: "<name>")', metavar='<title>') | 4055 parser.add_argument('--title', action='store', help='value used for -windowtitle and -doctitle javadoc args for overall documentation (default: "<name>")', metavar='<title>') |
4153 args = parser.parse_args(args) | 4056 args = parser.parse_args(args) |
4154 | 4057 |
4155 args.base = os.path.abspath(args.base) | 4058 args.base = os.path.abspath(args.base) |
4156 tmpbase = tempfile.mkdtemp(prefix=basename(args.base) + '.', dir=dirname(args.base)) | 4059 tmpbase = args.tmp if args.tmp else tempfile.mkdtemp(prefix=basename(args.base) + '.', dir=dirname(args.base)) |
4157 unified = join(tmpbase, 'all') | 4060 unified = join(tmpbase, 'all') |
4158 | 4061 |
4159 exclude_packages_arg = [] | 4062 exclude_packages_arg = [] |
4160 if args.exclude_packages is not None: | 4063 if args.exclude_packages is not None: |
4161 exclude_packages_arg = ['--exclude-packages', args.exclude_packages] | 4064 exclude_packages_arg = ['--exclude-packages', args.exclude_packages] |
4200 javadoc(['--base', tmpbase, | 4103 javadoc(['--base', tmpbase, |
4201 '--unified', | 4104 '--unified', |
4202 '--arg', '@-windowtitle', '--arg', '@' + title, | 4105 '--arg', '@-windowtitle', '--arg', '@' + title, |
4203 '--arg', '@-doctitle', '--arg', '@' + title, | 4106 '--arg', '@-doctitle', '--arg', '@' + title, |
4204 '--arg', '@-overview', '--arg', '@' + args.overview] + exclude_packages_arg + projects_arg + extra_javadoc_args) | 4107 '--arg', '@-overview', '--arg', '@' + args.overview] + exclude_packages_arg + projects_arg + extra_javadoc_args) |
4108 | |
4109 if exists(unified): | |
4110 shutil.rmtree(unified) | |
4205 os.rename(join(tmpbase, 'javadoc'), unified) | 4111 os.rename(join(tmpbase, 'javadoc'), unified) |
4206 | 4112 |
4207 # Generate dependency graph with Graphviz | 4113 # Generate dependency graph with Graphviz |
4208 if args.dot_output_base is not None: | 4114 if args.dot_output_base is not None: |
4209 dotErr = None | 4115 dotErr = None |
4253 | 4159 |
4254 # Create HTML that embeds the svg file in an <object> frame | 4160 # Create HTML that embeds the svg file in an <object> frame |
4255 with open(html, 'w') as fp: | 4161 with open(html, 'w') as fp: |
4256 print >> fp, '<html><body><object data="{}.svg" type="image/svg+xml"></object></body></html>'.format(args.dot_output_base) | 4162 print >> fp, '<html><body><object data="{}.svg" type="image/svg+xml"></object></body></html>'.format(args.dot_output_base) |
4257 | 4163 |
4258 top = join(tmpbase, 'all', 'overview-summary.html') | |
4259 for root, _, files in os.walk(tmpbase): | |
4260 for f in files: | |
4261 if f == 'overview-summary.html': | |
4262 path = join(root, f) | |
4263 topLink = '' | |
4264 if top != path: | |
4265 link = os.path.relpath(join(tmpbase, 'all', 'index.html'), dirname(path)) | |
4266 topLink = '<p><a href="' + link + '", target="_top"><b>[return to the overall ' + args.name + ' documentation]</b></a></p>' | |
4267 _fix_overview_summary(path, topLink) | |
4268 elif f == 'package-summary.html': | |
4269 path = join(root, f) | |
4270 _fix_package_summary(path) | |
4271 | |
4272 | |
4273 if exists(args.base): | 4164 if exists(args.base): |
4274 shutil.rmtree(args.base) | 4165 shutil.rmtree(args.base) |
4275 shutil.move(tmpbase, args.base) | 4166 if args.tmp: |
4167 shutil.copytree(tmpbase, args.base) | |
4168 else: | |
4169 shutil.move(tmpbase, args.base) | |
4276 | 4170 |
4277 print 'Created website - root is ' + join(args.base, 'all', 'index.html') | 4171 print 'Created website - root is ' + join(args.base, 'all', 'index.html') |
4278 | 4172 |
4279 finally: | 4173 finally: |
4280 if exists(tmpbase): | 4174 if not args.tmp and exists(tmpbase): |
4281 shutil.rmtree(tmpbase) | 4175 shutil.rmtree(tmpbase) |
4282 | 4176 |
4283 def _kwArg(kwargs): | 4177 def _kwArg(kwargs): |
4284 if len(kwargs) > 0: | 4178 if len(kwargs) > 0: |
4285 return kwargs.pop(0) | 4179 return kwargs.pop(0) |