comparison src/main/groovy/org/ssdt_ohio/gradle/tasks/UserDoc.groovy @ 13:a628135958e7

USASR-1307: inititial userdoc plugin/task to produce customizable groovy doc
author Dave Smith <smith@nwoca.org>
date Tue, 10 Dec 2013 22:53:57 +0000
parents
children 9de72de14ab3
comparison
equal deleted inserted replaced
12:0a2819478262 13:a628135958e7
1 package org.ssdt_ohio.gradle.tasks
2
3 import org.codehaus.groovy.tools.groovydoc.ClasspathResourceManager
4 import org.codehaus.groovy.tools.groovydoc.FileOutputTool
5 import org.codehaus.groovy.tools.groovydoc.GroovyDocTool
6 import org.codehaus.groovy.tools.groovydoc.gstringTemplates.GroovyDocTemplateInfo
7 import org.gradle.api.InvalidUserDataException
8 import org.gradle.api.file.FileCollection
9 import org.gradle.api.file.FileVisitDetails
10 import org.gradle.api.internal.ClassPathRegistry
11 import org.gradle.api.logging.LogLevel
12 import org.gradle.api.tasks.InputFiles
13 import org.gradle.api.tasks.OutputDirectory
14 import org.gradle.api.tasks.SourceTask
15 import org.gradle.api.tasks.TaskAction
16
17 class UserDoc extends SourceTask {
18
19 private FileCollection groovyClasspath;
20
21 private FileCollection classpath;
22
23 private File destinationDir;
24
25 ClassPathRegistry classPathRegistry
26
27 public UserDoc() {
28 getLogging().captureStandardOutput(LogLevel.INFO);
29 classPathRegistry = getServices().get(ClassPathRegistry.class);
30 }
31
32 @TaskAction
33 protected void generate() {
34 checkGroovyClasspathNonEmpty(getGroovyClasspath().getFiles());
35
36 def tmpDir = new File(project.buildDir, "tmp/userdoc")
37 logger.debug("userdoc tmpDir: $tmpDir")
38 project.delete tmpDir
39 logger.debug("userdoc source: ${super.source.collect { it.toString() }}")
40 project.copy {
41 from super.getSource()
42 into tmpDir
43 }
44
45 def args = [:]
46 args.sourcepath = tmpDir.toString()
47 args.destdir = destinationDir
48
49 Properties properties = new Properties();
50 // properties.setProperty("windowTitle", windowTitle);
51 // properties.setProperty("docTitle", docTitle);
52 // properties.setProperty("footer", footer);
53 // properties.setProperty("header", header);
54 // checkScopeProperties(properties);
55 // properties.setProperty("publicScope", publicScope.toString());
56 // properties.setProperty("protectedScope", protectedScope.toString());
57 // properties.setProperty("packageScope", packageScope.toString());
58 // properties.setProperty("privateScope", privateScope.toString());
59 // properties.setProperty("author", author.toString());
60 // properties.setProperty("processScripts", processScripts.toString());
61 // properties.setProperty("includeMainForScripts", includeMainForScripts.toString());
62 // properties.setProperty("overviewFile", overviewFile != null ? overviewFile.getAbsolutePath() : "");
63 // properties.setProperty("charset", charset != null ? charset : "");
64 // properties.setProperty("fileEncoding", fileEncoding != null ? fileEncoding : "");
65 //
66
67 def tool = new GroovyDocTool(new ClasspathResourceManager(),
68 [tmpDir.getPath()] as String[],
69 getDocTemplates(),
70 getPackageTemplates(),
71 getClassTemplates(), [],
72 properties)
73
74 def addFiles = []
75
76 super.getSource().visit { FileVisitDetails d ->
77 if (d.file.isFile()) {
78 addFiles << d.getRelativePath().toString()
79 }
80 }
81
82 tool.add(addFiles)
83 tool.renderToOutput(new FileOutputTool(), destinationDir.getCanonicalPath())
84 }
85
86 private void checkGroovyClasspathNonEmpty(Collection<File> classpath) {
87 if (classpath.isEmpty()) {
88 throw new InvalidUserDataException("You must assign a Groovy library to the groovy configuration!");
89 }
90 }
91
92 /**
93 * Returns the directory to generate the documentation into.
94 *
95 * @return The directory to generate the documentation into
96 */
97 @OutputDirectory
98 public File getDestinationDir() {
99 return destinationDir;
100 }
101
102 /**
103 * Sets the directory to generate the documentation into.
104 */
105 public void setDestinationDir(File destinationDir) {
106 this.destinationDir = destinationDir;
107 }
108
109 /**
110 * Returns the classpath containing the Groovy library to be used.
111 *
112 * @return The classpath containing the Groovy library to be used
113 */
114 @InputFiles
115 public FileCollection getGroovyClasspath() {
116 return groovyClasspath;
117 }
118
119 /**
120 * Sets the classpath containing the Groovy library to be used.
121 */
122 public void setGroovyClasspath(FileCollection groovyClasspath) {
123 this.groovyClasspath = groovyClasspath;
124 }
125
126 /**
127 * Returns the classpath used to locate classes referenced by the documented sources.
128 *
129 * @return The classpath used to locate classes referenced by the documented sources
130 */
131 @InputFiles
132 public FileCollection getClasspath() {
133 return classpath;
134 }
135
136 /**
137 * Sets the classpath used to locate classes referenced by the documented sources.
138 */
139 public void setClasspath(FileCollection classpath) {
140 this.classpath = classpath;
141 }
142
143 /**
144 * Creates and returns an array of package template classpath entries.
145 * <p>
146 * This method is meant to be overridden by custom GroovyDoc implementations, using custom package templates.
147 *
148 * @return an array of package templates, whereas each entry is resolved as classpath entry, defaults to
149 * {@link GroovyDocTemplateInfo#DEFAULT_PACKAGE_TEMPLATES}.
150 */
151 protected String[] getPackageTemplates() {
152 return GroovyDocTemplateInfo.DEFAULT_PACKAGE_TEMPLATES;
153 }
154
155 /**
156 * Creates and returns an array of doc template classpath entries.
157 * <p>
158 * This method is meant to be overridden by custom GroovyDoc implementations, using custom doc templates.
159 *
160 * @return an array of doc templates, whereas each entry is resolved as classpath entry, defaults to
161 * {@link GroovyDocTemplateInfo#DEFAULT_DOC_TEMPLATES}.
162 */
163 protected String[] getDocTemplates() {
164 return GroovyDocTemplateInfo.DEFAULT_DOC_TEMPLATES;
165 }
166
167 /**
168 * Creates and returns an array of class template classpath entries.
169 * <p>
170 * This method is meant to be overridden by custom GroovyDoc implementations, using custom class templates.
171 *
172 * @return an array of class templates, whereas each entry is resolved as classpath entry, defaults to
173 * {@link GroovyDocTemplateInfo#DEFAULT_CLASS_TEMPLATES}.
174 */
175 protected String[] getClassTemplates() {
176 return GroovyDocTemplateInfo.DEFAULT_CLASS_TEMPLATES;
177 }
178 }