Refactoring: specify internal visibility where possible

This commit is contained in:
Alexey Tsvetkov
2016-09-23 23:34:08 +03:00
parent 617bc6c296
commit 8cc384a6dd
26 changed files with 70 additions and 71 deletions
@@ -34,14 +34,13 @@ interface AdditionalGradleProperties {
} }
fun main(args: Array<String>) { fun main(args: Array<String>) {
val dslSrcDir = File("libraries/tools/kotlin-gradle-plugin-dsl/src/main/kotlin") val srcDir = File("libraries/tools/kotlin-gradle-plugin/src/main/kotlin")
val dslImplDir = File("libraries/tools/kotlin-gradle-plugin-core/src/main/kotlin")
val additionalGradleOptions = gradleOptions<AdditionalGradleProperties>() val additionalGradleOptions = gradleOptions<AdditionalGradleProperties>()
// generate jvm interface // generate jvm interface
val jvmInterfaceFqName = FqName("org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions") val jvmInterfaceFqName = FqName("org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions")
val optionsFromK2JVMCompilerArguments = gradleOptions<K2JVMCompilerArguments>() val optionsFromK2JVMCompilerArguments = gradleOptions<K2JVMCompilerArguments>()
File(dslSrcDir, jvmInterfaceFqName).usePrinter { File(srcDir, jvmInterfaceFqName).usePrinter {
generateInterface(jvmInterfaceFqName, generateInterface(jvmInterfaceFqName,
optionsFromK2JVMCompilerArguments + additionalGradleOptions) optionsFromK2JVMCompilerArguments + additionalGradleOptions)
} }
@@ -49,7 +48,7 @@ fun main(args: Array<String>) {
// generate jvm impl // generate jvm impl
val k2JvmCompilerArgumentsFqName = FqName(K2JVMCompilerArguments::class.qualifiedName!!) val k2JvmCompilerArgumentsFqName = FqName(K2JVMCompilerArguments::class.qualifiedName!!)
val jvmImplFqName = FqName("org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptionsBase") val jvmImplFqName = FqName("org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptionsBase")
File(dslImplDir, jvmImplFqName).usePrinter { File(srcDir, jvmImplFqName).usePrinter {
generateImpl(jvmImplFqName, generateImpl(jvmImplFqName,
jvmInterfaceFqName, jvmInterfaceFqName,
k2JvmCompilerArgumentsFqName, k2JvmCompilerArgumentsFqName,
@@ -59,7 +58,7 @@ fun main(args: Array<String>) {
// generate js interface // generate js interface
val jsInterfaceFqName = FqName("org.jetbrains.kotlin.gradle.dsl.KotlinJsOptions") val jsInterfaceFqName = FqName("org.jetbrains.kotlin.gradle.dsl.KotlinJsOptions")
val optionsFromK2JSCompilerArguments = gradleOptions<K2JSCompilerArguments>() val optionsFromK2JSCompilerArguments = gradleOptions<K2JSCompilerArguments>()
File(dslSrcDir, jsInterfaceFqName).usePrinter { File(srcDir, jsInterfaceFqName).usePrinter {
generateInterface(jsInterfaceFqName, generateInterface(jsInterfaceFqName,
optionsFromK2JSCompilerArguments + optionsFromK2JSCompilerArguments +
additionalGradleOptions) additionalGradleOptions)
@@ -67,7 +66,7 @@ fun main(args: Array<String>) {
val k2JsCompilerArgumentsFqName = FqName(K2JSCompilerArguments::class.qualifiedName!!) val k2JsCompilerArgumentsFqName = FqName(K2JSCompilerArguments::class.qualifiedName!!)
val jsImplFqName = FqName("org.jetbrains.kotlin.gradle.dsl.KotlinJsOptionsBase") val jsImplFqName = FqName("org.jetbrains.kotlin.gradle.dsl.KotlinJsOptionsBase")
File(dslImplDir, jsImplFqName).usePrinter { File(srcDir, jsImplFqName).usePrinter {
generateImpl(jsImplFqName, generateImpl(jsImplFqName,
jsInterfaceFqName, jsInterfaceFqName,
k2JsCompilerArgumentsFqName, k2JsCompilerArgumentsFqName,
@@ -110,7 +109,7 @@ private fun Printer.generateImpl(
argsType: FqName, argsType: FqName,
properties: List<KProperty1<*, *>> properties: List<KProperty1<*, *>>
) { ) {
generateDeclaration("abstract class", type, afterType = ": $parentType") { generateDeclaration("internal abstract class", type, afterType = ": $parentType") {
fun KProperty1<*, *>.backingField(): String = "${this.name}Field" fun KProperty1<*, *>.backingField(): String = "${this.name}Field"
for (property in properties) { for (property in properties) {
@@ -137,7 +136,7 @@ private fun Printer.generateImpl(
} }
println() println()
println("fun $argsType.fillDefaultValues() {") println("internal fun $argsType.fillDefaultValues() {")
withIndent { withIndent {
for (property in properties) { for (property in properties) {
println("${property.name} = ${property.gradleDefaultValue}") println("${property.name} = ${property.gradleDefaultValue}")
@@ -18,7 +18,7 @@ import java.util.*
* 2.1 remove classes corresponding to dirty source files * 2.1 remove classes corresponding to dirty source files
* 2.2 add annotations from newly generated annotations file * 2.2 add annotations from newly generated annotations file
*/ */
class AnnotationFileUpdater(private val generatedAnnotationFile: File) { internal class AnnotationFileUpdater(private val generatedAnnotationFile: File) {
private val logger = Logging.getLogger(this.javaClass) private val logger = Logging.getLogger(this.javaClass)
private val lastSuccessfullyUpdatedFile = File.createTempFile("kapt-annotations-copy", "tmp") private val lastSuccessfullyUpdatedFile = File.createTempFile("kapt-annotations-copy", "tmp")
@@ -4,7 +4,7 @@ import org.jetbrains.kotlin.incremental.components.SourceRetentionAnnotationHand
import java.io.* import java.io.*
import java.util.* import java.util.*
class SourceAnnotationsRegistry(private val file: File) : SourceRetentionAnnotationHandler { internal class SourceAnnotationsRegistry(private val file: File) : SourceRetentionAnnotationHandler {
private val mutableAnnotations: MutableSet<String> by lazy { readAnnotations() } private val mutableAnnotations: MutableSet<String> by lazy { readAnnotations() }
val annotations: Set<String> val annotations: Set<String>
get() = mutableAnnotations get() = mutableAnnotations
@@ -4,7 +4,7 @@ import org.jetbrains.org.objectweb.asm.*
import java.io.File import java.io.File
import java.util.* import java.util.*
class AnnotationsRemover(annotations: Iterable<String>) { internal class AnnotationsRemover(annotations: Iterable<String>) {
private val annotations = annotations.mapTo(HashSet()) { "L$it;" } private val annotations = annotations.mapTo(HashSet()) { "L$it;" }
fun transformClassFile(inputFile: File, outputFile: File) { fun transformClassFile(inputFile: File, outputFile: File) {
@@ -2,7 +2,7 @@
// Generated by org/jetbrains/kotlin/generators/arguments/GenerateGradleOptions.kt // Generated by org/jetbrains/kotlin/generators/arguments/GenerateGradleOptions.kt
package org.jetbrains.kotlin.gradle.dsl package org.jetbrains.kotlin.gradle.dsl
abstract class KotlinJsOptionsBase : org.jetbrains.kotlin.gradle.dsl.KotlinJsOptions { internal abstract class KotlinJsOptionsBase : org.jetbrains.kotlin.gradle.dsl.KotlinJsOptions {
private var kjsmField: kotlin.Boolean? = null private var kjsmField: kotlin.Boolean? = null
override var kjsm: kotlin.Boolean override var kjsm: kotlin.Boolean
@@ -74,7 +74,7 @@ abstract class KotlinJsOptionsBase : org.jetbrains.kotlin.gradle.dsl.KotlinJsOpt
} }
} }
fun org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments.fillDefaultValues() { internal fun org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments.fillDefaultValues() {
kjsm = true kjsm = true
languageVersion = "1.0" languageVersion = "1.0"
main = "noCall" main = "noCall"
@@ -3,7 +3,7 @@ package org.jetbrains.kotlin.gradle.dsl
import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments
import org.jetbrains.kotlin.cli.js.K2JSCompiler import org.jetbrains.kotlin.cli.js.K2JSCompiler
class KotlinJsOptionsImpl() : KotlinJsOptionsBase() { internal class KotlinJsOptionsImpl() : KotlinJsOptionsBase() {
override var freeCompilerArgs: List<String> = listOf() override var freeCompilerArgs: List<String> = listOf()
override fun updateArguments(args: K2JSCompilerArguments) { override fun updateArguments(args: K2JSCompilerArguments) {
@@ -2,7 +2,7 @@
// Generated by org/jetbrains/kotlin/generators/arguments/GenerateGradleOptions.kt // Generated by org/jetbrains/kotlin/generators/arguments/GenerateGradleOptions.kt
package org.jetbrains.kotlin.gradle.dsl package org.jetbrains.kotlin.gradle.dsl
abstract class KotlinJvmOptionsBase : org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions { internal abstract class KotlinJvmOptionsBase : org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions {
private var includeRuntimeField: kotlin.Boolean? = null private var includeRuntimeField: kotlin.Boolean? = null
override var includeRuntime: kotlin.Boolean override var includeRuntime: kotlin.Boolean
@@ -62,7 +62,7 @@ abstract class KotlinJvmOptionsBase : org.jetbrains.kotlin.gradle.dsl.KotlinJvmO
} }
} }
fun org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments.fillDefaultValues() { internal fun org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments.fillDefaultValues() {
includeRuntime = false includeRuntime = false
jdkHome = null jdkHome = null
jvmTarget = "1.6" jvmTarget = "1.6"
@@ -3,7 +3,7 @@ package org.jetbrains.kotlin.gradle.dsl
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler
open class KotlinJvmOptionsImpl : KotlinJvmOptionsBase() { internal class KotlinJvmOptionsImpl : KotlinJvmOptionsBase() {
override var freeCompilerArgs: List<String> = listOf() override var freeCompilerArgs: List<String> = listOf()
override fun updateArguments(args: K2JVMCompilerArguments) { override fun updateArguments(args: K2JVMCompilerArguments) {
@@ -40,7 +40,7 @@ import java.io.IOException
import java.util.* import java.util.*
import java.util.zip.ZipFile import java.util.zip.ZipFile
fun Project.initKapt( internal fun Project.initKapt(
kotlinTask: KotlinCompile, kotlinTask: KotlinCompile,
javaTask: AbstractCompile, javaTask: AbstractCompile,
kaptManager: AnnotationProcessingManager, kaptManager: AnnotationProcessingManager,
@@ -40,7 +40,7 @@ private fun comparableVersionStr(version: String) =
?.let { if (it.all { (it?.value?.length ?: 0).let { it > 0 && it < 4 }}) it else null } ?.let { if (it.all { (it?.value?.length ?: 0).let { it > 0 && it < 4 }}) it else null }
?.joinToString(".", transform = { it!!.value.padStart(3, '0') }) ?.joinToString(".", transform = { it!!.value.padStart(3, '0') })
class KotlinGradleBuildServices private constructor(gradle: Gradle): BuildAdapter() { internal class KotlinGradleBuildServices private constructor(gradle: Gradle): BuildAdapter() {
companion object { companion object {
private val CLASS_NAME = KotlinGradleBuildServices::class.java.simpleName private val CLASS_NAME = KotlinGradleBuildServices::class.java.simpleName
const val FORCE_SYSTEM_GC_MESSAGE = "Forcing System.gc()" const val FORCE_SYSTEM_GC_MESSAGE = "Forcing System.gc()"
@@ -133,7 +133,7 @@ class KotlinGradleBuildServices private constructor(gradle: Gradle): BuildAdapte
} }
class CompilerServicesCleanup() { internal class CompilerServicesCleanup() {
private val log = Logging.getLogger(this.javaClass) private val log = Logging.getLogger(this.javaClass)
operator fun invoke(gradleVersion: String) { operator fun invoke(gradleVersion: String) {
@@ -38,7 +38,7 @@ val KOTLIN_DSL_NAME = "kotlin"
val KOTLIN_JS_DSL_NAME = "kotlin2js" val KOTLIN_JS_DSL_NAME = "kotlin2js"
val KOTLIN_OPTIONS_DSL_NAME = "kotlinOptions" val KOTLIN_OPTIONS_DSL_NAME = "kotlinOptions"
abstract class KotlinSourceSetProcessor<T : AbstractKotlinCompile<*>>( internal abstract class KotlinSourceSetProcessor<T : AbstractKotlinCompile<*>>(
val project: Project, val project: Project,
val javaBasePlugin: JavaBasePlugin, val javaBasePlugin: JavaBasePlugin,
val sourceSet: SourceSet, val sourceSet: SourceSet,
@@ -91,7 +91,7 @@ abstract class KotlinSourceSetProcessor<T : AbstractKotlinCompile<*>>(
protected abstract fun doCreateTask(project: Project, taskName: String): T protected abstract fun doCreateTask(project: Project, taskName: String): T
} }
class Kotlin2JvmSourceSetProcessor( internal class Kotlin2JvmSourceSetProcessor(
project: Project, project: Project,
javaBasePlugin: JavaBasePlugin, javaBasePlugin: JavaBasePlugin,
sourceSet: SourceSet, sourceSet: SourceSet,
@@ -166,7 +166,7 @@ class Kotlin2JvmSourceSetProcessor(
} }
} }
class Kotlin2JsSourceSetProcessor( internal class Kotlin2JsSourceSetProcessor(
project: Project, project: Project,
javaBasePlugin: JavaBasePlugin, javaBasePlugin: JavaBasePlugin,
sourceSet: SourceSet, sourceSet: SourceSet,
@@ -207,8 +207,12 @@ class Kotlin2JsSourceSetProcessor(
} }
abstract class AbstractKotlinPlugin(val tasksProvider: KotlinTasksProvider, val kotlinSourceSetProvider: KotlinSourceSetProvider, val kotlinPluginVersion: String) : Plugin<Project> { internal abstract class AbstractKotlinPlugin(
abstract fun buildSourceSetProcessor(project: Project, javaBasePlugin: JavaBasePlugin, sourceSet: SourceSet, kotlinPluginVersion: String): KotlinSourceSetProcessor<*> val tasksProvider: KotlinTasksProvider,
val kotlinSourceSetProvider: KotlinSourceSetProvider,
protected val kotlinPluginVersion: String
) : Plugin<Project> {
internal abstract fun buildSourceSetProcessor(project: Project, javaBasePlugin: JavaBasePlugin, sourceSet: SourceSet, kotlinPluginVersion: String): KotlinSourceSetProcessor<*>
override fun apply(project: Project) { override fun apply(project: Project) {
val javaBasePlugin = project.plugins.apply(JavaBasePlugin::class.java) val javaBasePlugin = project.plugins.apply(JavaBasePlugin::class.java)
@@ -230,8 +234,7 @@ abstract class AbstractKotlinPlugin(val tasksProvider: KotlinTasksProvider, val
} }
} }
internal open class KotlinPlugin(
open class KotlinPlugin(
tasksProvider: KotlinTasksProvider, tasksProvider: KotlinTasksProvider,
kotlinSourceSetProvider: KotlinSourceSetProvider, kotlinSourceSetProvider: KotlinSourceSetProvider,
kotlinPluginVersion: String, kotlinPluginVersion: String,
@@ -247,7 +250,7 @@ open class KotlinPlugin(
} }
open class Kotlin2JsPlugin( internal open class Kotlin2JsPlugin(
tasksProvider: KotlinTasksProvider, tasksProvider: KotlinTasksProvider,
kotlinSourceSetProvider: KotlinSourceSetProvider, kotlinSourceSetProvider: KotlinSourceSetProvider,
kotlinPluginVersion: String kotlinPluginVersion: String
@@ -256,7 +259,7 @@ open class Kotlin2JsPlugin(
Kotlin2JsSourceSetProcessor(project, javaBasePlugin, sourceSet, tasksProvider, kotlinSourceSetProvider) Kotlin2JsSourceSetProcessor(project, javaBasePlugin, sourceSet, tasksProvider, kotlinSourceSetProvider)
} }
open class KotlinAndroidPlugin( internal open class KotlinAndroidPlugin(
val tasksProvider: KotlinTasksProvider, val tasksProvider: KotlinTasksProvider,
private val kotlinSourceSetProvider: KotlinSourceSetProvider, private val kotlinSourceSetProvider: KotlinSourceSetProvider,
private val kotlinPluginVersion: String, private val kotlinPluginVersion: String,
@@ -509,7 +512,7 @@ private fun loadSubplugins(project: Project): SubpluginEnvironment {
} }
} }
class SubpluginEnvironment( internal class SubpluginEnvironment(
val subpluginClasspaths: Map<KotlinGradleSubplugin<KotlinCompile>, List<File>>, val subpluginClasspaths: Map<KotlinGradleSubplugin<KotlinCompile>, List<File>>,
val subplugins: List<KotlinGradleSubplugin<KotlinCompile>> val subplugins: List<KotlinGradleSubplugin<KotlinCompile>>
) { ) {
@@ -25,7 +25,7 @@ abstract class KotlinBasePluginWrapper(protected val fileResolver: FileResolver)
plugin.apply(project) plugin.apply(project)
} }
protected abstract fun getPlugin(kotlinGradleBuildServices: KotlinGradleBuildServices): Plugin<Project> internal abstract fun getPlugin(kotlinGradleBuildServices: KotlinGradleBuildServices): Plugin<Project>
} }
open class KotlinPluginWrapper @Inject constructor(fileResolver: FileResolver): KotlinBasePluginWrapper(fileResolver) { open class KotlinPluginWrapper @Inject constructor(fileResolver: FileResolver): KotlinBasePluginWrapper(fileResolver) {
@@ -1,5 +1,5 @@
package org.jetbrains.kotlin.gradle.plugin package org.jetbrains.kotlin.gradle.plugin
interface KotlinSourceSetProvider { internal interface KotlinSourceSetProvider {
fun create(displayName: String): KotlinSourceSet fun create(displayName: String): KotlinSourceSet
} }
@@ -19,7 +19,7 @@ package org.jetbrains.kotlin.gradle.plugin
import org.gradle.api.Task import org.gradle.api.Task
import org.jetbrains.annotations.TestOnly import org.jetbrains.annotations.TestOnly
abstract class TaskToFriendTaskMapper { internal abstract class TaskToFriendTaskMapper {
operator fun get(task: Task): String? = operator fun get(task: Task): String? =
getFriendByName(task.name) getFriendByName(task.name)
@@ -30,7 +30,7 @@ abstract class TaskToFriendTaskMapper {
protected abstract fun getFriendByName(name: String): String? protected abstract fun getFriendByName(name: String): String?
} }
sealed class RegexTaskToFriendTaskMapper( sealed internal class RegexTaskToFriendTaskMapper(
private val prefix: String, private val prefix: String,
suffix: String suffix: String
) : TaskToFriendTaskMapper() { ) : TaskToFriendTaskMapper() {
@@ -30,7 +30,7 @@ internal fun Task.finalizedByIfNotFailed(finalizer: Task) {
this.finalizedBy(finalizer) this.finalizedBy(finalizer)
} }
fun AbstractCompile.mapClasspath(fn: ()->FileCollection) { internal fun AbstractCompile.mapClasspath(fn: ()->FileCollection) {
conventionMapping.map("classpath", fn) conventionMapping.map("classpath", fn)
} }
@@ -3,10 +3,10 @@ package org.jetbrains.kotlin.gradle.tasks
import org.jetbrains.kotlin.incremental.DirtyData import org.jetbrains.kotlin.incremental.DirtyData
import java.io.File import java.io.File
interface ArtifactDifferenceRegistry { internal interface ArtifactDifferenceRegistry {
operator fun get(artifact: File): Iterable<ArtifactDifference>? operator fun get(artifact: File): Iterable<ArtifactDifference>?
fun add(artifact: File, difference: ArtifactDifference) fun add(artifact: File, difference: ArtifactDifference)
fun remove(artifact: File) fun remove(artifact: File)
} }
class ArtifactDifference(val buildTS: Long, val dirtyData: DirtyData) internal class ArtifactDifference(val buildTS: Long, val dirtyData: DirtyData)
@@ -2,7 +2,7 @@ package org.jetbrains.kotlin.gradle.tasks
import java.io.File import java.io.File
class CompilerPluginOptions { internal class CompilerPluginOptions {
private val mutableClasspath = arrayListOf<String>() private val mutableClasspath = arrayListOf<String>()
private val mutableArguments = arrayListOf<String>() private val mutableArguments = arrayListOf<String>()
@@ -51,7 +51,7 @@ import kotlin.properties.Delegates
* if it's timestamp now is newer than when we copied it * if it's timestamp now is newer than when we copied it
* (assuming it was modified by javac when class was converted to java). * (assuming it was modified by javac when class was converted to java).
*/ */
open class SyncOutputTask : DefaultTask() { internal open class SyncOutputTask : DefaultTask() {
@get:InputFiles @get:InputFiles
var kotlinOutputDir: File by Delegates.notNull() var kotlinOutputDir: File by Delegates.notNull()
var javaOutputDir: File by Delegates.notNull() var javaOutputDir: File by Delegates.notNull()
@@ -63,12 +63,12 @@ abstract class AbstractKotlinCompile<T : CommonCompilerArguments>() : AbstractCo
System.setProperty("kotlin.incremental.compilation.experimental", value.toString()) System.setProperty("kotlin.incremental.compilation.experimental", value.toString())
} }
var compilerCalled: Boolean = false internal var compilerCalled: Boolean = false
// TODO: consider more reliable approach (see usage) // TODO: consider more reliable approach (see usage)
var anyClassesCompiled: Boolean = false internal var anyClassesCompiled: Boolean = false
var friendTaskName: String? = null internal var friendTaskName: String? = null
var javaOutputDir: File? = null internal var javaOutputDir: File? = null
var moduleName: String = "${project.name}-${this.name}" internal var moduleName: String = "${project.name}-${this.name}"
override fun compile() { override fun compile() {
assert(false, { "unexpected call to compile()" }) assert(false, { "unexpected call to compile()" })
@@ -109,7 +109,7 @@ abstract class AbstractKotlinCompile<T : CommonCompilerArguments>() : AbstractCo
open class KotlinCompile : AbstractKotlinCompile<K2JVMCompilerArguments>(), KotlinJvmCompile { open class KotlinCompile : AbstractKotlinCompile<K2JVMCompilerArguments>(), KotlinJvmCompile {
override val compiler = K2JVMCompiler() override val compiler = K2JVMCompiler()
var parentKotlinOptionsImpl: KotlinJvmOptionsImpl? = null internal var parentKotlinOptionsImpl: KotlinJvmOptionsImpl? = null
private val kotlinOptionsImpl = KotlinJvmOptionsImpl() private val kotlinOptionsImpl = KotlinJvmOptionsImpl()
override val kotlinOptions: KotlinJvmOptions override val kotlinOptions: KotlinJvmOptions
get() = kotlinOptionsImpl get() = kotlinOptionsImpl
@@ -117,7 +117,7 @@ open class KotlinCompile : AbstractKotlinCompile<K2JVMCompilerArguments>(), Kotl
private val sourceRoots = HashSet<File>() private val sourceRoots = HashSet<File>()
// lazy because name is probably not available when constructor is called // lazy because name is probably not available when constructor is called
val taskBuildDirectory: File by lazy { File(File(project.buildDir, KOTLIN_BUILD_DIR_NAME), name).apply { mkdirs() } } internal val taskBuildDirectory: File by lazy { File(File(project.buildDir, KOTLIN_BUILD_DIR_NAME), name).apply { mkdirs() } }
private val cacheDirectory: File by lazy { File(taskBuildDirectory, CACHES_DIR_NAME) } private val cacheDirectory: File by lazy { File(taskBuildDirectory, CACHES_DIR_NAME) }
private val dirtySourcesSinceLastTimeFile: File by lazy { File(taskBuildDirectory, DIRTY_SOURCES_FILE_NAME) } private val dirtySourcesSinceLastTimeFile: File by lazy { File(taskBuildDirectory, DIRTY_SOURCES_FILE_NAME) }
private val lastBuildInfoFile: File by lazy { File(taskBuildDirectory, LAST_BUILD_INFO_FILE_NAME) } private val lastBuildInfoFile: File by lazy { File(taskBuildDirectory, LAST_BUILD_INFO_FILE_NAME) }
@@ -127,7 +127,7 @@ open class KotlinCompile : AbstractKotlinCompile<K2JVMCompilerArguments>(), Kotl
dataContainerCacheVersion(taskBuildDirectory), dataContainerCacheVersion(taskBuildDirectory),
gradleCacheVersion(taskBuildDirectory)) gradleCacheVersion(taskBuildDirectory))
} }
val isCacheFormatUpToDate: Boolean internal val isCacheFormatUpToDate: Boolean
get() { get() {
if (!incremental) return true if (!incremental) return true
@@ -143,12 +143,12 @@ open class KotlinCompile : AbstractKotlinCompile<K2JVMCompilerArguments>(), Kotl
get() = File(project.buildDir, "generated/source/kapt2") get() = File(project.buildDir, "generated/source/kapt2")
val kaptOptions = KaptOptions() internal val kaptOptions = KaptOptions()
val pluginOptions = CompilerPluginOptions() internal val pluginOptions = CompilerPluginOptions()
var artifactDifferenceRegistry: ArtifactDifferenceRegistry? = null internal var artifactDifferenceRegistry: ArtifactDifferenceRegistry? = null
var artifactFile: File? = null internal var artifactFile: File? = null
// created only if kapt2 is active // created only if kapt2 is active
var sourceAnnotationsRegistry: SourceAnnotationsRegistry? = null internal var sourceAnnotationsRegistry: SourceAnnotationsRegistry? = null
override fun populateCompilerArguments(): K2JVMCompilerArguments { override fun populateCompilerArguments(): K2JVMCompilerArguments {
val args = K2JVMCompilerArguments().apply { fillDefaultValues() } val args = K2JVMCompilerArguments().apply { fillDefaultValues() }
@@ -578,7 +578,7 @@ open class KotlinCompile : AbstractKotlinCompile<K2JVMCompilerArguments>(), Kotl
return super.source(*sourcesToAdd) return super.source(*sourcesToAdd)
} }
fun findRootsForSources(sources: Iterable<File>): Set<File> { internal fun findRootsForSources(sources: Iterable<File>): Set<File> {
val resultRoots = HashSet<File>() val resultRoots = HashSet<File>()
val sourceDirs = sources.mapTo(HashSet()) { it.parentFile } val sourceDirs = sources.mapTo(HashSet()) { it.parentFile }
@@ -652,7 +652,7 @@ open class Kotlin2JsCompile() : AbstractKotlinCompile<K2JSCompilerArguments>(),
} }
} }
class GradleMessageCollector(val logger: Logger, val outputCollector: OutputItemsCollector? = null) : MessageCollector { internal class GradleMessageCollector(val logger: Logger, val outputCollector: OutputItemsCollector? = null) : MessageCollector {
private var hasErrors = false private var hasErrors = false
override fun hasErrors() = hasErrors override fun hasErrors() = hasErrors
@@ -712,8 +712,7 @@ internal fun Logger.kotlinDebug(message: String) {
this.debug("[KOTLIN] $message") this.debug("[KOTLIN] $message")
} }
inline internal inline fun Logger.kotlinDebug(message: ()->String) {
internal fun Logger.kotlinDebug(message: ()->String) {
if (isDebugEnabled) { if (isDebugEnabled) {
kotlinDebug(message()) kotlinDebug(message())
} }
@@ -5,7 +5,7 @@ import org.jetbrains.kotlin.gradle.plugin.RegexTaskToFriendTaskMapper
import org.jetbrains.kotlin.gradle.plugin.TaskToFriendTaskMapper import org.jetbrains.kotlin.gradle.plugin.TaskToFriendTaskMapper
import org.jetbrains.kotlin.gradle.plugin.mapKotlinTaskProperties import org.jetbrains.kotlin.gradle.plugin.mapKotlinTaskProperties
open class KotlinTasksProvider { internal open class KotlinTasksProvider {
fun createKotlinJVMTask(project: Project, name: String): KotlinCompile { fun createKotlinJVMTask(project: Project, name: String): KotlinCompile {
return project.tasks.create(name, KotlinCompile::class.java).apply { return project.tasks.create(name, KotlinCompile::class.java).apply {
friendTaskName = taskToFriendTaskMapper[this] friendTaskName = taskToFriendTaskMapper[this]
@@ -21,7 +21,7 @@ open class KotlinTasksProvider {
RegexTaskToFriendTaskMapper.Default() RegexTaskToFriendTaskMapper.Default()
} }
class AndroidTasksProvider : KotlinTasksProvider() { internal class AndroidTasksProvider : KotlinTasksProvider() {
override val taskToFriendTaskMapper: TaskToFriendTaskMapper = override val taskToFriendTaskMapper: TaskToFriendTaskMapper =
RegexTaskToFriendTaskMapper.Android() RegexTaskToFriendTaskMapper.Android()
} }
@@ -4,10 +4,10 @@ import org.jetbrains.kotlin.config.IncrementalCompilation
import org.jetbrains.kotlin.incremental.CacheVersion import org.jetbrains.kotlin.incremental.CacheVersion
import java.io.File import java.io.File
const val GRADLE_CACHE_VERSION = 1 internal const val GRADLE_CACHE_VERSION = 1
const val GRADLE_CACHE_VERSION_FILE_NAME = "gradle-format-version.txt" internal const val GRADLE_CACHE_VERSION_FILE_NAME = "gradle-format-version.txt"
fun gradleCacheVersion(dataRoot: File): CacheVersion = internal fun gradleCacheVersion(dataRoot: File): CacheVersion =
CacheVersion(ownVersion = GRADLE_CACHE_VERSION, CacheVersion(ownVersion = GRADLE_CACHE_VERSION,
versionFile = File(dataRoot, GRADLE_CACHE_VERSION_FILE_NAME), versionFile = File(dataRoot, GRADLE_CACHE_VERSION_FILE_NAME),
whenVersionChanged = CacheVersion.Action.REBUILD_ALL_KOTLIN, whenVersionChanged = CacheVersion.Action.REBUILD_ALL_KOTLIN,
@@ -10,7 +10,7 @@ import org.jetbrains.kotlin.gradle.tasks.ArtifactDifferenceRegistry
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.io.File import java.io.File
fun configureMultiProjectIncrementalCompilation( internal fun configureMultiProjectIncrementalCompilation(
project: Project, project: Project,
kotlinTask: KotlinCompile, kotlinTask: KotlinCompile,
javaTask: AbstractCompile, javaTask: AbstractCompile,
@@ -4,7 +4,7 @@ import org.jetbrains.org.objectweb.asm.*
import org.jetbrains.org.objectweb.asm.Opcodes.* import org.jetbrains.org.objectweb.asm.Opcodes.*
import java.io.File import java.io.File
fun generateKotlinAptAnnotation(outputDirectory: File): File { internal fun generateKotlinAptAnnotation(outputDirectory: File): File {
val packageName = "__gen" val packageName = "__gen"
val className = "KotlinAptAnnotation" val className = "KotlinAptAnnotation"
val classFqName = "$packageName/$className" val classFqName = "$packageName/$className"
@@ -25,7 +25,7 @@ fun generateKotlinAptAnnotation(outputDirectory: File): File {
return outputFile return outputFile
} }
fun generateAnnotationProcessorWrapper( internal fun generateAnnotationProcessorWrapper(
processorFqName: String, processorFqName: String,
packageName: String, packageName: String,
outputDirectory: File, outputDirectory: File,
@@ -19,7 +19,7 @@ package org.jetbrains.kotlin.incremental.snapshots
import java.io.File import java.io.File
import java.security.MessageDigest import java.security.MessageDigest
val File.md5: ByteArray internal val File.md5: ByteArray
get() { get() {
val messageDigest = MessageDigest.getInstance("MD5") val messageDigest = MessageDigest.getInstance("MD5")
val buffer = ByteArray(4048) val buffer = ByteArray(4048)
@@ -2,7 +2,6 @@ package org.jetbrains.kotlin.gradle
import org.gradle.api.logging.LogLevel import org.gradle.api.logging.LogLevel
import org.jetbrains.kotlin.com.intellij.openapi.util.io.FileUtil import org.jetbrains.kotlin.com.intellij.openapi.util.io.FileUtil
import org.jetbrains.kotlin.gradle.plugin.KotlinGradleBuildServices
import org.jetbrains.kotlin.gradle.util.checkBytecodeNotContains import org.jetbrains.kotlin.gradle.util.checkBytecodeNotContains
import org.jetbrains.kotlin.gradle.util.createGradleCommand import org.jetbrains.kotlin.gradle.util.createGradleCommand
import org.jetbrains.kotlin.gradle.util.runProcess import org.jetbrains.kotlin.gradle.util.runProcess
@@ -183,8 +182,8 @@ abstract class BaseGradleIT {
} }
fun CompiledProject.checkKotlinGradleBuildServices() { fun CompiledProject.checkKotlinGradleBuildServices() {
assertSubstringCount(KotlinGradleBuildServices.INIT_MESSAGE, expectedCount = 1) assertSubstringCount("Initialized KotlinGradleBuildServices", expectedCount = 1)
assertSubstringCount(KotlinGradleBuildServices.DISPOSE_MESSAGE, expectedCount = 1) assertSubstringCount("Disposed KotlinGradleBuildServices", expectedCount = 1)
} }
fun CompiledProject.assertNotContains(vararg expected: String): CompiledProject { fun CompiledProject.assertNotContains(vararg expected: String): CompiledProject {
@@ -1,7 +1,6 @@
package org.jetbrains.kotlin.gradle package org.jetbrains.kotlin.gradle
import org.gradle.api.logging.LogLevel import org.gradle.api.logging.LogLevel
import org.jetbrains.kotlin.gradle.plugin.KotlinGradleBuildServices
import org.jetbrains.kotlin.gradle.tasks.USING_EXPERIMENTAL_INCREMENTAL_MESSAGE import org.jetbrains.kotlin.gradle.tasks.USING_EXPERIMENTAL_INCREMENTAL_MESSAGE
import org.jetbrains.kotlin.gradle.util.getFileByName import org.jetbrains.kotlin.gradle.util.getFileByName
import org.jetbrains.kotlin.gradle.util.modify import org.jetbrains.kotlin.gradle.util.modify
@@ -106,12 +105,12 @@ class KotlinGradleIT: BaseGradleIT() {
fun testLogLevelForceGC() { fun testLogLevelForceGC() {
val debugProject = Project("simpleProject", GRADLE_VERSION, minLogLevel = LogLevel.DEBUG) val debugProject = Project("simpleProject", GRADLE_VERSION, minLogLevel = LogLevel.DEBUG)
debugProject.build("build") { debugProject.build("build") {
assertContains(KotlinGradleBuildServices.FORCE_SYSTEM_GC_MESSAGE) assertContains("Forcing System.gc()")
} }
val infoProject = Project("simpleProject", GRADLE_VERSION, minLogLevel = LogLevel.INFO) val infoProject = Project("simpleProject", GRADLE_VERSION, minLogLevel = LogLevel.INFO)
infoProject.build("clean", "build") { infoProject.build("clean", "build") {
assertNotContains(KotlinGradleBuildServices.FORCE_SYSTEM_GC_MESSAGE) assertNotContains("Forcing System.gc()")
} }
} }