diff options
author | Dmitry Jemerov <intelliyole@gmail.com> | 2016-03-31 16:15:35 +0200 |
---|---|---|
committer | Dmitry Jemerov <intelliyole@gmail.com> | 2016-03-31 16:15:35 +0200 |
commit | 3ed824ed77e87b09fc997189b74f1201e6e03b14 (patch) | |
tree | d2ec3d9a0889079bbf82b8ad82ea31dd69f59915 /dokka-gradle-plugin/src/main/kotlin/main.kt | |
parent | 6051ab5051be76d6c830a9996901bfbb9e1f901e (diff) | |
parent | 908aa606ea7c46346b590aaee79dd6cc1851e36d (diff) | |
download | dokka-3ed824ed77e87b09fc997189b74f1201e6e03b14.tar.gz dokka-3ed824ed77e87b09fc997189b74f1201e6e03b14.tar.bz2 dokka-3ed824ed77e87b09fc997189b74f1201e6e03b14.zip |
Merge pull request #64 from porokoro/android-and-custom-sources
Android support and custom sources
Diffstat (limited to 'dokka-gradle-plugin/src/main/kotlin/main.kt')
-rw-r--r-- | dokka-gradle-plugin/src/main/kotlin/main.kt | 75 |
1 files changed, 64 insertions, 11 deletions
diff --git a/dokka-gradle-plugin/src/main/kotlin/main.kt b/dokka-gradle-plugin/src/main/kotlin/main.kt index 476f7656..e3275501 100644 --- a/dokka-gradle-plugin/src/main/kotlin/main.kt +++ b/dokka-gradle-plugin/src/main/kotlin/main.kt @@ -44,6 +44,10 @@ open class DokkaTask : DefaultTask() { var samples: List<Any?> = arrayListOf() @Input var jdkVersion: Int = 6 + @Input + var sourceDirs: Iterable<File> = emptyList() + + protected open val sdkProvider: SdkProvider? = null fun linkMapping(closure: Closure<Any?>) { val mapping = LinkMapping() @@ -63,13 +67,15 @@ open class DokkaTask : DefaultTask() { @TaskAction fun generate() { val project = project + val sdkProvider = sdkProvider val sourceDirectories = getSourceDirectories() val allConfigurations = project.configurations val classpath = - processConfigurations - .map { allConfigurations?.getByName(it.toString()) ?: throw IllegalArgumentException("No configuration $it found") } - .flatMap { it } + if (sdkProvider != null && sdkProvider.isValid) sdkProvider.classpath else emptyList<File>() + + processConfigurations + .map { allConfigurations?.getByName(it.toString()) ?: throw IllegalArgumentException("No configuration $it found") } + .flatMap { it } if (sourceDirectories.isEmpty()) { logger.warn("No source directories found: skipping dokka generation") @@ -89,20 +95,33 @@ open class DokkaTask : DefaultTask() { ).generate() } - fun getSourceDirectories(): List<File> { - val javaPluginConvention = project.convention.getPlugin(JavaPluginConvention::class.java) - val sourceSets = javaPluginConvention.sourceSets?.findByName(SourceSet.MAIN_SOURCE_SET_NAME) - return sourceSets?.allSource?.srcDirs?.filter { it.exists() } ?: emptyList() + fun getSourceDirectories(): Collection<File> { + val provider = sdkProvider + val sourceDirs = if (sourceDirs.any()) { + logger.info("Dokka: Taking source directories provided by the user") + sourceDirs.toSet() + } else if (provider != null && provider.isValid) { + logger.info("Dokka: Taking source directories from ${provider.name} sdk provider") + provider.sourceDirs + } else { + logger.info("Dokka: Taking source directories from default java plugin") + val javaPluginConvention = project.convention.getPlugin(JavaPluginConvention::class.java) + val sourceSets = javaPluginConvention.sourceSets?.findByName(SourceSet.MAIN_SOURCE_SET_NAME) + sourceSets?.allSource?.srcDirs + } + + return sourceDirs?.filter { it.exists() } ?: emptyList() } + @Input @InputFiles @SkipWhenEmpty - fun getInputFiles() : FileCollection = project.files(getSourceDirectories().map { project.fileTree(it) }) + - project.files(includes) + - project.files(samples) + fun getInputFiles(): FileCollection = project.files(getSourceDirectories().map { project.fileTree(it) }) + + project.files(includes) + + project.files(samples) @OutputDirectory - fun getOutputDirectoryAsFile() : File = project.file(outputDirectory) + fun getOutputDirectoryAsFile(): File = project.file(outputDirectory) } @@ -111,3 +130,37 @@ open class LinkMapping { var url: String = "" var suffix: String? = null } + +/** + * A provider for SDKs that can be used if a project uses classes that live outside the JDK or uses a + * different method to determine the source directories. + * + * For example an Android library project configures its sources through the Android extension instead + * of the basic java convention. Also it has its custom classes located in the SDK installation directory. + */ +interface SdkProvider { + /** + * The name of this provider. Only used for logging purposes. + */ + val name: String + + /** + * Checks whether this provider has everything it needs to provide the source directories. + */ + val isValid: Boolean + + /** + * Provides additional classpath files where Dokka should search for external classes. + * The file list is injected **after** JDK Jars and **before** project dependencies. + * + * This is only called if [isValid] returns `true`. + */ + val classpath: List<File> + + /** + * Provides a list of directories where Dokka should search for source files. + * + * This is only called if [isValid] returns `true`. + */ + val sourceDirs: Set<File>? +} |