|
14 | 14 |
|
15 | 15 | package com.google.firebase.gradle.plugins;
|
16 | 16 |
|
| 17 | +import com.android.build.api.attributes.BuildTypeAttr; |
17 | 18 | import com.android.build.gradle.LibraryExtension;
|
18 | 19 | import com.google.common.collect.ImmutableMap;
|
19 | 20 | import com.sun.istack.Nullable;
|
|
24 | 25 | import java.util.Optional;
|
25 | 26 | import org.gradle.api.GradleException;
|
26 | 27 | import org.gradle.api.Project;
|
| 28 | +import org.gradle.api.artifacts.Configuration; |
27 | 29 | import org.gradle.api.attributes.Attribute;
|
28 | 30 | import org.gradle.api.file.FileCollection;
|
29 | 31 | import org.gradle.api.file.RelativePath;
|
@@ -53,83 +55,93 @@ static void configure(
|
53 | 55 | @Nullable LibraryExtension android,
|
54 | 56 | FirebaseLibraryExtension firebaseLibrary) {
|
55 | 57 |
|
56 |
| - String dokkaPluginName = |
57 |
| - android == null ? "org.jetbrains.dokka" : "org.jetbrains.dokka-android"; |
58 |
| - project.apply(ImmutableMap.of("plugin", dokkaPluginName)); |
| 58 | + Configuration javadocClasspath = project.getConfigurations().create("javadocClasspath"); |
| 59 | + javadocClasspath |
| 60 | + .getAttributes() |
| 61 | + .attribute( |
| 62 | + BuildTypeAttr.ATTRIBUTE, project.getObjects().named(BuildTypeAttr.class, "release")); |
59 | 63 |
|
60 |
| - if (!firebaseLibrary.publishJavadoc) { |
61 |
| - project.getTasks().register("kotlindoc"); |
62 |
| - return; |
63 |
| - } |
64 |
| - Class<? extends DokkaTask> taskClass = |
65 |
| - android == null ? DokkaTask.class : DokkaAndroidTask.class; |
66 |
| - DokkaTask dokkaTask = configure(project, taskClass); |
67 |
| - |
68 |
| - if (dokkaTask instanceof DokkaAndroidTask) { |
69 |
| - ((DokkaAndroidTask) dokkaTask).setNoAndroidSdkLink(true); |
70 |
| - |
71 |
| - android |
72 |
| - .getLibraryVariants() |
73 |
| - .all( |
74 |
| - v -> { |
75 |
| - if (v.getName().equals("release")) { |
76 |
| - project.afterEvaluate( |
77 |
| - p -> { |
| 64 | + project.afterEvaluate( |
| 65 | + p -> { |
| 66 | + String dokkaPluginName = |
| 67 | + android == null ? "org.jetbrains.dokka" : "org.jetbrains.dokka-android"; |
| 68 | + project.apply(ImmutableMap.of("plugin", dokkaPluginName)); |
| 69 | + |
| 70 | + if (!firebaseLibrary.publishJavadoc) { |
| 71 | + project.getTasks().register("kotlindoc"); |
| 72 | + return; |
| 73 | + } |
| 74 | + Class<? extends DokkaTask> taskClass = |
| 75 | + android == null ? DokkaTask.class : DokkaAndroidTask.class; |
| 76 | + DokkaTask dokkaTask = configure(project, taskClass); |
| 77 | + |
| 78 | + if (dokkaTask instanceof DokkaAndroidTask) { |
| 79 | + ((DokkaAndroidTask) dokkaTask).setNoAndroidSdkLink(true); |
| 80 | + |
| 81 | + android |
| 82 | + .getLibraryVariants() |
| 83 | + .all( |
| 84 | + v -> { |
| 85 | + if (v.getName().equals("release")) { |
78 | 86 | FileCollection artifactFiles =
|
79 |
| - v.getRuntimeConfiguration() |
80 |
| - .getIncoming() |
81 |
| - .artifactView( |
82 |
| - view -> { |
83 |
| - view.attributes( |
84 |
| - attrs -> |
85 |
| - attrs.attribute( |
86 |
| - Attribute.of("artifactType", String.class), |
87 |
| - "jar")); |
88 |
| - view.componentFilter( |
89 |
| - c -> |
90 |
| - !c.getDisplayName() |
91 |
| - .startsWith("androidx.annotation:annotation:")); |
92 |
| - }) |
93 |
| - .getArtifacts() |
94 |
| - .getArtifactFiles() |
| 87 | + getJars(v.getRuntimeConfiguration()) |
| 88 | + .plus(getJars(javadocClasspath)) |
95 | 89 | .plus(project.files(android.getBootClasspath()));
|
96 | 90 | dokkaTask.setClasspath(artifactFiles);
|
97 |
| - }); |
98 |
| - } |
99 |
| - }); |
100 |
| - } |
| 91 | + } |
| 92 | + }); |
| 93 | + } |
101 | 94 |
|
102 |
| - project |
103 |
| - .getTasks() |
104 |
| - .create( |
105 |
| - "kotlindoc", |
106 |
| - Copy.class, |
107 |
| - copy -> { |
108 |
| - copy.dependsOn(dokkaTask); |
109 |
| - copy.setDestinationDir( |
110 |
| - project.file(project.getRootProject().getBuildDir() + "/firebase-kotlindoc")); |
111 |
| - copy.from( |
112 |
| - project.getBuildDir() + "/dokka/firebase", |
113 |
| - cfg -> { |
114 |
| - cfg.exclude("package-list"); |
115 |
| - cfg.filesMatching( |
116 |
| - "_toc.yaml", |
117 |
| - fileCopy -> { |
118 |
| - fileCopy.setRelativePath( |
119 |
| - new RelativePath( |
120 |
| - true, "client", firebaseLibrary.artifactId.get(), "_toc.yaml")); |
121 |
| - fileCopy.filter( |
122 |
| - line -> |
123 |
| - line.replaceFirst( |
124 |
| - "\\spath:\\s/", " path: /docs/reference/kotlin/")); |
| 95 | + project |
| 96 | + .getTasks() |
| 97 | + .create( |
| 98 | + "kotlindoc", |
| 99 | + Copy.class, |
| 100 | + copy -> { |
| 101 | + copy.dependsOn(dokkaTask); |
| 102 | + copy.setDestinationDir( |
| 103 | + project.file( |
| 104 | + project.getRootProject().getBuildDir() + "/firebase-kotlindoc")); |
| 105 | + copy.from( |
| 106 | + project.getBuildDir() + "/dokka/firebase", |
| 107 | + cfg -> { |
| 108 | + cfg.exclude("package-list"); |
| 109 | + cfg.filesMatching( |
| 110 | + "_toc.yaml", |
| 111 | + fileCopy -> { |
| 112 | + fileCopy.setRelativePath( |
| 113 | + new RelativePath( |
| 114 | + true, |
| 115 | + "client", |
| 116 | + firebaseLibrary.artifactId.get(), |
| 117 | + "_toc.yaml")); |
| 118 | + fileCopy.filter( |
| 119 | + line -> |
| 120 | + line.replaceFirst( |
| 121 | + "\\spath:\\s/", " path: /docs/reference/kotlin/")); |
| 122 | + }); |
| 123 | + cfg.filesMatching( |
| 124 | + "**/*.html", |
| 125 | + fileCopy -> |
| 126 | + fileCopy.filter( |
| 127 | + line -> line.replaceAll("https://firebase.google.com", ""))); |
125 | 128 | });
|
126 |
| - cfg.filesMatching( |
127 |
| - "**/*.html", |
128 |
| - fileCopy -> |
129 |
| - fileCopy.filter( |
130 |
| - line -> line.replaceAll("https://firebase.google.com", ""))); |
131 | 129 | });
|
132 |
| - }); |
| 130 | + }); |
| 131 | + } |
| 132 | + |
| 133 | + private static FileCollection getJars(Configuration configuration) { |
| 134 | + return configuration |
| 135 | + .getIncoming() |
| 136 | + .artifactView( |
| 137 | + view -> { |
| 138 | + view.attributes( |
| 139 | + attrs -> attrs.attribute(Attribute.of("artifactType", String.class), "jar")); |
| 140 | + view.componentFilter( |
| 141 | + c -> !c.getDisplayName().startsWith("androidx.annotation:annotation:")); |
| 142 | + }) |
| 143 | + .getArtifacts() |
| 144 | + .getArtifactFiles(); |
133 | 145 | }
|
134 | 146 |
|
135 | 147 | static <T extends DokkaTask> T configure(Project project, Class<T> taskType) {
|
|
0 commit comments