16
16
17
17
import com .android .build .gradle .LibraryExtension ;
18
18
import com .google .common .collect .ImmutableMap ;
19
+ import com .sun .istack .Nullable ;
19
20
import java .io .File ;
20
21
import java .net .MalformedURLException ;
21
22
import java .net .URL ;
29
30
import org .gradle .api .tasks .Copy ;
30
31
import org .jetbrains .dokka .DokkaConfiguration ;
31
32
import org .jetbrains .dokka .gradle .DokkaAndroidTask ;
33
+ import org .jetbrains .dokka .gradle .DokkaTask ;
32
34
33
35
final class Dokka {
34
36
/**
@@ -47,94 +49,63 @@ final class Dokka {
47
49
* <li>Remove the "https://firebase.google.com" prefix from all urls
48
50
*/
49
51
static void configure (
50
- Project project , LibraryExtension android , FirebaseLibraryExtension firebaseLibrary ) {
51
- project .apply (ImmutableMap .of ("plugin" , "org.jetbrains.dokka-android" ));
52
+ Project project ,
53
+ @ Nullable LibraryExtension android ,
54
+ FirebaseLibraryExtension firebaseLibrary ) {
55
+
56
+ String dokkaPluginName =
57
+ android == null ? "org.jetbrains.dokka" : "org.jetbrains.dokka-android" ;
58
+ project .apply (ImmutableMap .of ("plugin" , dokkaPluginName ));
52
59
53
60
if (!firebaseLibrary .publishJavadoc ) {
54
61
project .getTasks ().register ("kotlindoc" );
55
62
return ;
56
63
}
57
- DokkaAndroidTask dokkaAndroidTask =
58
- project
59
- .getTasks ()
60
- .create (
61
- "kotlindocDokka" ,
62
- DokkaAndroidTask .class ,
63
- dokka -> {
64
- dokka .setOutputDirectory (project .getBuildDir () + "/dokka/firebase" );
65
- dokka .setOutputFormat ("dac" );
66
-
67
- dokka .setGenerateClassIndexPage (false );
68
- dokka .setGeneratePackageIndexPage (false );
69
- if (!project .getPluginManager ().hasPlugin ("kotlin-android" )) {
70
- dokka .dependsOn ("docStubs" );
71
- dokka .setSourceDirs (
72
- Collections .singletonList (
73
- project .file (project .getBuildDir () + "/doc-stubs" )));
74
- }
64
+ Class <? extends DokkaTask > taskClass =
65
+ android == null ? DokkaTask .class : DokkaAndroidTask .class ;
66
+ DokkaTask dokkaTask = configure (project , taskClass );
75
67
76
- dokka .setNoAndroidSdkLink (true );
68
+ if (dokkaTask instanceof DokkaAndroidTask ) {
69
+ ((DokkaAndroidTask ) dokkaTask ).setNoAndroidSdkLink (true );
77
70
78
- createLink (
79
- project ,
80
- "https://developers.android.com/reference/kotlin/" ,
81
- "kotlindoc/package-lists/android/package-list" )
82
- .map (dokka .getExternalDocumentationLinks ()::add );
83
- createLink (
84
- project ,
85
- "https://developers.google.com/android/reference/" ,
86
- "kotlindoc/package-lists/google/package-list" )
87
- .map (dokka .getExternalDocumentationLinks ()::add );
88
- createLink (
89
- project ,
90
- "https://firebase.google.com/docs/reference/kotlin/" ,
91
- "kotlindoc/package-lists/firebase/package-list" )
92
- .map (dokka .getExternalDocumentationLinks ()::add );
93
- createLink (
94
- project ,
95
- "https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/" ,
96
- "kotlindoc/package-lists/coroutines/package-list" )
97
- .map (dokka .getExternalDocumentationLinks ()::add );
71
+ android
72
+ .getLibraryVariants ()
73
+ .all (
74
+ v -> {
75
+ if (v .getName ().equals ("release" )) {
76
+ project .afterEvaluate (
77
+ p -> {
78
+ FileCollection artifactFiles =
79
+ v .getRuntimeConfiguration ()
80
+ .getIncoming ()
81
+ .artifactView (
82
+ view -> {
83
+ view .attributes (
84
+ attrs ->
85
+ attrs .attribute (
86
+ Attribute .of ("artifactType" , String .class ),
87
+ "jar" ));
88
+ view .componentFilter (
89
+ c ->
90
+ !c .getDisplayName ()
91
+ .startsWith ("androidx.annotation:annotation:" ));
92
+ })
93
+ .getArtifacts ()
94
+ .getArtifactFiles ()
95
+ .plus (project .files (android .getBootClasspath ()));
96
+ dokkaTask .setClasspath (artifactFiles );
97
+ });
98
+ }
99
+ });
100
+ }
98
101
99
- android
100
- .getLibraryVariants ()
101
- .all (
102
- v -> {
103
- if (v .getName ().equals ("release" )) {
104
- project .afterEvaluate (
105
- p -> {
106
- FileCollection artifactFiles =
107
- v .getRuntimeConfiguration ()
108
- .getIncoming ()
109
- .artifactView (
110
- view -> {
111
- view .attributes (
112
- attrs ->
113
- attrs .attribute (
114
- Attribute .of (
115
- "artifactType" , String .class ),
116
- "jar" ));
117
- view .componentFilter (
118
- c ->
119
- !c .getDisplayName ()
120
- .startsWith (
121
- "androidx.annotation:annotation:" ));
122
- })
123
- .getArtifacts ()
124
- .getArtifactFiles ()
125
- .plus (project .files (android .getBootClasspath ()));
126
- dokka .setClasspath (artifactFiles );
127
- });
128
- }
129
- });
130
- });
131
102
project
132
103
.getTasks ()
133
104
.create (
134
105
"kotlindoc" ,
135
106
Copy .class ,
136
107
copy -> {
137
- copy .dependsOn (dokkaAndroidTask );
108
+ copy .dependsOn (dokkaTask );
138
109
copy .setDestinationDir (
139
110
project .file (project .getRootProject ().getBuildDir () + "/firebase-kotlindoc" ));
140
111
copy .from (
@@ -161,6 +132,49 @@ static void configure(
161
132
});
162
133
}
163
134
135
+ static <T extends DokkaTask > T configure (Project project , Class <T > taskType ) {
136
+ return project
137
+ .getTasks ()
138
+ .create (
139
+ "kotlindocDokka" ,
140
+ taskType ,
141
+ dokka -> {
142
+ dokka .setOutputDirectory (project .getBuildDir () + "/dokka/firebase" );
143
+ dokka .setOutputFormat ("dac" );
144
+
145
+ dokka .setGenerateClassIndexPage (false );
146
+ dokka .setGeneratePackageIndexPage (false );
147
+ if (!project .getPluginManager ().hasPlugin ("kotlin-android" )) {
148
+ dokka .dependsOn ("docStubs" );
149
+ dokka .setSourceDirs (
150
+ Collections .singletonList (project .file (project .getBuildDir () + "/doc-stubs" )));
151
+ }
152
+
153
+ dokka .setNoJdkLink (true );
154
+
155
+ createLink (
156
+ project ,
157
+ "https://developers.android.com/reference/kotlin/" ,
158
+ "kotlindoc/package-lists/android/package-list" )
159
+ .map (dokka .getExternalDocumentationLinks ()::add );
160
+ createLink (
161
+ project ,
162
+ "https://developers.google.com/android/reference/" ,
163
+ "kotlindoc/package-lists/google/package-list" )
164
+ .map (dokka .getExternalDocumentationLinks ()::add );
165
+ createLink (
166
+ project ,
167
+ "https://firebase.google.com/docs/reference/kotlin/" ,
168
+ "kotlindoc/package-lists/firebase/package-list" )
169
+ .map (dokka .getExternalDocumentationLinks ()::add );
170
+ createLink (
171
+ project ,
172
+ "https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/" ,
173
+ "kotlindoc/package-lists/coroutines/package-list" )
174
+ .map (dokka .getExternalDocumentationLinks ()::add );
175
+ });
176
+ }
177
+
164
178
private static Optional <DokkaConfiguration .ExternalDocumentationLink > createLink (
165
179
Project project , String url , String packageListPath ) {
166
180
0 commit comments