diff options
author | Simon Ogorodnik <sem-oro@yandex.ru> | 2016-11-01 02:10:32 +0300 |
---|---|---|
committer | Simon Ogorodnik <Simon.Ogorodnik@jetbrains.com> | 2016-11-01 14:46:01 +0300 |
commit | 769701f99a1aefbc9d385c1938c9c7d3a7b2e38e (patch) | |
tree | c3ea4802d9e627c90870808aba9343eb224a114c /runners/android-gradle-plugin | |
parent | 08bcaa257f7b48929af6ee29007dd6f0d7bb1b52 (diff) | |
download | dokka-769701f99a1aefbc9d385c1938c9c7d3a7b2e38e.tar.gz dokka-769701f99a1aefbc9d385c1938c9c7d3a7b2e38e.tar.bz2 dokka-769701f99a1aefbc9d385c1938c9c7d3a7b2e38e.zip |
Total build refactoring, prepare for new development iteration
Removed old and useless build helpers
Remove old .xml's from .idea and add .idea/shelf to .gitignore
build-docs.xml fixed, dokka_version set to 0.9.10
Diffstat (limited to 'runners/android-gradle-plugin')
3 files changed, 134 insertions, 0 deletions
diff --git a/runners/android-gradle-plugin/build.gradle b/runners/android-gradle-plugin/build.gradle new file mode 100644 index 00000000..dd6f2e3d --- /dev/null +++ b/runners/android-gradle-plugin/build.gradle @@ -0,0 +1,57 @@ +apply plugin: 'java' + +sourceCompatibility = 1.6 + +task wrapper(type: Wrapper) { + gradleVersion = '2.5' + distributionUrl = "https://services.gradle.org/distributions/gradle-$gradleVersion-all.zip" +} + +apply plugin: 'com.github.johnrengelman.shadow' + +configurations { + provided +} + +tasks.withType(AbstractCompile) { + classpath += configurations.provided + classpath += configurations.shadow +} + +dependencies { + testCompile group: 'junit', name: 'junit', version: '4.12' + shadow project(':runners:fatjar') + shadow project(':runners:gradle-plugin') + + provided gradleApi() + provided localGroovy() + + shadow 'com.android.tools.build:gradle:2.0.0' +} + +task sourceJar(type: Jar) { + from sourceSets.main.allSource +} + +shadowJar { + baseName = 'dokka-android-gradle-plugin' + classifier = '' + relocate('kotlin.', 'dokkakotlin.') +} + +apply plugin: 'maven-publish' + +publishing { + publications { + dokkaAndroidGradlePlugin(MavenPublication) { + from components.shadow + artifactId = 'dokka-android-gradle-plugin' + + artifact sourceJar { + classifier "sources" + } + } + } +} + +bintrayPublication(project, ['dokkaAndroidGradlePlugin'])
\ No newline at end of file diff --git a/runners/android-gradle-plugin/src/main/kotlin/main.kt b/runners/android-gradle-plugin/src/main/kotlin/main.kt new file mode 100644 index 00000000..054ed358 --- /dev/null +++ b/runners/android-gradle-plugin/src/main/kotlin/main.kt @@ -0,0 +1,76 @@ +package org.jetbrains.dokka.gradle + +import com.android.build.gradle.AppExtension +import com.android.build.gradle.LibraryExtension +import com.android.build.gradle.api.BaseVariant +import org.gradle.api.Plugin +import org.gradle.api.Project +import org.gradle.api.tasks.SourceSet +import java.io.File + +open class DokkaAndroidPlugin : Plugin<Project> { + val allVariantsClassPath = mutableSetOf<File>() + + override fun apply(project: Project) { + project.tasks.create("dokka", DokkaAndroidTask::class.java).apply { + moduleName = project.name + outputDirectory = File(project.buildDir, "dokka").absolutePath + } + + if (project.hasAndroidPlugin()) { + project.afterEvaluate { + collectClasspath(project) + } + } + else { + project.plugins.whenPluginAdded { + if (project.hasAndroidPlugin()) { + collectClasspath(project) + } + } + } + } + + private fun collectClasspath(project: Project) { + val variants = project.collectAllVariants() + variants.flatMapTo(allVariantsClassPath) { it.javaCompiler.classpath.files } + } +} + +open class DokkaAndroidTask : DokkaTask() { + override val sdkProvider: SdkProvider? = AndroidSdkProvider(project) +} + +private fun Project.hasAndroidPlugin() = plugins.hasPlugin("com.android.library") || plugins.hasPlugin("com.android.application") + +private fun Project.findDokkaAndroidPlugin() = plugins.findPlugin(DokkaAndroidPlugin::class.java) + +private fun Project.collectAllVariants(): Collection<BaseVariant> { + extensions.findByType(LibraryExtension::class.java)?.let { + return it.libraryVariants + } + extensions.findByType(AppExtension::class.java)?.let { + return it.applicationVariants + } + return emptyList() +} + +private class AndroidSdkProvider(private val project: Project) : SdkProvider { + private val ext by lazy { + project.extensions.findByType(LibraryExtension::class.java) ?: project.extensions.findByType(AppExtension::class.java) + } + + override val name: String = "android" + + override val isValid: Boolean + get() = project.hasAndroidPlugin() + + override val classpath: List<File> + get() = ext.bootClasspath + (project.findDokkaAndroidPlugin()?.allVariantsClassPath ?: emptyList<File>()) + + override val sourceDirs: Set<File>? + get() { + val sourceSet = ext?.sourceSets?.findByName(SourceSet.MAIN_SOURCE_SET_NAME) + return sourceSet?.java?.srcDirs + } +} diff --git a/runners/android-gradle-plugin/src/main/resources/META-INF/gradle-plugins/org.jetbrains.dokka-android.properties b/runners/android-gradle-plugin/src/main/resources/META-INF/gradle-plugins/org.jetbrains.dokka-android.properties new file mode 100644 index 00000000..03b28d93 --- /dev/null +++ b/runners/android-gradle-plugin/src/main/resources/META-INF/gradle-plugins/org.jetbrains.dokka-android.properties @@ -0,0 +1 @@ +implementation-class=org.jetbrains.dokka.gradle.DokkaAndroidPlugin
\ No newline at end of file |