Skip to content

Improve kotlindoc rendering. #1777

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
152 changes: 82 additions & 70 deletions buildSrc/src/main/java/com/google/firebase/gradle/plugins/Dokka.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

package com.google.firebase.gradle.plugins;

import com.android.build.api.attributes.BuildTypeAttr;
import com.android.build.gradle.LibraryExtension;
import com.google.common.collect.ImmutableMap;
import com.sun.istack.Nullable;
Expand All @@ -24,6 +25,7 @@
import java.util.Optional;
import org.gradle.api.GradleException;
import org.gradle.api.Project;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.attributes.Attribute;
import org.gradle.api.file.FileCollection;
import org.gradle.api.file.RelativePath;
Expand Down Expand Up @@ -53,83 +55,93 @@ static void configure(
@Nullable LibraryExtension android,
FirebaseLibraryExtension firebaseLibrary) {

String dokkaPluginName =
android == null ? "org.jetbrains.dokka" : "org.jetbrains.dokka-android";
project.apply(ImmutableMap.of("plugin", dokkaPluginName));
Configuration javadocClasspath = project.getConfigurations().create("javadocClasspath");
javadocClasspath
.getAttributes()
.attribute(
BuildTypeAttr.ATTRIBUTE, project.getObjects().named(BuildTypeAttr.class, "release"));

if (!firebaseLibrary.publishJavadoc) {
project.getTasks().register("kotlindoc");
return;
}
Class<? extends DokkaTask> taskClass =
android == null ? DokkaTask.class : DokkaAndroidTask.class;
DokkaTask dokkaTask = configure(project, taskClass);

if (dokkaTask instanceof DokkaAndroidTask) {
((DokkaAndroidTask) dokkaTask).setNoAndroidSdkLink(true);

android
.getLibraryVariants()
.all(
v -> {
if (v.getName().equals("release")) {
project.afterEvaluate(
p -> {
project.afterEvaluate(
p -> {
String dokkaPluginName =
android == null ? "org.jetbrains.dokka" : "org.jetbrains.dokka-android";
project.apply(ImmutableMap.of("plugin", dokkaPluginName));

if (!firebaseLibrary.publishJavadoc) {
project.getTasks().register("kotlindoc");
return;
}
Class<? extends DokkaTask> taskClass =
android == null ? DokkaTask.class : DokkaAndroidTask.class;
DokkaTask dokkaTask = configure(project, taskClass);

if (dokkaTask instanceof DokkaAndroidTask) {
((DokkaAndroidTask) dokkaTask).setNoAndroidSdkLink(true);

android
.getLibraryVariants()
.all(
v -> {
if (v.getName().equals("release")) {
FileCollection artifactFiles =
v.getRuntimeConfiguration()
.getIncoming()
.artifactView(
view -> {
view.attributes(
attrs ->
attrs.attribute(
Attribute.of("artifactType", String.class),
"jar"));
view.componentFilter(
c ->
!c.getDisplayName()
.startsWith("androidx.annotation:annotation:"));
})
.getArtifacts()
.getArtifactFiles()
getJars(v.getRuntimeConfiguration())
.plus(getJars(javadocClasspath))
.plus(project.files(android.getBootClasspath()));
dokkaTask.setClasspath(artifactFiles);
});
}
});
}
}
});
}

project
.getTasks()
.create(
"kotlindoc",
Copy.class,
copy -> {
copy.dependsOn(dokkaTask);
copy.setDestinationDir(
project.file(project.getRootProject().getBuildDir() + "/firebase-kotlindoc"));
copy.from(
project.getBuildDir() + "/dokka/firebase",
cfg -> {
cfg.exclude("package-list");
cfg.filesMatching(
"_toc.yaml",
fileCopy -> {
fileCopy.setRelativePath(
new RelativePath(
true, "client", firebaseLibrary.artifactId.get(), "_toc.yaml"));
fileCopy.filter(
line ->
line.replaceFirst(
"\\spath:\\s/", " path: /docs/reference/kotlin/"));
project
.getTasks()
.create(
"kotlindoc",
Copy.class,
copy -> {
copy.dependsOn(dokkaTask);
copy.setDestinationDir(
project.file(
project.getRootProject().getBuildDir() + "/firebase-kotlindoc"));
copy.from(
project.getBuildDir() + "/dokka/firebase",
cfg -> {
cfg.exclude("package-list");
cfg.filesMatching(
"_toc.yaml",
fileCopy -> {
fileCopy.setRelativePath(
new RelativePath(
true,
"client",
firebaseLibrary.artifactId.get(),
"_toc.yaml"));
fileCopy.filter(
line ->
line.replaceFirst(
"\\spath:\\s/", " path: /docs/reference/kotlin/"));
});
cfg.filesMatching(
"**/*.html",
fileCopy ->
fileCopy.filter(
line -> line.replaceAll("https://firebase.google.com", "")));
});
cfg.filesMatching(
"**/*.html",
fileCopy ->
fileCopy.filter(
line -> line.replaceAll("https://firebase.google.com", "")));
});
});
});
}

private static FileCollection getJars(Configuration configuration) {
return configuration
.getIncoming()
.artifactView(
view -> {
view.attributes(
attrs -> attrs.attribute(Attribute.of("artifactType", String.class), "jar"));
view.componentFilter(
c -> !c.getDisplayName().startsWith("androidx.annotation:annotation:"));
})
.getArtifacts()
.getArtifactFiles();
}

static <T extends DokkaTask> T configure(Project project, Class<T> taskType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ public void apply(Project project) {
.setFreeCompilerArgs(
ImmutableList.of("-module-name", kotlinModuleName(project))));

project.afterEvaluate(p -> Dokka.configure(project, android, firebaseLibrary));

Dokka.configure(project, android, firebaseLibrary);
}

private static void setupApiInformationAnalysis(Project project, LibraryExtension android) {
Expand Down
3 changes: 3 additions & 0 deletions firebase-common/firebase-common.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ dependencies {
implementation 'com.google.android.gms:play-services-basement:17.0.0'
implementation "com.google.android.gms:play-services-tasks:17.0.0"

// FirebaseApp references storage, so storage needs to be on classpath when dokka runs.
javadocClasspath project(path: ':firebase-storage')

compileOnly 'com.google.auto.value:auto-value-annotations:1.6.6'
compileOnly 'com.google.code.findbugs:jsr305:3.0.2'

Expand Down
3 changes: 2 additions & 1 deletion kotlindoc/package-lists/firebase/package-list
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ com.google.firebase.inappmessaging.display
com.google.firebase.inappmessaging.display.ktx
com.google.firebase.inappmessaging.ktx
com.google.firebase.inappmessaging.model
com.google.firebase.installations
com.google.firebase.ktx
com.google.firebase.messaging
com.google.firebase.ml.common
Expand Down Expand Up @@ -73,4 +74,4 @@ com.google.firebase.remoteconfig.ktx
com.google.firebase.storage
com.google.firebase.storage.ktx
io.fabric.sdk.android.fabric
io.fabric.sdk.android.fabric.services.concurrency
io.fabric.sdk.android.fabric.services.concurrency