diff --git a/community-guitests/testSrc/com/intellij/ide/projectWizard/kotlin/model/ProjectsWithKotlin.kt b/community-guitests/testSrc/com/intellij/ide/projectWizard/kotlin/model/ProjectsWithKotlin.kt index c895771dfb8a..ea8803777e6f 100644 --- a/community-guitests/testSrc/com/intellij/ide/projectWizard/kotlin/model/ProjectsWithKotlin.kt +++ b/community-guitests/testSrc/com/intellij/ide/projectWizard/kotlin/model/ProjectsWithKotlin.kt @@ -11,6 +11,8 @@ import com.intellij.testGuiFramework.util.* import com.intellij.testGuiFramework.util.scenarios.* import org.fest.swing.exception.ComponentLookupException import java.io.File +import java.nio.file.Path +import java.nio.file.Paths import org.hamcrest.core.Is.`is` as Matcher_Is /** @@ -428,7 +430,7 @@ fun KotlinGuiTestCase.editorClearSearchAndReplace() { } } -fun KotlinGuiTestCase.addDevRepositoryToBuildGradle(fileName: String, isKotlinDslUsed: Boolean) { +fun KotlinGuiTestCase.addDevRepositoryToBuildGradle(fileName: Path, isKotlinDslUsed: Boolean) { val mavenCentral = "mavenCentral()" val urlGDsl = "maven { url 'https://dl.bintray.com/kotlin/kotlin-dev' }" val urlKDsl = "maven { setUrl (\"https://dl.bintray.com/kotlin/kotlin-dev/\") }" @@ -446,7 +448,7 @@ fun KotlinGuiTestCase.addDevRepositoryToBuildGradle(fileName: String, isKotlinDs } } -fun KotlinGuiTestCase.addDevRepositoryToPomXml(fileName: String) { +fun KotlinGuiTestCase.addDevRepositoryToPomXml(fileName: Path) { val searchedLine = """""" val changingLine = """ @@ -474,7 +476,7 @@ fun KotlinGuiTestCase.addDevRepositoryToPomXml(fileName: String) { } } -fun KotlinGuiTestCase.changeKotlinVersionInBuildGradle(fileName: String, +fun KotlinGuiTestCase.changeKotlinVersionInBuildGradle(fileName: Path, isKotlinDslUsed: Boolean, kotlinVersion: String) { fileSearchAndReplace( fileName = fileName){ @@ -490,7 +492,7 @@ fun KotlinGuiTestCase.changeKotlinVersionInBuildGradle(fileName: String, } } -fun KotlinGuiTestCase.changeKotlinVersionInPomXml(fileName: String, kotlinVersion: String) { +fun KotlinGuiTestCase.changeKotlinVersionInPomXml(fileName: Path, kotlinVersion: String) { val oldVersion = ".+<\\/kotlin\\.version>" val newVersion = "$kotlinVersion" fileSearchAndReplace(fileName = fileName) { @@ -526,19 +528,18 @@ fun KotlinGuiTestCase.openPomXml(vararg projectName: String) { fun KotlinGuiTestCase.editSettingsGradle(){ // if project is configured to old Kotlin version, it must be released and no changes are required in the settings.gradle file if (!KotlinTestProperties.isActualKotlinUsed()) return - val fileName = "$projectFolder/settings.gradle" + val fileName = Paths.get(projectFolder, "settings.gradle") if (KotlinTestProperties.isArtifactOnlyInDevRep) addDevRepositoryToBuildGradle(fileName, isKotlinDslUsed = false) } fun KotlinGuiTestCase.editBuildGradle( kotlinVersion: String, isKotlinDslUsed: Boolean = false, - vararg projectName: String = arrayOf()) { + vararg projectName: String = emptyArray()) { // if project is configured to old Kotlin version, it must be released and no changes are required in the build.gradle file if (!KotlinTestProperties.isActualKotlinUsed()) return - val innerPath = if (projectName.isNotEmpty()) "/" + projectName.joinToString(separator = "/") else "" - val fileName = projectFolder + innerPath + "/build.gradle${if (isKotlinDslUsed) ".kts" else ""}" + val fileName = Paths.get(projectFolder, *projectName , "build.gradle${if (isKotlinDslUsed) ".kts" else ""}") logTestStep("Going to edit $fileName") if (KotlinTestProperties.isArtifactOnlyInDevRep) addDevRepositoryToBuildGradle(fileName, isKotlinDslUsed) @@ -548,12 +549,11 @@ fun KotlinGuiTestCase.editBuildGradle( fun KotlinGuiTestCase.editPomXml(kotlinVersion: String, kotlinKind: KotlinKind, - vararg projectName: String = arrayOf()) { + vararg projectName: String = emptyArray()) { // if project is configured to old Kotlin version, it must be released and no changes are required in the pom.xml file if (!KotlinTestProperties.isActualKotlinUsed()) return - val innerPath = if (projectName.isNotEmpty()) "/" + projectName.joinToString(separator = "/") else "" - val fileName = "$projectFolder$innerPath/pom.xml" + val fileName = Paths.get(projectFolder, *projectName, "pom.xml") logTestStep("Going to edit $fileName") if (KotlinTestProperties.isArtifactOnlyInDevRep) addDevRepositoryToPomXml(fileName) diff --git a/platform/testGuiFramework/src/com/intellij/testGuiFramework/framework/GuiTestUtil.kt b/platform/testGuiFramework/src/com/intellij/testGuiFramework/framework/GuiTestUtil.kt index 7dfe2d32a88c..019549a5a75e 100644 --- a/platform/testGuiFramework/src/com/intellij/testGuiFramework/framework/GuiTestUtil.kt +++ b/platform/testGuiFramework/src/com/intellij/testGuiFramework/framework/GuiTestUtil.kt @@ -73,7 +73,7 @@ import java.awt.event.KeyEvent import java.io.File import java.io.IOException import java.nio.file.Files -import java.nio.file.Paths +import java.nio.file.Path import java.nio.file.StandardCopyOption import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit.MINUTES @@ -802,15 +802,14 @@ object GuiTestUtil { return null } - fun fileSearchAndReplace(fileName: String, condition: (String) -> String) { + fun fileSearchAndReplace(fileName: Path, condition: (String) -> String) { val buffer = mutableListOf() - val inputFile = Paths.get(fileName) - for (line in Files.readAllLines(inputFile)) { + for (line in Files.readAllLines(fileName)) { buffer.add(condition(line)) } - val tmpFile = Files.createTempFile(inputFile.fileName.toString(), "tmp") + val tmpFile = Files.createTempFile(fileName.fileName.toString(), "tmp") Files.write(tmpFile, buffer) - Files.copy(tmpFile, inputFile, StandardCopyOption.REPLACE_EXISTING) + Files.copy(tmpFile, fileName, StandardCopyOption.REPLACE_EXISTING) tmpFile.toFile().deleteOnExit() } diff --git a/platform/testGuiFramework/src/com/intellij/testGuiFramework/impl/GuiTestCaseExt.kt b/platform/testGuiFramework/src/com/intellij/testGuiFramework/impl/GuiTestCaseExt.kt index 49ba5061b265..07d56f62cec6 100644 --- a/platform/testGuiFramework/src/com/intellij/testGuiFramework/impl/GuiTestCaseExt.kt +++ b/platform/testGuiFramework/src/com/intellij/testGuiFramework/impl/GuiTestCaseExt.kt @@ -14,9 +14,8 @@ import org.junit.Rule import org.junit.rules.ErrorCollector import org.junit.rules.TemporaryFolder import org.junit.rules.TestName -import java.io.File import java.nio.file.Files -import java.nio.file.Paths +import java.nio.file.Path open class GuiTestCaseExt : GuiTestCase() { @@ -251,13 +250,12 @@ fun GuiTestCase.checkRunGutterIcons(expectedNumberOfRunIcons: Int, expectedRunLi } } -fun GuiTestCase.checkFileExists(filePath: String){ +fun GuiTestCase.checkFileExists(filePath: Path) { logTestStep("Going to check whether file `$filePath` created") - assert(File(filePath).exists()) { "Can't find a file `$filePath`" } + assert(filePath.toFile().exists()) { "Can't find a file `$filePath`" } } -fun GuiTestCase.checkFileContainsLine(filePath: String, line: String){ - val inputFile = Paths.get(filePath) - logTestStep("Going to check whether ${inputFile.fileName} contains line `$line`") - assert(Files.readAllLines(inputFile).contains(line)) { "Line `$line` not found" } +fun GuiTestCase.checkFileContainsLine(filePath: Path, line: String) { + logTestStep("Going to check whether ${filePath.fileName} contains line `$line`") + assert(Files.readAllLines(filePath).contains(line)) { "Line `$line` not found" } } \ No newline at end of file