From 57b96480414d40266817c365fb5e22cfeada084b Mon Sep 17 00:00:00 2001 From: Dmitry Gridin Date: Wed, 13 Apr 2022 18:40:21 +0700 Subject: [PATCH] make jps-plugin testable from IJ infrastructure ^KTIJ-20456 --- build.gradle.kts | 1 + .../jetbrains/kotlin/test/MockLibraryUtil.kt | 9 ++++- .../jps/build/AbstractIncrementalJpsTest.kt | 22 ++++------- .../build/AbstractKotlinJpsBuildTestCase.kt | 18 ++------- .../jps/build/AbstractLookupTrackerTest.kt | 18 ++------- .../kotlin/jps/build/KotlinJpsBuildTest.kt | 18 ++------- .../kotlin/jps/build/KotlinLibraries.kt | 38 +++++++++++++------ .../kotlin/jps/incremental/compilerUtils.kt | 24 ++++-------- .../kotlin/jvm/compiler/ClasspathOrderTest.kt | 24 ++++-------- .../modules/KotlinModuleXmlGeneratorTest.java | 29 +++++--------- .../kotlin/jps/build/KotlinBuilder.kt | 19 ++-------- .../build.gradle.kts | 4 +- .../build.gradle.kts | 9 +++++ settings.gradle | 1 + 14 files changed, 96 insertions(+), 138 deletions(-) create mode 100644 prepare/ide-plugin-dependencies/kotlin-jps-plugin-tests-for-ide/build.gradle.kts diff --git a/build.gradle.kts b/build.gradle.kts index 185c1c1e466..85b3f38b82a 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -285,6 +285,7 @@ extra["compilerArtifactsForIde"] = listOf( ":prepare:ide-plugin-dependencies:kotlin-gradle-statistics-for-ide", ":prepare:ide-plugin-dependencies:kotlin-jps-common-for-ide", ":prepare:ide-plugin-dependencies:kotlin-jps-plugin-classpath", + ":prepare:ide-plugin-dependencies:kotlin-jps-plugin-tests-for-ide", ":prepare:ide-plugin-dependencies:kotlinx-serialization-compiler-plugin-for-ide", ":prepare:ide-plugin-dependencies:noarg-compiler-plugin-for-ide", ":prepare:ide-plugin-dependencies:sam-with-receiver-compiler-plugin-for-ide", diff --git a/compiler/tests-compiler-utils/tests/org/jetbrains/kotlin/test/MockLibraryUtil.kt b/compiler/tests-compiler-utils/tests/org/jetbrains/kotlin/test/MockLibraryUtil.kt index 6d53d4b71d9..6a851393217 100644 --- a/compiler/tests-compiler-utils/tests/org/jetbrains/kotlin/test/MockLibraryUtil.kt +++ b/compiler/tests-compiler-utils/tests/org/jetbrains/kotlin/test/MockLibraryUtil.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2022 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. */ @@ -16,6 +16,8 @@ import org.jetbrains.kotlin.preloading.ClassPreloadingUtils import org.jetbrains.kotlin.preloading.Preloader import org.jetbrains.kotlin.test.KtAssert.assertTrue import org.jetbrains.kotlin.test.util.KtTestUtil +import org.jetbrains.kotlin.utils.KotlinPaths +import org.jetbrains.kotlin.utils.KotlinPathsFromHomeDir import org.jetbrains.kotlin.utils.PathUtil import java.io.ByteArrayOutputStream import java.io.File @@ -26,6 +28,9 @@ import java.util.regex.Pattern import java.util.zip.ZipOutputStream import kotlin.reflect.KClass +val PathUtil.kotlinPathsForDistDirectoryForTests: KotlinPaths + get() = System.getProperty("jps.kotlin.home")?.let(::File)?.let(::KotlinPathsFromHomeDir) ?: kotlinPathsForDistDirectory + object MockLibraryUtil { private var compilerClassLoader = SoftReference(null) @@ -230,7 +235,7 @@ object MockLibraryUtil { @Synchronized private fun createCompilerClassLoader(): ClassLoader { return ClassPreloadingUtils.preloadClasses( - listOf(PathUtil.kotlinPathsForDistDirectory.compilerPath), + listOf(PathUtil.kotlinPathsForDistDirectoryForTests.compilerPath), Preloader.DEFAULT_CLASS_NUMBER_ESTIMATE, null, null ) } diff --git a/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/AbstractIncrementalJpsTest.kt b/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/AbstractIncrementalJpsTest.kt index 71f0fce7c2f..55f68956764 100644 --- a/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/AbstractIncrementalJpsTest.kt +++ b/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/AbstractIncrementalJpsTest.kt @@ -1,17 +1,6 @@ /* - * Copyright 2010-2016 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. + * Copyright 2010-2022 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.jps.build @@ -66,6 +55,7 @@ import org.jetbrains.kotlin.platform.idePlatformKind import org.jetbrains.kotlin.platform.impl.isJavaScript import org.jetbrains.kotlin.platform.impl.isJvm import org.jetbrains.kotlin.platform.orDefault +import org.jetbrains.kotlin.test.KotlinTestUtils import org.jetbrains.kotlin.utils.Printer import java.io.ByteArrayInputStream import java.io.ByteArrayOutputStream @@ -325,11 +315,15 @@ abstract class AbstractIncrementalJpsTest( } protected open fun doTest(testDataPath: String) { + KotlinTestUtils.runTest(this::executeTest, this, testDataPath) + } + + private fun executeTest(testDataPath: String) { testDataDir = File(testDataPath) workDir = FileUtilRt.createTempDirectory(TEMP_DIRECTORY_TO_USE, "aijt-jps-build", null) additionalCommandLineArguments = parseAdditionalArgs(File(testDataPath)) val buildLogFile = buildLogFinder.findBuildLog(testDataDir) - Disposer.register(testRootDisposable, Disposable { FileUtilRt.delete(workDir) }) + Disposer.register(testRootDisposable) { FileUtilRt.delete(workDir) } val modulesTxt = configureModules() if (modulesTxt?.muted == true) return diff --git a/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/AbstractKotlinJpsBuildTestCase.kt b/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/AbstractKotlinJpsBuildTestCase.kt index 7c720a34ac6..465155fcead 100644 --- a/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/AbstractKotlinJpsBuildTestCase.kt +++ b/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/AbstractKotlinJpsBuildTestCase.kt @@ -1,17 +1,6 @@ /* - * Copyright 2010-2015 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. + * Copyright 2010-2022 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.jps.build @@ -23,7 +12,6 @@ import org.jetbrains.jps.model.java.JpsJavaLibraryType import org.jetbrains.jps.model.library.JpsLibrary import org.jetbrains.jps.model.library.JpsOrderRootType import org.jetbrains.jps.model.module.JpsModule -import org.jetbrains.jps.util.JpsPathUtil import java.io.File import java.io.IOException @@ -60,7 +48,7 @@ abstract class AbstractKotlinJpsBuildTestCase : BaseKotlinJpsBuildTestCase() { } companion object { - val TEST_DATA_PATH = "jps/jps-plugin/testData/" + val TEST_DATA_PATH get() = System.getProperty("pass.jps.testData.home") ?: "jps/jps-plugin/testData/" @JvmStatic protected fun addKotlinStdlibDependency(modules: Collection, exported: Boolean = false): JpsLibrary { diff --git a/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/AbstractLookupTrackerTest.kt b/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/AbstractLookupTrackerTest.kt index 78a5f496ba2..217dff4a7ad 100644 --- a/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/AbstractLookupTrackerTest.kt +++ b/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/AbstractLookupTrackerTest.kt @@ -1,17 +1,6 @@ /* - * Copyright 2010-2015 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. + * Copyright 2010-2022 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.jps.build @@ -44,6 +33,7 @@ import org.jetbrains.kotlin.jps.build.fixtures.EnableICFixture import org.jetbrains.kotlin.jps.incremental.createTestingCompilerEnvironment import org.jetbrains.kotlin.jps.incremental.runJSCompiler import org.jetbrains.kotlin.test.KotlinTestUtils +import org.jetbrains.kotlin.test.kotlinPathsForDistDirectoryForTests import org.jetbrains.kotlin.utils.JsMetadataVersion import org.jetbrains.kotlin.utils.PathUtil import java.io.* @@ -167,7 +157,7 @@ abstract class AbstractJsLookupTrackerTest : AbstractLookupTrackerTest() { } protected open val jsStdlibFile: File - get() = PathUtil.kotlinPathsForDistDirectory.jsStdLibJarPath + get() = PathUtil.kotlinPathsForDistDirectoryForTests.jsStdLibJarPath protected open fun configureAdditionalArgs(args: K2JSCompilerArguments) { args.outputFile = File(outDir, "out.js").canonicalPath diff --git a/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/KotlinJpsBuildTest.kt b/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/KotlinJpsBuildTest.kt index 05b660732cf..ba654ff3b67 100644 --- a/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/KotlinJpsBuildTest.kt +++ b/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/KotlinJpsBuildTest.kt @@ -1,17 +1,6 @@ /* - * Copyright 2010-2016 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. + * Copyright 2010-2022 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.jps.build @@ -66,6 +55,7 @@ import org.jetbrains.kotlin.load.kotlin.PackagePartClassUtils import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.test.KotlinTestUtils import org.jetbrains.kotlin.test.MockLibraryUtilExt +import org.jetbrains.kotlin.test.kotlinPathsForDistDirectoryForTests import org.jetbrains.kotlin.test.util.KtTestUtil import org.jetbrains.kotlin.utils.PathUtil import org.jetbrains.kotlin.utils.Printer @@ -243,7 +233,7 @@ open class KotlinJpsBuildTest : KotlinJpsBuildTestBase() { fun testKotlinJavaScriptProjectWithDirectoryAsStdlib() { initProject() setupKotlinJSFacet() - val jslibJar = PathUtil.kotlinPathsForDistDirectory.jsStdLibJarPath + val jslibJar = PathUtil.kotlinPathsForDistDirectoryForTests.jsStdLibJarPath val jslibDir = File(workDir, "KotlinJavaScript") try { Decompressor.Zip(jslibJar).extract(jslibDir) diff --git a/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/KotlinLibraries.kt b/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/KotlinLibraries.kt index 16757a2350c..05e817eacb0 100644 --- a/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/KotlinLibraries.kt +++ b/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/KotlinLibraries.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2022 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. */ @@ -9,40 +9,56 @@ import org.jetbrains.jps.model.JpsProject import org.jetbrains.jps.model.java.JpsJavaLibraryType import org.jetbrains.jps.model.library.JpsLibrary import org.jetbrains.jps.model.library.JpsOrderRootType +import org.jetbrains.kotlin.test.kotlinPathsForDistDirectoryForTests import org.jetbrains.kotlin.utils.PathUtil import java.io.File -enum class KotlinJpsLibrary(val id: String, vararg val roots: File) { +enum class KotlinJpsLibrary(val id: String, roots: () -> Array) { MockRuntime( "kotlin-mock-runtime", - PathUtil.kotlinPathsForDistDirectory.stdlibPath, - File(PathUtil.kotlinPathsForDistDirectory.libPath, "annotations-13.0.jar") + { + arrayOf( + PathUtil.kotlinPathsForDistDirectoryForTests.stdlibPath, + File(PathUtil.kotlinPathsForDistDirectoryForTests.libPath, "annotations-13.0.jar"), + ) + } ), JvmStdLib( "kotlin-stdlib", - PathUtil.kotlinPathsForDistDirectory.stdlibPath, - File(PathUtil.kotlinPathsForDistDirectory.libPath, "annotations-13.0.jar") + { + arrayOf( + PathUtil.kotlinPathsForDistDirectoryForTests.stdlibPath, + File(PathUtil.kotlinPathsForDistDirectoryForTests.libPath, "annotations-13.0.jar"), + ) + } ), + JvmTest( "kotlin-test", - PathUtil.kotlinPathsForDistDirectory.kotlinTestPath + { arrayOf(PathUtil.kotlinPathsForDistDirectoryForTests.kotlinTestPath) }, ), JsStdLib( "KotlinJavaScript", - PathUtil.kotlinPathsForDistDirectory.jsStdLibJarPath + { arrayOf(PathUtil.kotlinPathsForDistDirectoryForTests.jsStdLibJarPath) } ), JsTest( "KotlinJavaScriptTest", - PathUtil.kotlinPathsForDistDirectory.jsKotlinTestJarPath + { arrayOf(PathUtil.kotlinPathsForDistDirectoryForTests.jsKotlinTestJarPath) } ), Lombok( "lombok", - PathUtil.kotlinPathsForDistDirectory.stdlibPath, - File(lombok.Lombok::class.java.protectionDomain.codeSource.location.toURI().path) + { + arrayOf( + PathUtil.kotlinPathsForDistDirectoryForTests.stdlibPath, + File(lombok.Lombok::class.java.protectionDomain.codeSource.location.toURI().path), + ) + } ); + val roots: Array by lazy(roots) + fun create(project: JpsProject): JpsLibrary { val library = project.addLibrary(id, JpsJavaLibraryType.INSTANCE) diff --git a/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/incremental/compilerUtils.kt b/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/incremental/compilerUtils.kt index 1eae8c7231f..78dc7ec5358 100644 --- a/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/incremental/compilerUtils.kt +++ b/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/incremental/compilerUtils.kt @@ -1,17 +1,6 @@ /* - * 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. + * Copyright 2010-2022 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.jps.incremental @@ -23,16 +12,19 @@ import org.jetbrains.kotlin.cli.js.K2JSCompiler import org.jetbrains.kotlin.compilerRunner.* import org.jetbrains.kotlin.config.Services import org.jetbrains.kotlin.jps.build.KotlinBuilder +import org.jetbrains.kotlin.test.kotlinPathsForDistDirectoryForTests import org.jetbrains.kotlin.utils.PathUtil -import java.io.* +import java.io.BufferedReader +import java.io.ByteArrayOutputStream +import java.io.PrintStream +import java.io.StringReader fun createTestingCompilerEnvironment( messageCollector: MessageCollector, outputItemsCollector: OutputItemsCollectorImpl, services: Services ): JpsCompilerEnvironment { - val paths = PathUtil.kotlinPathsForDistDirectory - + val paths = PathUtil.kotlinPathsForDistDirectoryForTests val wrappedMessageCollector = MessageCollectorToOutputItemsCollectorAdapter(messageCollector, outputItemsCollector) return JpsCompilerEnvironment( paths, diff --git a/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jvm/compiler/ClasspathOrderTest.kt b/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jvm/compiler/ClasspathOrderTest.kt index 2663e5a8acc..c1c3eb627b5 100644 --- a/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jvm/compiler/ClasspathOrderTest.kt +++ b/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jvm/compiler/ClasspathOrderTest.kt @@ -1,17 +1,6 @@ /* - * Copyright 2010-2015 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. + * Copyright 2010-2022 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.jvm.compiler @@ -19,12 +8,12 @@ package org.jetbrains.kotlin.jvm.compiler import org.jetbrains.jps.builders.java.JavaModuleBuildTargetType import org.jetbrains.kotlin.build.JvmSourceRoot import org.jetbrains.kotlin.config.IncrementalCompilation +import org.jetbrains.kotlin.jps.build.AbstractKotlinJpsBuildTestCase import org.jetbrains.kotlin.modules.KotlinModuleXmlBuilder import org.jetbrains.kotlin.test.MockLibraryUtil import org.jetbrains.kotlin.test.TestCaseWithTmpdir -import org.jetbrains.kotlin.test.util.KtTestUtil +import org.jetbrains.kotlin.test.kotlinPathsForDistDirectoryForTests import org.jetbrains.kotlin.utils.PathUtil -import org.junit.Ignore import java.io.File /** @@ -34,7 +23,8 @@ import java.io.File */ class ClasspathOrderTest : TestCaseWithTmpdir() { companion object { - private val sourceDir = File(KtTestUtil.getTestDataPathBase() + "/classpathOrder").absoluteFile + private val sourceDir + get() = File(AbstractKotlinJpsBuildTestCase.TEST_DATA_PATH + "/../../../compiler/testData/classpathOrder").absoluteFile } fun testClasspathOrderForCLI() { @@ -47,7 +37,7 @@ class ClasspathOrderTest : TestCaseWithTmpdir() { File(tmpdir, "output").absolutePath, listOf(sourceDir), listOf(JvmSourceRoot(sourceDir)), - listOf(PathUtil.kotlinPathsForDistDirectory.stdlibPath), + listOf(PathUtil.kotlinPathsForDistDirectoryForTests.stdlibPath), emptyList(), null, JavaModuleBuildTargetType.PRODUCTION.typeId, diff --git a/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/modules/KotlinModuleXmlGeneratorTest.java b/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/modules/KotlinModuleXmlGeneratorTest.java index 32c0ed2df7e..da63e280448 100644 --- a/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/modules/KotlinModuleXmlGeneratorTest.java +++ b/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/modules/KotlinModuleXmlGeneratorTest.java @@ -1,17 +1,6 @@ /* - * Copyright 2010-2015 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. + * Copyright 2010-2022 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.modules; @@ -20,15 +9,17 @@ import junit.framework.TestCase; import org.jetbrains.jps.builders.java.JavaModuleBuildTargetType; import org.jetbrains.kotlin.build.JvmSourceRoot; import org.jetbrains.kotlin.config.IncrementalCompilation; +import org.jetbrains.kotlin.jps.build.AbstractKotlinJpsBuildTestCase; import org.jetbrains.kotlin.test.KotlinTestUtils; -import org.jetbrains.kotlin.test.util.KtTestUtil; import java.io.File; import java.util.Arrays; import java.util.Collections; public class KotlinModuleXmlGeneratorTest extends TestCase { - private final static String testDataPath = "jps/jps-plugin/testData/modules.xml"; + private static String getTestDataPath() { + return AbstractKotlinJpsBuildTestCase.Companion.getTEST_DATA_PATH() + "/modules.xml"; + } public void testBasic() { String actual = new KotlinModuleXmlBuilder().addModule( @@ -45,7 +36,7 @@ public class KotlinModuleXmlGeneratorTest extends TestCase { Collections.emptyList(), IncrementalCompilation.isEnabledForJvm() ).asText().toString(); - KotlinTestUtils.assertEqualsToFile(new File(testDataPath + "/basic.xml"), actual); + KotlinTestUtils.assertEqualsToFile(new File(getTestDataPath() + "/basic.xml"), actual); } public void testFiltered() { @@ -63,7 +54,7 @@ public class KotlinModuleXmlGeneratorTest extends TestCase { Collections.emptyList(), IncrementalCompilation.isEnabledForJvm() ).asText().toString(); - KotlinTestUtils.assertEqualsToFile(new File(testDataPath + "/filtered.xml"), actual); + KotlinTestUtils.assertEqualsToFile(new File(getTestDataPath() + "/filtered.xml"), actual); } public void testMultiple() { @@ -97,7 +88,7 @@ public class KotlinModuleXmlGeneratorTest extends TestCase { IncrementalCompilation.isEnabledForJvm() ); String actual = builder.asText().toString(); - KotlinTestUtils.assertEqualsToFile(new File(testDataPath + "/multiple.xml"), actual); + KotlinTestUtils.assertEqualsToFile(new File(getTestDataPath() + "/multiple.xml"), actual); } public void testModularJdkRoot() { @@ -115,6 +106,6 @@ public class KotlinModuleXmlGeneratorTest extends TestCase { Collections.emptyList(), IncrementalCompilation.isEnabledForJvm() ).asText().toString(); - KotlinTestUtils.assertEqualsToFile(new File(testDataPath + "/modularJdkRoot.xml"), actual); + KotlinTestUtils.assertEqualsToFile(new File(getTestDataPath() + "/modularJdkRoot.xml"), actual); } } diff --git a/jps/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinBuilder.kt b/jps/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinBuilder.kt index 8e7e2a7c37e..aaa5cedcf35 100644 --- a/jps/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinBuilder.kt +++ b/jps/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinBuilder.kt @@ -1,17 +1,6 @@ /* - * Copyright 2010-2016 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. + * Copyright 2010-2022 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.jps.build @@ -636,11 +625,11 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) { // When JPS is run on TeamCity, it can not rely on Kotlin plugin layout, // so the path to Kotlin is specified in a system property private fun computeKotlinPathsForJpsPlugin(messageCollector: MessageCollectorAdapter): KotlinPaths? { - if (System.getProperty("kotlin.jps.tests").equals("true", ignoreCase = true)) { + val jpsKotlinHome = System.getProperty(JPS_KOTLIN_HOME_PROPERTY)?.let { File(it) } + if (System.getProperty("kotlin.jps.tests").equals("true", ignoreCase = true) && jpsKotlinHome == null) { return PathUtil.kotlinPathsForDistDirectory } - val jpsKotlinHome = System.getProperty(JPS_KOTLIN_HOME_PROPERTY)?.let { File(it) } return when { jpsKotlinHome == null -> { messageCollector.report(ERROR, "Make sure that '$JPS_KOTLIN_HOME_PROPERTY' system property is set in JPS process") diff --git a/prepare/ide-plugin-dependencies/kotlin-compiler-testdata-for-ide/build.gradle.kts b/prepare/ide-plugin-dependencies/kotlin-compiler-testdata-for-ide/build.gradle.kts index 957d3707e09..492bf9080b9 100644 --- a/prepare/ide-plugin-dependencies/kotlin-compiler-testdata-for-ide/build.gradle.kts +++ b/prepare/ide-plugin-dependencies/kotlin-compiler-testdata-for-ide/build.gradle.kts @@ -19,7 +19,9 @@ idePluginDependency { "compiler/testData/diagnostics/helpers", "compiler/tests-spec/testData", "compiler/testData/diagnostics/testsWithStdLib", - "compiler/fir/raw-fir/psi2fir/testData" + "compiler/fir/raw-fir/psi2fir/testData", + "jps/jps-plugin/testData", + "compiler/testData/classpathOrder", ).forEach { from(rootDir.resolve(it)) { into(it) diff --git a/prepare/ide-plugin-dependencies/kotlin-jps-plugin-tests-for-ide/build.gradle.kts b/prepare/ide-plugin-dependencies/kotlin-jps-plugin-tests-for-ide/build.gradle.kts new file mode 100644 index 00000000000..7e58dbe5d5e --- /dev/null +++ b/prepare/ide-plugin-dependencies/kotlin-jps-plugin-tests-for-ide/build.gradle.kts @@ -0,0 +1,9 @@ +plugins { + kotlin("jvm") +} + +publishTestJarsForIde( + listOf( + ":jps:jps-plugin", + ) +) diff --git a/settings.gradle b/settings.gradle index 9b89815f5f0..44f1200c33c 100644 --- a/settings.gradle +++ b/settings.gradle @@ -352,6 +352,7 @@ if (!buildProperties.inJpsBuildIdeaSync) { ":prepare:ide-plugin-dependencies:kotlin-gradle-statistics-for-ide", ":prepare:ide-plugin-dependencies:kotlin-jps-common-for-ide", ":prepare:ide-plugin-dependencies:kotlin-jps-plugin-classpath", + ":prepare:ide-plugin-dependencies:kotlin-jps-plugin-tests-for-ide", ":prepare:ide-plugin-dependencies:kotlinx-serialization-compiler-plugin-for-ide", ":prepare:ide-plugin-dependencies:noarg-compiler-plugin-for-ide", ":prepare:ide-plugin-dependencies:sam-with-receiver-compiler-plugin-for-ide",