KT-15120 Gradle JS test compile task doesn't pick up production code
This commit is contained in:
+20
-4
@@ -15,9 +15,9 @@ class Kotlin2JsGradlePluginIT : BaseGradleIT() {
|
||||
assertReportExists()
|
||||
|
||||
assertContains(
|
||||
":libraryProject:jarSources\n",
|
||||
":mainProject:compileKotlin2Js\n",
|
||||
":libraryProject:compileKotlin2Js\n"
|
||||
":libraryProject:jarSources",
|
||||
":mainProject:compileKotlin2Js",
|
||||
":libraryProject:compileKotlin2Js"
|
||||
)
|
||||
|
||||
listOf("mainProject/web/js/app.js",
|
||||
@@ -75,6 +75,23 @@ class Kotlin2JsGradlePluginIT : BaseGradleIT() {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testCompileTestCouldAccessProduction() {
|
||||
val project = Project("kotlin2JsProjectWithTests", "2.10")
|
||||
|
||||
project.build("build") {
|
||||
assertSuccessful()
|
||||
|
||||
assertContains(
|
||||
":compileKotlin2Js",
|
||||
":compileTestKotlin2Js"
|
||||
)
|
||||
|
||||
assertFileExists("build/kotlin2js/main/module.js")
|
||||
assertFileExists("build/kotlin2js/test/module-tests.js")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testKotlinJsBuiltins() {
|
||||
val project = Project("kotlinBuiltins", "3.2")
|
||||
@@ -90,4 +107,3 @@ class Kotlin2JsGradlePluginIT : BaseGradleIT() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenLocal()
|
||||
}
|
||||
dependencies {
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'kotlin2js'
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile "org.jetbrains.kotlin:kotlin-js-library:$kotlin_version"
|
||||
}
|
||||
|
||||
task jarSources(type: Jar) {
|
||||
from sourceSets.main.allSource
|
||||
classifier = 'source'
|
||||
}
|
||||
artifacts {
|
||||
compile jarSources
|
||||
}
|
||||
|
||||
compileKotlin2Js.kotlinOptions.outputFile = "${buildDir}/kotlin2js/main/module.js"
|
||||
compileTestKotlin2Js.kotlinOptions.outputFile = "${buildDir}/kotlin2js/test/module-tests.js"
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
package example
|
||||
|
||||
class MyProductionClass {
|
||||
var i = 0
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
package test
|
||||
|
||||
import org.junit.Test
|
||||
import example.MyProductionClass
|
||||
|
||||
class MyTest {
|
||||
@Test
|
||||
fun mySimpleTest() {
|
||||
MyProductionClass().i = 10
|
||||
}
|
||||
}
|
||||
+2
-3
@@ -22,8 +22,7 @@ import org.gradle.api.internal.file.FileResolver
|
||||
import org.gradle.api.logging.Logger
|
||||
import org.gradle.api.logging.Logging
|
||||
import org.jetbrains.kotlin.gradle.internal.KotlinSourceSetProviderImpl
|
||||
import org.jetbrains.kotlin.gradle.tasks.AndroidTasksProvider
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinTasksProvider
|
||||
import org.jetbrains.kotlin.gradle.tasks.*
|
||||
import java.io.FileNotFoundException
|
||||
import java.util.*
|
||||
import javax.inject.Inject
|
||||
@@ -56,7 +55,7 @@ open class KotlinAndroidPluginWrapper @Inject constructor(fileResolver: FileReso
|
||||
|
||||
open class Kotlin2JsPluginWrapper @Inject constructor(fileResolver: FileResolver): KotlinBasePluginWrapper(fileResolver) {
|
||||
override fun getPlugin(kotlinGradleBuildServices: KotlinGradleBuildServices) =
|
||||
Kotlin2JsPlugin(KotlinTasksProvider(), KotlinSourceSetProviderImpl(fileResolver), kotlinPluginVersion)
|
||||
Kotlin2JsPlugin(Kotlin2JsTasksProvider(), KotlinSourceSetProviderImpl(fileResolver), kotlinPluginVersion)
|
||||
}
|
||||
|
||||
private fun Any.loadKotlinVersionFromResource(log: Logger): String {
|
||||
|
||||
+6
-4
@@ -32,16 +32,18 @@ internal abstract class TaskToFriendTaskMapper {
|
||||
|
||||
sealed internal class RegexTaskToFriendTaskMapper(
|
||||
private val prefix: String,
|
||||
suffix: String
|
||||
suffix: String,
|
||||
private val postfixReplacement: String
|
||||
) : TaskToFriendTaskMapper() {
|
||||
class Default : RegexTaskToFriendTaskMapper("compile", "TestKotlin")
|
||||
class Android : RegexTaskToFriendTaskMapper("compile", "(Unit|Android)TestKotlin")
|
||||
class Default : RegexTaskToFriendTaskMapper("compile", "TestKotlin", "Kotlin")
|
||||
class JavaScript : RegexTaskToFriendTaskMapper("compile", "TestKotlin2Js", "Kotlin2Js")
|
||||
class Android : RegexTaskToFriendTaskMapper("compile", "(Unit|Android)TestKotlin", "Kotlin")
|
||||
|
||||
private val regex = "$prefix(.*)$suffix".toRegex()
|
||||
|
||||
override fun getFriendByName(name: String): String? {
|
||||
val match = regex.matchEntire(name) ?: return null
|
||||
val variant = match.groups[1]?.value ?: ""
|
||||
return prefix + variant + "Kotlin"
|
||||
return prefix + variant + postfixReplacement
|
||||
}
|
||||
}
|
||||
+14
-7
@@ -19,17 +19,13 @@ package org.jetbrains.kotlin.gradle.tasks
|
||||
import org.codehaus.groovy.runtime.MethodClosure
|
||||
import org.gradle.api.GradleException
|
||||
import org.gradle.api.Task
|
||||
import org.gradle.api.file.FileTree
|
||||
import org.gradle.api.file.SourceDirectorySet
|
||||
import org.gradle.api.logging.Logger
|
||||
import org.gradle.api.tasks.SourceTask
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
import org.gradle.api.tasks.compile.AbstractCompile
|
||||
import org.gradle.api.tasks.incremental.IncrementalTaskInputs
|
||||
import org.gradle.util.GradleVersion
|
||||
import org.jetbrains.kotlin.annotation.AnnotationFileUpdater
|
||||
import org.jetbrains.kotlin.annotation.SourceAnnotationsRegistry
|
||||
import org.jetbrains.kotlin.build.JvmSourceRoot
|
||||
import org.jetbrains.kotlin.cli.common.CLICompiler
|
||||
import org.jetbrains.kotlin.cli.common.ExitCode
|
||||
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
|
||||
@@ -321,10 +317,22 @@ open class Kotlin2JsCompile() : AbstractKotlinCompile<K2JSCompilerArguments>(),
|
||||
|
||||
override fun populateCompilerArguments(): K2JSCompilerArguments {
|
||||
val args = K2JSCompilerArguments().apply { fillDefaultValues() }
|
||||
args.libraryFiles = project.configurations.getByName("compile")
|
||||
val friendDependency = friendTaskName
|
||||
?.let { project.getTasksByName(it, false).singleOrNull() as? Kotlin2JsCompile }
|
||||
?.outputFile
|
||||
?.let { File(it).parentFile }
|
||||
?.let { if (LibraryUtils.isKotlinJavascriptLibrary(it)) it else null }
|
||||
?.absolutePath
|
||||
|
||||
val dependencies = project.configurations.getByName("compile")
|
||||
.filter { LibraryUtils.isKotlinJavascriptLibrary(it) }
|
||||
.map { it.canonicalPath }
|
||||
.toTypedArray()
|
||||
|
||||
args.libraryFiles = when (friendDependency) {
|
||||
null -> dependencies.toTypedArray()
|
||||
else -> (dependencies + friendDependency).toTypedArray()
|
||||
}
|
||||
|
||||
kotlinOptionsImpl.updateArguments(args)
|
||||
return args
|
||||
}
|
||||
@@ -334,7 +342,6 @@ open class Kotlin2JsCompile() : AbstractKotlinCompile<K2JSCompilerArguments>(),
|
||||
override fun callCompiler(args: K2JSCompilerArguments, sourceRoots: SourceRoots, changedFiles: ChangedFiles) {
|
||||
sourceRoots as SourceRoots.ForJs
|
||||
|
||||
val messageCollector = GradleMessageCollector(logger)
|
||||
logger.debug("Calling compiler")
|
||||
destinationDir.mkdirs()
|
||||
args.freeArgs = args.freeArgs + sourceRoots.kotlinSourceFiles.map { it.absolutePath }
|
||||
|
||||
+8
-1
@@ -32,12 +32,19 @@ internal open class KotlinTasksProvider {
|
||||
}
|
||||
|
||||
fun createKotlinJSTask(project: Project, name: String, sourceSetName: String): Kotlin2JsCompile =
|
||||
project.tasks.create(name, Kotlin2JsCompile::class.java)
|
||||
project.tasks.create(name, Kotlin2JsCompile::class.java).apply {
|
||||
friendTaskName = taskToFriendTaskMapper[this]
|
||||
}
|
||||
|
||||
protected open val taskToFriendTaskMapper: TaskToFriendTaskMapper =
|
||||
RegexTaskToFriendTaskMapper.Default()
|
||||
}
|
||||
|
||||
internal class Kotlin2JsTasksProvider : KotlinTasksProvider() {
|
||||
override val taskToFriendTaskMapper: TaskToFriendTaskMapper =
|
||||
RegexTaskToFriendTaskMapper.JavaScript()
|
||||
}
|
||||
|
||||
internal class AndroidTasksProvider : KotlinTasksProvider() {
|
||||
override val taskToFriendTaskMapper: TaskToFriendTaskMapper =
|
||||
RegexTaskToFriendTaskMapper.Android()
|
||||
|
||||
+7
@@ -27,6 +27,13 @@ class RegexTaskToFriendTaskMapperTest {
|
||||
Assert.assertEquals(null, mapper["compileKotlin"])
|
||||
}
|
||||
|
||||
@Test
|
||||
fun getFriendTasksNameJavaScript() {
|
||||
val mapper = RegexTaskToFriendTaskMapper.JavaScript()
|
||||
Assert.assertEquals("compileKotlin2Js", mapper["compileTestKotlin2Js"])
|
||||
Assert.assertEquals(null, mapper["compileKotlin2Js"])
|
||||
}
|
||||
|
||||
@Test
|
||||
fun getFriendTaskNameAndroid() {
|
||||
val mapper = RegexTaskToFriendTaskMapper.Android()
|
||||
|
||||
Reference in New Issue
Block a user