Skip to content

Configure kotlindoc generation per SDK. #1106

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 2 commits into from
Jan 9, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion buildSrc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ dependencies {
runtime 'io.opencensus:opencensus-impl:0.18.0'
implementation group: 'com.google.code.gson', name: 'gson', version: '2.8.6'

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

implementation 'com.android.tools.build:gradle:3.4.1'
testImplementation 'junit:junit:4.12'
Expand Down
179 changes: 179 additions & 0 deletions buildSrc/src/main/groovy/com/google/firebase/gradle/plugins/Dokka.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
// Copyright 2019 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.firebase.gradle.plugins;

import com.android.build.gradle.LibraryExtension;
import com.google.common.collect.ImmutableMap;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Collections;
import java.util.Optional;
import org.gradle.api.GradleException;
import org.gradle.api.Project;
import org.gradle.api.attributes.Attribute;
import org.gradle.api.file.FileCollection;
import org.gradle.api.file.RelativePath;
import org.gradle.api.tasks.Copy;
import org.jetbrains.dokka.DokkaConfiguration;
import org.jetbrains.dokka.gradle.DokkaAndroidTask;

final class Dokka {
/**
* Configures the dokka task for a 'firebase-library'.
*
* <p>Configuration includes:
*
* <ol>
* <li>Configure Metalava task for Java(non-Kotlin) libraries
* <li>Configure Dokka with the DAC format and full classpath for symbol resolution
* <li>Postprocessing of the produced Kotlindoc
* <ul>
* <li>Copy the _toc.yaml file to "client/{libName}/_toc.yaml"
* <li>Filter out unneeded files
* <li>Copy docs to the buildDir of the root project
* <li>Remove the "https://firebase.google.com" prefix from all urls
*/
static void configure(
Project project, LibraryExtension android, FirebaseLibraryExtension firebaseLibrary) {
project.apply(ImmutableMap.of("plugin", "org.jetbrains.dokka-android"));

if (!firebaseLibrary.publishJavadoc) {
project.getTasks().register("kotlindoc");
return;
}
DokkaAndroidTask dokkaAndroidTask =
project
.getTasks()
.create(
"kotlindocDokka",
DokkaAndroidTask.class,
dokka -> {
dokka.setOutputDirectory(project.getBuildDir() + "/dokka/firebase");
dokka.setOutputFormat("dac");

dokka.setGenerateClassIndexPage(false);
dokka.setGeneratePackageIndexPage(false);
if (!project.getPluginManager().hasPlugin("kotlin-android")) {
dokka.dependsOn("docStubs");
dokka.setSourceDirs(
Collections.singletonList(
project.file(project.getBuildDir() + "/doc-stubs")));
}

dokka.setNoAndroidSdkLink(true);

createLink(
project,
"https://developers.android.com/reference/kotlin/",
"kotlindoc/package-lists/android/package-list")
.map(dokka.getExternalDocumentationLinks()::add);
createLink(
project,
"https://developers.google.com/android/reference/",
"kotlindoc/package-lists/google/package-list")
.map(dokka.getExternalDocumentationLinks()::add);
createLink(
project,
"https://firebase.google.com/docs/reference/kotlin/",
"kotlindoc/package-lists/firebase/package-list")
.map(dokka.getExternalDocumentationLinks()::add);
createLink(
project,
"https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/",
"kotlindoc/package-lists/coroutines/package-list")
.map(dokka.getExternalDocumentationLinks()::add);

android
.getLibraryVariants()
.all(
v -> {
if (v.getName().equals("release")) {
project.afterEvaluate(
p -> {
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()
.plus(project.files(android.getBootClasspath()));
dokka.setClasspath(artifactFiles);
});
}
});
});
project
.getTasks()
.create(
"kotlindoc",
Copy.class,
copy -> {
copy.dependsOn(dokkaAndroidTask);
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")));
cfg.filesMatching(
"**/*.html",
fileCopy ->
fileCopy.filter(
line -> line.replaceAll("https://firebase.google.com", "")));
});
});
}

private static Optional<DokkaConfiguration.ExternalDocumentationLink> createLink(
Project project, String url, String packageListPath) {

File packageListFile = project.getRootProject().file(packageListPath);
if (!packageListFile.exists()) {
return Optional.empty();
}
try {
DokkaConfiguration.ExternalDocumentationLink.Builder builder =
new DokkaConfiguration.ExternalDocumentationLink.Builder();
builder.setUrl(new URL(url));
builder.setPackageListUrl(packageListFile.toURI().toURL());
return Optional.of(builder.build());
} catch (MalformedURLException e) {
throw new GradleException("Could not parse url", e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ public void apply(Project project) {
.getKotlinOptions()
.setFreeCompilerArgs(
ImmutableList.of("-module-name", kotlinModuleName(project))));

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

private static void setupApiInformationAnalysis(Project project, LibraryExtension android) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ class PublishingPlugin implements Plugin<Project> {
def publishProjectsToBuildDir = project.task('publishProjectsToBuildDir') {
projectsToPublish.each { projectToPublish ->
dependsOn getPublishTask(projectToPublish, 'BuildDirRepository')
dependsOn "$projectToPublish.path:kotlindoc"
}
}
def buildMavenZip = project.task('buildMavenZip', type: Zip) {
Expand All @@ -146,15 +147,24 @@ class PublishingPlugin implements Plugin<Project> {

from "$project.buildDir/m2repository"
}
def buildKotlindocZip = project.task('buildKotlindocZip', type: Zip) {
dependsOn publishProjectsToBuildDir

archiveFileName = 'kotlindoc.zip'
destinationDirectory = project.buildDir

from "$project.buildDir/firebase-kotlindoc"
}

def info = project.task('publishPrintInfo') {
doLast {
project.logger.lifecycle("Publishing the following libraries: \n{}", projectsToPublish.collect{it.path}.join('\n'))
}
}
buildMavenZip.mustRunAfter info
buildKotlindocZip.mustRunAfter info

firebasePublish.dependsOn info, buildMavenZip
firebasePublish.dependsOn info, buildMavenZip, buildKotlindocZip

try {
project.project(':kotlindoc')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ class PublishingPluginSpec extends Specification {
repositories {
google()
jcenter()
maven {
url 'https://storage.googleapis.com/android-ci/mvn/'
}
}
}
plugins {
Expand Down
1 change: 1 addition & 0 deletions firebase-components/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
# limitations under the License.

version=16.0.1
latestReleasedVersion=16.0.0
20 changes: 0 additions & 20 deletions kotlindoc/README.md

This file was deleted.

Loading