Pass list of modules to javadoc generator
Previously the generator always uses hardcoded list of modules. This fix replaces hardcoded list with actual set of modules coming from cmake.
This commit is contained in:
parent
c78884c780
commit
5c01d13f38
@ -108,10 +108,10 @@ file(GLOB_RECURSE refman_rst_headers "${CMAKE_CURRENT_SOURCE_DIR}/../*.rst")
|
|||||||
set(java_documented_headers_deps ${handwrittren_java_sources} ${generated_java_sources} ${java_hdr_deps} ${refman_rst_headers}
|
set(java_documented_headers_deps ${handwrittren_java_sources} ${generated_java_sources} ${java_hdr_deps} ${refman_rst_headers}
|
||||||
"${GEN_JAVADOC}" "${RST_PARSER}" "${GEN_JAVA}" "${HDR_PARSER}")
|
"${GEN_JAVADOC}" "${RST_PARSER}" "${GEN_JAVA}" "${HDR_PARSER}")
|
||||||
|
|
||||||
#TODO: pass list of modules
|
string(REPLACE ";" "," OPENCV_JAVA_MODULES_STR "${OPENCV_JAVA_MODULES}")
|
||||||
add_custom_command(
|
add_custom_command(
|
||||||
OUTPUT ${documented_java_files}
|
OUTPUT ${documented_java_files}
|
||||||
COMMAND ${PYTHON_EXECUTABLE} "${GEN_JAVADOC}" "${CMAKE_CURRENT_SOURCE_DIR}/generator/src/java" "${CMAKE_CURRENT_BINARY_DIR}" 2>"${CMAKE_CURRENT_BINARY_DIR}/get_javadoc_errors.log"
|
COMMAND ${PYTHON_EXECUTABLE} "${GEN_JAVADOC}" --modules ${OPENCV_JAVA_MODULES_STR} "${CMAKE_CURRENT_SOURCE_DIR}/generator/src/java" "${CMAKE_CURRENT_BINARY_DIR}" 2>"${CMAKE_CURRENT_BINARY_DIR}/get_javadoc_errors.log"
|
||||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||||
DEPENDS ${java_documented_headers_deps}
|
DEPENDS ${java_documented_headers_deps}
|
||||||
)
|
)
|
||||||
|
@ -1,17 +1,18 @@
|
|||||||
import os, sys, re, string, glob
|
import os, sys, re, string, glob
|
||||||
allmodules = ["core", "flann", "imgproc", "ml", "highgui", "video", "features2d", "calib3d", "objdetect", "legacy", "contrib", "gpu", "androidcamera", "haartraining", "java", "python", "stitching", "traincascade", "ts", "photo", "videostab"]
|
from optparse import OptionParser
|
||||||
verbose = False
|
|
||||||
show_warnings = True
|
|
||||||
show_errors = True
|
|
||||||
|
|
||||||
class JavadocGenerator(object):
|
class JavadocGenerator(object):
|
||||||
def __init__(self, definitions = {}, javadoc_marker = "//javadoc:"):
|
def __init__(self, definitions = {}, modules= [], javadoc_marker = "//javadoc:"):
|
||||||
self.definitions = definitions
|
self.definitions = definitions
|
||||||
self.javadoc_marker = javadoc_marker
|
self.javadoc_marker = javadoc_marker
|
||||||
self.markers_processed = 0
|
self.markers_processed = 0
|
||||||
self.markers_documented = 0
|
self.markers_documented = 0
|
||||||
self.params_documented = 0
|
self.params_documented = 0
|
||||||
self.params_undocumented = 0
|
self.params_undocumented = 0
|
||||||
|
self.known_modules = modules
|
||||||
|
self.verbose = False
|
||||||
|
self.show_warnings = True
|
||||||
|
self.show_errors = True
|
||||||
|
|
||||||
def parceJavadocMarker(self, line):
|
def parceJavadocMarker(self, line):
|
||||||
assert line.lstrip().startswith(self.javadoc_marker)
|
assert line.lstrip().startswith(self.javadoc_marker)
|
||||||
@ -35,7 +36,7 @@ class JavadocGenerator(object):
|
|||||||
inf = open(infile, "rt")
|
inf = open(infile, "rt")
|
||||||
outf = open(outfile, "wt")
|
outf = open(outfile, "wt")
|
||||||
module = os.path.splitext(os.path.basename(infile))[0].split("+")[0]
|
module = os.path.splitext(os.path.basename(infile))[0].split("+")[0]
|
||||||
if module not in allmodules:
|
if module not in self.known_modules:
|
||||||
module = "unknown"
|
module = "unknown"
|
||||||
try:
|
try:
|
||||||
for l in inf.readlines():
|
for l in inf.readlines():
|
||||||
@ -47,14 +48,14 @@ class JavadocGenerator(object):
|
|||||||
decl = self.definitions.get(marker[0],None)
|
decl = self.definitions.get(marker[0],None)
|
||||||
if decl:
|
if decl:
|
||||||
javadoc = self.makeJavadoc(decl, marker[2])
|
javadoc = self.makeJavadoc(decl, marker[2])
|
||||||
if verbose:
|
if self.verbose:
|
||||||
print
|
print
|
||||||
print "Javadoc for \"%s\" File: %s (line %s)" % (decl["name"], decl["file"], decl["line"])
|
print "Javadoc for \"%s\" File: %s (line %s)" % (decl["name"], decl["file"], decl["line"])
|
||||||
print javadoc
|
print javadoc
|
||||||
for line in javadoc.split("\n"):
|
for line in javadoc.split("\n"):
|
||||||
outf.write(marker[1] + line + "\n")
|
outf.write(marker[1] + line + "\n")
|
||||||
self.markers_documented += 1
|
self.markers_documented += 1
|
||||||
elif show_errors:
|
elif self.show_errors:
|
||||||
print >> sys.stderr, "gen_javadoc error: could not find documentation for %s (module: %s)" % (l.lstrip()[len(self.javadoc_marker):-1].strip(), module)
|
print >> sys.stderr, "gen_javadoc error: could not find documentation for %s (module: %s)" % (l.lstrip()[len(self.javadoc_marker):-1].strip(), module)
|
||||||
else:
|
else:
|
||||||
outf.write(org.replace("\t", " ").rstrip()+"\n")
|
outf.write(org.replace("\t", " ").rstrip()+"\n")
|
||||||
@ -176,7 +177,7 @@ class JavadocGenerator(object):
|
|||||||
doc += prefix + self.ReformatForJavadoc(decl["brief"])
|
doc += prefix + self.ReformatForJavadoc(decl["brief"])
|
||||||
prefix = " *\n"
|
prefix = " *\n"
|
||||||
elif "long" not in decl:
|
elif "long" not in decl:
|
||||||
if show_warnings:
|
if self.show_warnings:
|
||||||
print >> sys.stderr, "gen_javadoc warning: no description for " + decl_type + " \"%s\" File: %s (line %s)" % (func["name"], func["file"], func["line"])
|
print >> sys.stderr, "gen_javadoc warning: no description for " + decl_type + " \"%s\" File: %s (line %s)" % (func["name"], func["file"], func["line"])
|
||||||
doc += prefix + self.ReformatForJavadoc("This " + decl_type + " is undocumented")
|
doc += prefix + self.ReformatForJavadoc("This " + decl_type + " is undocumented")
|
||||||
prefix = " *\n"
|
prefix = " *\n"
|
||||||
@ -193,7 +194,7 @@ class JavadocGenerator(object):
|
|||||||
arg_doc = documented_params.get(arg, None)
|
arg_doc = documented_params.get(arg, None)
|
||||||
if not arg_doc:
|
if not arg_doc:
|
||||||
arg_doc = "a " + arg
|
arg_doc = "a " + arg
|
||||||
if show_warnings:
|
if self.show_warnings:
|
||||||
print >> sys.stderr, "gen_javadoc warning: parameter \"%s\" of \"%s\" is undocumented. File: %s (line %s)" % (arg, decl["name"], decl["file"], decl["line"])
|
print >> sys.stderr, "gen_javadoc warning: parameter \"%s\" of \"%s\" is undocumented. File: %s (line %s)" % (arg, decl["name"], decl["file"], decl["line"])
|
||||||
self.params_undocumented += 1
|
self.params_undocumented += 1
|
||||||
else:
|
else:
|
||||||
@ -233,9 +234,6 @@ class JavadocGenerator(object):
|
|||||||
print
|
print
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
if len(sys.argv) < 2:
|
|
||||||
print "Usage:\n", os.path.basename(sys.argv[0]), " <input dir1> [<input dir2> [...]]"
|
|
||||||
exit(0)
|
|
||||||
|
|
||||||
selfpath = os.path.dirname(os.path.abspath(sys.argv[0]))
|
selfpath = os.path.dirname(os.path.abspath(sys.argv[0]))
|
||||||
hdr_parser_path = os.path.join(selfpath, "../../python/src2")
|
hdr_parser_path = os.path.join(selfpath, "../../python/src2")
|
||||||
@ -245,17 +243,34 @@ if __name__ == "__main__":
|
|||||||
import hdr_parser
|
import hdr_parser
|
||||||
import rst_parser
|
import rst_parser
|
||||||
|
|
||||||
|
parser = OptionParser()
|
||||||
|
parser.add_option("-v", "--verbose", dest="verbose", help="Print verbose log to stdout", action="store_true", default=False)
|
||||||
|
parser.add_option("", "--no-warnings", dest="warnings", help="Hide warning messages", action="store_false", default=True)
|
||||||
|
parser.add_option("", "--no-errors", dest="errors", help="Hide error messages", action="store_false", default=True)
|
||||||
|
parser.add_option("", "--modules", dest="modules", help="comma-separated list of modules to generate comments", metavar="MODS", default=",".join(rst_parser.allmodules))
|
||||||
|
|
||||||
|
(options, args) = parser.parse_args(sys.argv)
|
||||||
|
options.modules = options.modules.split(",")
|
||||||
|
|
||||||
|
if len(args) < 2 or len(options.modules) < 1:
|
||||||
|
parser.print_help()
|
||||||
|
exit(0)
|
||||||
|
|
||||||
print "Parsing documentation..."
|
print "Parsing documentation..."
|
||||||
parser = rst_parser.RstParser(hdr_parser.CppHeaderParser())
|
parser = rst_parser.RstParser(hdr_parser.CppHeaderParser())
|
||||||
for m in allmodules:
|
for m in options.modules:
|
||||||
parser.parse(m, os.path.join(selfpath, "../../" + m))
|
parser.parse(m, os.path.join(selfpath, "../../" + m))
|
||||||
|
|
||||||
parser.printSummary()
|
parser.printSummary()
|
||||||
|
|
||||||
print "Generating javadoc comments..."
|
generator = JavadocGenerator(parser.definitions, options.modules)
|
||||||
generator = JavadocGenerator(parser.definitions)
|
generator.verbose = options.verbose
|
||||||
for i in range(1, len(sys.argv)):
|
generator.show_warnings = options.warnings
|
||||||
folder = os.path.abspath(sys.argv[i])
|
generator.show_errors = options.errors
|
||||||
|
|
||||||
|
print "Generating javadoc comments for " + ", ".join(options.modules)
|
||||||
|
for path in args:
|
||||||
|
folder = os.path.abspath(path)
|
||||||
for jfile in [f for f in glob.glob(os.path.join(folder,"*.java")) if not f.endswith("-jdoc.java")]:
|
for jfile in [f for f in glob.glob(os.path.join(folder,"*.java")) if not f.endswith("-jdoc.java")]:
|
||||||
outfile = os.path.abspath(os.path.basename(jfile).replace(".java", "-jdoc.java"))
|
outfile = os.path.abspath(os.path.basename(jfile).replace(".java", "-jdoc.java"))
|
||||||
generator.document(jfile, outfile)
|
generator.document(jfile, outfile)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user