|
1 | | -import org.gradle.internal.os.OperatingSystem |
| 1 | +import javax.inject.Inject |
2 | 2 |
|
3 | 3 | apply plugin: 'com.android.library' |
4 | 4 | apply plugin: 'maven-publish' |
@@ -128,73 +128,6 @@ android { |
128 | 128 | } |
129 | 129 | } |
130 | 130 |
|
131 | | -task generateJavadocs(type: Javadoc) { |
132 | | - if (project.hasProperty("online")) { |
133 | | - options.addStringOption("toroot", "/") |
134 | | - options.addStringOption("hdf", "android.whichdoc online") |
135 | | - options.addStringOption("hdf", "dac") |
136 | | - options.addBooleanOption("devsite", true) |
137 | | - options.addBooleanOption("yamlV2", true) |
138 | | - options.addStringOption("dac_libraryroot", "com/google/android/material") |
139 | | - options.addStringOption("dac_dataname", "MATERIAL_DATA") |
140 | | - } |
141 | | - |
142 | | - if (project.hasProperty("docletPathRoot")) { |
143 | | - def docletPathRoot = project.property("docletPathRoot") |
144 | | - def outputPath = project.hasProperty("outputPath") ? project.property("outputPath") : "doclava-out" |
145 | | - def doclavaJar = project.getProperty("doclavaJar") |
146 | | - |
147 | | - source = android.sourceSets.main.java.source |
148 | | - source = source.findAll { it.name.endsWith(".java") } |
149 | | - |
150 | | - title = null |
151 | | - destinationDir = new File(outputPath) |
152 | | - classpath = files("${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar") |
153 | | - options.addStringOption("federate Android", "https://developer.android.com") |
154 | | - options.encoding = "UTF-8" |
155 | | - options.doclet = "com.google.doclava.Doclava" |
156 | | - options.docletpath = [ |
157 | | - file(doclavaJar), |
158 | | - file(docletPathRoot + "/jsilver/v1_0_0/jsilver.jar") |
159 | | - ] |
160 | | - } |
161 | | -} |
162 | | - |
163 | | -task getVersion { |
164 | | - doLast { |
165 | | - println version |
166 | | - } |
167 | | -} |
168 | | - |
169 | | -def R_CLASS_PATH = "build/generated/not_namespaced_r_class_sources/releaseUnitTest/processReleaseUnitTestResources/r/com/google/android/material/R.java" |
170 | | -Attribute<String> ARTIFACT_TYPE = Attribute.of("artifactType", String.class) |
171 | | -afterEvaluate { |
172 | | - [generateJavadocs].forEach { task -> |
173 | | - task.dependsOn(':lib:processReleaseUnitTestResources') |
174 | | - task.source += R_CLASS_PATH |
175 | | - |
176 | | - def releaseVariant = android.libraryVariants.find { it.name == 'release' } |
177 | | - if (releaseVariant == null) { |
178 | | - return |
179 | | - } |
180 | | - |
181 | | - // Add transitive runtime dependencies to classpath |
182 | | - task.classpath += releaseVariant.runtimeConfiguration.incoming.artifactView { aView -> |
183 | | - aView.attributes.attribute(ARTIFACT_TYPE, "android-classes") |
184 | | - }.files |
185 | | - |
186 | | - // Add project and compile dependencies to classpath |
187 | | - releaseVariant.javaCompileProvider.configure { javaCompileProvider -> |
188 | | - task.classpath += releaseVariant.getCompileClasspath(null) |
189 | | - task.classpath += task.project.files(javaCompileProvider.destinationDir) |
190 | | - task.source += javaCompileProvider.source |
191 | | - } |
192 | | - |
193 | | - // Doclava does not understand -notimestamp option that is default since Gradle 6.0 |
194 | | - task.options.setNoTimestamp(false) |
195 | | - } |
196 | | -} |
197 | | - |
198 | 131 | task androidSourcesJar(type: Jar) { |
199 | 132 | archiveClassifier.set('sources') |
200 | 133 | from(android.sourceSets.main.java.srcDirs) { |
@@ -250,3 +183,151 @@ afterEvaluate { |
250 | 183 | } |
251 | 184 | } |
252 | 185 | } |
| 186 | + |
| 187 | +/** |
| 188 | + * Generate library documentation. |
| 189 | + * |
| 190 | + * This task requires a Dackka jar to be run. This can be passed to the task |
| 191 | + * by running the task from the command line and setting the --dackkaJar |
| 192 | + * option. |
| 193 | + * |
| 194 | + * Example: ./gradlew generateDocumentation --dackkaJar="<path/to/dackka.jar>" |
| 195 | + * |
| 196 | + * The resulting documentation will be placed in `lib/build/docs` and contain |
| 197 | + * documentation for both java and kotlin clients. |
| 198 | + * |
| 199 | + * TODO: b/149338266 - Dackka does not support links to resources in documentation. |
| 200 | + * TODO: b/396171398 - inheritDoc results hav formatting issues with Dackka. |
| 201 | + */ |
| 202 | +tasks.register("generateDocumentation", DackkaRunner) { |
| 203 | + group = "Publishing" |
| 204 | + description = "Generate javadocs using dackka" |
| 205 | + version = mdcLibraryVersion |
| 206 | + config = layout.buildDirectory.file("resources/dackka_config.json").get().asFile |
| 207 | + outputDirectory = layout.buildDirectory.dir("docs").get() |
| 208 | + // Add all the files from the main source set to be documented by dackka |
| 209 | + sourceDirectories.setFrom( |
| 210 | + android.sourceSets.main.java.srcDirs.absolutePath |
| 211 | + ) |
| 212 | + dependenciesClasspath.setFrom( |
| 213 | + files("${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar"), |
| 214 | + ) |
| 215 | +} |
| 216 | + |
| 217 | +/** |
| 218 | + * A task that uses Dackka to generate javadoc. |
| 219 | + */ |
| 220 | +abstract class DackkaRunner extends DefaultTask { |
| 221 | + |
| 222 | + private String dackkaJar; |
| 223 | + |
| 224 | + /** |
| 225 | + * Set the path to the Dackka jar to use by setting the --dackkaJar command |
| 226 | + * line argument when running the gradle task used by this task. |
| 227 | + * |
| 228 | + * @param path the path to the dackka jar |
| 229 | + */ |
| 230 | + @Option(option = "dackkaJar", description = "path to daccka jar") |
| 231 | + void setDackkaJar(String path) { |
| 232 | + this.dackkaJar = path |
| 233 | + } |
| 234 | + |
| 235 | + @Input |
| 236 | + String getDackkaJar() { |
| 237 | + return dackkaJar; |
| 238 | + } |
| 239 | + |
| 240 | + /** |
| 241 | + * The Material library version of these docs. |
| 242 | + * |
| 243 | + * This should most likely match mdcLibraryVersion from the projects build |
| 244 | + * file. |
| 245 | + */ |
| 246 | + @Input |
| 247 | + String version; |
| 248 | + |
| 249 | + /** Source directories to be documented. */ |
| 250 | + @InputFiles |
| 251 | + final ConfigurableFileCollection sourceDirectories = project.files() |
| 252 | + |
| 253 | + @InputFiles |
| 254 | + final ConfigurableFileCollection dependenciesClasspath = project.files(); |
| 255 | + |
| 256 | + /** A file that should be populated with the Dackka configuration. */ |
| 257 | + @OutputFile |
| 258 | + abstract File config; |
| 259 | + |
| 260 | + /** The output containing documentation generated by Dackka. */ |
| 261 | + @OutputDirectory |
| 262 | + abstract Directory outputDirectory; |
| 263 | + |
| 264 | + @Inject |
| 265 | + abstract ExecOperations getExecOperations() |
| 266 | + |
| 267 | + @TaskAction |
| 268 | + void run() { |
| 269 | + // Delete any previously generated documentation |
| 270 | + outputDirectory.asFile.deleteDir() |
| 271 | + // Populate the Dackka config json file with Material-specific properties |
| 272 | + writeDackkaConfig() |
| 273 | + // Run the Dackka jar and generate docs |
| 274 | + getExecOperations().javaexec { |
| 275 | + classpath(dackkaJar) |
| 276 | + args(config.absolutePath) |
| 277 | + } |
| 278 | + } |
| 279 | + |
| 280 | + /** Populate the Dackka config file with project specific values. */ |
| 281 | + private void writeDackkaConfig() { |
| 282 | + def configContents = """ |
| 283 | + { |
| 284 | + "modeuleName": "Material Components", |
| 285 | + "moduleVersion": "$version", |
| 286 | + "outputDir": "${outputDirectory.asFile.absolutePath}", |
| 287 | + "offlineMode": "true", |
| 288 | + "noJdkLink": "true", |
| 289 | + "sourceSets": [ |
| 290 | + { |
| 291 | + "moduleDisplayName": "lib", |
| 292 | + "analysisPlatform": "jvm", |
| 293 | + "externalDocumentationLinks": [], |
| 294 | + "sourceSetID": { |
| 295 | + "scopeId": "com", |
| 296 | + "sourceSetName": "main" |
| 297 | + }, |
| 298 | + "sourceRoots": [${sourceDirectories.collect { '"' + it.absolutePath + '"' }.join(", ")}], |
| 299 | + "samples": [], |
| 300 | + "includes": [], |
| 301 | + "classpath": [${dependenciesClasspath.collect { '"' + it.absolutePath + '"'}.join(", ")}], |
| 302 | + "sourceLinks": [], |
| 303 | + "documentedVisibilities": ["PUBLIC", "PROTECTED"] |
| 304 | + } |
| 305 | + ], |
| 306 | + "pluginsConfiguration": [ |
| 307 | + { |
| 308 | + "fqPluginName": "com.google.devsite.DevsitePlugin", |
| 309 | + "serializationFormat": "JSON", |
| 310 | + "values": "${getDevsitePluginConfigValues()}" |
| 311 | + } |
| 312 | + ] |
| 313 | + } |
| 314 | + """.trim(); |
| 315 | + |
| 316 | + config.write(configContents) |
| 317 | + } |
| 318 | + |
| 319 | + /** Returns the Dackka Devsite plugin configuration json string. */ |
| 320 | + private String getDevsitePluginConfigValues() { |
| 321 | + return """ |
| 322 | + { |
| 323 | + "docRootPath": "reference", |
| 324 | + "projectPath": "com/google/android/material", |
| 325 | + "excludedPackages": [ ".*excluded.*" ], |
| 326 | + "javaDocsPath": "", |
| 327 | + "kotlinDocsPath": "kotlin", |
| 328 | + "baseSourceLink": "https://github.com/material-components/material-components-android/blob/${version}/lib/java/%s", |
| 329 | + "annotationsNotToDisplay": [ "java.lang.Override", "kotlin.ParameterName" ] |
| 330 | + } |
| 331 | + """.trim().replace("\n", "").replace('"', '\\\"') |
| 332 | + } |
| 333 | +} |
0 commit comments