Skip to content

Commit 0cef0e9

Browse files
authored
* Kotlindoc generation for http://firebase.github.io/firebase-android-sdk * copyright
1 parent a4fcac3 commit 0cef0e9

File tree

6 files changed

+183
-0
lines changed

6 files changed

+183
-0
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import com.google.common.collect.ImmutableMap;
2222
import com.google.firebase.gradle.plugins.apiinfo.GenerateApiTxtFileTask;
2323
import com.google.firebase.gradle.plugins.apiinfo.ApiInformationTask;
24+
import com.google.firebase.gradle.plugins.apiinfo.GenerateStubsTask;
2425
import com.google.firebase.gradle.plugins.apiinfo.GetMetalavaJarTask;
2526
import com.google.firebase.gradle.plugins.ci.device.FirebaseTestServer;
2627

@@ -126,6 +127,14 @@ private static void setupApiInformationAnalysis(Project project, LibraryExtensio
126127
}
127128
task.dependsOn("getMetalavaJar");
128129
});
130+
131+
project.getTasks().register("docStubs", GenerateStubsTask.class, task -> {
132+
task.setMetalavaJarPath(metalavaOutputJarFile.getAbsolutePath());
133+
task.setOutputDir(new File(project.getBuildDir(), "doc-stubs"));
134+
task.dependsOn("getMetalavaJar");
135+
136+
task.setSourceDirs(android.getSourceSets().getByName("main").getJava().getSrcDirs());
137+
});
129138
}
130139

131140
private static void setupStaticAnalysis(
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// Copyright 2019 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.apiinfo;
16+
17+
import java.io.File;
18+
import java.util.Arrays;
19+
import java.util.Collection;
20+
import java.util.stream.Collectors;
21+
import org.gradle.api.DefaultTask;
22+
import org.gradle.api.tasks.Input;
23+
import org.gradle.api.tasks.InputFiles;
24+
import org.gradle.api.tasks.OutputDirectory;
25+
import org.gradle.api.tasks.TaskAction;
26+
27+
public abstract class GenerateStubsTask extends DefaultTask {
28+
@Input
29+
public abstract String getMetalavaJarPath();
30+
31+
public abstract void setMetalavaJarPath(String path);
32+
33+
@InputFiles
34+
public abstract Collection<File> getSourceDirs();
35+
36+
public abstract void setSourceDirs(Collection<File> dirs);
37+
38+
@OutputDirectory
39+
public abstract File getOutputDir();
40+
41+
public abstract void setOutputDir(File dir);
42+
43+
@TaskAction
44+
public void run() {
45+
String sourcePath =
46+
getSourceDirs().stream().map(File::getAbsolutePath).collect(Collectors.joining(":"));
47+
48+
getProject()
49+
.javaexec(
50+
spec -> {
51+
spec.setMain("-jar");
52+
spec.setArgs(
53+
Arrays.asList(
54+
getMetalavaJarPath(),
55+
"--quiet",
56+
"--source-path",
57+
sourcePath,
58+
"--include-annotations",
59+
"--doc-stubs",
60+
getOutputDir().getAbsolutePath()));
61+
});
62+
}
63+
}

kotlindoc/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Tooling to generate Kotlin documentation.
2+
3+
This module contains configuration for generating Kotlindoc that is hosted at
4+
[firebase.github.io](https://firebase.github.io/firebase-android-sdk/reference/kotlin/firebase-ktx/).
5+
6+
To generate documentation for all "supported" SDKs(ones that have Kotlin extensions) run:
7+
8+
```bash
9+
./gradlew :kotlindoc:dokka
10+
```
11+
12+
To generate documentation for a subset of SDKs run:
13+
14+
```bash
15+
./gradlew -PkotlindocProjects=":firebase-common,:firebase-firestore" :kotlindoc:dokka
16+
```
17+
18+
The output will be located in `kotlindoc/build/dokka/html`.
19+
20+
To update the live reference, create a PR with the contents of the above directory into the `gh-pages` branch.

kotlindoc/kotlindoc.gradle

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// Copyright 2019 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+
plugins {
16+
id 'com.android.library'
17+
id 'kotlin-android'
18+
id 'org.jetbrains.dokka-android' version '0.9.18'
19+
}
20+
21+
android {
22+
compileSdkVersion project.targetSdkVersion
23+
defaultConfig {
24+
minSdkVersion project.minSdkVersion
25+
targetSdkVersion project.targetSdkVersion
26+
}
27+
}
28+
29+
configurations {
30+
dokkapath
31+
dokkapath.description = "dokka project classpath"
32+
}
33+
34+
def ALL_SUPPORTED_PROJECTS = [
35+
':firebase-common',
36+
':firebase-config',
37+
':firebase-firestore',
38+
':firebase-functions',
39+
':firebase-storage',
40+
]
41+
42+
43+
def PROJECTS_TO_DOCUMENT = (project.findProperty('kotlindocProjects')?.split(',') ?: ALL_SUPPORTED_PROJECTS).collect {
44+
project(it)
45+
}
46+
47+
def javaDeps = PROJECTS_TO_DOCUMENT
48+
def kotlinDeps = javaDeps.collect {
49+
project("$it.path:ktx")
50+
}
51+
52+
dokka {
53+
moduleName = "firebase-ktx"
54+
outputDirectory = "$buildDir/dokka/html"
55+
outputFormat = "html"
56+
processConfigurations = []
57+
58+
javaDeps.each { Project p ->
59+
dependsOn "$p.path:docStubs"
60+
sourceRoot {
61+
path = "$p.buildDir/doc-stubs"
62+
}
63+
}
64+
afterEvaluate {
65+
sourceDirs = files(kotlinDeps.collect {
66+
"$it.projectDir/src/main/kotlin"
67+
})
68+
}
69+
70+
externalDocumentationLink {
71+
url = new URL('https://developer.android.com/reference/kotlin')
72+
}
73+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- Copyright 2019 Google LLC -->
3+
<!-- -->
4+
<!-- Licensed under the Apache License, Version 2.0 (the "License"); -->
5+
<!-- you may not use this file except in compliance with the License. -->
6+
<!-- You may obtain a copy of the License at -->
7+
<!-- -->
8+
<!-- http://www.apache.org/licenses/LICENSE-2.0 -->
9+
<!-- -->
10+
<!-- Unless required by applicable law or agreed to in writing, software -->
11+
<!-- distributed under the License is distributed on an "AS IS" BASIS, -->
12+
<!-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -->
13+
<!-- See the License for the specific language governing permissions and -->
14+
<!-- limitations under the License. -->
15+
16+
<manifest package="com.google.firebase.kotlindoc" />

subprojects.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,5 @@ transport
3030
transport:transport-api
3131
transport:transport-backend-cct
3232
transport:transport-runtime
33+
34+
kotlindoc

0 commit comments

Comments
 (0)