# HG changeset patch # User Doug Simon # Date 1398694978 -7200 # Node ID ca16edfcecd5b4ca1cad9ba2402bd24e529da083 # Parent 21204413a6de751f946773d670e463e08824eebe mx: fixed site command by removing brittle post-processing of javadoc output diff -r 21204413a6de -r ca16edfcecd5 mxtool/mx.py --- a/mxtool/mx.py Sun Apr 27 18:03:36 2014 +0200 +++ b/mxtool/mx.py Mon Apr 28 16:22:58 2014 +0200 @@ -3985,7 +3985,7 @@ try: log('Generating {2} for {0} in {1}'.format(p.name, out, docDir)) projectJava = java(p.javaCompliance) - run([java().javadoc, memory, + run([projectJava.javadoc, memory, '-XDignore.symbol.file', '-classpath', cp, '-quiet', @@ -3995,7 +3995,7 @@ '-source', str(projectJava.javaCompliance), '-bootclasspath', projectJava.bootclasspath(), '-extdirs', projectJava.extdirs()] + - ([] if java().javaCompliance < JavaCompliance('1.8') else ['-Xdoclint:none']) + + ([] if projectJava.javaCompliance < JavaCompliance('1.8') else ['-Xdoclint:none']) + links + extraArgs + nowarnAPI + @@ -4040,109 +4040,12 @@ list(pkgs)) log('Generated {2} for {0} in {1}'.format(', '.join(names), out, docDir)) -class Chunk: - def __init__(self, content, ldelim, rdelim=None): - lindex = content.find(ldelim) - if rdelim is not None: - rindex = content.find(rdelim) - else: - rindex = lindex + len(ldelim) - self.ldelim = ldelim - self.rdelim = rdelim - if lindex != -1 and rindex != -1 and rindex > lindex: - self.text = content[lindex + len(ldelim):rindex] - else: - self.text = None - - def replace(self, content, repl): - lindex = content.find(self.ldelim) - if self.rdelim is not None: - rindex = content.find(self.rdelim) - rdelimLen = len(self.rdelim) - else: - rindex = lindex + len(self.ldelim) - rdelimLen = 0 - old = content[lindex:rindex + rdelimLen] - return content.replace(old, repl) - -# Post-process an overview-summary.html file to move the -# complete overview to the top of the page -def _fix_overview_summary(path, topLink): - """ - Processes an "overview-summary.html" generated by javadoc to put the complete - summary text above the Packages table. - """ - - # This uses scraping and so will break if the relevant content produced by javadoc changes in any way! - with open(path) as fp: - content = fp.read() - - chunk1 = Chunk(content, """
-
-
""", """
-
-

See: Description

-
""") - - chunk2 = Chunk(content, """
- - -
""", """
-
-""") - - assert chunk1.text, 'Could not find header section in ' + path - assert chunk2.text, 'Could not find footer section in ' + path - - content = chunk1.replace(content, '
' + topLink + chunk2.text + '
') - content = chunk2.replace(content, '') - - with open(path, 'w') as fp: - fp.write(content) - - -# Post-process a package-summary.html file to move the -# complete package description to the top of the page -def _fix_package_summary(path): - """ - Processes an "overview-summary.html" generated by javadoc to put the complete - summary text above the Packages table. - """ - - # This uses scraping and so will break if the relevant content produced by javadoc changes in any way! - with open(path) as fp: - content = fp.read() - - chunk1 = Chunk(content, """
-

Package""", """

See: Description

-

""") - - chunk2 = Chunk(content, """ - -""", """ - -""") - - if chunk1.text: - if chunk2.text: - repl = re.sub(r'

', r'

', chunk2.text, 1) - content = chunk1.replace(content, '
' + repl + '
') - content = chunk2.replace(content, '') - - with open(path, 'w') as fp: - fp.write(content) - else: - log('warning: Could not find package description detail section in ' + path) - - else: - # no package description given - pass - def site(args): """creates a website containing javadoc and the project dependency graph""" parser = ArgumentParser(prog='site') parser.add_argument('-d', '--base', action='store', help='directory for generated site', required=True, metavar='') + parser.add_argument('--tmp', action='store', help='directory to use for intermediate results', metavar='') parser.add_argument('--name', action='store', help='name of overall documentation', required=True, metavar='') parser.add_argument('--overview', action='store', help='path to the overview content for overall documentation', required=True, metavar='') parser.add_argument('--projects', action='store', help='comma separated projects to process (omit to process all projects)') @@ -4153,7 +4056,7 @@ args = parser.parse_args(args) args.base = os.path.abspath(args.base) - tmpbase = tempfile.mkdtemp(prefix=basename(args.base) + '.', dir=dirname(args.base)) + tmpbase = args.tmp if args.tmp else tempfile.mkdtemp(prefix=basename(args.base) + '.', dir=dirname(args.base)) unified = join(tmpbase, 'all') exclude_packages_arg = [] @@ -4202,6 +4105,9 @@ '--arg', '@-windowtitle', '--arg', '@' + title, '--arg', '@-doctitle', '--arg', '@' + title, '--arg', '@-overview', '--arg', '@' + args.overview] + exclude_packages_arg + projects_arg + extra_javadoc_args) + + if exists(unified): + shutil.rmtree(unified) os.rename(join(tmpbase, 'javadoc'), unified) # Generate dependency graph with Graphviz @@ -4255,29 +4161,17 @@ with open(html, 'w') as fp: print >> fp, ''.format(args.dot_output_base) - top = join(tmpbase, 'all', 'overview-summary.html') - for root, _, files in os.walk(tmpbase): - for f in files: - if f == 'overview-summary.html': - path = join(root, f) - topLink = '' - if top != path: - link = os.path.relpath(join(tmpbase, 'all', 'index.html'), dirname(path)) - topLink = '

[return to the overall ' + args.name + ' documentation]

' - _fix_overview_summary(path, topLink) - elif f == 'package-summary.html': - path = join(root, f) - _fix_package_summary(path) - - if exists(args.base): shutil.rmtree(args.base) - shutil.move(tmpbase, args.base) + if args.tmp: + shutil.copytree(tmpbase, args.base) + else: + shutil.move(tmpbase, args.base) print 'Created website - root is ' + join(args.base, 'all', 'index.html') finally: - if exists(tmpbase): + if not args.tmp and exists(tmpbase): shutil.rmtree(tmpbase) def _kwArg(kwargs):