Skip to content

Commit 6608e97

Browse files
committed
JPS JS: simplified the code and added tests for the missing meta.js case (e.g. empty sourceroot; fixed by yole in 00ed024)
1 parent 2d9392a commit 6608e97

File tree

35 files changed

+235
-17
lines changed

35 files changed

+235
-17
lines changed

jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/KotlinJpsBuildTest.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,11 @@ class KotlinJpsBuildTest : AbstractKotlinJpsBuildTestCase() {
371371
assertEquals(Collections.EMPTY_SET, contentOfOutputDir(PROJECT_NAME))
372372
}
373373

374+
fun testKotlinJavaScriptProjectWithEmptyDependencies() {
375+
initProject(JS_STDLIB)
376+
makeAll().assertSuccessful()
377+
}
378+
374379
fun testKotlinJavaScriptProjectWithTests() {
375380
initProject(JS_STDLIB)
376381
makeAll().assertSuccessful()
@@ -387,9 +392,8 @@ class KotlinJpsBuildTest : AbstractKotlinJpsBuildTestCase() {
387392
buildResult.assertSuccessful()
388393

389394
val warnings = buildResult.getMessages(BuildMessage.Kind.WARNING)
390-
assertEquals("Warning about duplicate module definition: $warnings", 2, warnings.size)
395+
assertEquals("Warning about duplicate module definition: $warnings", 1, warnings.size)
391396
assertEquals("Module \"srcAndTests\" is defined in more, than one file", warnings[0].messageText)
392-
assertEquals("Module \"srcAndTests\" is defined in more, than one file", warnings[1].messageText)
393397
}
394398

395399
fun testKotlinJavaScriptProjectWithTwoSrcModuleDependency() {

jps-plugin/src/org/jetbrains/kotlin/jps/build/JpsJsModuleUtils.kt

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,22 +50,12 @@ object JpsJsModuleUtils {
5050
override fun consume(module: JpsModule) {
5151
if (module.moduleType != JpsJavaModuleType.INSTANCE) return
5252

53-
var yieldProduction = module != target.module || target.isTests
54-
var yieldTests = module != target.module
53+
if ((module != target.module || target.isTests) && module.sourceRoots.any { it.rootType == JavaSourceRootType.SOURCE}) {
54+
addTarget(module, JavaModuleBuildTargetType.PRODUCTION)
55+
}
5556

56-
module.sourceRoots.forEach {
57-
if (it.rootType == JavaSourceRootType.SOURCE) {
58-
if (yieldProduction) {
59-
addTarget(module, JavaModuleBuildTargetType.PRODUCTION)
60-
yieldProduction = false
61-
}
62-
}
63-
else {
64-
if (yieldTests) {
65-
addTarget(module, JavaModuleBuildTargetType.TEST)
66-
yieldTests = false
67-
}
68-
}
57+
if (module != target.module && target.isTests && module.sourceRoots.any { it.rootType == JavaSourceRootType.TEST_SOURCE}) {
58+
addTarget(module, JavaModuleBuildTargetType.TEST)
6959
}
7060
}
7161

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
7+
</content>
8+
<orderEntry type="inheritedJdk" />
9+
<orderEntry type="sourceFolder" forTests="false" />
10+
</component>
11+
</module>

jps-plugin/testData/general/KotlinJavaScriptProjectWithEmptyDependencies/emptySrc/src/dummy

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />i
7+
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
8+
</content>
9+
<orderEntry type="inheritedJdk" />
10+
<orderEntry type="sourceFolder" forTests="false" />
11+
</component>
12+
</module>

jps-plugin/testData/general/KotlinJavaScriptProjectWithEmptyDependencies/emptySrcEmptyTests/src/dummy

Whitespace-only changes.

jps-plugin/testData/general/KotlinJavaScriptProjectWithEmptyDependencies/emptySrcEmptyTests/test/dummy

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />i
7+
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
8+
</content>
9+
<orderEntry type="inheritedJdk" />
10+
<orderEntry type="sourceFolder" forTests="false" />
11+
</component>
12+
</module>

jps-plugin/testData/general/KotlinJavaScriptProjectWithEmptyDependencies/emptySrcMissingTests/src/dummy

Whitespace-only changes.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
7+
</content>
8+
<orderEntry type="inheritedJdk" />
9+
<orderEntry type="sourceFolder" forTests="false" />
10+
</component>
11+
</module>

jps-plugin/testData/general/KotlinJavaScriptProjectWithEmptyDependencies/emptyTests/test/dummy

Whitespace-only changes.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
7+
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
8+
</content>
9+
<orderEntry type="inheritedJdk" />
10+
<orderEntry type="sourceFolder" forTests="false" />
11+
<orderEntry type="module" module-name="emptySrc" />
12+
<orderEntry type="module" module-name="missingSrc" />
13+
<orderEntry type="module" module-name="emptyTests" />
14+
<orderEntry type="module" module-name="missingTests" />
15+
<orderEntry type="module" module-name="srcEmptyTests" />
16+
<orderEntry type="module" module-name="srcMissingTests" />
17+
<orderEntry type="module" module-name="testsEmptySrc" />
18+
<orderEntry type="module" module-name="testsMissingSrc" />
19+
<orderEntry type="module" module-name="emptySrcEmptyTests" />
20+
<orderEntry type="module" module-name="emptySrcMissingTests" />
21+
<orderEntry type="module" module-name="missingSrcEmptyTests" />
22+
<orderEntry type="module" module-name="missingSrcMissingTests" />
23+
<orderEntry type="module" module-name="missingModule" />
24+
</component>
25+
</module>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project version="4">
3+
<component name="CompilerConfiguration">
4+
<option name="DEFAULT_COMPILER" value="Javac" />
5+
</component>
6+
<component name="ProjectModuleManager">
7+
<modules>
8+
<module fileurl="file://$PROJECT_DIR$/emptySrc/emptySrc.iml" filepath="$PROJECT_DIR$/emptySrc/emptySrc.iml" />
9+
<module fileurl="file://$PROJECT_DIR$/missingSrc/missingSrc.iml" filepath="$PROJECT_DIR$/missingSrc/missingSrc.iml" />
10+
<module fileurl="file://$PROJECT_DIR$/emptyTests/emptyTests.iml" filepath="$PROJECT_DIR$/emptyTests/emptyTests.iml" />
11+
<module fileurl="file://$PROJECT_DIR$/missingTests/missingTests.iml" filepath="$PROJECT_DIR$/missingTests/missingTests.iml" />
12+
<module fileurl="file://$PROJECT_DIR$/srcEmptyTests/srcEmptyTests.iml" filepath="$PROJECT_DIR$/srcEmptyTests/srcEmptyTests.iml" />
13+
<module fileurl="file://$PROJECT_DIR$/srcMissingTests/srcMissingTests.iml" filepath="$PROJECT_DIR$/srcMissingTests/srcMissingTests.iml" />
14+
<module fileurl="file://$PROJECT_DIR$/testsEmptySrc/testsEmptySrc.iml" filepath="$PROJECT_DIR$/testsEmptySrc/testsEmptySrc.iml" />
15+
<module fileurl="file://$PROJECT_DIR$/testsMissingSrc/testsMissingSrc.iml" filepath="$PROJECT_DIR$/testsMissingSrc/testsMissingSrc.iml" />
16+
<module fileurl="file://$PROJECT_DIR$/emptySrcEmptyTests/emptySrcEmptyTests.iml" filepath="$PROJECT_DIR$/emptySrcEmptyTests/emptySrcEmptyTests.iml" />
17+
<module fileurl="file://$PROJECT_DIR$/emptySrcMissingTests/emptySrcMissingTests.iml" filepath="$PROJECT_DIR$/emptySrcMissingTests/emptySrcMissingTests.iml" />
18+
<module fileurl="file://$PROJECT_DIR$/missingSrcEmptyTests/missingSrcEmptyTests.iml" filepath="$PROJECT_DIR$/missingSrcEmptyTests/missingSrcEmptyTests.iml" />
19+
<module fileurl="file://$PROJECT_DIR$/missingSrcMissingTests/missingSrcMissingTests.iml" filepath="$PROJECT_DIR$/missingSrcMissingTests/missingSrcMissingTests.iml" />
20+
<module fileurl="file://$PROJECT_DIR$/missingModule/missingModule.iml" filepath="$PROJECT_DIR$/missingModule/missingModule.iml" />
21+
<module fileurl="file://$PROJECT_DIR$/kotlinProject.iml" filepath="$PROJECT_DIR$/kotlinProject.iml" />
22+
</modules>
23+
</component>
24+
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.6" project-jdk-type="JavaSDK">
25+
<output url="file://$PROJECT_DIR$/out" />
26+
</component>
27+
</project>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
7+
</content>
8+
<orderEntry type="inheritedJdk" />
9+
<orderEntry type="sourceFolder" forTests="false" />
10+
</component>
11+
</module>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />i
7+
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
8+
</content>
9+
<orderEntry type="inheritedJdk" />
10+
<orderEntry type="sourceFolder" forTests="false" />
11+
</component>
12+
</module>

jps-plugin/testData/general/KotlinJavaScriptProjectWithEmptyDependencies/missingSrcEmptyTests/test/dummy

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />i
7+
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
8+
</content>
9+
<orderEntry type="inheritedJdk" />
10+
<orderEntry type="sourceFolder" forTests="false" />
11+
</component>
12+
</module>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
7+
</content>
8+
<orderEntry type="inheritedJdk" />
9+
<orderEntry type="sourceFolder" forTests="false" />
10+
</component>
11+
</module>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
fun main() {
2+
srcEmptyTestsSrc()
3+
srcMissingTestsSrc()
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fun srcEmptyTestsSrc() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />i
7+
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
8+
</content>
9+
<orderEntry type="inheritedJdk" />
10+
<orderEntry type="sourceFolder" forTests="false" />
11+
</component>
12+
</module>

jps-plugin/testData/general/KotlinJavaScriptProjectWithEmptyDependencies/srcEmptyTests/test/dummy

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fun srcMissingTestsSrc() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />i
7+
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
8+
</content>
9+
<orderEntry type="inheritedJdk" />
10+
<orderEntry type="sourceFolder" forTests="false" />
11+
</component>
12+
</module>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
fun test() {
2+
testsEmptySrcTest()
3+
testsMissingSrcTest()
4+
}

jps-plugin/testData/general/KotlinJavaScriptProjectWithEmptyDependencies/testsEmptySrc/src/dummy

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fun testsEmptySrcTest() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />i
7+
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
8+
</content>
9+
<orderEntry type="inheritedJdk" />
10+
<orderEntry type="sourceFolder" forTests="false" />
11+
</component>
12+
</module>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fun testsMissingSrcTest() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />i
7+
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
8+
</content>
9+
<orderEntry type="inheritedJdk" />
10+
<orderEntry type="sourceFolder" forTests="false" />
11+
</component>
12+
</module>
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
import src.*
2+
import test.*
3+
14
fun main() {
25
srcAndTests()
6+
ambiguous()
37
}
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1+
package src
2+
13
fun srcAndTests() {}
4+
5+
fun ambiguous() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package test
2+
3+
private fun dummy() {}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
package test
2+
3+
import src.srcAndTests
4+
15
fun testSrcAndTests() {
26
srcAndTests()
37
}
8+
9+
fun ambiguous() {}

jps-plugin/testData/general/KotlinJavaScriptProjectWithTestsAndTestAndSrcModuleDependency/tests/MainTests.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import src.*
2+
import test.*
3+
14
fun testMain() {
25
main()
36
srcAndTests()

0 commit comments

Comments
 (0)