@@ -169,7 +169,8 @@ open class KotlinJpsBuildTest : AbstractKotlinJpsBuildTestCase() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun findFileInOutputDir(module: JpsModule, relativePath: String): File {
|
||||
@JvmStatic
|
||||
protected fun findFileInOutputDir(module: JpsModule, relativePath: String): File {
|
||||
val outputUrl = JpsJavaExtensionService.getInstance().getOutputUrl(module, false)
|
||||
assertNotNull(outputUrl)
|
||||
val outputDir = File(JpsPathUtil.urlToPath(outputUrl))
|
||||
|
||||
+57
@@ -1,10 +1,33 @@
|
||||
/*
|
||||
* Copyright 2010-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.jps.build
|
||||
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
|
||||
import org.jetbrains.jps.builders.JpsBuildTestCase
|
||||
import org.jetbrains.kotlin.compilerRunner.JpsKotlinCompilerRunner
|
||||
import org.jetbrains.kotlin.config.IncrementalCompilation
|
||||
import org.jetbrains.kotlin.config.LanguageVersion
|
||||
import org.jetbrains.kotlin.jps.JpsKotlinCompilerSettings
|
||||
import kotlin.reflect.KMutableProperty1
|
||||
import org.jetbrains.kotlin.daemon.common.COMPILE_DAEMON_CUSTOM_RUN_FILES_PATH_FOR_TESTS
|
||||
import org.jetbrains.kotlin.daemon.common.COMPILE_DAEMON_ENABLED_PROPERTY
|
||||
import org.jetbrains.kotlin.daemon.common.isDaemonEnabled
|
||||
import java.io.File
|
||||
|
||||
class KotlinJpsBuildTestIncremental : KotlinJpsBuildTest() {
|
||||
var isICEnabledBackup: Boolean = false
|
||||
@@ -20,6 +43,40 @@ class KotlinJpsBuildTestIncremental : KotlinJpsBuildTest() {
|
||||
super.tearDown()
|
||||
}
|
||||
|
||||
fun testJpsDaemonIC() {
|
||||
fun testImpl() {
|
||||
assertTrue("Daemon was not enabled!", isDaemonEnabled())
|
||||
|
||||
doTest()
|
||||
val module = myProject.modules.get(0)
|
||||
val mainKtClassFile = findFileInOutputDir(module, "MainKt.class")
|
||||
assertTrue("$mainKtClassFile does not exist!", mainKtClassFile.exists())
|
||||
|
||||
val fooKt = File(workDir, "src/Foo.kt")
|
||||
JpsBuildTestCase.change(fooKt.path, null)
|
||||
buildAllModules().assertSuccessful()
|
||||
assertCompiled(KotlinBuilder.KOTLIN_BUILDER_NAME, "src/Foo.kt")
|
||||
|
||||
JpsBuildTestCase.change(fooKt.path, "class Foo(val x: Int = 0)")
|
||||
buildAllModules().assertSuccessful()
|
||||
assertCompiled(KotlinBuilder.KOTLIN_BUILDER_NAME, "src/main.kt", "src/Foo.kt")
|
||||
}
|
||||
|
||||
val daemonHome = FileUtil.createTempDirectory("daemon-home", "testJpsDaemonIC")
|
||||
try {
|
||||
withSystemProperty(COMPILE_DAEMON_CUSTOM_RUN_FILES_PATH_FOR_TESTS, daemonHome.absolutePath) {
|
||||
withSystemProperty(COMPILE_DAEMON_ENABLED_PROPERTY, "true") {
|
||||
withSystemProperty(JpsKotlinCompilerRunner.FAIL_ON_FALLBACK_PROPERTY, "true") {
|
||||
testImpl()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
finally {
|
||||
daemonHome.deleteRecursively()
|
||||
}
|
||||
}
|
||||
|
||||
fun testManyFiles() {
|
||||
doTest()
|
||||
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright 2010-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.jps.build
|
||||
|
||||
inline fun withSystemProperty(property: String, newValue: String?, fn: ()->Unit) {
|
||||
val backup = System.getProperty(property)
|
||||
setOrClearSysProperty(property, newValue)
|
||||
|
||||
try {
|
||||
fn()
|
||||
}
|
||||
finally {
|
||||
setOrClearSysProperty(property, backup)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
inline fun setOrClearSysProperty(property: String, newValue: String?) {
|
||||
if (newValue != null) {
|
||||
System.setProperty(property, newValue)
|
||||
}
|
||||
else {
|
||||
System.clearProperty(property)
|
||||
}
|
||||
}
|
||||
@@ -69,6 +69,8 @@ class JpsKotlinCompilerRunner : KotlinCompilerRunner<JpsCompilerEnvironment>() {
|
||||
|
||||
return _jpsCompileServiceSession
|
||||
}
|
||||
|
||||
const val FAIL_ON_FALLBACK_PROPERTY = "test.kotlin.jps.compiler.runner.fail.on.fallback"
|
||||
}
|
||||
|
||||
fun runK2JvmCompiler(
|
||||
@@ -190,6 +192,10 @@ class JpsKotlinCompilerRunner : KotlinCompilerRunner<JpsCompilerEnvironment>() {
|
||||
compilerClassName: String,
|
||||
environment: JpsCompilerEnvironment
|
||||
): ExitCode {
|
||||
if ("true" == System.getProperty("kotlin.jps.tests") && "true" == System.getProperty(FAIL_ON_FALLBACK_PROPERTY)) {
|
||||
error("Fallback strategy is disabled in tests!")
|
||||
}
|
||||
|
||||
// otherwise fallback to in-process
|
||||
log.info("Compile in-process")
|
||||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
<?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" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="IDEA_JDK" jdkType="JavaSDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="KotlinRuntime" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -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_6" assert-keyword="true" jdk-15="true" project-jdk-name="IDEA_JDK" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
@@ -0,0 +1 @@
|
||||
class Foo()
|
||||
@@ -0,0 +1,3 @@
|
||||
fun main() {
|
||||
Foo()
|
||||
}
|
||||
Reference in New Issue
Block a user