<commit_before>package org.jetbrains.dokka.gradle

import com.android.build.gradle.AppExtension
import com.android.build.gradle.LibraryExtension
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> {
    override fun apply(project: Project) {
        project.tasks.create("dokka", DokkaAndroidTask::class.java).apply {
            moduleName = project.name
            outputDirectory = File(project.buildDir, "dokka").absolutePath
        }
    }
}

open class DokkaAndroidTask : DokkaTask() {
    override val sdkProvider: SdkProvider? = AndroidSdkProvider(project)
}

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.plugins.hasPlugin("com.android.library") || project.plugins.hasPlugin("com.android.application")

    override val classpath: List<File>
        get() = ext.bootClasspath

    override val sourceDirs: Set<File>?
        get() {
            val sourceSet = ext?.sourceSets?.findByName(SourceSet.MAIN_SOURCE_SET_NAME)
            return sourceSet?.java?.srcDirs
        }
}<commit_msg>Correctly include dependencies in classpath of Dokka Android build. Resolves #78<commit_after>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
        }
}
{'fraction_non_alphanumeric': 0.10066453359586512, 'fraction_numerical': 0.0004922471080482402, 'mean_word_length': 3.341880341880342, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '409973', 'n_tokens_mistral': 1160, 'n_tokens_neox': 1126, 'n_words': 215}