# HG changeset patch # User smith@nwoca.org # Date 1458167066 -3600 # Node ID e2d02e8742be29a2085e9e18288a9b14ae56132a # Parent b3282a66cc055b06d471f11fdac71cb1b420e6c8 usasr-1307: for render tables for properties and reportable properties with label and group names diff -r b3282a66cc05 -r e2d02e8742be build.gradle --- a/build.gradle Mon Jan 11 16:55:32 2016 +0000 +++ b/build.gradle Wed Mar 16 23:24:26 2016 +0100 @@ -17,6 +17,9 @@ dependencies { compile localGroovy() compile gradleApi() + compile "org.asciidoctor:asciidoctorj:1.5.4" + compile 'org.apache.commons:commons-lang3:3.4' + testCompile 'junit:junit:4.10' } diff -r b3282a66cc05 -r e2d02e8742be gradle.properties --- a/gradle.properties Mon Jan 11 16:55:32 2016 +0000 +++ b/gradle.properties Wed Mar 16 23:24:26 2016 +0100 @@ -1,2 +1,2 @@ -version=0.4.1.SNAPSHOT +version=0.4.2.SNAPSHOT group=org.ssdt_ohio diff -r b3282a66cc05 -r e2d02e8742be src/main/groovy/org/ssdt_ohio/gradle/doc/tools/UserClassDocProxy.groovy --- a/src/main/groovy/org/ssdt_ohio/gradle/doc/tools/UserClassDocProxy.groovy Mon Jan 11 16:55:32 2016 +0000 +++ b/src/main/groovy/org/ssdt_ohio/gradle/doc/tools/UserClassDocProxy.groovy Wed Mar 16 23:24:26 2016 +0100 @@ -7,11 +7,16 @@ package org.ssdt_ohio.gradle.doc.tools import org.codehaus.groovy.groovydoc.GroovyFieldDoc +import org.codehaus.groovy.groovydoc.GroovyProgramElementDoc + +import static org.apache.commons.lang3.StringUtils.splitByCharacterTypeCamelCase class UserClassDocProxy extends groovy.util.Proxy { + private static LABEL_PATTERN = ~/.*label = '([\w\s]*)'.*/ + private static GROUP_PATTERN = ~/.*group = '([\w\s]*)'.*/ + GroovyFieldDoc[] properties() { - println "getting properties for $adaptee" getAdaptee().properties().findAll { GroovyFieldDoc p -> !p.isTransient() && p.name() != 'version' && @@ -22,4 +27,42 @@ def propertyMissing(String name) { getAdaptee()."$name" } + def getLabel(GroovyProgramElementDoc p) { + def result + def d = p.annotations().find { + it.name() == 'Display' + } + if (d) { + def m = LABEL_PATTERN.matcher(d.description()) + if (m.matches()) { + result = m.group(1) + } + } + + return result ?: labelFromCamelCase(p.name() - "get") + + } + + def getGroup(GroovyProgramElementDoc p) { + def result + def d = p.annotations().find { + it.name() == 'Display' + } + if (d) { + def m = GROUP_PATTERN.matcher(d.description()) + if (m.matches()) { + result = m.group(1) + } + } + + return labelFromCamelCase(result) ?: '' + + } + + + static String labelFromCamelCase(String s) { + splitByCharacterTypeCamelCase(s).collect { it.trim() }.findAll { it }.join(' ').capitalize() + + } + } diff -r b3282a66cc05 -r e2d02e8742be src/main/groovy/org/ssdt_ohio/gradle/tasks/UserDoc.groovy --- a/src/main/groovy/org/ssdt_ohio/gradle/tasks/UserDoc.groovy Mon Jan 11 16:55:32 2016 +0000 +++ b/src/main/groovy/org/ssdt_ohio/gradle/tasks/UserDoc.groovy Wed Mar 16 23:24:26 2016 +0100 @@ -75,7 +75,9 @@ // properties.setProperty("charset", charset != null ? charset : ""); // properties.setProperty("fileEncoding", fileEncoding != null ? fileEncoding : ""); - properties.put('userdocHelper',new UserDocHelper()) +// properties.put('doctor',Asciidoctor.Factory.create()) + + properties.put('userdocHelper', new UserDocHelper()) def tool = new GroovyDocTool(new ClasspathResourceManager(this.getClass().getClassLoader()), [tmpDir.getPath()] as String[], diff -r b3282a66cc05 -r e2d02e8742be src/main/resources/org/ssdt_ohio/gradle/userdoc/templates/classDocName.html --- a/src/main/resources/org/ssdt_ohio/gradle/userdoc/templates/classDocName.html Mon Jan 11 16:55:32 2016 +0000 +++ b/src/main/resources/org/ssdt_ohio/gradle/userdoc/templates/classDocName.html Wed Mar 16 23:24:26 2016 +0100 @@ -1,9 +1,23 @@ + + 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. + +--> @@ -11,15 +25,17 @@ <% - println "Generating for $classDoc (${classDoc.class})" classDoc = props.get('userdocHelper').wrap(classDoc) def title = classDoc.name() + (props.docTitle ? " (${props.docTitle})" : "") def isVisible = { it.isPublic() || (it.isProtected() && props.protectedScope == 'true') || (!it.isProtected() && !it.isPrivate() && props.packageScope == 'true') || props.privateScope == 'true' } def isVisibleExt = { t -> java.lang.reflect.Modifier.isPublic(t.modifiers) || java.lang.reflect.Modifier.isProtected(t.modifiers) } def visibleFields = classDoc.fields().findAll(isVisible) - def visibleProperties = classDoc.properties() // props visible be defn + def visibleProperties = classDoc.properties() // props visible be def def visibleMethods = classDoc.methods().findAll(isVisible) + def getterMethods = visibleMethods.findAll { it.name().startsWith('get') } + def nonGetterMethods = visibleMethods - getterMethods + def visibleConstructors = classDoc.constructors().findAll(isVisible) def visibleNested = classDoc.innerClasses().findAll(isVisible) boolean hasFields = !classDoc.isAnnotationType() && visibleFields @@ -31,7 +47,7 @@ def dolink = { t, boolean b -> boolean isArray = false if (!t || t instanceof String) { - return (classDoc.getDocUrl(t, b) -'java.util.' - 'java.lang.') + return classDoc.getDocUrl(t, b) } if (t instanceof org.codehaus.groovy.tools.groovydoc.ArrayClassDocWrapper) { t = t.delegate @@ -39,12 +55,13 @@ } if (t instanceof org.codehaus.groovy.tools.groovydoc.SimpleGroovyClassDoc) { if (t.fullPathName == 'def') return classDoc.getDocUrl("java.lang.Object def", b) - return "" + ( (b ? t.qualifiedTypeName() : t.name() ) - "java.lang." - "java.util." ) + "" + (isArray ? "[]" : "") + if (!t.qualifiedTypeName().contains("<") && t.name().size() > 1) + return "" + (b ? t.qualifiedTypeName() : t.name()) + "" + (isArray ? "[]" : "") } - return ( classDoc.getDocUrl(t.qualifiedTypeName(), b) - 'java.util.' - 'java.lang.' ) + (isArray ? "[]" : "") + return classDoc.getDocUrl(t.qualifiedTypeName(), b) + (isArray ? "[]" : "") } - def linkfull = { t -> dolink(t, true) } - def linkable = { t -> dolink(t, false) } + def linkfull = { t -> dolink(t, true) - "java.lang." - "java.util." } + def linkable = { t -> dolink(t, false) - "java.lang." - "java.util." } def modifiersWithIgnore = { t, boolean ignorePublic -> (t.isPrivate()?"private ":"") + (t.isPublic() && !ignorePublic?"public ":"") + @@ -60,22 +77,19 @@ (t.isStatic()?"static ":"") } def annotations = { t, sepChar -> - t.annotations() ? t.annotations().collect { -// it.isTypeAvailable() ? '@'+linkable(it.type().name())+(it.description()-('@'+it.type().name())): it.description() - it.description() - }.join(sepChar) + sepChar : '' + t.annotations() ? t.annotations().collect{it.isTypeAvailable()?'@'+linkable(it.type().name())+(it.description()-('@'+it.type().name())):it.description()}.join(sepChar) + sepChar : '' } def elementTypes = [ "required":"true", "optional":"false" ] - def isRequired = { f, v -> - def req = f.constantValueExpression() == null; req.toString() == v - } + def isRequired = { f, v -> def req = f.constantValueExpression() == null; req.toString() == v } def upcase = { n -> n[0].toUpperCase() + n[1..-1] } + def lowcase = { n -> n ? n[0].toLowerCase() + n[1..-1] : "" } def paramsOf = { n, boolean brief -> n.parameters().collect{ param -> (brief?'':annotations(param, ' ')) + linkable(param.isTypeAvailable()?param.type():param.typeName()) + (param.vararg()?'... ':' ') + param.name() + (param.defaultValue() ? " = " + param.defaultValue():"") }.join(", ") } def nameFromParams = { n -> n.name() + '(' + n.parameters().collect{ param -> param.isTypeAvailable()?param.type().qualifiedTypeName():param.typeName() }.join(', ') + ')' } def nameFromJavaParams = { n -> n.name + '(' + n.parameterTypes.collect{ param -> param.name }.join(', ') + ')' } + def asPropertyName = { lowcase(it - 'get') } %>
@@ -127,19 +141,19 @@ if (classDoc.isAnnotationType()) { def hasReq = classDoc.fields().any{ isRequired(it, "true") } def hasOpt = classDoc.fields().any{ isRequired(it, "false") } - if (hasReq) { %>${annotations(classDoc, '\n') + modifiers(classDoc) + classDoc.typeSourceDescription + ' ' + classDoc.name()} -<% if (classDoc.isInterface() && classDoc.interfaces()) { -%>extends ${classDoc.interfaces().collect{ linkable(it) }.join(', ')} -<% } else if (classDoc.superclass()) { -%>extends ${linkable(classDoc.superclass())} ++${ annotations(classDoc, '+
')} +${modifiers(classDoc) + classDoc.typeSourceDescription + ' ' + classDoc.name()} +<% if (classDoc.isInterface() && classDoc.interfaces()) {%>extends ${classDoc.interfaces().collect{ linkable(it) }.join(', ')} +<% } else if (classDoc.superclass()) { %>extends ${linkable(classDoc.superclass())} <% } %><% } %> @@ -232,7 +249,7 @@ <% if (classDoc.commentText()) { %>${classDoc.commentText()}
<% } %> - +
Type | -Name and description | +Name | +Type | +Label | +Group | +Description |
---|---|---|---|---|---|---|
${modifiersBrief(prop) + linkable(prop.type())} |
- ${prop.name()} ${prop.firstSentenceCommentText()} |
+ ${prop.name()} |
+ ${modifiersBrief(prop) + linkable(prop.type())} |
+ ${classDoc.getLabel(prop)} | +${classDoc.getGroup(prop)} | +${prop.firstSentenceCommentText()} |
Name | +Type | +Label | +Group | +Description | +
---|---|---|---|---|
${asPropertyName(method.name())} |
+ ${modifiersBrief(method)}${linkable(method.returnType())} |
+ ${classDoc.getLabel(method)} | +${classDoc.getGroup(method)} | +${method.firstSentenceCommentText()} | +
${modifiersBrief(method)}${linkable(method.returnType())}
${method.name()}(${paramsOf(method, true)})
+${annotations(prop, '\n')}
${prop.commentText()}
+${annotations(method, '\n')}
${method.commentText()}