From ace44070324b2c746aa07a39d0037b2781cc1e85 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Fri, 16 Dec 2016 13:44:50 +0100 Subject: [PATCH] Add 1.1 EAP repository when creating a new Gradle project with 1.1 EAP #KT-15293 Fixed --- .../configuration/KotlinMavenConfigurator.kt | 6 +++- .../ConfigureKotlinInProjectUtils.kt | 10 ++++++ ...radleKotlinJavaFrameworkSupportProvider.kt | 3 ++ .../KotlinWithGradleConfigurator.kt | 32 ++++++++---------- .../gradle/m04Version_after.gradle | 33 +++++++++++++++++++ .../gradle/m04Version_before.gradle | 14 ++++++++ .../configuration/ConfigureKotlinUtilTest.kt | 33 +++++++++++++++++++ ...ureProjectByChangingFileTestGenerated.java | 6 ++++ 8 files changed, 118 insertions(+), 19 deletions(-) create mode 100644 idea/testData/configuration/gradle/m04Version_after.gradle create mode 100644 idea/testData/configuration/gradle/m04Version_before.gradle create mode 100644 idea/tests/org/jetbrains/kotlin/idea/configuration/ConfigureKotlinUtilTest.kt diff --git a/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/configuration/KotlinMavenConfigurator.kt b/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/configuration/KotlinMavenConfigurator.kt index e70b739d527..a7d3799bc10 100644 --- a/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/configuration/KotlinMavenConfigurator.kt +++ b/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/configuration/KotlinMavenConfigurator.kt @@ -133,7 +133,11 @@ abstract class KotlinMavenConfigurator pom.addLibraryRepository(SNAPSHOT_REPOSITORY) pom.addPluginRepository(SNAPSHOT_REPOSITORY) } - if (isEap(version)) { + else if (is11Prerelease(version)) { + pom.addLibraryRepository(EAP_11_REPOSITORY) + pom.addPluginRepository(EAP_11_REPOSITORY) + } + else if (isEap(version)) { pom.addLibraryRepository(EAP_REPOSITORY) pom.addPluginRepository(EAP_REPOSITORY) } diff --git a/idea/src/org/jetbrains/kotlin/idea/configuration/ConfigureKotlinInProjectUtils.kt b/idea/src/org/jetbrains/kotlin/idea/configuration/ConfigureKotlinInProjectUtils.kt index a7a36ce69ef..f0eb0af5d33 100644 --- a/idea/src/org/jetbrains/kotlin/idea/configuration/ConfigureKotlinInProjectUtils.kt +++ b/idea/src/org/jetbrains/kotlin/idea/configuration/ConfigureKotlinInProjectUtils.kt @@ -47,6 +47,13 @@ val EAP_REPOSITORY = RepositoryDescription( "http://dl.bintray.com/kotlin/kotlin-eap", isSnapshot = false) +@JvmField +val EAP_11_REPOSITORY = RepositoryDescription( + "bintray.kotlin.eap", + "Bintray Kotlin 1.1 EAP Repository", + "http://dl.bintray.com/kotlin/kotlin-eap-1.1", + isSnapshot = false) + fun isModuleConfigured(module: Module): Boolean { return Extensions.getExtensions(KotlinProjectConfigurator.EP_NAME).any { it.getStatus(module) == ConfigureKotlinStatus.CONFIGURED @@ -151,3 +158,6 @@ fun isEap(version: String): Boolean { return version.contains("rc") || version.contains("eap") } +fun is11Prerelease(version: String): Boolean { + return Regex("1\\.1-[A-Za-z][A-Za-z0-9-]*").matches(version) && !version.startsWith("1.1-dev") +} diff --git a/idea/src/org/jetbrains/kotlin/idea/configuration/GradleKotlinJavaFrameworkSupportProvider.kt b/idea/src/org/jetbrains/kotlin/idea/configuration/GradleKotlinJavaFrameworkSupportProvider.kt index 85a732d7752..45c2d17a6eb 100644 --- a/idea/src/org/jetbrains/kotlin/idea/configuration/GradleKotlinJavaFrameworkSupportProvider.kt +++ b/idea/src/org/jetbrains/kotlin/idea/configuration/GradleKotlinJavaFrameworkSupportProvider.kt @@ -47,6 +47,9 @@ class GradleKotlinJavaFrameworkSupportProvider : GradleFrameworkSupportProvider( kotlinVersion = "1.1-SNAPSHOT" KotlinWithGradleConfigurator.SNAPSHOT_REPOSITORY_SNIPPET } + is11Prerelease(kotlinVersion) -> { + KotlinWithGradleConfigurator.EAP_11_REPOSITORY_SNIPPET + } isEap(kotlinVersion) -> { KotlinWithGradleConfigurator.EAP_REPOSITORY_SNIPPET } diff --git a/idea/src/org/jetbrains/kotlin/idea/configuration/KotlinWithGradleConfigurator.kt b/idea/src/org/jetbrains/kotlin/idea/configuration/KotlinWithGradleConfigurator.kt index 0e6afdd2d73..16ea9f66e8b 100644 --- a/idea/src/org/jetbrains/kotlin/idea/configuration/KotlinWithGradleConfigurator.kt +++ b/idea/src/org/jetbrains/kotlin/idea/configuration/KotlinWithGradleConfigurator.kt @@ -137,15 +137,7 @@ abstract class KotlinWithGradleConfigurator : KotlinProjectConfigurator { } val repositoriesBlock = getRepositoriesBlock(file) - if (isSnapshot(version)) { - wasModified = wasModified or addLastExpressionInBlockIfNeeded(SNAPSHOT_REPOSITORY_SNIPPET, repositoriesBlock) - } - else if (isEap(version)) { - wasModified = wasModified or addLastExpressionInBlockIfNeeded(EAP_REPOSITORY_SNIPPET, repositoriesBlock) - } - else if (!isRepositoryConfigured(repositoriesBlock)) { - wasModified = wasModified or addLastExpressionInBlockIfNeeded(MAVEN_CENTRAL, repositoriesBlock) - } + wasModified = wasModified or addRepository(repositoriesBlock, version) val dependenciesBlock = getDependenciesBlock(file) wasModified = wasModified or addExpressionInBlockIfNeeded(LIBRARY, dependenciesBlock, false) @@ -195,6 +187,7 @@ abstract class KotlinWithGradleConfigurator : KotlinProjectConfigurator { val SNAPSHOT_REPOSITORY_SNIPPET = "maven {\nurl '" + SNAPSHOT_REPOSITORY.url + "'\n}" val EAP_REPOSITORY_SNIPPET = "maven {\nurl '" + EAP_REPOSITORY.url + "'\n}" + val EAP_11_REPOSITORY_SNIPPET = "maven {\nurl '" + EAP_11_REPOSITORY.url + "'\n}" private val MAVEN_CENTRAL = "mavenCentral()\n" private val JCENTER = "jcenter()\n" @@ -279,15 +272,7 @@ abstract class KotlinWithGradleConfigurator : KotlinProjectConfigurator { wasModified = addFirstExpressionInBlockIfNeeded(VERSION.replace(VERSION_TEMPLATE, version), buildScriptBlock) val buildScriptRepositoriesBlock = getBuildScriptRepositoriesBlock(file) - if (isSnapshot(version)) { - wasModified = wasModified or addLastExpressionInBlockIfNeeded(SNAPSHOT_REPOSITORY_SNIPPET, buildScriptRepositoriesBlock) - } - else if (isEap(version)) { - wasModified = wasModified or addLastExpressionInBlockIfNeeded(EAP_REPOSITORY_SNIPPET, buildScriptRepositoriesBlock) - } - else if (!isRepositoryConfigured(buildScriptRepositoriesBlock)) { - wasModified = wasModified or addLastExpressionInBlockIfNeeded(MAVEN_CENTRAL, buildScriptRepositoriesBlock) - } + wasModified = wasModified or addRepository(buildScriptRepositoriesBlock, version) val buildScriptDependenciesBlock = getBuildScriptDependenciesBlock(file) wasModified = wasModified or addLastExpressionInBlockIfNeeded(CLASSPATH, buildScriptDependenciesBlock) @@ -410,5 +395,16 @@ abstract class KotlinWithGradleConfigurator : KotlinProjectConfigurator { "
See manual installation instructions here.", "Configure Kotlin-Gradle Plugin") } + + private fun addRepository(repositoriesBlock: GrClosableBlock, version: String): Boolean { + val snippet = when { + isSnapshot(version) -> SNAPSHOT_REPOSITORY_SNIPPET + is11Prerelease(version) -> EAP_11_REPOSITORY_SNIPPET + isEap(version) -> EAP_REPOSITORY_SNIPPET + !isRepositoryConfigured(repositoriesBlock) -> MAVEN_CENTRAL + else -> return false + } + return addLastExpressionInBlockIfNeeded(snippet, repositoriesBlock) + } } } diff --git a/idea/testData/configuration/gradle/m04Version_after.gradle b/idea/testData/configuration/gradle/m04Version_after.gradle new file mode 100644 index 00000000000..ded3a2edf4c --- /dev/null +++ b/idea/testData/configuration/gradle/m04Version_after.gradle @@ -0,0 +1,33 @@ +apply plugin: 'java' +apply plugin: 'kotlin' + +sourceCompatibility = 1.5 +version = '1.0' + +repositories { + mavenCentral() + maven { + url 'http://dl.bintray.com/kotlin/kotlin-eap-1.1' + } +} + +dependencies { + testCompile group: 'junit', name: 'junit', version: '4.11' + compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" +} +buildscript { + ext.kotlin_version = '$VERSION$' + repositories { + maven { + url 'http://dl.bintray.com/kotlin/kotlin-eap-1.1' + } + } + dependencies { + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + } +} +sourceSets { + main.java.srcDirs += 'src/main/kotlin' +} + +// VERSION: $VERSION$ \ No newline at end of file diff --git a/idea/testData/configuration/gradle/m04Version_before.gradle b/idea/testData/configuration/gradle/m04Version_before.gradle new file mode 100644 index 00000000000..396de7d058a --- /dev/null +++ b/idea/testData/configuration/gradle/m04Version_before.gradle @@ -0,0 +1,14 @@ +apply plugin: 'java' + +sourceCompatibility = 1.5 +version = '1.0' + +repositories { + mavenCentral() +} + +dependencies { + testCompile group: 'junit', name: 'junit', version: '4.11' +} + +// VERSION: 1.1-M04 \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/configuration/ConfigureKotlinUtilTest.kt b/idea/tests/org/jetbrains/kotlin/idea/configuration/ConfigureKotlinUtilTest.kt new file mode 100644 index 00000000000..792f57425f5 --- /dev/null +++ b/idea/tests/org/jetbrains/kotlin/idea/configuration/ConfigureKotlinUtilTest.kt @@ -0,0 +1,33 @@ +/* + * 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. + */ + +package org.jetbrains.kotlin.idea.configuration + +import com.intellij.testFramework.UsefulTestCase +import org.junit.Assert + +class ConfigureKotlinUtilTest : UsefulTestCase() { + fun test11Prerelease() { + Assert.assertTrue(is11Prerelease("1.1-M04")) + Assert.assertTrue(is11Prerelease("1.1-beta")) + Assert.assertTrue(is11Prerelease("1.1-beta-2")) + Assert.assertTrue(is11Prerelease("1.1-rc2")) + Assert.assertFalse(is11Prerelease("1.1")) + Assert.assertFalse(is11Prerelease("1.1.2")) + Assert.assertFalse(is11Prerelease("1.1.2-3")) + Assert.assertFalse(is11Prerelease("1.1-dev-1234")) + } +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/configuration/GradleConfigureProjectByChangingFileTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/configuration/GradleConfigureProjectByChangingFileTestGenerated.java index 4cec3f9ee64..8c40d78e96e 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/configuration/GradleConfigureProjectByChangingFileTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/configuration/GradleConfigureProjectByChangingFileTestGenerated.java @@ -48,6 +48,12 @@ public class GradleConfigureProjectByChangingFileTestGenerated extends AbstractG doTestGradle(fileName); } + @TestMetadata("m04Version_before.gradle") + public void testM04Version() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/configuration/gradle/m04Version_before.gradle"); + doTestGradle(fileName); + } + @TestMetadata("missedLibrary_before.gradle") public void testMissedLibrary() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/configuration/gradle/missedLibrary_before.gradle");