JPS: support KotlinResourceSourceRootType
Implementation is similar to KotlinSourceRootProvider. This workaround is required since ResourcesTarget.computeRootDescriptors supports only JavaResourceRoots. #KT-27622 Fixed
This commit is contained in:
@@ -268,6 +268,13 @@ open class KotlinJpsBuildTest : AbstractKotlinJpsBuildTestCase() {
|
||||
return list.toTypedArray()
|
||||
}
|
||||
|
||||
fun testKotlinJavaScriptProjectNewSourceRootTypes() {
|
||||
initProject(JS_STDLIB)
|
||||
buildAllModules().assertSuccessful()
|
||||
|
||||
checkOutputFilesList()
|
||||
}
|
||||
|
||||
fun testKotlinJavaScriptProjectWithCustomOutputPaths() {
|
||||
initProject(JS_STDLIB)
|
||||
buildAllModules().assertSuccessful()
|
||||
|
||||
+2
-1
@@ -1 +1,2 @@
|
||||
org.jetbrains.kotlin.jps.build.KotlinSourceRootProvider
|
||||
org.jetbrains.kotlin.jps.build.KotlinSourceRootProvider
|
||||
org.jetbrains.kotlin.jps.build.KotlinResourcesRootProvider
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. 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.jps.build
|
||||
|
||||
import org.jetbrains.jps.builders.AdditionalRootsProviderService
|
||||
import org.jetbrains.jps.builders.BuildTarget
|
||||
import org.jetbrains.jps.builders.java.ResourceRootDescriptor
|
||||
import org.jetbrains.jps.builders.java.ResourcesTargetType
|
||||
import org.jetbrains.jps.builders.storage.BuildDataPaths
|
||||
import org.jetbrains.jps.incremental.ResourcesTarget
|
||||
import org.jetbrains.jps.model.java.JavaResourceRootProperties
|
||||
import org.jetbrains.kotlin.config.KotlinResourceRootType
|
||||
|
||||
class KotlinResourcesRootProvider : AdditionalRootsProviderService<ResourceRootDescriptor>(ResourcesTargetType.ALL_TYPES) {
|
||||
override fun getAdditionalRoots(
|
||||
target: BuildTarget<ResourceRootDescriptor>,
|
||||
dataPaths: BuildDataPaths?
|
||||
): List<ResourceRootDescriptor> {
|
||||
val moduleBuildTarget = target as? ResourcesTarget ?: return listOf()
|
||||
val module = moduleBuildTarget.module
|
||||
|
||||
val result = mutableListOf<ResourceRootDescriptor>()
|
||||
|
||||
// Add source roots with type KotlinResourceRootType.
|
||||
// See the note in KotlinSourceRootProvider
|
||||
val kotlinResourceRootType = if (target.isTests) KotlinResourceRootType.TestResource else KotlinResourceRootType.Resource
|
||||
module.getSourceRoots(kotlinResourceRootType).forEach {
|
||||
result.add(
|
||||
ResourceRootDescriptor(
|
||||
it.file,
|
||||
target,
|
||||
it.properties.packagePrefix,
|
||||
setOf()
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Copied from implementation of org.jetbrains.jps.incremental.ResourcesTarget.computeRootDescriptors
|
||||
*/
|
||||
private val JavaResourceRootProperties.packagePrefix: String
|
||||
get() = relativeOutputPath.replace('/', '.')
|
||||
Vendored
Executable
+1
@@ -0,0 +1 @@
|
||||
test
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
kotlinProject/
|
||||
kotlinProject/
|
||||
root-package.kjsm
|
||||
kotlinProject.js
|
||||
kotlinProject.meta.js
|
||||
lib/
|
||||
kotlin.js
|
||||
kotlin.meta.js
|
||||
resource.txt
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" type="kotlin-source" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/assets" type="kotlin-resource" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="KotlinJavaScript" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<option name="DEFAULT_COMPILER" value="Javac" />
|
||||
</component>
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/kotlinProject.iml" filepath="$PROJECT_DIR$/kotlinProject.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_3" default="true" project-jdk-name="Kotlin SDK" project-jdk-type="KotlinSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
Vendored
Executable
+3
@@ -0,0 +1,3 @@
|
||||
fun main(args: Array<String>) {
|
||||
println("Hello")
|
||||
}
|
||||
Reference in New Issue
Block a user