Skip to content

Commit 580e8d5

Browse files
committed
[Build] Updated build to use Dackka for documentation generation
PiperOrigin-RevId: 730522331
1 parent c39dc38 commit 580e8d5

File tree

5 files changed

+168
-69
lines changed

5 files changed

+168
-69
lines changed

lib/build.gradle

Lines changed: 149 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import org.gradle.internal.os.OperatingSystem
1+
import javax.inject.Inject
22

33
apply plugin: 'com.android.library'
44
apply plugin: 'maven-publish'
@@ -128,73 +128,6 @@ android {
128128
}
129129
}
130130

131-
task generateJavadocs(type: Javadoc) {
132-
if (project.hasProperty("online")) {
133-
options.addStringOption("toroot", "/")
134-
options.addStringOption("hdf", "android.whichdoc online")
135-
options.addStringOption("hdf", "dac")
136-
options.addBooleanOption("devsite", true)
137-
options.addBooleanOption("yamlV2", true)
138-
options.addStringOption("dac_libraryroot", "com/google/android/material")
139-
options.addStringOption("dac_dataname", "MATERIAL_DATA")
140-
}
141-
142-
if (project.hasProperty("docletPathRoot")) {
143-
def docletPathRoot = project.property("docletPathRoot")
144-
def outputPath = project.hasProperty("outputPath") ? project.property("outputPath") : "doclava-out"
145-
def doclavaJar = project.getProperty("doclavaJar")
146-
147-
source = android.sourceSets.main.java.source
148-
source = source.findAll { it.name.endsWith(".java") }
149-
150-
title = null
151-
destinationDir = new File(outputPath)
152-
classpath = files("${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar")
153-
options.addStringOption("federate Android", "https://developer.android.com")
154-
options.encoding = "UTF-8"
155-
options.doclet = "com.google.doclava.Doclava"
156-
options.docletpath = [
157-
file(doclavaJar),
158-
file(docletPathRoot + "/jsilver/v1_0_0/jsilver.jar")
159-
]
160-
}
161-
}
162-
163-
task getVersion {
164-
doLast {
165-
println version
166-
}
167-
}
168-
169-
def R_CLASS_PATH = "build/generated/not_namespaced_r_class_sources/releaseUnitTest/processReleaseUnitTestResources/r/com/google/android/material/R.java"
170-
Attribute<String> ARTIFACT_TYPE = Attribute.of("artifactType", String.class)
171-
afterEvaluate {
172-
[generateJavadocs].forEach { task ->
173-
task.dependsOn(':lib:processReleaseUnitTestResources')
174-
task.source += R_CLASS_PATH
175-
176-
def releaseVariant = android.libraryVariants.find { it.name == 'release' }
177-
if (releaseVariant == null) {
178-
return
179-
}
180-
181-
// Add transitive runtime dependencies to classpath
182-
task.classpath += releaseVariant.runtimeConfiguration.incoming.artifactView { aView ->
183-
aView.attributes.attribute(ARTIFACT_TYPE, "android-classes")
184-
}.files
185-
186-
// Add project and compile dependencies to classpath
187-
releaseVariant.javaCompileProvider.configure { javaCompileProvider ->
188-
task.classpath += releaseVariant.getCompileClasspath(null)
189-
task.classpath += task.project.files(javaCompileProvider.destinationDir)
190-
task.source += javaCompileProvider.source
191-
}
192-
193-
// Doclava does not understand -notimestamp option that is default since Gradle 6.0
194-
task.options.setNoTimestamp(false)
195-
}
196-
}
197-
198131
task androidSourcesJar(type: Jar) {
199132
archiveClassifier.set('sources')
200133
from(android.sourceSets.main.java.srcDirs) {
@@ -250,3 +183,151 @@ afterEvaluate {
250183
}
251184
}
252185
}
186+
187+
/**
188+
* Generate library documentation.
189+
*
190+
* This task requires a Dackka jar to be run. This can be passed to the task
191+
* by running the task from the command line and setting the --dackkaJar
192+
* option.
193+
*
194+
* Example: ./gradlew generateDocumentation --dackkaJar="<path/to/dackka.jar>"
195+
*
196+
* The resulting documentation will be placed in `lib/build/docs` and contain
197+
* documentation for both java and kotlin clients.
198+
*
199+
* TODO: b/149338266 - Dackka does not support links to resources in documentation.
200+
* TODO: b/396171398 - inheritDoc results hav formatting issues with Dackka.
201+
*/
202+
tasks.register("generateDocumentation", DackkaRunner) {
203+
group = "Publishing"
204+
description = "Generate javadocs using dackka"
205+
version = mdcLibraryVersion
206+
config = layout.buildDirectory.file("resources/dackka_config.json").get().asFile
207+
outputDirectory = layout.buildDirectory.dir("docs").get()
208+
// Add all the files from the main source set to be documented by dackka
209+
sourceDirectories.setFrom(
210+
android.sourceSets.main.java.srcDirs.absolutePath
211+
)
212+
dependenciesClasspath.setFrom(
213+
files("${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar"),
214+
)
215+
}
216+
217+
/**
218+
* A task that uses Dackka to generate javadoc.
219+
*/
220+
abstract class DackkaRunner extends DefaultTask {
221+
222+
private String dackkaJar;
223+
224+
/**
225+
* Set the path to the Dackka jar to use by setting the --dackkaJar command
226+
* line argument when running the gradle task used by this task.
227+
*
228+
* @param path the path to the dackka jar
229+
*/
230+
@Option(option = "dackkaJar", description = "path to daccka jar")
231+
void setDackkaJar(String path) {
232+
this.dackkaJar = path
233+
}
234+
235+
@Input
236+
String getDackkaJar() {
237+
return dackkaJar;
238+
}
239+
240+
/**
241+
* The Material library version of these docs.
242+
*
243+
* This should most likely match mdcLibraryVersion from the projects build
244+
* file.
245+
*/
246+
@Input
247+
String version;
248+
249+
/** Source directories to be documented. */
250+
@InputFiles
251+
final ConfigurableFileCollection sourceDirectories = project.files()
252+
253+
@InputFiles
254+
final ConfigurableFileCollection dependenciesClasspath = project.files();
255+
256+
/** A file that should be populated with the Dackka configuration. */
257+
@OutputFile
258+
abstract File config;
259+
260+
/** The output containing documentation generated by Dackka. */
261+
@OutputDirectory
262+
abstract Directory outputDirectory;
263+
264+
@Inject
265+
abstract ExecOperations getExecOperations()
266+
267+
@TaskAction
268+
void run() {
269+
// Delete any previously generated documentation
270+
outputDirectory.asFile.deleteDir()
271+
// Populate the Dackka config json file with Material-specific properties
272+
writeDackkaConfig()
273+
// Run the Dackka jar and generate docs
274+
getExecOperations().javaexec {
275+
classpath(dackkaJar)
276+
args(config.absolutePath)
277+
}
278+
}
279+
280+
/** Populate the Dackka config file with project specific values. */
281+
private void writeDackkaConfig() {
282+
def configContents = """
283+
{
284+
"modeuleName": "Material Components",
285+
"moduleVersion": "$version",
286+
"outputDir": "${outputDirectory.asFile.absolutePath}",
287+
"offlineMode": "true",
288+
"noJdkLink": "true",
289+
"sourceSets": [
290+
{
291+
"moduleDisplayName": "lib",
292+
"analysisPlatform": "jvm",
293+
"externalDocumentationLinks": [],
294+
"sourceSetID": {
295+
"scopeId": "com",
296+
"sourceSetName": "main"
297+
},
298+
"sourceRoots": [${sourceDirectories.collect { '"' + it.absolutePath + '"' }.join(", ")}],
299+
"samples": [],
300+
"includes": [],
301+
"classpath": [${dependenciesClasspath.collect { '"' + it.absolutePath + '"'}.join(", ")}],
302+
"sourceLinks": [],
303+
"documentedVisibilities": ["PUBLIC", "PROTECTED"]
304+
}
305+
],
306+
"pluginsConfiguration": [
307+
{
308+
"fqPluginName": "com.google.devsite.DevsitePlugin",
309+
"serializationFormat": "JSON",
310+
"values": "${getDevsitePluginConfigValues()}"
311+
}
312+
]
313+
}
314+
""".trim();
315+
316+
config.write(configContents)
317+
}
318+
319+
/** Returns the Dackka Devsite plugin configuration json string. */
320+
private String getDevsitePluginConfigValues() {
321+
return """
322+
{
323+
"docRootPath": "reference",
324+
"projectPath": "com/google/android/material",
325+
"excludedPackages": [ ".*excluded.*" ],
326+
"javaDocsPath": "",
327+
"kotlinDocsPath": "kotlin",
328+
"baseSourceLink": "https://github.com/material-components/material-components-android/blob/${version}/lib/java/%s",
329+
"annotationsNotToDisplay": [ "java.lang.Override", "kotlin.ParameterName" ]
330+
}
331+
""".trim().replace("\n", "").replace('"', '\\\"')
332+
}
333+
}

