Add gradle.properties file with new codestyle for new Gradle projects (KT-23400)
This commit is contained in:
+1
@@ -131,6 +131,7 @@ abstract class GradleKotlinFrameworkSupportProvider(
|
|||||||
|
|
||||||
if (isInNewProject(module)) {
|
if (isInNewProject(module)) {
|
||||||
ProjectCodeStyleImporter.apply(module.project, KotlinStyleGuideCodeStyle.INSTANCE)
|
ProjectCodeStyleImporter.apply(module.project, KotlinStyleGuideCodeStyle.INSTANCE)
|
||||||
|
GradlePropertiesFileUtils.addCodeStyleProperty(module.project, KotlinStyleGuideCodeStyle.CODE_STYLE_SETTING)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+29
@@ -5,7 +5,9 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.configuration
|
package org.jetbrains.kotlin.idea.configuration
|
||||||
|
|
||||||
|
import com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil
|
||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
|
import java.io.File
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
internal object GradlePropertiesFileUtils {
|
internal object GradlePropertiesFileUtils {
|
||||||
@@ -28,4 +30,31 @@ internal object GradlePropertiesFileUtils {
|
|||||||
|
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun addCodeStyleProperty(project: Project, value: String) {
|
||||||
|
addProperty(project, KOTLIN_CODE_STYLE_GRADLE_SETTING, value)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun addProperty(project: Project, key: String, value: String) {
|
||||||
|
val propertiesFile = projectPropertiesFile(project)
|
||||||
|
|
||||||
|
val keyValue = "$key=$value"
|
||||||
|
|
||||||
|
val updatedText = if (propertiesFile.exists()) {
|
||||||
|
propertiesFile.readText() + System.lineSeparator() + keyValue
|
||||||
|
} else {
|
||||||
|
keyValue
|
||||||
|
}
|
||||||
|
|
||||||
|
propertiesFile.writeText(updatedText)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun projectPropertiesFile(project: Project): File {
|
||||||
|
return File(getBaseDirPath(project), "gradle.properties")
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getBaseDirPath(project: Project): File {
|
||||||
|
val basePath = project.basePath!!
|
||||||
|
return File(ExternalSystemApiUtil.toCanonicalPath(basePath))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+1
@@ -101,6 +101,7 @@ abstract class KotlinDslGradleKotlinFrameworkSupportProvider(
|
|||||||
|
|
||||||
if (isInNewProject(module)) {
|
if (isInNewProject(module)) {
|
||||||
ProjectCodeStyleImporter.apply(module.project, KotlinStyleGuideCodeStyle.INSTANCE)
|
ProjectCodeStyleImporter.apply(module.project, KotlinStyleGuideCodeStyle.INSTANCE)
|
||||||
|
GradlePropertiesFileUtils.addCodeStyleProperty(module.project, KotlinStyleGuideCodeStyle.CODE_STYLE_SETTING)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user