# 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) { %>
  • <% } %>Required<% if (hasReq) { %>
  • <% } %>   <% - if (hasOpt) { %>
  • <% } %>Optional<% if (hasOpt) { %>
  • <% } %>   <% + if (hasReq) { %>
  • <% } %>Required<% if (hasReq) { %>
  • <% } %>   <% + if (hasOpt) { %>
  • <% } %>Optional<% if (hasOpt) { %>
  • <% } %>   <% } else { - if (visibleNested) { %>
  • <% } %>Nested<% if (visibleNested) { %>
  • <% } %>   <% + if (visibleNested) { %>
  • <% } %>Nested<% if (visibleNested) { %>
  • <% } %>   <% if (classDoc.isEnum()) { - if (hasEnumConstants) { %>
  • <% } %>Enum constants<% if (hasEnumConstants) { %>
  • <% } %>   <% + if (hasEnumConstants) { %>
  • <% } %>Enum constants<% if (hasEnumConstants) { %>
  • <% } %>   <% } - if (hasFields) { %>
  • <% } %>Field<% if (hasFields) { %>
  • <% } %>   <% - if (hasProperties) { %>
  • Property
  • <% } %>   <% + if (hasFields) { %>
  • <% } %>Field<% if (hasFields) { %>
  • <% } %>   <% + if (hasProperties) { %>
  • Property
  • <% } %>   <% if (classDoc.isClass()) { - if (visibleConstructors) { %>
  • <% } %>Constructor<% if (visibleConstructors) { %>
  • <% } %>   <% + if (visibleConstructors) { %>
  • <% } %>Constructor<% if (visibleConstructors) { %>
  • <% } %>   <% } - if (visibleMethods) { %>
  • <% } %>Method<% if (visibleMethods) { %>
  • <% } %>   <% + if (visibleMethods) { %>
  • <% } %>Method<% if (visibleMethods) { %>
  • <% } %>   <% } %> @@ -147,17 +161,17 @@
  •  | Detail: 
  • <% if (classDoc.isAnnotationType()) { - if (hasElements) { %>
  • <% } %>Element<% if (hasElements) { %>
  • <% } %>   <% + if (hasElements) { %>
  • <% } %>Element<% if (hasElements) { %>
  • <% } %>   <% } else { if (classDoc.isEnum()) { - if (hasEnumConstants) { %>
  • <% } %>Enum constants<% if (hasEnumConstants) { %>
  • <% } %>   <% + if (hasEnumConstants) { %>
  • <% } %>Enum constants<% if (hasEnumConstants) { %>
  • <% } %>   <% } - if (hasFields) { %>
  • <% } %>Field<% if (hasFields) { %>
  • <% } %>   <% - if (hasProperties) { %>
  • Property
  • <% } %>   <% + if (hasFields) { %>
  • <% } %>Field<% if (hasFields) { %>
  • <% } %>   <% + if (hasProperties) { %>
  • Property
  • <% } %>   <% if (classDoc.isClass()) { - if (visibleConstructors) { %>
  • <% } %>Constructor<% if (visibleConstructors) { %>
  • <% } %>   <% + if (visibleConstructors) { %>
  • <% } %>Constructor<% if (visibleConstructors) { %>
  • <% } %>   <% } - if (visibleMethods) { %>
  • <% } %>Method<% if (visibleMethods) { %>
  • <% } %>   <% + if (visibleMethods) { %>
  • <% } %>Method<% if (visibleMethods) { %>
  • <% } %>   <% } %> @@ -176,7 +190,9 @@ %>
    Package: ${pkg}
    <%}%> -

    ${classDesc}

    +

    ${classDesc} + <% if (classDoc.superclass()) { %> extends ${linkable(classDoc.superclass())} <% } %> +

    @@ -379,13 +396,19 @@ - - + + + + + <% visibleProperties.eachWithIndex { prop, i -> %> - - + + + + + <% } %>
    Properties 
    TypeName and descriptionNameTypeLabelGroupDescription
    ${modifiersBrief(prop) + linkable(prop.type())} ${prop.name()}
    ${prop.firstSentenceCommentText()}
    ${prop.name()}${modifiersBrief(prop) + linkable(prop.type())}  ${classDoc.getLabel(prop)} ${classDoc.getGroup(prop)} ${prop.firstSentenceCommentText()}
    @@ -488,7 +511,34 @@ if (visibleMethods || buffer.length()>0) { %> diff -r b3282a66cc05 -r e2d02e8742be src/main/resources/org/ssdt_ohio/gradle/userdoc/templates/stylesheet.css --- a/src/main/resources/org/ssdt_ohio/gradle/userdoc/templates/stylesheet.css Mon Jan 11 16:55:32 2016 +0000 +++ b/src/main/resources/org/ssdt_ohio/gradle/userdoc/templates/stylesheet.css Wed Mar 16 23:24:26 2016 +0100 @@ -1,3 +1,21 @@ +/** + * 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. + */ @charset "${props.charset}"; /*! normalize.css v2.1.0 | MIT License | git.io/normalize */ @@ -2159,6 +2177,20 @@ display: inline } +table.overviewSummary tr { + border-left: 1px solid #EEE; + border-right: 1px solid #EEE; +} + +table.overviewSummary tr:first-child { + border-top: 1px solid #EEE; + border-bottom: 1px solid #EEE; +} + +table.overviewSummary tr:last-child { + border-bottom: 1px solid #EEE; +} + table.overviewSummary, .contentContainer ul li table { width: 100%; margin: 20px 0 @@ -2171,22 +2203,23 @@ float: left; padding: 0 10px; margin-top: 10px; - background: #db4800; + background: #6884db; color: white } table.overviewSummary tr th, .contentContainer ul li table tr th { - padding: 10px; + padding: 5px 10px; font-weight: bold; font-size: 1em; - text-align: left + text-align: left; + white-space: nowrap; + background: #f2f2f2 } table.overviewSummary tr td, .contentContainer ul li table tr td { vertical-align: top; font-size: .9em; - padding: 5px 10px; - border-top: 1px solid #EEE + padding: 5px 10px } table.overviewSummary tbody > tr:nth-child(odd) > td, .contentContainer ul li table tbody > tr:nth-child(odd) > td { @@ -2205,7 +2238,7 @@ margin: 0 10px; padding: 3px 10px; margin-top: 10px; - background: #db4800; + background: #6884DB; color: white; line-height: 40px } @@ -2303,4 +2336,4 @@ a span.strong { font-weight: normal -} \ No newline at end of file +}