You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@yetus.apache.org by aw...@apache.org on 2019/04/08 23:35:05 UTC
[yetus] branch master updated: YETUS-759. shelldocs should be added
to yetus-maven-plugin
This is an automated email from the ASF dual-hosted git repository.
aw pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/yetus.git
The following commit(s) were added to refs/heads/master by this push:
new 19060c9 YETUS-759. shelldocs should be added to yetus-maven-plugin
19060c9 is described below
commit 19060c91836be9d2b7397683cb80e96adcda9cf4
Author: Allen Wittenauer <aw...@apache.org>
AuthorDate: Thu Apr 4 18:28:47 2019 -0700
YETUS-759. shelldocs should be added to yetus-maven-plugin
Signed-off-by: Allen Wittenauer <aw...@apache.org>
---
shelldocs/src/main/python/shelldocs/__init__.py | 149 +++++++++++++--------
yetus-maven-plugin/pom.xml | 7 +
.../src/main/assemblies/yetus-maven-plugin.xml | 7 +
.../maven/plugin/shelldocs/ShellDocsMojo.java | 106 +++++++++++++++
.../yetus/maven/plugin/shelldocs/package-info.java | 22 +++
5 files changed, 237 insertions(+), 54 deletions(-)
diff --git a/shelldocs/src/main/python/shelldocs/__init__.py b/shelldocs/src/main/python/shelldocs/__init__.py
index e6c16c2..765fd5e 100755
--- a/shelldocs/src/main/python/shelldocs/__init__.py
+++ b/shelldocs/src/main/python/shelldocs/__init__.py
@@ -21,6 +21,7 @@
import sys
import os
import re
+import errno
from optparse import OptionParser
sys.dont_write_bytecode = True
@@ -305,8 +306,99 @@ def marked_as_ignored(file_path):
return True
return False
+def process_file(filename, skipprnorep):
+ """ stuff all of the functions into an array """
+ allfuncs = []
+ try:
+ with open(filename, "r") as shellcode:
+ # if the file contains a comment containing
+ # only "SHELLDOC-IGNORE" then skip that file
+ if marked_as_ignored(filename):
+ return None
+ funcdef = ShellFunction(filename)
+ linenum = 0
+ for line in shellcode:
+ linenum = linenum + 1
+ if line.startswith('## @description'):
+ funcdef.adddesc(line)
+ elif line.startswith('## @audience'):
+ funcdef.setaudience(line)
+ elif line.startswith('## @stability'):
+ funcdef.setstability(line)
+ elif line.startswith('## @replaceable'):
+ funcdef.setreplace(line)
+ elif line.startswith('## @param'):
+ funcdef.addparam(line)
+ elif line.startswith('## @return'):
+ funcdef.addreturn(line)
+ elif line.startswith('function'):
+ funcdef.setname(line)
+ funcdef.setlinenum(linenum)
+ if skipprnorep and \
+ funcdef.getaudience() == "Private" and \
+ funcdef.getreplace() == "No":
+ pass
+ else:
+ allfuncs.append(funcdef)
+ funcdef = ShellFunction(filename)
+ except IOError, err:
+ print >> sys.stderr, "ERROR: Failed to read from file: %s. Skipping." % err.filename
+ return None
+ return allfuncs
+
+def process_input(inputlist, skipprnorep):
+ """ take the input and loop around it """
+ allfuncs = []
+ for filename in inputlist: #pylint: disable=too-many-nested-blocks
+ if os.path.isdir(filename):
+ for root, dirs, files in os.walk(filename): #pylint: disable=unused-variable
+ for fname in files:
+ if fname.endswith('sh'):
+ newfuncs = process_file(filename=os.path.join(root, fname),
+ skipprnorep=skipprnorep)
+ if newfuncs:
+ allfuncs = allfuncs + newfuncs
+ else:
+ newfuncs = process_file(filename=filename, skipprnorep=skipprnorep)
+ if newfuncs:
+ allfuncs = allfuncs + newfuncs
-def main(): # pylint: disable=too-many-statements, too-many-branches
+ if allfuncs is None:
+ print >> sys.stderr, "ERROR: no functions found."
+ sys.exit(1)
+
+ allfuncs = sorted(allfuncs)
+ return allfuncs
+
+def write_output(filename, functions):
+ """ write the markdown file """
+ try:
+ directory = os.path.dirname(filename)
+ if not os.path.exists(directory):
+ os.makedirs(directory)
+ except OSError as exc:
+ if exc.errno == errno.EEXIST and os.path.isdir(directory):
+ pass
+ else:
+ print "Unable to create output directory %s: %u, %s" % \
+ (directory, exc.errno, exc.message)
+ sys.exit(1)
+
+ with open(filename, "w") as outfile:
+ outfile.write(ASFLICENSE)
+ for line in toc(functions):
+ outfile.write(line)
+ outfile.write("\n------\n\n")
+
+ header = []
+ for funcs in functions:
+ if header != funcs.getinter():
+ header = funcs.getinter()
+ line = "## %s\n" % (funcs.headerbuild())
+ outfile.write(line)
+ outfile.write(funcs.getdocpage())
+
+def main():
'''main entry point'''
parser = OptionParser(
usage="usage: %prog [--skipprnorep] " + "[--output OUTFILE|--lint] " +
@@ -360,45 +452,7 @@ def main(): # pylint: disable=too-many-statements, too-many-branches
parser.error(
"At least one of output file and lint mode needs to be specified")
- allfuncs = []
- try:
- for filename in options.infile:
- with open(filename, "r") as shellcode:
- # if the file contains a comment containing
- # only "SHELLDOC-IGNORE" then skip that file
- if marked_as_ignored(filename):
- continue
- funcdef = ShellFunction(filename)
- linenum = 0
- for line in shellcode:
- linenum = linenum + 1
- if line.startswith('## @description'):
- funcdef.adddesc(line)
- elif line.startswith('## @audience'):
- funcdef.setaudience(line)
- elif line.startswith('## @stability'):
- funcdef.setstability(line)
- elif line.startswith('## @replaceable'):
- funcdef.setreplace(line)
- elif line.startswith('## @param'):
- funcdef.addparam(line)
- elif line.startswith('## @return'):
- funcdef.addreturn(line)
- elif line.startswith('function'):
- funcdef.setname(line)
- funcdef.setlinenum(linenum)
- if options.skipprnorep and \
- funcdef.getaudience() == "Private" and \
- funcdef.getreplace() == "No":
- pass
- else:
- allfuncs.append(funcdef)
- funcdef = ShellFunction(filename)
- except IOError, err:
- print >> sys.stderr, "ERROR: Failed to read from file: %s. Aborting." % err.filename
- sys.exit(1)
-
- allfuncs = sorted(allfuncs)
+ allfuncs = process_input(options.infile, options.skipprnorep)
if options.lint:
for funcs in allfuncs:
@@ -407,20 +461,7 @@ def main(): # pylint: disable=too-many-statements, too-many-branches
print message
if options.outfile is not None:
- with open(options.outfile, "w") as outfile:
- outfile.write(ASFLICENSE)
- for line in toc(allfuncs):
- outfile.write(line)
- outfile.write("\n------\n\n")
-
- header = []
- for funcs in allfuncs:
- if header != funcs.getinter():
- header = funcs.getinter()
- line = "## %s\n" % (funcs.headerbuild())
- outfile.write(line)
- outfile.write(funcs.getdocpage())
-
+ write_output(options.outfile, allfuncs)
if __name__ == "__main__":
main()
diff --git a/yetus-maven-plugin/pom.xml b/yetus-maven-plugin/pom.xml
index 030c0d6..09906ed 100644
--- a/yetus-maven-plugin/pom.xml
+++ b/yetus-maven-plugin/pom.xml
@@ -48,6 +48,7 @@
<groupId>org.apache.yetus</groupId>
<artifactId>audience-annotations</artifactId>
<version>${project.version}</version>
+ <scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
@@ -61,6 +62,12 @@
<version>${project.version}</version>
<classifier>jar-with-dependencies</classifier>
</dependency>
+ <dependency>
+ <groupId>org.apache.yetus</groupId>
+ <artifactId>shelldocs</artifactId>
+ <version>${project.version}</version>
+ <classifier>jar-with-dependencies</classifier>
+ </dependency>
</dependencies>
<build>
diff --git a/yetus-maven-plugin/src/main/assemblies/yetus-maven-plugin.xml b/yetus-maven-plugin/src/main/assemblies/yetus-maven-plugin.xml
index 4e8c748..c829344 100644
--- a/yetus-maven-plugin/src/main/assemblies/yetus-maven-plugin.xml
+++ b/yetus-maven-plugin/src/main/assemblies/yetus-maven-plugin.xml
@@ -33,5 +33,12 @@
<include>**</include>
</includes>
</fileSet>
+ <fileSet>
+ <directory>${project.build.directory}/../../shelldocs/target/dist/apache-yetus-${project.version}</directory>
+ <outputDirectory>.</outputDirectory>
+ <includes>
+ <include>**</include>
+ </includes>
+ </fileSet>
</fileSets>
</assembly>
\ No newline at end of file
diff --git a/yetus-maven-plugin/src/main/java/org/apache/yetus/maven/plugin/shelldocs/ShellDocsMojo.java b/yetus-maven-plugin/src/main/java/org/apache/yetus/maven/plugin/shelldocs/ShellDocsMojo.java
new file mode 100644
index 0000000..05bd59f
--- /dev/null
+++ b/yetus-maven-plugin/src/main/java/org/apache/yetus/maven/plugin/shelldocs/ShellDocsMojo.java
@@ -0,0 +1,106 @@
+/*
+ * Licensed 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.
+ */
+package org.apache.yetus.maven.plugin.shelldocs;
+
+import java.util.ArrayList;
+
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugins.annotations.LifecyclePhase;
+import org.apache.maven.plugins.annotations.Mojo;
+import org.apache.maven.plugins.annotations.Parameter;
+
+import org.apache.yetus.audience.InterfaceAudience;
+import org.apache.yetus.audience.InterfaceStability;
+import org.apache.yetus.shelldocs.ShellDocs;
+
+/**
+ * Goal which executes releasedocmaker.
+ */
+@Mojo(name = "shelldocs",
+ defaultPhase = LifecyclePhase.PRE_SITE,
+ threadSafe = true)
+@InterfaceAudience.Private
+@InterfaceStability.Unstable
+public final class ShellDocsMojo extends AbstractMojo {
+
+ /**
+ * Run in --lint mode.
+ */
+ @Parameter(defaultValue = "false")
+ private Boolean lint;
+
+ /**
+ * Run in --skipprnorep mode.
+ */
+ @Parameter(defaultValue = "false")
+ private Boolean skipprnorep;
+
+ /**
+ * Location of output.
+ */
+ @Parameter(defaultValue = "${project.build.directory}/generated-site/markdown/${project.name}.md")
+ private String output;
+
+ /**
+ * Version to generate.
+ */
+ @Parameter(defaultValue = "${project.basedir}/src/main/shell")
+ private String[] inputs;
+
+ /**
+ * Build our argument list to pass to the executor.
+ */
+ private ArrayList<String> argList = new ArrayList<String>();
+
+ /**
+ * Execute our plugin.
+ * @throws MojoExecutionException an error occurred
+ */
+ @InterfaceAudience.Private
+ @InterfaceStability.Unstable
+ public void execute() throws MojoExecutionException {
+
+ buildArgs();
+ String[] args = argList.toArray(new String[0]);
+
+ ShellDocs shelldocs = new ShellDocs();
+ shelldocs.main(args);
+ }
+
+
+ /**
+ * Based upon what we got from maven, build our shelldocs command line params.
+ */
+ private void buildArgs() {
+
+ if (lint) {
+ argList.add("--lint");
+ }
+
+ argList.add("--output");
+ argList.add(output);
+
+ for (String p: inputs) {
+ argList.add("--input");
+ argList.add(p);
+ }
+
+ if (skipprnorep) {
+ argList.add("--skipprnorep");
+ }
+
+ }
+
+}
diff --git a/yetus-maven-plugin/src/main/java/org/apache/yetus/maven/plugin/shelldocs/package-info.java b/yetus-maven-plugin/src/main/java/org/apache/yetus/maven/plugin/shelldocs/package-info.java
new file mode 100644
index 0000000..1a83c36
--- /dev/null
+++ b/yetus-maven-plugin/src/main/java/org/apache/yetus/maven/plugin/shelldocs/package-info.java
@@ -0,0 +1,22 @@
+/*
+ * 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.
+ */
+
+/**
+ * Utilities for running releasedocmaker.
+ */
+package org.apache.yetus.maven.plugin.shelldocs;