-
Notifications
You must be signed in to change notification settings - Fork 617
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
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
179 changes: 179 additions & 0 deletions
179
buildSrc/src/main/groovy/com/google/firebase/gradle/plugins/Dokka.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,4 @@ | |
# limitations under the License. | ||
|
||
version=16.0.1 | ||
latestReleasedVersion=16.0.0 |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.