From 6fd060b166fa33a4fa3c02818989d84211a44561 Mon Sep 17 00:00:00 2001 From: Alexey Sedunov Date: Thu, 24 May 2018 17:01:12 +0300 Subject: [PATCH] Configuration: Support TeamCity repository for dev-versions --- .../gradle/GradleConfiguratorTest.kt | 130 ++++++++++++++++++ .../ConfigureKotlinInProjectUtils.kt | 13 ++ 2 files changed, 143 insertions(+) diff --git a/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/GradleConfiguratorTest.kt b/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/GradleConfiguratorTest.kt index 1669caf530d..6a1b36aabc8 100644 --- a/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/GradleConfiguratorTest.kt +++ b/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/GradleConfiguratorTest.kt @@ -183,6 +183,136 @@ class GradleConfiguratorTest : GradleImportingTestCase() { } } + @Test + fun testConfigureKotlinDevVersion() { + createProjectSubFile("settings.gradle", "include ':app'") + val file = createProjectSubFile( + "app/build.gradle", """ + group 'testgroup' + version '1.0-SNAPSHOT' + """.trimIndent() + ) + + importProject() + + runInEdtAndWait { + runWriteAction { + val module = ModuleManager.getInstance(myProject).findModuleByName("app")!! + val configurator = findGradleModuleConfigurator() + val collector = createConfigureKotlinNotificationCollector(myProject) + configurator.configureWithVersion(myProject, listOf(module), "1.2.60-dev-286", collector) + + FileDocumentManager.getInstance().saveAllDocuments() + val content = LoadTextUtil.loadText(file).toString() + assertEquals( + """ + group 'testgroup' + version '1.0-SNAPSHOT' + buildscript { + ext.kotlin_version = '1.2.60-dev-286' + repositories { + maven { + url 'https://teamcity.jetbrains.com/guestAuth/app/rest/builds/buildType:(id:Kotlin_dev_Compiler),number:1.2.60-dev-286,branch:default:any/artifacts/content/maven/' + } + mavenCentral() + } + dependencies { + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${"$"}kotlin_version" + } + } + apply plugin: 'kotlin' + repositories { + maven { + url 'https://teamcity.jetbrains.com/guestAuth/app/rest/builds/buildType:(id:Kotlin_dev_Compiler),number:1.2.60-dev-286,branch:default:any/artifacts/content/maven/' + } + mavenCentral() + } + dependencies { + compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:${"$"}kotlin_version" + } + compileKotlin { + kotlinOptions { + jvmTarget = "1.8" + } + } + compileTestKotlin { + kotlinOptions { + jvmTarget = "1.8" + } + } + """.trimIndent(), content + ) + } + } + } + + @Test + fun testConfigureGradleKtsKotlinDevVersion() { + createProjectSubFile("settings.gradle", "include ':app'") + val file = createProjectSubFile( + "app/build.gradle.kts", """ + group = "testgroup" + version = "1.0-SNAPSHOT" + """.trimIndent() + ) + + importProject() + + runInEdtAndWait { + runWriteAction { + val module = ModuleManager.getInstance(myProject).findModuleByName("app")!! + val configurator = findGradleModuleConfigurator() + val collector = createConfigureKotlinNotificationCollector(myProject) + configurator.configureWithVersion(myProject, listOf(module), "1.2.60-dev-286", collector) + + FileDocumentManager.getInstance().saveAllDocuments() + val content = LoadTextUtil.loadText(file).toString() + assertEquals( + """ + import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + + val kotlin_version: String by extra + buildscript { + var kotlin_version: String by extra + kotlin_version = "1.2.60-dev-286" + repositories { + maven { + setUrl("https://teamcity.jetbrains.com/guestAuth/app/rest/builds/buildType:(id:Kotlin_dev_Compiler),number:1.2.60-dev-286,branch:default:any/artifacts/content/maven/") + } + mavenCentral() + } + dependencies { + classpath(kotlinModule("gradle-plugin", kotlin_version)) + } + } + group = "testgroup" + version = "1.0-SNAPSHOT" + apply { + plugin("kotlin") + } + dependencies { + compile(kotlinModule("stdlib-jdk8", kotlin_version)) + } + repositories { + maven { + setUrl("https://teamcity.jetbrains.com/guestAuth/app/rest/builds/buildType:(id:Kotlin_dev_Compiler),number:1.2.60-dev-286,branch:default:any/artifacts/content/maven/") + } + mavenCentral() + } + val compileKotlin: KotlinCompile by tasks + compileKotlin.kotlinOptions { + jvmTarget = "1.8" + } + val compileTestKotlin: KotlinCompile by tasks + compileTestKotlin.kotlinOptions { + jvmTarget = "1.8" + } + """.trimIndent(), content + ) + } + } + } + @Test @Ignore // Enable in Gradle 4.4+ fun testConfigureJvmWithBuildGradle() { diff --git a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/configuration/ConfigureKotlinInProjectUtils.kt b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/configuration/ConfigureKotlinInProjectUtils.kt index 66cfa88938e..01ca87a480b 100644 --- a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/configuration/ConfigureKotlinInProjectUtils.kt +++ b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/configuration/ConfigureKotlinInProjectUtils.kt @@ -60,6 +60,14 @@ val EAP_REPOSITORY = RepositoryDescription( "https://bintray.com/kotlin/kotlin-eap/kotlin/", isSnapshot = false) +fun devRepository(version: String) = RepositoryDescription( + "teamcity.kotlin.dev", + "Teamcity Repository of Kotlin Development Builds", + "https://teamcity.jetbrains.com/guestAuth/app/rest/builds/buildType:(id:Kotlin_dev_Compiler),number:$version,branch:default:any/artifacts/content/maven/", + null, + isSnapshot = false +) + val MAVEN_CENTRAL = "mavenCentral()" val JCENTER = "jcenter()" @@ -85,6 +93,7 @@ fun RepositoryDescription.toKotlinRepositorySnippet() = "maven {\n setUrl(\"$ fun getRepositoryForVersion(version: String): RepositoryDescription? = when { isSnapshot(version) -> SNAPSHOT_REPOSITORY isEap(version) -> EAP_REPOSITORY + isDev(version) -> devRepository(version) else -> null } @@ -271,6 +280,10 @@ fun isEap(version: String): Boolean { return version.contains("rc") || version.contains("eap") || version.contains("-M") } +fun isDev(version: String): Boolean { + return version.contains("dev") +} + private class LibraryKindSearchScope(val module: Module, val baseScope: GlobalSearchScope, val libraryKind: PersistentLibraryKind<*>