Skip to content

Commit 29f561d

Browse files
authored
Configure kotlindoc generation per SDK. (#1106)
This makes it easier to generate docs for a subset of SDKs, additionally it produces a set of separate _toc.yaml files as opposed to a global one.
1 parent 227121f commit 29f561d

File tree

13 files changed

+310
-187
lines changed

13 files changed

+310
-187
lines changed

.idea/copyright/Apache_2___Google.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

buildSrc/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ dependencies {
4848
runtime 'io.opencensus:opencensus-impl:0.18.0'
4949
implementation group: 'com.google.code.gson', name: 'gson', version: '2.8.6'
5050

51-
implementation 'org.jetbrains.dokka:dokka-android-gradle-plugin:0.9.17-g004'
51+
implementation 'org.jetbrains.dokka:dokka-android-gradle-plugin:0.9.17-g005'
5252

5353
implementation 'com.android.tools.build:gradle:3.4.1'
5454
testImplementation 'junit:junit:4.12'
Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
// Copyright 2020 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package com.google.firebase.gradle.plugins;
16+
17+
import com.android.build.gradle.LibraryExtension;
18+
import com.google.common.collect.ImmutableMap;
19+
import java.io.File;
20+
import java.net.MalformedURLException;
21+
import java.net.URL;
22+
import java.util.Collections;
23+
import java.util.Optional;
24+
import org.gradle.api.GradleException;
25+
import org.gradle.api.Project;
26+
import org.gradle.api.attributes.Attribute;
27+
import org.gradle.api.file.FileCollection;
28+
import org.gradle.api.file.RelativePath;
29+
import org.gradle.api.tasks.Copy;
30+
import org.jetbrains.dokka.DokkaConfiguration;
31+
import org.jetbrains.dokka.gradle.DokkaAndroidTask;
32+
33+
final class Dokka {
34+
/**
35+
* Configures the dokka task for a 'firebase-library'.
36+
*
37+
* <p>Configuration includes:
38+
*
39+
* <ol>
40+
* <li>Configure Metalava task for Java(non-Kotlin) libraries
41+
* <li>Configure Dokka with the DAC format and full classpath for symbol resolution
42+
* <li>Postprocessing of the produced Kotlindoc
43+
* <ul>
44+
* <li>Copy the _toc.yaml file to "client/{libName}/_toc.yaml"
45+
* <li>Filter out unneeded files
46+
* <li>Copy docs to the buildDir of the root project
47+
* <li>Remove the "https://firebase.google.com" prefix from all urls
48+
*/
49+
static void configure(
50+
Project project, LibraryExtension android, FirebaseLibraryExtension firebaseLibrary) {
51+
project.apply(ImmutableMap.of("plugin", "org.jetbrains.dokka-android"));
52+
53+
if (!firebaseLibrary.publishJavadoc) {
54+
project.getTasks().register("kotlindoc");
55+
return;
56+
}
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+
}
75+
76+
dokka.setNoAndroidSdkLink(true);
77+
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);
98+
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+
project
132+
.getTasks()
133+
.create(
134+
"kotlindoc",
135+
Copy.class,
136+
copy -> {
137+
copy.dependsOn(dokkaAndroidTask);
138+
copy.setDestinationDir(
139+
project.file(project.getRootProject().getBuildDir() + "/firebase-kotlindoc"));
140+
copy.from(
141+
project.getBuildDir() + "/dokka/firebase",
142+
cfg -> {
143+
cfg.exclude("package-list");
144+
cfg.filesMatching(
145+
"_toc.yaml",
146+
fileCopy ->
147+
fileCopy.setRelativePath(
148+
new RelativePath(
149+
true,
150+
"client",
151+
firebaseLibrary.artifactId.get(),
152+
"_toc.yaml")));
153+
cfg.filesMatching(
154+
"**/*.html",
155+
fileCopy ->
156+
fileCopy.filter(
157+
line -> line.replaceAll("https://firebase.google.com", "")));
158+
});
159+
});
160+
}
161+
162+
private static Optional<DokkaConfiguration.ExternalDocumentationLink> createLink(
163+
Project project, String url, String packageListPath) {
164+
165+
File packageListFile = project.getRootProject().file(packageListPath);
166+
if (!packageListFile.exists()) {
167+
return Optional.empty();
168+
}
169+
try {
170+
DokkaConfiguration.ExternalDocumentationLink.Builder builder =
171+
new DokkaConfiguration.ExternalDocumentationLink.Builder();
172+
builder.setUrl(new URL(url));
173+
builder.setPackageListUrl(packageListFile.toURI().toURL());
174+
return Optional.of(builder.build());
175+
} catch (MalformedURLException e) {
176+
throw new GradleException("Could not parse url", e);
177+
}
178+
}
179+
}

buildSrc/src/main/groovy/com/google/firebase/gradle/plugins/FirebaseLibraryPlugin.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ public void apply(Project project) {
8181
.getKotlinOptions()
8282
.setFreeCompilerArgs(
8383
ImmutableList.of("-module-name", kotlinModuleName(project))));
84+
85+
project.afterEvaluate(p -> Dokka.configure(project, android, firebaseLibrary));
8486
}
8587

8688
private static void setupApiInformationAnalysis(Project project, LibraryExtension android) {

buildSrc/src/main/groovy/com/google/firebase/gradle/plugins/publish/PublishingPlugin.groovy

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ class PublishingPlugin implements Plugin<Project> {
136136
def publishProjectsToBuildDir = project.task('publishProjectsToBuildDir') {
137137
projectsToPublish.each { projectToPublish ->
138138
dependsOn getPublishTask(projectToPublish, 'BuildDirRepository')
139+
dependsOn "$projectToPublish.path:kotlindoc"
139140
}
140141
}
141142
def buildMavenZip = project.task('buildMavenZip', type: Zip) {
@@ -146,15 +147,24 @@ class PublishingPlugin implements Plugin<Project> {
146147

147148
from "$project.buildDir/m2repository"
148149
}
150+
def buildKotlindocZip = project.task('buildKotlindocZip', type: Zip) {
151+
dependsOn publishProjectsToBuildDir
152+
153+
archiveFileName = 'kotlindoc.zip'
154+
destinationDirectory = project.buildDir
155+
156+
from "$project.buildDir/firebase-kotlindoc"
157+
}
149158

150159
def info = project.task('publishPrintInfo') {
151160
doLast {
152161
project.logger.lifecycle("Publishing the following libraries: \n{}", projectsToPublish.collect{it.path}.join('\n'))
153162
}
154163
}
155164
buildMavenZip.mustRunAfter info
165+
buildKotlindocZip.mustRunAfter info
156166

157-
firebasePublish.dependsOn info, buildMavenZip
167+
firebasePublish.dependsOn info, buildMavenZip, buildKotlindocZip
158168

159169
try {
160170
project.project(':kotlindoc')

buildSrc/src/test/groovy/com/google/firebase/gradle/plugins/publish/PublishingPluginSpec.groovy

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ class PublishingPluginSpec extends Specification {
9494
repositories {
9595
google()
9696
jcenter()
97+
maven {
98+
url 'https://storage.googleapis.com/android-ci/mvn/'
99+
}
97100
}
98101
}
99102
plugins {

firebase-components/gradle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@
1313
# limitations under the License.
1414

1515
version=16.0.1
16+
latestReleasedVersion=16.0.0

kotlindoc/README.md

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)