@@ -6,10 +6,13 @@ import org.gradle.api.DefaultTask
6
6
import org.gradle.api.provider.ListProperty
7
7
import org.gradle.api.provider.Property
8
8
import org.gradle.api.provider.SetProperty
9
- import org.gradle.api.tasks.Input
9
+ import org.gradle.api.tasks.CacheableTask
10
+ import org.gradle.api.tasks.Classpath
10
11
import org.gradle.api.tasks.InputFile
11
12
import org.gradle.api.tasks.InputFiles
12
13
import org.gradle.api.tasks.OutputDirectory
14
+ import org.gradle.api.tasks.PathSensitive
15
+ import org.gradle.api.tasks.PathSensitivity
13
16
import org.gradle.api.tasks.TaskAction
14
17
import org.gradle.process.ExecOperations
15
18
import org.gradle.workers.WorkAction
@@ -29,26 +32,48 @@ import org.json.JSONObject
29
32
* @property suppressedFiles a list of files to exclude from documentation
30
33
* @property outputDirectory where to store the generated files
31
34
*/
35
+ @CacheableTask
32
36
abstract class GenerateDocumentationTaskExtension : DefaultTask () {
33
- @get:InputFile
37
+ @get: [ InputFile Classpath ]
34
38
abstract val dackkaJarFile: Property <File >
35
39
36
- @get:Input
40
+ @get: [ InputFiles Classpath ]
37
41
abstract val dependencies: ListProperty <File >
38
42
39
43
@get:InputFiles
44
+ @get:PathSensitive(PathSensitivity .RELATIVE )
40
45
abstract val kotlinSources: ListProperty <File >
41
46
42
47
@get:InputFiles
48
+ @get:PathSensitive(PathSensitivity .RELATIVE )
43
49
abstract val javaSources: ListProperty <File >
44
50
45
51
@get:InputFiles
52
+ @get:PathSensitive(PathSensitivity .RELATIVE )
46
53
abstract val suppressedFiles: ListProperty <File >
47
54
55
+ @get:InputFiles
56
+ @get:PathSensitive(PathSensitivity .RELATIVE )
57
+ abstract val packageListFiles: ListProperty <File >
58
+
48
59
@get:OutputDirectory
49
60
abstract val outputDirectory: Property <File >
50
61
}
51
62
63
+ /* *
64
+ * Wrapper data class for External package-lists in Dokka
65
+ *
66
+ * This class allows us to map package-lists in a type-safe way, versus inline straight to
67
+ * a map. This extra step could be removed- but it could also catch bugs in the future.
68
+ *
69
+ * @property packageList the prepared package-list file to map against
70
+ * @property externalLink the url to map with when generating the docs
71
+ */
72
+ data class ExternalDocumentationLink (
73
+ val packageList : File ,
74
+ val externalLink : String
75
+ )
76
+
52
77
/* *
53
78
* Task to run Dackka on a project.
54
79
*
@@ -68,14 +93,6 @@ abstract class GenerateDocumentationTask @Inject constructor(
68
93
}
69
94
70
95
private fun constructArguments (): JSONObject {
71
- // TODO(b/243675474): Move these to a task input for caching purposes
72
- val linksMap = mapOf (
73
- " android" to " https://developer.android.com/reference/kotlin/" ,
74
- " google" to " https://developer.android.com/reference/" ,
75
- " firebase" to " https://firebase.google.com/docs/reference/kotlin/" ,
76
- " coroutines" to " https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/"
77
- )
78
-
79
96
val jsonMap = mapOf (
80
97
" moduleName" to " " ,
81
98
" outputDir" to outputDirectory.get().path,
@@ -90,9 +107,9 @@ abstract class GenerateDocumentationTask @Inject constructor(
90
107
" documentedVisibilities" to listOf (" PUBLIC" , " PROTECTED" ),
91
108
" skipEmptyPackages" to " true" ,
92
109
" suppressedFiles" to suppressedFiles.get().map { it.path },
93
- " externalDocumentationLinks" to linksMap .map { (name, url) -> mapOf (
94
- " url" to url ,
95
- " packageListUrl" to " file:// ${project.rootDir.absolutePath} /kotlindoc/package-lists/ $name /package-list "
110
+ " externalDocumentationLinks" to createExternalLinks(packageListFiles) .map { mapOf (
111
+ " url" to it.externalLink ,
112
+ " packageListUrl" to it.packageList.toURI()
96
113
) }
97
114
)),
98
115
" offlineMode" to " true" ,
@@ -102,6 +119,20 @@ abstract class GenerateDocumentationTask @Inject constructor(
102
119
return JSONObject (jsonMap)
103
120
}
104
121
122
+ private fun createExternalLinks (packageLists : ListProperty <File >): List <ExternalDocumentationLink > {
123
+ val linksMap = mapOf (
124
+ " android" to " https://developer.android.com/reference/kotlin/" ,
125
+ " google" to " https://developer.android.com/reference/" ,
126
+ " firebase" to " https://firebase.google.com/docs/reference/kotlin/" ,
127
+ " coroutines" to " https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/"
128
+ )
129
+
130
+ return packageLists.get().map {
131
+ val externalLink = linksMap[it.parentFile.nameWithoutExtension] ? : throw RuntimeException (" Unexpected package-list found: ${it.name} " )
132
+ ExternalDocumentationLink (it, externalLink)
133
+ }
134
+ }
135
+
105
136
private fun saveToJsonFile (jsonObject : JSONObject ): File {
106
137
val outputFile = File .createTempFile(" dackkaArgs" , " .json" )
107
138
0 commit comments