2012-03-22 11:24:44 -04:00
|
|
|
# Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
# contributor license agreements. See the NOTICE file distributed with
|
|
|
|
# this work for additional information regarding copyright ownership.
|
|
|
|
# The ASF licenses this file to You under the Apache License, Version 2.0
|
|
|
|
# (the "License"); you may not use this file except in compliance with
|
|
|
|
# the License. You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
|
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
import re
|
|
|
|
|
|
|
|
reHREF = re.compile('<a.*?>(.*?)</a>', re.IGNORECASE)
|
|
|
|
|
|
|
|
reMarkup = re.compile('<.*?>')
|
2012-08-27 19:23:25 -04:00
|
|
|
reDivBlock = re.compile('<div class="block">(.*?)</div>', re.IGNORECASE)
|
|
|
|
reCaption = re.compile('<caption><span>(.*?)</span>', re.IGNORECASE)
|
2012-08-28 08:36:00 -04:00
|
|
|
reTDLastNested = re.compile('^<td class="colLast"><code><strong><a href="[^>]*\.([^>]*?)\.html" title="class in[^>]*">', re.IGNORECASE)
|
|
|
|
reTDLast = re.compile('^<td class="colLast"><code><strong><a href="[^>]*#([^>]*?)">', re.IGNORECASE)
|
|
|
|
reColOne = re.compile('^<td class="colOne"><code><strong><a href="[^>]*#([^>]*?)">', re.IGNORECASE)
|
2012-03-22 11:24:44 -04:00
|
|
|
|
2012-08-27 23:47:47 -04:00
|
|
|
# the Method detail section at the end
|
|
|
|
reMethodDetail = re.compile('^<h3>Method Detail</h3>$', re.IGNORECASE)
|
2012-08-28 08:36:00 -04:00
|
|
|
reMethodDetailAnchor = re.compile('^(?:</a>)?<a name="([^>]*?)">$', re.IGNORECASE)
|
2012-08-27 23:47:47 -04:00
|
|
|
reMethodOverridden = re.compile('^<dt><strong>(Specified by:|Overrides:)</strong></dt>$', re.IGNORECASE)
|
|
|
|
|
2012-08-28 10:08:01 -04:00
|
|
|
reTag = re.compile("(?i)<(\/?\w+)((\s+\w+(\s*=\s*(?:\".*?\"|'.*?'|[^'\">\s]+))?)+\s*|\s*)\/?>")
|
|
|
|
|
|
|
|
def verifyHTML(s):
|
|
|
|
|
|
|
|
stack = []
|
|
|
|
upto = 0
|
|
|
|
while True:
|
|
|
|
m = reTag.search(s, upto)
|
|
|
|
if m is None:
|
|
|
|
break
|
|
|
|
tag = m.group(1)
|
|
|
|
upto = m.end(0)
|
|
|
|
|
|
|
|
if tag[:1] == '/':
|
|
|
|
justTag = tag[1:]
|
|
|
|
else:
|
|
|
|
justTag = tag
|
|
|
|
|
2012-08-28 14:14:07 -04:00
|
|
|
if justTag.lower() in ('br', 'li', 'p', 'col'):
|
2012-08-28 10:08:01 -04:00
|
|
|
continue
|
|
|
|
|
|
|
|
if tag[:1] == '/':
|
|
|
|
if len(stack) == 0:
|
|
|
|
raise RuntimeError('saw closing "%s" without opening <%s...>' % (m.group(0), tag[1:]))
|
|
|
|
elif stack[-1][0] != tag[1:].lower():
|
|
|
|
raise RuntimeError('closing "%s" does not match opening "%s"' % (m.group(0), stack[-1][1]))
|
|
|
|
stack.pop()
|
|
|
|
else:
|
|
|
|
stack.append((tag.lower(), m.group(0)))
|
|
|
|
|
|
|
|
if len(stack) != 0:
|
|
|
|
raise RuntimeError('"%s" was never closed' % stack[-1][1])
|
|
|
|
|
2012-08-27 19:23:25 -04:00
|
|
|
def cleanHTML(s):
|
|
|
|
s = reMarkup.sub('', s)
|
|
|
|
s = s.replace(' ', ' ')
|
|
|
|
s = s.replace('<', '<')
|
|
|
|
s = s.replace('>', '>')
|
|
|
|
s = s.replace('&', '&')
|
|
|
|
return s.strip()
|
|
|
|
|
2012-08-28 15:03:42 -04:00
|
|
|
reH3 = re.compile('^<h3>(.*?)</h3>', re.IGNORECASE | re.MULTILINE)
|
|
|
|
reH4 = re.compile('^<h4>(.*?)</h4>', re.IGNORECASE | re.MULTILINE)
|
2012-08-28 14:14:07 -04:00
|
|
|
|
|
|
|
def checkClassDetails(fullPath):
|
|
|
|
"""
|
|
|
|
Checks for invalid HTML in the full javadocs under each field/method.
|
|
|
|
"""
|
|
|
|
|
|
|
|
# TODO: only works with java7 generated javadocs now!
|
|
|
|
with open(fullPath, encoding='UTF-8') as f:
|
|
|
|
desc = None
|
|
|
|
cat = None
|
|
|
|
item = None
|
|
|
|
errors = []
|
|
|
|
for line in f.readlines():
|
|
|
|
m = reH3.search(line)
|
|
|
|
if m is not None:
|
|
|
|
if desc is not None:
|
|
|
|
# Have to fake <ul> context because we pulled a fragment out "across" two <ul>s:
|
|
|
|
desc = ''.join(desc)
|
|
|
|
if True or cat == 'Constructor Detail':
|
|
|
|
idx = desc.find('</div>')
|
|
|
|
if idx == -1:
|
|
|
|
# Ctor missing javadocs ... checkClassSummaries catches it
|
|
|
|
desc = None
|
|
|
|
continue
|
|
|
|
desc = desc[:idx+6]
|
|
|
|
else:
|
|
|
|
desc = '<ul>%s</ul>' % ''.join(desc)
|
|
|
|
#print(' VERIFY %s: %s: %s' % (cat, item, desc))
|
|
|
|
try:
|
|
|
|
verifyHTML(desc)
|
|
|
|
except RuntimeError as re:
|
|
|
|
#print(' FAILED: %s' % re)
|
|
|
|
errors.append((cat, item, str(re)))
|
|
|
|
desc = None
|
|
|
|
cat = m.group(1)
|
|
|
|
continue
|
|
|
|
|
|
|
|
m = reH4.search(line)
|
|
|
|
if m is not None:
|
|
|
|
if desc is not None:
|
|
|
|
# Have to fake <ul> context because we pulled a fragment out "across" two <ul>s:
|
|
|
|
desc = '<ul>%s</ul>' % ''.join(desc)
|
|
|
|
#print(' VERIFY %s: %s: %s' % (cat, item, desc))
|
|
|
|
try:
|
|
|
|
verifyHTML(desc)
|
|
|
|
except RuntimeError as re:
|
|
|
|
#print(' FAILED: %s' % re)
|
|
|
|
errors.append((cat, item, str(re)))
|
|
|
|
item = m.group(1)
|
|
|
|
desc = []
|
|
|
|
continue
|
|
|
|
|
|
|
|
if desc is not None:
|
|
|
|
desc.append(line)
|
|
|
|
|
|
|
|
if len(errors) != 0:
|
|
|
|
print()
|
|
|
|
print(fullPath)
|
|
|
|
for cat, item, message in errors:
|
|
|
|
print(' broken details HTML: %s: %s: %s' % (cat, item, message))
|
2012-08-29 09:29:48 -04:00
|
|
|
return True
|
|
|
|
else:
|
|
|
|
return False
|
2012-08-28 14:14:07 -04:00
|
|
|
|
|
|
|
def checkClassSummaries(fullPath):
|
|
|
|
|
2012-08-27 19:23:25 -04:00
|
|
|
# TODO: only works with java7 generated javadocs now!
|
|
|
|
f = open(fullPath, encoding='UTF-8')
|
2012-08-28 10:08:01 -04:00
|
|
|
|
2012-08-27 23:20:37 -04:00
|
|
|
missing = []
|
2012-08-28 10:08:01 -04:00
|
|
|
broken = []
|
2012-08-27 19:23:25 -04:00
|
|
|
inThing = False
|
|
|
|
lastCaption = None
|
|
|
|
lastItem = None
|
|
|
|
|
|
|
|
desc = None
|
2012-08-27 23:47:47 -04:00
|
|
|
|
|
|
|
foundMethodDetail = False
|
|
|
|
lastMethodAnchor = None
|
2012-08-27 19:23:25 -04:00
|
|
|
|
|
|
|
for line in f.readlines():
|
2012-08-27 23:47:47 -04:00
|
|
|
m = reMethodDetail.search(line)
|
|
|
|
if m is not None:
|
|
|
|
foundMethodDetail = True
|
|
|
|
continue
|
|
|
|
|
|
|
|
# prune methods that are just @Overrides of other interface/classes,
|
|
|
|
# they should be specified elsewhere, if they are e.g. jdk or
|
|
|
|
# external classes we cannot inherit their docs anyway
|
|
|
|
if foundMethodDetail:
|
|
|
|
m = reMethodDetailAnchor.search(line)
|
|
|
|
if m is not None:
|
2012-08-28 08:36:00 -04:00
|
|
|
lastMethodAnchor = m.group(1)
|
2012-08-27 23:47:47 -04:00
|
|
|
continue
|
|
|
|
m = reMethodOverridden.search(line)
|
|
|
|
if m is not None and ('Methods', lastMethodAnchor) in missing:
|
|
|
|
#print('removing @overridden method: %s' % lastMethodAnchor)
|
|
|
|
missing.remove(('Methods', lastMethodAnchor))
|
|
|
|
|
2012-08-27 19:23:25 -04:00
|
|
|
m = reCaption.search(line)
|
|
|
|
if m is not None:
|
|
|
|
lastCaption = m.group(1)
|
|
|
|
#print(' caption %s' % lastCaption)
|
2012-08-27 22:53:39 -04:00
|
|
|
m = reTDLastNested.search(line)
|
2012-08-27 19:23:25 -04:00
|
|
|
if m is not None:
|
2012-08-27 22:53:39 -04:00
|
|
|
# nested classes
|
2012-08-27 22:18:58 -04:00
|
|
|
lastItem = m.group(1)
|
2012-08-27 19:23:25 -04:00
|
|
|
#print(' item %s' % lastItem)
|
|
|
|
else:
|
2012-08-27 22:53:39 -04:00
|
|
|
m = reTDLast.search(line)
|
2012-08-27 19:23:25 -04:00
|
|
|
if m is not None:
|
2012-08-27 22:53:39 -04:00
|
|
|
# methods etc
|
2012-08-27 22:32:51 -04:00
|
|
|
lastItem = m.group(1)
|
2012-08-27 22:53:39 -04:00
|
|
|
else:
|
|
|
|
# ctors etc
|
|
|
|
m = reColOne.search(line)
|
|
|
|
if m is not None:
|
|
|
|
lastItem = m.group(1)
|
|
|
|
#print(' item %s' % lastItem)
|
2012-08-27 19:23:25 -04:00
|
|
|
|
|
|
|
lineLower = line.strip().lower()
|
|
|
|
|
|
|
|
if lineLower.find('<tr class="') != -1:
|
|
|
|
inThing = True
|
|
|
|
hasDesc = False
|
|
|
|
continue
|
|
|
|
|
|
|
|
if inThing:
|
|
|
|
if lineLower.find('</tr>') != -1:
|
|
|
|
if not hasDesc:
|
2012-08-27 23:20:37 -04:00
|
|
|
missing.append((lastCaption, lastItem))
|
2012-08-27 19:23:25 -04:00
|
|
|
inThing = False
|
|
|
|
continue
|
|
|
|
else:
|
|
|
|
if line.find('<div class="block">') != -1:
|
|
|
|
desc = []
|
|
|
|
if desc is not None:
|
|
|
|
desc.append(line)
|
|
|
|
if line.find('</div>') != -1:
|
|
|
|
desc = ''.join(desc)
|
2012-08-28 10:08:01 -04:00
|
|
|
|
|
|
|
try:
|
|
|
|
verifyHTML(desc)
|
|
|
|
except RuntimeError as e:
|
|
|
|
broken.append((lastCaption, lastItem, str(e)))
|
|
|
|
#print('FAIL: %s: %s: %s: %s' % (lastCaption, lastItem, e, desc))
|
|
|
|
|
2012-08-27 19:23:25 -04:00
|
|
|
desc = desc.replace('<div class="block">', '')
|
|
|
|
desc = desc.replace('</div>', '')
|
|
|
|
desc = desc.strip()
|
|
|
|
hasDesc = len(desc) > 0
|
2012-08-28 10:08:01 -04:00
|
|
|
|
2012-08-27 19:23:25 -04:00
|
|
|
desc = None
|
|
|
|
f.close()
|
2012-08-28 10:08:01 -04:00
|
|
|
if len(missing) > 0 or len(broken) > 0:
|
2012-08-27 23:20:37 -04:00
|
|
|
print()
|
|
|
|
print(fullPath)
|
|
|
|
for (caption, item) in missing:
|
|
|
|
print(' missing %s: %s' % (caption, item))
|
2012-08-28 10:08:01 -04:00
|
|
|
for (caption, item, why) in broken:
|
|
|
|
print(' broken HTML: %s: %s: %s' % (caption, item, why))
|
2012-08-27 23:20:37 -04:00
|
|
|
return True
|
|
|
|
else:
|
|
|
|
return False
|
2012-08-27 19:23:25 -04:00
|
|
|
|
2012-03-22 11:24:44 -04:00
|
|
|
def checkSummary(fullPath):
|
|
|
|
printed = False
|
2012-07-30 11:31:45 -04:00
|
|
|
f = open(fullPath, encoding='UTF-8')
|
2012-03-22 11:24:44 -04:00
|
|
|
anyMissing = False
|
|
|
|
sawPackage = False
|
|
|
|
desc = []
|
2012-05-01 10:46:20 -04:00
|
|
|
lastHREF = None
|
2012-03-22 11:24:44 -04:00
|
|
|
for line in f.readlines():
|
|
|
|
lineLower = line.strip().lower()
|
|
|
|
if desc is not None:
|
|
|
|
# TODO: also detect missing description in overview-summary
|
|
|
|
if lineLower.startswith('package ') or lineLower.startswith('<h1 title="package" '):
|
|
|
|
sawPackage = True
|
|
|
|
elif sawPackage:
|
|
|
|
if lineLower.startswith('<table ') or lineLower.startswith('<b>see: '):
|
|
|
|
desc = ' '.join(desc)
|
|
|
|
desc = reMarkup.sub(' ', desc)
|
|
|
|
desc = desc.strip()
|
|
|
|
if desc == '':
|
|
|
|
if not printed:
|
2012-07-30 08:49:40 -04:00
|
|
|
print()
|
|
|
|
print(fullPath)
|
2012-03-22 11:24:44 -04:00
|
|
|
printed = True
|
2012-07-30 08:49:40 -04:00
|
|
|
print(' no package description (missing package.html in src?)')
|
2012-03-22 11:24:44 -04:00
|
|
|
anyMissing = True
|
|
|
|
desc = None
|
|
|
|
else:
|
|
|
|
desc.append(lineLower)
|
|
|
|
|
|
|
|
if lineLower in ('<td> </td>', '<td></td>', '<td class="collast"> </td>'):
|
|
|
|
if not printed:
|
2012-07-30 08:49:40 -04:00
|
|
|
print()
|
|
|
|
print(fullPath)
|
2012-03-22 11:24:44 -04:00
|
|
|
printed = True
|
2012-07-30 08:49:40 -04:00
|
|
|
print(' missing: %s' % unescapeHTML(lastHREF))
|
2012-03-22 11:24:44 -04:00
|
|
|
anyMissing = True
|
2012-04-28 11:39:41 -04:00
|
|
|
elif lineLower.find('licensed to the apache software foundation') != -1 or lineLower.find('copyright 2004 the apache software foundation') != -1:
|
|
|
|
if not printed:
|
2012-07-30 08:49:40 -04:00
|
|
|
print()
|
|
|
|
print(fullPath)
|
2012-04-28 11:39:41 -04:00
|
|
|
printed = True
|
2012-07-30 08:49:40 -04:00
|
|
|
print(' license-is-javadoc: %s' % unescapeHTML(lastHREF))
|
2012-04-28 11:39:41 -04:00
|
|
|
anyMissing = True
|
2012-05-01 10:46:20 -04:00
|
|
|
m = reHREF.search(line)
|
|
|
|
if m is not None:
|
|
|
|
lastHREF = m.group(1)
|
2012-03-22 11:24:44 -04:00
|
|
|
if desc is not None and fullPath.find('/overview-summary.html') == -1:
|
|
|
|
raise RuntimeError('BUG: failed to locate description in %s' % fullPath)
|
|
|
|
f.close()
|
|
|
|
return anyMissing
|
|
|
|
|
|
|
|
def unescapeHTML(s):
|
|
|
|
s = s.replace('<', '<')
|
|
|
|
s = s.replace('>', '>')
|
|
|
|
s = s.replace('&', '&')
|
|
|
|
return s
|
|
|
|
|
2012-04-23 16:19:01 -04:00
|
|
|
def checkPackageSummaries(root, level='class'):
|
2012-03-22 11:24:44 -04:00
|
|
|
"""
|
|
|
|
Just checks for blank summary lines in package-summary.html; returns
|
|
|
|
True if there are problems.
|
|
|
|
"""
|
2012-04-23 16:19:01 -04:00
|
|
|
|
2012-09-10 15:00:45 -04:00
|
|
|
if level != 'class' and level != 'package' and level != 'method' and level != 'none':
|
|
|
|
print('unsupported level: %s, must be "class" or "package" or "method" or "none"' % level)
|
2012-04-23 16:19:01 -04:00
|
|
|
sys.exit(1)
|
2012-03-22 11:24:44 -04:00
|
|
|
|
|
|
|
#for dirPath, dirNames, fileNames in os.walk('%s/lucene/build/docs/api' % root):
|
|
|
|
|
|
|
|
if False:
|
|
|
|
os.chdir(root)
|
2012-07-30 08:49:40 -04:00
|
|
|
print()
|
|
|
|
print('Run "ant javadocs" > javadocs.log...')
|
2012-03-22 11:24:44 -04:00
|
|
|
if os.system('ant javadocs > javadocs.log 2>&1'):
|
2012-07-30 08:49:40 -04:00
|
|
|
print(' FAILED')
|
2012-03-22 11:24:44 -04:00
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
anyMissing = False
|
2012-08-28 14:14:07 -04:00
|
|
|
if not os.path.isdir(root):
|
|
|
|
checkClassSummaries(root)
|
|
|
|
checkClassDetails(root)
|
|
|
|
sys.exit(0)
|
|
|
|
|
2012-03-22 11:24:44 -04:00
|
|
|
for dirPath, dirNames, fileNames in os.walk(root):
|
2012-08-27 19:23:25 -04:00
|
|
|
|
2012-03-22 11:24:44 -04:00
|
|
|
if dirPath.find('/all/') != -1:
|
|
|
|
# These are dups (this is a bit risk, eg, root IS this /all/ directory..)
|
|
|
|
continue
|
|
|
|
|
|
|
|
if 'package-summary.html' in fileNames:
|
2012-09-10 15:00:45 -04:00
|
|
|
if (level == 'class' or level == 'method') and checkSummary('%s/package-summary.html' % dirPath):
|
2012-03-22 11:24:44 -04:00
|
|
|
anyMissing = True
|
2012-08-29 09:29:48 -04:00
|
|
|
for fileName in fileNames:
|
|
|
|
fullPath = '%s/%s' % (dirPath, fileName)
|
|
|
|
if not fileName.startswith('package-') and fileName.endswith('.html') and os.path.isfile(fullPath):
|
|
|
|
if level == 'method':
|
2012-08-28 14:14:07 -04:00
|
|
|
if checkClassSummaries(fullPath):
|
|
|
|
anyMissing = True
|
2012-08-29 09:29:48 -04:00
|
|
|
# always look for broken html, regardless of level supplied
|
|
|
|
if checkClassDetails(fullPath):
|
|
|
|
anyMissing = True
|
2012-08-28 14:14:07 -04:00
|
|
|
|
2012-03-22 11:24:44 -04:00
|
|
|
if 'overview-summary.html' in fileNames:
|
2012-09-10 15:00:45 -04:00
|
|
|
if level != 'none' and checkSummary('%s/overview-summary.html' % dirPath):
|
2012-03-22 11:24:44 -04:00
|
|
|
anyMissing = True
|
|
|
|
|
|
|
|
return anyMissing
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2012-04-23 16:19:01 -04:00
|
|
|
if len(sys.argv) < 2 or len(sys.argv) > 3:
|
2012-09-10 15:00:45 -04:00
|
|
|
print('usage: %s <dir> [none|package|class|method]' % sys.argv[0])
|
2012-04-23 16:19:01 -04:00
|
|
|
sys.exit(1)
|
|
|
|
if len(sys.argv) == 2:
|
|
|
|
level = 'class'
|
|
|
|
else:
|
|
|
|
level = sys.argv[2]
|
|
|
|
if checkPackageSummaries(sys.argv[1], level):
|
2012-07-30 08:49:40 -04:00
|
|
|
print()
|
|
|
|
print('Missing javadocs were found!')
|
2012-04-23 16:19:01 -04:00
|
|
|
sys.exit(1)
|
|
|
|
sys.exit(0)
|