Repository: zest-java Updated Branches: refs/heads/develop 274ae43a0 -> a944b2f79
ZEST-108 Fix asciidoc filters setup Project: http://git-wip-us.apache.org/repos/asf/zest-java/repo Commit: http://git-wip-us.apache.org/repos/asf/zest-java/commit/a944b2f7 Tree: http://git-wip-us.apache.org/repos/asf/zest-java/tree/a944b2f7 Diff: http://git-wip-us.apache.org/repos/asf/zest-java/diff/a944b2f7 Branch: refs/heads/develop Commit: a944b2f79986c0c1c74ce75987012a258d7e652d Parents: 274ae43 Author: Paul Merlin (Apache) <[email protected]> Authored: Sun Aug 2 12:07:51 2015 +0200 Committer: Paul Merlin (Apache) <[email protected]> Committed: Sun Aug 2 12:07:51 2015 +0200 ---------------------------------------------------------------------- .../asciidoc/filters/devstatus/devstatus.conf | 27 +++++ .../src/asciidoc/filters/devstatus/devstatus.py | 89 +++++++++++++++ .../src/asciidoc/filters/snippet/snippet.conf | 27 +++++ .../src/asciidoc/filters/snippet/snippet.py | 109 +++++++++++++++++++ buildSrc/src/bin/devstatus.conf | 27 ----- buildSrc/src/bin/devstatus.py | 89 --------------- buildSrc/src/bin/snippet.conf | 27 ----- buildSrc/src/bin/snippet.py | 109 ------------------- .../zest/gradle/plugin/Documentation.groovy | 49 +++++---- 9 files changed, 281 insertions(+), 272 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/zest-java/blob/a944b2f7/buildSrc/src/asciidoc/filters/devstatus/devstatus.conf ---------------------------------------------------------------------- diff --git a/buildSrc/src/asciidoc/filters/devstatus/devstatus.conf b/buildSrc/src/asciidoc/filters/devstatus/devstatus.conf new file mode 100644 index 0000000..1ab3f7b --- /dev/null +++ b/buildSrc/src/asciidoc/filters/devstatus/devstatus.conf @@ -0,0 +1,27 @@ +# 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. + +# +# AsciiDoc Snippet filter configuration file. +# + +[devstatus-filter-style] +devstatus-style=template="devstatus-block",posattrs=("style"),filter='devstatus.py' + +[blockdef-listing] +template::[devstatus-filter-style] + +[devstatus-block] +<comment/> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-java/blob/a944b2f7/buildSrc/src/asciidoc/filters/devstatus/devstatus.py ---------------------------------------------------------------------- diff --git a/buildSrc/src/asciidoc/filters/devstatus/devstatus.py b/buildSrc/src/asciidoc/filters/devstatus/devstatus.py new file mode 100755 index 0000000..81bbc04 --- /dev/null +++ b/buildSrc/src/asciidoc/filters/devstatus/devstatus.py @@ -0,0 +1,89 @@ +#!/usr/bin/env python +# -*- mode: Python; coding: utf-8 -*- +# 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. +""" +source=ignored +tag=self-test +""" + +import sys +import xml.dom.minidom + +PATH_PATTERN="%(source)s" +NS="http://zest.apache.org/schemas/2008/dev-status/1" + +def configuration(indata): + config = {} + for line in indata: + line = line.strip() + if not line: continue + try: + key, value = line.split('=',1) + except: + raise ValueError('invalid config line: "%s"' % (line,)) + config[key] = value + return config + +def devstatus(source=None, **other): + for key in other: + sys.stderr.write("WARNING: unknown config key: '%s'\n" % key) + if not source: raise ValueError("'source' must be specified") + + tablength = ' ' + sourceFile = open(PATH_PATTERN % locals()) + xmlDoc = xml.dom.minidom.parse(sourceFile) + mindent = 1<<32 # a large number - no indentation is this long + + try: + docs = xmlDoc.getElementsByTagNameNS(NS, "documentation")[0].childNodes[0].nodeValue + code = xmlDoc.getElementsByTagNameNS(NS, "codebase")[0].childNodes[0].nodeValue + tests = xmlDoc.getElementsByTagNameNS(NS, "unittests")[0].childNodes[0].nodeValue + buff = [] + + buff.append( "<para role=\"devstatus-code-"+code+"\">") + buff.append( "code") + buff.append( "</para>\n") + + buff.append( "<para role=\"devstatus-docs-"+docs+"\">") + buff.append( "docs") + buff.append( "</para>\n") + + buff.append( "<para role=\"devstatus-tests-"+tests+"\">") + buff.append( "tests") + buff.append( "</para>\n") + + finally: + sourceFile.close() + + for line in buff: + if line: + yield line + else: + yield '\n' + + +if __name__ == '__main__': + import traceback + indata = sys.stdin + if len(sys.argv) == 2 and sys.argv[1] == '--self-test': + PATH_PATTERN = __file__ + indata = __doc__.split('\n') + try: + for line in devstatus(**configuration(indata)): + sys.stdout.write(line) + except: + traceback.print_exc(file=sys.stdout) + raise http://git-wip-us.apache.org/repos/asf/zest-java/blob/a944b2f7/buildSrc/src/asciidoc/filters/snippet/snippet.conf ---------------------------------------------------------------------- diff --git a/buildSrc/src/asciidoc/filters/snippet/snippet.conf b/buildSrc/src/asciidoc/filters/snippet/snippet.conf new file mode 100644 index 0000000..e0ba039 --- /dev/null +++ b/buildSrc/src/asciidoc/filters/snippet/snippet.conf @@ -0,0 +1,27 @@ +# 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. + +# +# AsciiDoc Snippet filter configuration file. +# + +[snippet-filter-style] +snippet-style=template="snippet-block",posattrs=("style","language"),filter='snippet.py' + +[blockdef-listing] +template::[snippet-filter-style] + +[snippet-block] +template::[source-highlight-block] \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-java/blob/a944b2f7/buildSrc/src/asciidoc/filters/snippet/snippet.py ---------------------------------------------------------------------- diff --git a/buildSrc/src/asciidoc/filters/snippet/snippet.py b/buildSrc/src/asciidoc/filters/snippet/snippet.py new file mode 100755 index 0000000..9cb0bfb --- /dev/null +++ b/buildSrc/src/asciidoc/filters/snippet/snippet.py @@ -0,0 +1,109 @@ +#!/usr/bin/env python +# -*- mode: Python; coding: utf-8 -*- +# 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. +""" +source=ignored +tag=self-test +""" + +import sys + +PATH_PATTERN="%(source)s" + +def configuration(indata): + config = {} + for line in indata: + line = line.strip() + if not line: continue + try: + key, value = line.split('=',1) + except: + raise ValueError('invalid config line: "%s"' % (line,)) + config[key] = value + return config + +def snippet(source=None, tag=None, tablength="4", snipMarker=" [...snip...]\n\n", **other): + for key in other: + sys.stderr.write("WARNING: unknown config key: '%s'\n" % key) + if not tag: raise ValueError("'tag' must be specified") + if not source: raise ValueError("'source' must be specified") + try: + tablength = ' ' * int(tablength) + except: + raise ValueError("'tablength' must be specified as an integer") + + START = "START SNIPPET: %s" % tag + END = "END SNIPPET: %s" % tag + + sourceFile = open(PATH_PATTERN % locals()) + + try: + # START SNIPPET: self-test + buff = [] + mindent = 1<<32 # a large number - no indentation is this long + emit = False + emitted = False + + for line in sourceFile: + if END in line: emit = False + if emit: + emitted = True + if not "SNIPPET" in line: + line = line.replace(']]>',']]>]]><![CDATA[') + meat = line.lstrip() + if meat: + indent = line[:-len(meat)].replace('\t', tablength) + mindent = min(mindent, len(indent)) + buff.append(indent + meat) + else: + buff.append('') + if START in line: + if emitted: + buff.append(indent + snipMarker) + emit = True + # END SNIPPET: self-test + + finally: + sourceFile.close() + + if not buff: + raise ValueError('Missing snippet for tag "' + tag + '" in file "' + source + '".') + for line in buff: + if line: + yield line[mindent:] + else: + yield '\n' + + +if __name__ == '__main__': + import traceback + indata = sys.stdin + if len(sys.argv) == 2 and sys.argv[1] == '--self-test': + PATH_PATTERN = __file__ + indata = __doc__.split('\n') + try: + # START SNIPPET: self-test + sys.stdout.write("<![CDATA[") + for line in snippet(**configuration(indata)): + sys.stdout.write(line) + # END SNIPPET: self-test + except: + traceback.print_exc(file=sys.stdout) + raise + finally: + # START SNIPPET: self-test + sys.stdout.write("]]>") + # END SNIPPET: self-test http://git-wip-us.apache.org/repos/asf/zest-java/blob/a944b2f7/buildSrc/src/bin/devstatus.conf ---------------------------------------------------------------------- diff --git a/buildSrc/src/bin/devstatus.conf b/buildSrc/src/bin/devstatus.conf deleted file mode 100644 index 1ab3f7b..0000000 --- a/buildSrc/src/bin/devstatus.conf +++ /dev/null @@ -1,27 +0,0 @@ -# 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. - -# -# AsciiDoc Snippet filter configuration file. -# - -[devstatus-filter-style] -devstatus-style=template="devstatus-block",posattrs=("style"),filter='devstatus.py' - -[blockdef-listing] -template::[devstatus-filter-style] - -[devstatus-block] -<comment/> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-java/blob/a944b2f7/buildSrc/src/bin/devstatus.py ---------------------------------------------------------------------- diff --git a/buildSrc/src/bin/devstatus.py b/buildSrc/src/bin/devstatus.py deleted file mode 100755 index 81bbc04..0000000 --- a/buildSrc/src/bin/devstatus.py +++ /dev/null @@ -1,89 +0,0 @@ -#!/usr/bin/env python -# -*- mode: Python; coding: utf-8 -*- -# 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. -""" -source=ignored -tag=self-test -""" - -import sys -import xml.dom.minidom - -PATH_PATTERN="%(source)s" -NS="http://zest.apache.org/schemas/2008/dev-status/1" - -def configuration(indata): - config = {} - for line in indata: - line = line.strip() - if not line: continue - try: - key, value = line.split('=',1) - except: - raise ValueError('invalid config line: "%s"' % (line,)) - config[key] = value - return config - -def devstatus(source=None, **other): - for key in other: - sys.stderr.write("WARNING: unknown config key: '%s'\n" % key) - if not source: raise ValueError("'source' must be specified") - - tablength = ' ' - sourceFile = open(PATH_PATTERN % locals()) - xmlDoc = xml.dom.minidom.parse(sourceFile) - mindent = 1<<32 # a large number - no indentation is this long - - try: - docs = xmlDoc.getElementsByTagNameNS(NS, "documentation")[0].childNodes[0].nodeValue - code = xmlDoc.getElementsByTagNameNS(NS, "codebase")[0].childNodes[0].nodeValue - tests = xmlDoc.getElementsByTagNameNS(NS, "unittests")[0].childNodes[0].nodeValue - buff = [] - - buff.append( "<para role=\"devstatus-code-"+code+"\">") - buff.append( "code") - buff.append( "</para>\n") - - buff.append( "<para role=\"devstatus-docs-"+docs+"\">") - buff.append( "docs") - buff.append( "</para>\n") - - buff.append( "<para role=\"devstatus-tests-"+tests+"\">") - buff.append( "tests") - buff.append( "</para>\n") - - finally: - sourceFile.close() - - for line in buff: - if line: - yield line - else: - yield '\n' - - -if __name__ == '__main__': - import traceback - indata = sys.stdin - if len(sys.argv) == 2 and sys.argv[1] == '--self-test': - PATH_PATTERN = __file__ - indata = __doc__.split('\n') - try: - for line in devstatus(**configuration(indata)): - sys.stdout.write(line) - except: - traceback.print_exc(file=sys.stdout) - raise http://git-wip-us.apache.org/repos/asf/zest-java/blob/a944b2f7/buildSrc/src/bin/snippet.conf ---------------------------------------------------------------------- diff --git a/buildSrc/src/bin/snippet.conf b/buildSrc/src/bin/snippet.conf deleted file mode 100644 index e0ba039..0000000 --- a/buildSrc/src/bin/snippet.conf +++ /dev/null @@ -1,27 +0,0 @@ -# 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. - -# -# AsciiDoc Snippet filter configuration file. -# - -[snippet-filter-style] -snippet-style=template="snippet-block",posattrs=("style","language"),filter='snippet.py' - -[blockdef-listing] -template::[snippet-filter-style] - -[snippet-block] -template::[source-highlight-block] \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-java/blob/a944b2f7/buildSrc/src/bin/snippet.py ---------------------------------------------------------------------- diff --git a/buildSrc/src/bin/snippet.py b/buildSrc/src/bin/snippet.py deleted file mode 100755 index 9cb0bfb..0000000 --- a/buildSrc/src/bin/snippet.py +++ /dev/null @@ -1,109 +0,0 @@ -#!/usr/bin/env python -# -*- mode: Python; coding: utf-8 -*- -# 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. -""" -source=ignored -tag=self-test -""" - -import sys - -PATH_PATTERN="%(source)s" - -def configuration(indata): - config = {} - for line in indata: - line = line.strip() - if not line: continue - try: - key, value = line.split('=',1) - except: - raise ValueError('invalid config line: "%s"' % (line,)) - config[key] = value - return config - -def snippet(source=None, tag=None, tablength="4", snipMarker=" [...snip...]\n\n", **other): - for key in other: - sys.stderr.write("WARNING: unknown config key: '%s'\n" % key) - if not tag: raise ValueError("'tag' must be specified") - if not source: raise ValueError("'source' must be specified") - try: - tablength = ' ' * int(tablength) - except: - raise ValueError("'tablength' must be specified as an integer") - - START = "START SNIPPET: %s" % tag - END = "END SNIPPET: %s" % tag - - sourceFile = open(PATH_PATTERN % locals()) - - try: - # START SNIPPET: self-test - buff = [] - mindent = 1<<32 # a large number - no indentation is this long - emit = False - emitted = False - - for line in sourceFile: - if END in line: emit = False - if emit: - emitted = True - if not "SNIPPET" in line: - line = line.replace(']]>',']]>]]><![CDATA[') - meat = line.lstrip() - if meat: - indent = line[:-len(meat)].replace('\t', tablength) - mindent = min(mindent, len(indent)) - buff.append(indent + meat) - else: - buff.append('') - if START in line: - if emitted: - buff.append(indent + snipMarker) - emit = True - # END SNIPPET: self-test - - finally: - sourceFile.close() - - if not buff: - raise ValueError('Missing snippet for tag "' + tag + '" in file "' + source + '".') - for line in buff: - if line: - yield line[mindent:] - else: - yield '\n' - - -if __name__ == '__main__': - import traceback - indata = sys.stdin - if len(sys.argv) == 2 and sys.argv[1] == '--self-test': - PATH_PATTERN = __file__ - indata = __doc__.split('\n') - try: - # START SNIPPET: self-test - sys.stdout.write("<![CDATA[") - for line in snippet(**configuration(indata)): - sys.stdout.write(line) - # END SNIPPET: self-test - except: - traceback.print_exc(file=sys.stdout) - raise - finally: - # START SNIPPET: self-test - sys.stdout.write("]]>") - # END SNIPPET: self-test http://git-wip-us.apache.org/repos/asf/zest-java/blob/a944b2f7/buildSrc/src/main/groovy/org/apache/zest/gradle/plugin/Documentation.groovy ---------------------------------------------------------------------- diff --git a/buildSrc/src/main/groovy/org/apache/zest/gradle/plugin/Documentation.groovy b/buildSrc/src/main/groovy/org/apache/zest/gradle/plugin/Documentation.groovy index 3c06602..04d9d47 100644 --- a/buildSrc/src/main/groovy/org/apache/zest/gradle/plugin/Documentation.groovy +++ b/buildSrc/src/main/groovy/org/apache/zest/gradle/plugin/Documentation.groovy @@ -65,31 +65,40 @@ class Documentation extends DefaultTask def void installAsciidocFilters() { + def digester = java.security.MessageDigest.getInstance( 'SHA' ) + def filtersDir = project.rootProject.file( 'buildSrc/src/asciidoc/filters' ) def userHome = new File( System.getProperty( 'user.home' ) ) - def snippetDir = new File( userHome, '.asciidoc/filters/snippet' ).absoluteFile - if( !snippetDir.exists() ) - { - println "Installing [snippet] into $snippetDir" - snippetDir.mkdirs() - project.copy { - from "${project.rootDir}/buildSrc/src/bin" - into snippetDir - include 'snippet.*' + def dotAsciidocFiltersDir = new File( userHome, '.asciidoc/filters' ) + def installSnippets = false + filtersDir.eachFileRecurse( groovy.io.FileType.FILES ) { originalFile -> + def targetFile = new File( dotAsciidocFiltersDir, (originalFile.toURI() as String) - (filtersDir.toURI() as String) ) + if( !targetFile.exists() ) + { + installSnippets = true + } + else + { + def originalDigest = digester.digest( originalFile.bytes ) + def targetDigest = digester.digest( targetFile.bytes ) + if( originalDigest != targetDigest ) + { + installSnippets = true + } } - ant.chmod( dir: snippetDir, perm: '755', includes: 'snippet.py' ) } - - def devstatusDir = new File( userHome, '.asciidoc/filters/devstatus' ).absoluteFile - if( !devstatusDir.exists() ) + if( installSnippets ) { - println "Installing [devstatus] into $devstatusDir" - snippetDir.mkdirs() - project.copy { - from "${project.rootDir}/buildSrc/src/bin" - into devstatusDir - include 'devstatus.*' + dotAsciidocFiltersDir.mkdirs() + project.rootProject.copy { + from filtersDir + into dotAsciidocFiltersDir + } + dotAsciidocFiltersDir.eachFileRecurse( groovy.io.FileType.FILES ) { file -> + if( file.name.endsWith( '.py' ) ) { + ant.chmod( file: file.absolutePath, perm: '755' ) + } } - ant.chmod( dir: devstatusDir, perm: '755', includes: 'devstatus.py' ) + println "Zest Asciidoc Filters Installed!" } }
