• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright (C) 2017 The Android Open Source Project
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.
14apply from: "${buildscript.sourceFile.parentFile}/javadoc_util.gradle"
15
16class CombinedJavadocPlugin implements Plugin<Project> {
17
18  static final String TASK_NAME = "generateCombinedJavadoc"
19
20  @Override
21  void apply(Project project) {
22    project.gradle.projectsEvaluated {
23      Set<Project> libraryModules = getLibraryModules(project)
24      if (!libraryModules.isEmpty()) {
25        project.task(TASK_NAME, type: Javadoc) {
26          description = "Generates combined Javadoc."
27          title = "ExoPlayer library"
28          source = libraryModules.generateJavadoc.source
29          classpath = project.files([])
30          destinationDir = project.file("$project.buildDir/docs/javadoc")
31          options {
32            links "https://developer.android.com/reference"
33            encoding = "UTF-8"
34          }
35          exclude "**/BuildConfig.java"
36          exclude "**/R.java"
37          doFirst {
38            libraryModules.each { libraryModule ->
39              libraryModule.android.libraryVariants.all { variant ->
40                def name = variant.buildType.name
41                if (name == "release") {
42                  classpath +=
43                      libraryModule.project.files(
44                          variant.javaCompileProvider.get().classpath.files,
45                          libraryModule.project.android.getBootClasspath())
46                }
47              }
48            }
49          }
50          doLast {
51            libraryModules.each { libraryModule ->
52              project.copy {
53                from "${libraryModule.projectDir}/src/main/javadoc"
54                into "${project.buildDir}/docs/javadoc"
55              }
56            }
57            project.fixJavadoc()
58          }
59        }
60      }
61    }
62  }
63
64  // Returns Android library modules that declare a generateJavadoc task.
65  private static Set<Project> getLibraryModules(Project project) {
66    project.subprojects.findAll {
67      it.plugins.findPlugin("com.android.library") &&
68      it.tasks.findByName("generateJavadoc")
69    }
70  }
71
72}
73
74apply plugin: CombinedJavadocPlugin
75