org.jetbrains.kotlin.gradle.targets.js.KotlinJsTargetConfigurator.kt Maven / Gradle / Ivy
/*
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.gradle.targets.js
import org.gradle.api.tasks.TaskProvider
import org.jetbrains.kotlin.gradle.plugin.Kotlin2JsSourceSetProcessor
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSetProcessor
import org.jetbrains.kotlin.gradle.plugin.KotlinOnlyTargetConfigurator
import org.jetbrains.kotlin.gradle.plugin.KotlinTargetWithTestsConfigurator
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJsCompilation
import org.jetbrains.kotlin.gradle.tasks.KotlinTasksProvider
import org.jetbrains.kotlin.gradle.testing.internal.KotlinTestReport
import org.jetbrains.kotlin.gradle.testing.internal.kotlinTestRegistry
import org.jetbrains.kotlin.gradle.testing.testTaskName
open class KotlinJsTargetConfigurator(kotlinPluginVersion: String) :
KotlinOnlyTargetConfigurator(true, true, kotlinPluginVersion),
KotlinTargetWithTestsConfigurator {
override val testRunClass: Class get() = KotlinJsReportAggregatingTestRun::class.java
override fun createTestRun(
name: String,
target: KotlinJsTarget
): KotlinJsReportAggregatingTestRun {
val result = KotlinJsReportAggregatingTestRun(name, target)
val testTask = target.project.kotlinTestRegistry.getOrCreateAggregatedTestTask(
name = result.testTaskName,
description = "Run JS tests for all platforms"
)
// workaround to avoid the infinite recursion in item factories of the target and the subtargets:
target.testRuns.matching { it.name == name }.whenObjectAdded {
it.configureAllExecutions {
// do not do anything with the aggregated test run, but ensure that they are created
}
}
result.executionTask = testTask
return result
}
override fun buildCompilationProcessor(compilation: KotlinJsCompilation): KotlinSourceSetProcessor<*> {
val tasksProvider = KotlinTasksProvider(compilation.target.targetName)
return Kotlin2JsSourceSetProcessor(compilation.target.project, tasksProvider, compilation, kotlinPluginVersion)
}
override fun configureCompilations(target: KotlinJsTarget) {
super.configureCompilations(target)
target.compilations.all {
it.compileKotlinTask.kotlinOptions {
moduleKind = "umd"
sourceMap = true
sourceMapEmbedSources = null
}
}
}
}