lib/java/com/google/android/material/carousel/MaskableFrameLayout.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,12 @@ public RectF getMaskRectF() {
182182
return maskRect;
183183
}
184184

185+
/**
186+
* Sets an {@link OnMaskChangedListener}.
187+
*
188+
* @param onMaskChangedListener a listener to receive callbacks for changes in the mask or null
189+
* to clear the listener.
190+
*/
185191
@Override
186192
public void setOnMaskChangedListener(@Nullable OnMaskChangedListener onMaskChangedListener) {
187193
this.onMaskChangedListener = onMaskChangedListener;

lib/java/com/google/android/material/snackbar/BaseTransientBottomBar.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,6 +1376,12 @@ private void setBaseTransientBottomBar(
13761376
delegate.setBaseTransientBottomBar(baseTransientBottomBar);
13771377
}
13781378

1379+
/**
1380+
* Called when the user's input indicates that they want to swipe the given view.
1381+
*
1382+
* @param child View the user is attempting to swipe
1383+
* @return true if the view can be dismissed via swiping, false otherwise
1384+
*/
13791385
@Override
13801386
public boolean canSwipeDismissView(View child) {
13811387
return delegate.canSwipeDismissView(child);

lib/java/com/google/android/material/snackbar/Snackbar.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,12 @@ public static class Callback extends BaseCallback<Snackbar> {
9797
/** Indicates that the Snackbar was dismissed from a new Snackbar being shown. */
9898
public static final int DISMISS_EVENT_CONSECUTIVE = BaseCallback.DISMISS_EVENT_CONSECUTIVE;
9999

100+
/**
101+
* Called when the given {@link Snackbar} is visible.
102+
*
103+
* @param sb The snackbar which is now visible.
104+
* @see Snackbar#show()
105+
*/
100106
@Override
101107
public void onShown(Snackbar sb) {
102108
// Stub implementation to make API check happy.

lib/java/com/google/android/material/tabs/TabLayout.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2193,7 +2193,7 @@ public Tab setTag(@Nullable Object tag) {
21932193
*
21942194
* <p>Do not rely on this if using {@link TabLayout#setupWithViewPager(ViewPager)}
21952195
*
2196-
* @param id, unique id for this tab
2196+
* @param id unique id for this tab
21972197
*/
21982198
@NonNull
21992199
@CanIgnoreReturnValue

0 commit comments

Comments
 (0)