Test for Gradle and Maven migration (KT-23401)
This commit is contained in:
+84
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. 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.idea.codeInsight.gradle
|
||||
|
||||
import com.intellij.openapi.application.runReadAction
|
||||
import com.intellij.openapi.application.runWriteAction
|
||||
import com.intellij.psi.PsiDocumentManager
|
||||
import com.intellij.psi.PsiManager
|
||||
import org.jetbrains.kotlin.config.ApiVersion
|
||||
import org.jetbrains.kotlin.config.LanguageVersion
|
||||
import org.jetbrains.kotlin.idea.configuration.KotlinMigrationProjectComponent
|
||||
import org.jetbrains.kotlin.idea.configuration.MigrationInfo
|
||||
import org.jetbrains.kotlin.test.testFramework.runInEdtAndWait
|
||||
import org.junit.Assert
|
||||
import org.junit.Test
|
||||
|
||||
class GradleMigrateTest : GradleImportingTestCase() {
|
||||
@Test
|
||||
fun testMigrateStdlib() {
|
||||
createProjectSubFile("settings.gradle", "include ':app'")
|
||||
val gradleFile = createProjectSubFile(
|
||||
"app/build.gradle",
|
||||
"""
|
||||
buildscript {
|
||||
repositories {
|
||||
jcenter()
|
||||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.1.0"
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'kotlin'
|
||||
|
||||
dependencies {
|
||||
compile "org.jetbrains.kotlin:kotlin-stdlib:1.1.0"
|
||||
}
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
importProject()
|
||||
|
||||
val document = runReadAction {
|
||||
val gradlePsiFile = PsiManager.getInstance(myProject).findFile(gradleFile) ?: error("Can't find psi file for gradle file")
|
||||
PsiDocumentManager.getInstance(myProject).getDocument(gradlePsiFile) ?: error("Can't find document for gradle file")
|
||||
}
|
||||
|
||||
runInEdtAndWait {
|
||||
runWriteAction {
|
||||
document.setText(
|
||||
"""
|
||||
buildscript {
|
||||
repositories {
|
||||
jcenter()
|
||||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.0"
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'kotlin'
|
||||
|
||||
dependencies {
|
||||
compile "org.jetbrains.kotlin:kotlin-stdlib:1.2.0"
|
||||
}
|
||||
""".trimIndent()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
importProject()
|
||||
|
||||
val actualMigrationInfo = KotlinMigrationProjectComponent.getInstance(myProject).requestLastMigrationInfo()
|
||||
|
||||
Assert.assertEquals(
|
||||
MigrationInfo.create("1.1.0", ApiVersion.KOTLIN_1_2, LanguageVersion.KOTLIN_1_2, newStdlibVersion = "1.2.0"),
|
||||
actualMigrationInfo)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. 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.idea.maven
|
||||
|
||||
import com.intellij.openapi.application.runReadAction
|
||||
import com.intellij.openapi.application.runWriteAction
|
||||
import com.intellij.psi.PsiDocumentManager
|
||||
import com.intellij.psi.PsiManager
|
||||
import org.jetbrains.kotlin.config.ApiVersion
|
||||
import org.jetbrains.kotlin.config.LanguageVersion
|
||||
import org.jetbrains.kotlin.idea.configuration.KotlinMigrationProjectComponent
|
||||
import org.jetbrains.kotlin.idea.configuration.MigrationInfo
|
||||
import org.jetbrains.kotlin.test.testFramework.runInEdtAndWait
|
||||
import org.junit.Assert
|
||||
import java.io.File
|
||||
|
||||
class MavenMigrateTest : MavenImportingTestCase() {
|
||||
private val kotlinVersion = "1.1.3"
|
||||
|
||||
override fun setUp() {
|
||||
super.setUp()
|
||||
repositoryPath = File(myDir, "repo").path
|
||||
createStdProjectFolders()
|
||||
}
|
||||
|
||||
fun testMigrateApiAndLanguageVersions() {
|
||||
val pomFile = createProjectPom(
|
||||
"""
|
||||
<groupId>test</groupId>
|
||||
<artifactId>project</artifactId>
|
||||
<version>1.0.0</version>
|
||||
|
||||
<properties>
|
||||
<kotlin.version>1.2.50</kotlin.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-stdlib</artifactId>
|
||||
<version>${'$'}{kotlin.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>kotlin-maven-plugin</artifactId>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<version>${'$'}{kotlin.version}</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
importProject()
|
||||
|
||||
val document = runReadAction {
|
||||
val pomPsiFile = PsiManager.getInstance(myProject).findFile(pomFile) ?: error("Can't find psi file for pom file")
|
||||
PsiDocumentManager.getInstance(myProject).getDocument(pomPsiFile) ?: error("Can't find document for pom file")
|
||||
}
|
||||
|
||||
runInEdtAndWait {
|
||||
runWriteAction {
|
||||
document.setText(
|
||||
MavenTestCase.createPomXml(
|
||||
"""
|
||||
<groupId>test</groupId>
|
||||
<artifactId>project</artifactId>
|
||||
<version>1.0.0</version>
|
||||
|
||||
<properties>
|
||||
<kotlin.version>1.2.50</kotlin.version>
|
||||
<kotlin.compiler.apiVersion>1.3</kotlin.compiler.apiVersion>
|
||||
<kotlin.compiler.languageVersion>1.3</kotlin.compiler.languageVersion>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-stdlib</artifactId>
|
||||
<version>${'$'}{kotlin.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>kotlin-maven-plugin</artifactId>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<version>${'$'}{kotlin.version}/version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
""".trimIndent()
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
importProject()
|
||||
|
||||
val actualMigrationInfo = KotlinMigrationProjectComponent.getInstance(myProject).requestLastMigrationInfo()
|
||||
|
||||
Assert.assertEquals(
|
||||
MigrationInfo.create("1.2.50", ApiVersion.KOTLIN_1_2, LanguageVersion.KOTLIN_1_2,
|
||||
newApiVersion = ApiVersion.KOTLIN_1_3, newLanguageVersion = LanguageVersion.KOTLIN_1_3),
|
||||
actualMigrationInfo)
|
||||
}
|
||||
}
|
||||
+32
-1
@@ -20,6 +20,7 @@ import com.intellij.openapi.vcs.changes.ChangeListManager
|
||||
import com.intellij.openapi.vcs.ex.ProjectLevelVcsManagerEx
|
||||
import com.intellij.util.CommonProcessors
|
||||
import com.intellij.util.text.VersionComparatorUtil
|
||||
import org.jetbrains.annotations.TestOnly
|
||||
import org.jetbrains.kotlin.config.ApiVersion
|
||||
import org.jetbrains.kotlin.config.LanguageVersion
|
||||
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
||||
@@ -37,6 +38,8 @@ class KotlinMigrationProjectComponent(val project: Project) {
|
||||
private var old: MigrationState? = null
|
||||
private var new: MigrationState? = null
|
||||
|
||||
private var lastMigrationInfo: MigrationInfo? = null
|
||||
|
||||
init {
|
||||
val connection = project.messageBus.connect()
|
||||
connection.subscribe(ProjectDataImportListener.TOPIC, ProjectDataImportListener {
|
||||
@@ -44,6 +47,14 @@ class KotlinMigrationProjectComponent(val project: Project) {
|
||||
})
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
@TestOnly
|
||||
fun requestLastMigrationInfo(): MigrationInfo? {
|
||||
val temp = lastMigrationInfo
|
||||
lastMigrationInfo = null
|
||||
return temp
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
fun onImportAboutToStart() {
|
||||
if (!CodeMigrationToggleAction.isEnabled(project) || !hasChangesInProjectFiles(project)) {
|
||||
@@ -51,6 +62,8 @@ class KotlinMigrationProjectComponent(val project: Project) {
|
||||
return
|
||||
}
|
||||
|
||||
lastMigrationInfo = null
|
||||
|
||||
old = MigrationState.build(project)
|
||||
}
|
||||
|
||||
@@ -70,6 +83,7 @@ class KotlinMigrationProjectComponent(val project: Project) {
|
||||
new = null
|
||||
|
||||
if (ApplicationManager.getApplication().isUnitTestMode) {
|
||||
lastMigrationInfo = migrationInfo
|
||||
return
|
||||
}
|
||||
|
||||
@@ -165,7 +179,24 @@ data class MigrationInfo(
|
||||
val newApiVersion: ApiVersion,
|
||||
val oldLanguageVersion: LanguageVersion,
|
||||
val newLanguageVersion: LanguageVersion
|
||||
)
|
||||
) {
|
||||
companion object {
|
||||
fun create(
|
||||
oldStdlibVersion: String,
|
||||
oldApiVersion: ApiVersion,
|
||||
oldLanguageVersion: LanguageVersion,
|
||||
newStdlibVersion: String = oldStdlibVersion,
|
||||
newApiVersion: ApiVersion = oldApiVersion,
|
||||
newLanguageVersion: LanguageVersion = oldLanguageVersion
|
||||
): MigrationInfo {
|
||||
return MigrationInfo(
|
||||
oldStdlibVersion, newStdlibVersion,
|
||||
oldApiVersion, newApiVersion,
|
||||
oldLanguageVersion, newLanguageVersion
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun MigrationInfo.isLanguageVersionUpdate(old: LanguageVersion, new: LanguageVersion): Boolean {
|
||||
return oldLanguageVersion <= old && newLanguageVersion >= new
|
||||
|
||||
Reference in New Issue
Block a user