diff --git a/.idea/dictionaries/Nikolay_Krasko.xml b/.idea/dictionaries/Nikolay_Krasko.xml index 83417f16864..fb8bbdedea8 100644 --- a/.idea/dictionaries/Nikolay_Krasko.xml +++ b/.idea/dictionaries/Nikolay_Krasko.xml @@ -2,6 +2,7 @@ accessors + coroutines crossinline fqname goto diff --git a/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/KotlinMavenArchetypesProvider.kt b/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/KotlinMavenArchetypesProvider.kt index 5ded4450674..15017b0b6fa 100644 --- a/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/KotlinMavenArchetypesProvider.kt +++ b/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/KotlinMavenArchetypesProvider.kt @@ -29,10 +29,36 @@ import java.net.HttpURLConnection import java.net.URLEncoder import java.util.concurrent.TimeUnit -class KotlinMavenArchetypesProvider(val kotlinPluginVersion: String, val predefinedInternalMode: Boolean?) : MavenArchetypesProvider { +class KotlinMavenArchetypesProvider(private val kotlinPluginVersion: String, private val predefinedInternalMode: Boolean?) : + MavenArchetypesProvider { + + @Suppress("unused") constructor() : this(KotlinPluginUtil.getPluginVersion(), null) - val VERSIONS_LIST_URL = mavenSearchUrl("org.jetbrains.kotlin", packaging = "maven-archetype", rowsLimit = 1000) + companion object { + private val VERSIONS_LIST_URL = mavenSearchUrl("org.jetbrains.kotlin", packaging = "maven-archetype", rowsLimit = 1000) + + private fun mavenSearchUrl( + group: String, + artifactId: String? = null, + version: String? = null, + packaging: String? = null, + rowsLimit: Int = 20 + ): String { + val q = listOf( + "g" to group, + "a" to artifactId, + "v" to version, + "p" to packaging + ) + .filter { it.second != null }.joinToString(separator = " AND ") { "${it.first}:\"${it.second}\"" } + + return "http://search.maven.org/solrsearch/select?q=${q.encodeURL()}&core=gav&rows=$rowsLimit&wt=json" + } + + private fun String.encodeURL() = URLEncoder.encode(this, "UTF-8") + } + private val versionPrefix by lazy { versionPrefix(kotlinPluginVersion) } private val fallbackVersion = "1.0.3" private val internalMode: Boolean @@ -41,8 +67,7 @@ class KotlinMavenArchetypesProvider(val kotlinPluginVersion: String, val predefi private val archetypesBlocking by lazy { try { loadVersions().ifEmpty { fallbackArchetypes() } - } - catch (t: Throwable) { + } catch (t: Throwable) { fallbackArchetypes() } } @@ -50,8 +75,8 @@ class KotlinMavenArchetypesProvider(val kotlinPluginVersion: String, val predefi override fun getArchetypes() = archetypesBlocking.toMutableList() private fun fallbackArchetypes() = - listOf("kotlin-archetype-jvm", "kotlin-archetype-js") - .map { MavenArchetype("org.jetbrains.kotlin", it, fallbackVersion, null, null) } + listOf("kotlin-archetype-jvm", "kotlin-archetype-js") + .map { MavenArchetype("org.jetbrains.kotlin", it, fallbackVersion, null, null) } private fun loadVersions(): List { return connectAndApply(VERSIONS_LIST_URL) { urlConnection -> @@ -62,39 +87,27 @@ class KotlinMavenArchetypesProvider(val kotlinPluginVersion: String, val predefi } internal fun extractVersions(root: JsonElement) = - root.asJsonObject.get("response") - .asJsonObject.get("docs") - .asJsonArray - .map { it.asJsonObject } - .map { MavenArchetype(it.get("g").asString, it.get("a").asString, it.get("v").asString, null, null) } - .let { versions -> - val prefix = versionPrefix + root.asJsonObject.get("response") + .asJsonObject.get("docs") + .asJsonArray + .map { it.asJsonObject } + .map { MavenArchetype(it.get("g").asString, it.get("a").asString, it.get("v").asString, null, null) } + .let { versions -> + val prefix = versionPrefix - when { - internalMode || prefix == null -> versions - else -> versions.filter { it.version?.startsWith(prefix) ?: false }.ifEmpty { versions } - } - .groupBy { it.groupId + ":" + it.artifactId + ":" + versionPrefix(it.version) } - .mapValues { chooseVersion(it.value) } - .mapNotNull { it.value } - } + when { + internalMode || prefix == null -> versions + else -> versions.filter { it.version?.startsWith(prefix) ?: false }.ifEmpty { versions } + } + .groupBy { it.groupId + ":" + it.artifactId + ":" + versionPrefix(it.version) } + .mapValues { chooseVersion(it.value) } + .mapNotNull { it.value } + } private fun chooseVersion(versions: List): MavenArchetype? { return versions.maxBy { MavenVersionComparable(it.version) } } - private fun mavenSearchUrl(group: String, artifactId: String? = null, version: String? = null, packaging: String? = null, rowsLimit: Int = 20): String { - val q = listOf( - "g" to group, - "a" to artifactId, - "v" to version, - "p" to packaging - ) - .filter { it.second != null }.joinToString(separator = " AND ") { "${it.first}:\"${it.second}\"" } - - return "http://search.maven.org/solrsearch/select?q=${q.encodeURL()}&core=gav&rows=$rowsLimit&wt=json" - } - private fun connectAndApply(url: String, timeoutSeconds: Int = 15, block: (HttpURLConnection) -> R): R { return HttpConfigurable.getInstance().openHttpConnection(url).use { urlConnection -> val timeout = TimeUnit.SECONDS.toMillis(timeoutSeconds.toLong()).toInt() @@ -107,14 +120,11 @@ class KotlinMavenArchetypesProvider(val kotlinPluginVersion: String, val predefi } private fun HttpURLConnection.use(block: (HttpURLConnection) -> R): R = - try { - block(this) - } - finally { - disconnect() - } - - private fun String.encodeURL() = URLEncoder.encode(this, "UTF-8") + try { + block(this) + } finally { + disconnect() + } private fun versionPrefix(version: String) = """^\d+\.\d+\.""".toRegex().find(version)?.value } diff --git a/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/KotlinMavenImporter.kt b/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/KotlinMavenImporter.kt index fee7e5bfc9d..7904eec3936 100644 --- a/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/KotlinMavenImporter.kt +++ b/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/KotlinMavenImporter.kt @@ -53,8 +53,8 @@ import java.util.* interface MavenProjectImportHandler { companion object : ProjectExtensionDescriptor( - "org.jetbrains.kotlin.mavenProjectImportHandler", - MavenProjectImportHandler::class.java + "org.jetbrains.kotlin.mavenProjectImportHandler", + MavenProjectImportHandler::class.java ) operator fun invoke(facet: KotlinFacet, mavenProject: MavenProject) @@ -62,30 +62,42 @@ interface MavenProjectImportHandler { class KotlinMavenImporter : MavenImporter(KOTLIN_PLUGIN_GROUP_ID, KOTLIN_PLUGIN_ARTIFACT_ID) { companion object { - val KOTLIN_PLUGIN_GROUP_ID = "org.jetbrains.kotlin" - val KOTLIN_PLUGIN_ARTIFACT_ID = "kotlin-maven-plugin" + const val KOTLIN_PLUGIN_GROUP_ID = "org.jetbrains.kotlin" + const val KOTLIN_PLUGIN_ARTIFACT_ID = "kotlin-maven-plugin" - val KOTLIN_PLUGIN_SOURCE_DIRS_CONFIG = "sourceDirs" + const val KOTLIN_PLUGIN_SOURCE_DIRS_CONFIG = "sourceDirs" } - override fun preProcess(module: Module, mavenProject: MavenProject, changes: MavenProjectChanges, modifiableModelsProvider: IdeModifiableModelsProvider) { + override fun preProcess( + module: Module, + mavenProject: MavenProject, + changes: MavenProjectChanges, + modifiableModelsProvider: IdeModifiableModelsProvider + ) { } - override fun process(modifiableModelsProvider: IdeModifiableModelsProvider, - module: Module, - rootModel: MavenRootModelAdapter, - mavenModel: MavenProjectsTree, - mavenProject: MavenProject, - changes: MavenProjectChanges, - mavenProjectToModuleName: MutableMap, - postTasks: MutableList) { + override fun process( + modifiableModelsProvider: IdeModifiableModelsProvider, + module: Module, + rootModel: MavenRootModelAdapter, + mavenModel: MavenProjectsTree, + mavenProject: MavenProject, + changes: MavenProjectChanges, + mavenProjectToModuleName: MutableMap, + postTasks: MutableList + ) { if (changes.plugins) { contributeSourceDirectories(mavenProject, module, rootModel) } } - override fun postProcess(module: Module, mavenProject: MavenProject, changes: MavenProjectChanges, modifiableModelsProvider: IdeModifiableModelsProvider) { + override fun postProcess( + module: Module, + mavenProject: MavenProject, + changes: MavenProjectChanges, + modifiableModelsProvider: IdeModifiableModelsProvider + ) { super.postProcess(module, mavenProject, changes, modifiableModelsProvider) if (changes.dependencies) { @@ -108,7 +120,8 @@ class KotlinMavenImporter : MavenImporter(KOTLIN_PLUGIN_GROUP_ID, KOTLIN_PLUGIN_ private fun scheduleDownloadStdlibSources(mavenProject: MavenProject, module: Module) { // TODO: here we have to process all kotlin libraries but for now we only handle standard libraries - val artifacts = mavenProject.dependencyArtifactIndex.data[KOTLIN_PLUGIN_GROUP_ID]?.values?.flatMap { it.filter { it.isResolved } } ?: emptyList() + val artifacts = mavenProject.dependencyArtifactIndex.data[KOTLIN_PLUGIN_GROUP_ID]?.values?.flatMap { it.filter { it.isResolved } } + ?: emptyList() val librariesWithNoSources = ArrayList() OrderEnumerator.orderEntries(module).forEachLibrary { library -> @@ -121,21 +134,26 @@ class KotlinMavenImporter : MavenImporter(KOTLIN_PLUGIN_GROUP_ID, KOTLIN_PLUGIN_ val toBeDownloaded = artifacts.filter { it.libraryName in libraryNames } if (toBeDownloaded.isNotEmpty()) { - MavenProjectsManager.getInstance(module.project).scheduleArtifactsDownloading(listOf(mavenProject), toBeDownloaded, true, false, AsyncResult()) + MavenProjectsManager.getInstance(module.project) + .scheduleArtifactsDownloading(listOf(mavenProject), toBeDownloaded, true, false, AsyncResult()) } } - private fun getCompilerArgumentsByConfigurationElement(mavenProject: MavenProject, - configuration: Element?, - platform: TargetPlatformKind<*>): List { + private fun getCompilerArgumentsByConfigurationElement( + mavenProject: MavenProject, + configuration: Element?, + platform: TargetPlatformKind<*> + ): List { val arguments = when (platform) { is TargetPlatformKind.Jvm -> K2JVMCompilerArguments() - is TargetPlatformKind.JavaScript -> K2JSCompilerArguments() - is TargetPlatformKind.Common -> K2MetadataCompilerArguments() + TargetPlatformKind.JavaScript -> K2JSCompilerArguments() + TargetPlatformKind.Common -> K2MetadataCompilerArguments() } - arguments.apiVersion = configuration?.getChild("apiVersion")?.text ?: mavenProject.properties["kotlin.compiler.apiVersion"]?.toString() - arguments.languageVersion = configuration?.getChild("languageVersion")?.text ?: mavenProject.properties["kotlin.compiler.languageVersion"]?.toString() + arguments.apiVersion = configuration?.getChild("apiVersion")?.text ?: + mavenProject.properties["kotlin.compiler.apiVersion"]?.toString() + arguments.languageVersion = configuration?.getChild("languageVersion")?.text ?: + mavenProject.properties["kotlin.compiler.languageVersion"]?.toString() arguments.multiPlatform = configuration?.getChild("multiPlatform")?.text?.trim()?.toBoolean() ?: false arguments.suppressWarnings = configuration?.getChild("nowarn")?.text?.trim()?.toBoolean() ?: false @@ -147,7 +165,8 @@ class KotlinMavenImporter : MavenImporter(KOTLIN_PLUGIN_GROUP_ID, KOTLIN_PLUGIN_ is K2JVMCompilerArguments -> { arguments.classpath = configuration?.getChild("classpath")?.text arguments.jdkHome = configuration?.getChild("jdkHome")?.text - arguments.jvmTarget = configuration?.getChild("jvmTarget")?.text ?: mavenProject.properties["kotlin.compiler.jvmTarget"]?.toString() + arguments.jvmTarget = configuration?.getChild("jvmTarget")?.text ?: + mavenProject.properties["kotlin.compiler.jvmTarget"]?.toString() } is K2JSCompilerArguments -> { arguments.sourceMap = configuration?.getChild("sourceMap")?.text?.trim()?.toBoolean() ?: false @@ -181,11 +200,13 @@ class KotlinMavenImporter : MavenImporter(KOTLIN_PLUGIN_GROUP_ID, KOTLIN_PLUGIN_ return ArgumentUtils.convertArgumentsToStringList(arguments) } - private val compilationGoals = listOf(PomFile.KotlinGoals.Compile, - PomFile.KotlinGoals.TestCompile, - PomFile.KotlinGoals.Js, - PomFile.KotlinGoals.TestJs, - PomFile.KotlinGoals.MetaData) + private val compilationGoals = listOf( + PomFile.KotlinGoals.Compile, + PomFile.KotlinGoals.TestCompile, + PomFile.KotlinGoals.Js, + PomFile.KotlinGoals.TestJs, + PomFile.KotlinGoals.MetaData + ) private fun configureFacet(mavenProject: MavenProject, modifiableModelsProvider: IdeModifiableModelsProvider, module: Module) { val mavenPlugin = mavenProject.findPlugin(KotlinMavenConfigurator.GROUP_ID, KotlinMavenConfigurator.MAVEN_PLUGIN_ID) ?: return @@ -197,9 +218,9 @@ class KotlinMavenImporter : MavenImporter(KOTLIN_PLUGIN_GROUP_ID, KOTLIN_PLUGIN_ val configuredPlatform = kotlinFacet.configuration.settings.targetPlatformKind!! val configuration = mavenPlugin.configurationElement val sharedArguments = getCompilerArgumentsByConfigurationElement(mavenProject, configuration, configuredPlatform) - val executionArguments = mavenPlugin.executions?.filter { it.goals.any { it in compilationGoals } } - ?.firstOrNull() - ?.configurationElement?.let { getCompilerArgumentsByConfigurationElement(mavenProject, it, configuredPlatform) } + val executionArguments = mavenPlugin.executions + ?.firstOrNull { it.goals.any { it in compilationGoals } } + ?.configurationElement?.let { getCompilerArgumentsByConfigurationElement(mavenProject, it, configuredPlatform) } parseCompilerArgumentsToFacet(sharedArguments, emptyList(), kotlinFacet, modifiableModelsProvider) if (executionArguments != null) { parseCompilerArgumentsToFacet(executionArguments, emptyList(), kotlinFacet, modifiableModelsProvider) @@ -209,18 +230,19 @@ class KotlinMavenImporter : MavenImporter(KOTLIN_PLUGIN_GROUP_ID, KOTLIN_PLUGIN_ kotlinFacet.noVersionAutoAdvance() } - private fun detectPlatform(mavenProject: MavenProject) = detectPlatformByExecutions(mavenProject) ?: - detectPlatformByLibraries(mavenProject) + private fun detectPlatform(mavenProject: MavenProject) = + detectPlatformByExecutions(mavenProject) ?: detectPlatformByLibraries(mavenProject) private fun detectPlatformByExecutions(mavenProject: MavenProject): TargetPlatformKind<*>? { - return mavenProject.findPlugin(KOTLIN_PLUGIN_GROUP_ID, KOTLIN_PLUGIN_ARTIFACT_ID)?.executions?.flatMap { it.goals }?.mapNotNull { goal -> - when (goal) { - PomFile.KotlinGoals.Compile, PomFile.KotlinGoals.TestCompile -> TargetPlatformKind.Jvm[JvmTarget.JVM_1_6] - PomFile.KotlinGoals.Js, PomFile.KotlinGoals.TestJs -> TargetPlatformKind.JavaScript - PomFile.KotlinGoals.MetaData -> TargetPlatformKind.Common - else -> null - } - }?.distinct()?.singleOrNull() + return mavenProject.findPlugin(KOTLIN_PLUGIN_GROUP_ID, KOTLIN_PLUGIN_ARTIFACT_ID)?.executions?.flatMap { it.goals } + ?.mapNotNull { goal -> + when (goal) { + PomFile.KotlinGoals.Compile, PomFile.KotlinGoals.TestCompile -> TargetPlatformKind.Jvm[JvmTarget.JVM_1_6] + PomFile.KotlinGoals.Js, PomFile.KotlinGoals.TestJs -> TargetPlatformKind.JavaScript + PomFile.KotlinGoals.MetaData -> TargetPlatformKind.Common + else -> null + } + }?.distinct()?.singleOrNull() } private fun detectPlatformByLibraries(mavenProject: MavenProject): TargetPlatformKind<*>? { @@ -270,10 +292,12 @@ class KotlinMavenImporter : MavenImporter(KOTLIN_PLUGIN_GROUP_ID, KOTLIN_PLUGIN_ } private fun collectSourceDirectories(mavenProject: MavenProject): List> = - mavenProject.plugins.filter { it.isKotlinPlugin() }.flatMap { plugin -> - plugin.configurationElement.sourceDirectories().map { SourceType.PROD to it } + - plugin.executions.flatMap { execution -> execution.configurationElement.sourceDirectories().map { execution.sourceType() to it } } - }.distinct() + mavenProject.plugins.filter { it.isKotlinPlugin() }.flatMap { plugin -> + plugin.configurationElement.sourceDirectories().map { SourceType.PROD to it } + + plugin.executions.flatMap { execution -> + execution.configurationElement.sourceDirectories().map { execution.sourceType() to it } + } + }.distinct() private fun setImplementedModuleName(kotlinFacet: KotlinFacet, mavenProject: MavenProject, module: Module) { if (kotlinFacet.configuration.settings.targetPlatformKind == TargetPlatformKind.Common) { @@ -288,12 +312,17 @@ class KotlinMavenImporter : MavenImporter(KOTLIN_PLUGIN_GROUP_ID, KOTLIN_PLUGIN_ } } -private fun MavenPlugin.isKotlinPlugin() = groupId == KotlinMavenImporter.KOTLIN_PLUGIN_GROUP_ID && artifactId == KotlinMavenImporter.KOTLIN_PLUGIN_ARTIFACT_ID -private fun Element?.sourceDirectories(): List = this?.getChildren(KotlinMavenImporter.KOTLIN_PLUGIN_SOURCE_DIRS_CONFIG)?.flatMap { it.children ?: emptyList() }?.map { it.textTrim } ?: emptyList() +private fun MavenPlugin.isKotlinPlugin() = + groupId == KotlinMavenImporter.KOTLIN_PLUGIN_GROUP_ID && artifactId == KotlinMavenImporter.KOTLIN_PLUGIN_ARTIFACT_ID + +private fun Element?.sourceDirectories(): List = + this?.getChildren(KotlinMavenImporter.KOTLIN_PLUGIN_SOURCE_DIRS_CONFIG)?.flatMap { it.children ?: emptyList() }?.map { it.textTrim } + ?: emptyList() + private fun MavenPlugin.Execution.sourceType() = - goals.map { if (isTestGoalName(it)) SourceType.TEST else SourceType.PROD } - .distinct() - .singleOrNull() ?: SourceType.PROD + goals.map { if (isTestGoalName(it)) SourceType.TEST else SourceType.PROD } + .distinct() + .singleOrNull() ?: SourceType.PROD private fun isTestGoalName(goalName: String) = goalName.startsWith("test-") @@ -301,14 +330,14 @@ private enum class SourceType { PROD, TEST } -@State(name = "AutoImportedSourceRoots", - storages = arrayOf( - Storage(id = "other", file = StoragePathMacros.MODULE_FILE) - )) +@State( + name = "AutoImportedSourceRoots", + storages = [(Storage(id = "other", file = StoragePathMacros.MODULE_FILE))] +) class KotlinImporterComponent : PersistentStateComponent { class State(var directories: List = ArrayList()) - val addedSources = Collections.synchronizedSet(HashSet()) + val addedSources: MutableSet = Collections.synchronizedSet(HashSet()) override fun loadState(state: State?) { addedSources.clear() diff --git a/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/MavenCompletionProviders.kt b/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/MavenCompletionProviders.kt index fe2790ebe58..afa4c749af6 100644 --- a/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/MavenCompletionProviders.kt +++ b/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/MavenCompletionProviders.kt @@ -24,21 +24,21 @@ import org.jetbrains.kotlin.config.LanguageVersion import org.jetbrains.kotlin.idea.actions.internal.KotlinInternalMode class MavenLanguageVersionsCompletionProvider : MavenFixedValueReferenceProvider( - LanguageVersion.values().filter { it.isStable || KotlinInternalMode.enabled }.map { it.versionString }.toTypedArray() + LanguageVersion.values().filter { it.isStable || KotlinInternalMode.enabled }.map { it.versionString }.toTypedArray() ) class MavenApiVersionsCompletionProvider : MavenFixedValueReferenceProvider( - LanguageVersion.values().filter { it.isStable || KotlinInternalMode.enabled }.map { it.versionString }.toTypedArray() + LanguageVersion.values().filter { it.isStable || KotlinInternalMode.enabled }.map { it.versionString }.toTypedArray() ) class MavenJvmTargetsCompletionProvider : MavenFixedValueReferenceProvider( - JvmTarget.values().map(JvmTarget::description).toTypedArray() + JvmTarget.values().map(JvmTarget::description).toTypedArray() ) class MavenJsModuleKindsCompletionProvider : MavenFixedValueReferenceProvider( - DefaultValues.JsModuleKinds.possibleValues!!.map(StringUtil::unquoteString).toTypedArray() + DefaultValues.JsModuleKinds.possibleValues!!.map(StringUtil::unquoteString).toTypedArray() ) class MavenJsMainCallCompletionProvider : MavenFixedValueReferenceProvider( - DefaultValues.JsMain.possibleValues!!.map(StringUtil::unquoteString).toTypedArray() + DefaultValues.JsMain.possibleValues!!.map(StringUtil::unquoteString).toTypedArray() ) \ No newline at end of file diff --git a/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/PomFile.kt b/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/PomFile.kt index 8e06ed704ec..f4f14837554 100644 --- a/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/PomFile.kt +++ b/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/PomFile.kt @@ -47,8 +47,12 @@ import java.util.* fun kotlinPluginId(version: String?) = MavenId(KotlinMavenConfigurator.GROUP_ID, KotlinMavenConfigurator.MAVEN_PLUGIN_ID, version) -class PomFile private constructor(val xmlFile: XmlFile, val domModel: MavenDomProjectModel) { - constructor(xmlFile: XmlFile) : this(xmlFile, MavenDomUtil.getMavenDomProjectModel(xmlFile.project, xmlFile.virtualFile) ?: throw IllegalStateException("No DOM model found for pom ${xmlFile.name}")) +class PomFile private constructor(private val xmlFile: XmlFile, val domModel: MavenDomProjectModel) { + constructor(xmlFile: XmlFile) : this( + xmlFile, + MavenDomUtil.getMavenDomProjectModel(xmlFile.project, xmlFile.virtualFile) + ?: throw IllegalStateException("No DOM model found for pom ${xmlFile.name}") + ) private val nodesByName = HashMap() private val projectElement: XmlTag @@ -62,12 +66,10 @@ class PomFile private constructor(val xmlFile: XmlFile, val domModel: MavenDomPr if (element is XmlTag && element.localName in recommendedElementsOrder && element.parent === projectElement) { nodesByName[element.localName] = element - } - else if (element is XmlTag && element.localName == "project") { + } else if (element is XmlTag && element.localName == "project") { projectElement = element element.acceptChildren(this) - } - else { + } else { element.acceptChildren(this) } } @@ -86,13 +88,11 @@ class PomFile private constructor(val xmlFile: XmlFile, val domModel: MavenDomPr val textNode = tag.children.filterIsInstance().firstOrNull() if (textNode != null) { textNode.value = value - } - else { + } else { tag.replace(projectElement.createChildTag(name, value)) } } - } - else { + } else { properties.add(projectElement.createChildTag(name, value)) } } @@ -102,7 +102,13 @@ class PomFile private constructor(val xmlFile: XmlFile, val domModel: MavenDomPr return propertiesNode.findFirstSubTag(name) } - fun addDependency(artifact: MavenId, scope: MavenArtifactScope? = null, classifier: String? = null, optional: Boolean = false, systemPath: String? = null): MavenDomDependency { + fun addDependency( + artifact: MavenId, + scope: MavenArtifactScope? = null, + classifier: String? = null, + optional: Boolean = false, + systemPath: String? = null + ): MavenDomDependency { require(systemPath == null || scope == MavenArtifactScope.SYSTEM) { "systemPath is only applicable for system scope dependency" } require(artifact.groupId != null) { "groupId shouldn't be null" } require(artifact.artifactId != null) { "artifactId shouldn't be null" } @@ -163,7 +169,7 @@ class PomFile private constructor(val xmlFile: XmlFile, val domModel: MavenDomPr return true } - fun ensurePluginAfter(plugin: MavenDomPlugin, referencePlugin: MavenDomPlugin): MavenDomPlugin { + private fun ensurePluginAfter(plugin: MavenDomPlugin, referencePlugin: MavenDomPlugin): MavenDomPlugin { if (!isPluginAfter(plugin, referencePlugin)) { // rearrange val referenceElement = referencePlugin.xmlElement!! @@ -180,8 +186,9 @@ class PomFile private constructor(val xmlFile: XmlFile, val domModel: MavenDomPr fun findKotlinExecutions(vararg goals: String) = findKotlinExecutions().filter { it.goals.goals.any { it.rawText in goals } } fun findKotlinExecutions() = findKotlinPlugins().flatMap { it.executions.executions } - fun findExecutions(plugin: MavenDomPlugin) = plugin.executions.executions - fun findExecutions(plugin: MavenDomPlugin, vararg goals: String) = findExecutions(plugin).filter { it.goals.goals.any { it.rawText in goals } } + private fun findExecutions(plugin: MavenDomPlugin) = plugin.executions.executions + fun findExecutions(plugin: MavenDomPlugin, vararg goals: String) = + findExecutions(plugin).filter { it.goals.goals.any { it.rawText in goals } } fun addExecution(plugin: MavenDomPlugin, executionId: String, phase: String, goals: List): MavenDomPluginExecution { require(executionId.isNotEmpty()) { "executionId shouldn't be empty" } @@ -200,32 +207,39 @@ class PomFile private constructor(val xmlFile: XmlFile, val domModel: MavenDomPr return execution } - fun addKotlinExecution(module: Module, plugin: MavenDomPlugin, executionId: String, phase: String, isTest: Boolean, goals: List) { + fun addKotlinExecution( + module: Module, + plugin: MavenDomPlugin, + executionId: String, + phase: String, + isTest: Boolean, + goals: List + ) { val execution = addExecution(plugin, executionId, phase, goals) val sourceDirs = ModuleRootManager.getInstance(module) - .contentEntries - .flatMap { it.sourceFolders.filter { it.isRelatedSourceRoot(isTest) } } - .mapNotNull { it.file } - .mapNotNull { VfsUtilCore.getRelativePath(it, xmlFile.virtualFile.parent, '/') } + .contentEntries + .flatMap { it.sourceFolders.filter { it.isRelatedSourceRoot(isTest) } } + .mapNotNull { it.file } + .mapNotNull { VfsUtilCore.getRelativePath(it, xmlFile.virtualFile.parent, '/') } executionSourceDirs(execution, sourceDirs) } - fun isPluginExecutionMissing(plugin: MavenPlugin?, excludedExecutionId: String, goal: String) = plugin == null || plugin.executions.none { it.executionId != excludedExecutionId && goal in it.goals } + fun isPluginExecutionMissing(plugin: MavenPlugin?, excludedExecutionId: String, goal: String) = + plugin == null || plugin.executions.none { it.executionId != excludedExecutionId && goal in it.goals } fun addJavacExecutions(module: Module, kotlinPlugin: MavenDomPlugin) { val javacPlugin = ensurePluginAfter(addPlugin(MavenId("org.apache.maven.plugins", "maven-compiler-plugin", null)), kotlinPlugin) val project: MavenProject = - MavenProjectsManager.getInstance(module.project).findProject(module) ?: - run { - if (ApplicationManager.getApplication().isUnitTestMode) { - LOG.warn("WARNING: Bad project configuration in tests. Javac execution configuration was skipped.") - return - } - error("Can't find maven project for $module") + MavenProjectsManager.getInstance(module.project).findProject(module) ?: run { + if (ApplicationManager.getApplication().isUnitTestMode) { + LOG.warn("WARNING: Bad project configuration in tests. Javac execution configuration was skipped.") + return } + error("Can't find maven project for $module") + } val plugin = project.findPlugin("org.apache.maven.plugins", "maven-compiler-plugin") @@ -252,16 +266,17 @@ class PomFile private constructor(val xmlFile: XmlFile, val domModel: MavenDomPr } if (domModel.build.plugins.plugins.any { - it.groupId.stringValue == "org.apache.maven.plugins" - && it.artifactId.stringValue == "maven-compiler-plugin" - && it.executions.executions.any { it.id.stringValue == executionId && it.phase.stringValue == DefaultPhases.None } - }) { + it.groupId.stringValue == "org.apache.maven.plugins" + && it.artifactId.stringValue == "maven-compiler-plugin" + && it.executions.executions.any { it.id.stringValue == executionId && it.phase.stringValue == DefaultPhases.None } + }) { return false } // TODO: getPhase has been added as per https://youtrack.jetbrains.com/issue/IDEA-153582 and available only in latest IDEAs return plugin.executions.filter { it.executionId == executionId }.all { execution -> - execution::class.java.methods.filter { it.name == "getPhase" && it.parameterTypes.isEmpty() }.all { it.invoke(execution) == DefaultPhases.None } + execution::class.java.methods.filter { it.name == "getPhase" && it.parameterTypes.isEmpty() } + .all { it.invoke(execution) == DefaultPhases.None } } } @@ -272,20 +287,17 @@ class PomFile private constructor(val xmlFile: XmlFile, val domModel: MavenDomPr val defaultDir = if (isTest) "test" else "main" val singleDirectoryElement = if (isTest) { domModel.build.testSourceDirectory - } - else { + } else { domModel.build.sourceDirectory } if (sourceDirs.isEmpty() || sourceDirs.singleOrNull() == "src/$defaultDir/java") { execution.configuration.xmlTag?.findSubTags("sourceDirs")?.forEach { it.deleteCascade() } singleDirectoryElement.undefine() - } - else if (sourceDirs.size == 1 && !forceSingleSource) { + } else if (sourceDirs.size == 1 && !forceSingleSource) { singleDirectoryElement.stringValue = sourceDirs.single() execution.configuration.xmlTag?.findSubTags("sourceDirs")?.forEach { it.deleteCascade() } - } - else { + } else { val sourceDirsTag = executionConfiguration(execution, "sourceDirs") val newSourceDirsTag = execution.configuration.createChildTag("sourceDirs") for (dir in sourceDirs) { @@ -297,13 +309,13 @@ class PomFile private constructor(val xmlFile: XmlFile, val domModel: MavenDomPr fun executionSourceDirs(execution: MavenDomPluginExecution): List { return execution.configuration.xmlTag - .getChildrenOfType().firstOrNull { it.localName == "sourceDirs" } - ?.getChildrenOfType() - ?.map { it.getChildrenOfType().joinToString("") { it.text } } - ?: emptyList() + .getChildrenOfType().firstOrNull { it.localName == "sourceDirs" } + ?.getChildrenOfType() + ?.map { it.getChildrenOfType().joinToString("") { it.text } } + ?: emptyList() } - fun executionConfiguration(execution: MavenDomPluginExecution, name: String): XmlTag { + private fun executionConfiguration(execution: MavenDomPluginExecution, name: String): XmlTag { val configurationTag = execution.configuration.ensureTagExists()!! val existingTag = configurationTag.findSubTags(name).firstOrNull() @@ -320,39 +332,70 @@ class PomFile private constructor(val xmlFile: XmlFile, val domModel: MavenDomPr val existingTag = configurationTag.findFirstSubTag(optionName) if (existingTag != null) { existingTag.value.text = optionValue - } - else { + } else { configurationTag.add(configurationTag.createChildTag(optionName, optionValue)) } return configurationTag } - fun addPluginRepository(id: String, name: String, url: String, snapshots: Boolean = false, releases: Boolean = true): MavenDomRepository { + private fun addPluginRepository( + id: String, + name: String, + url: String, + snapshots: Boolean = false, + releases: Boolean = true + ): MavenDomRepository { ensurePluginRepositories() - return addRepository(id, name, url, snapshots, releases, { domModel.pluginRepositories.pluginRepositories }, { domModel.pluginRepositories.addPluginRepository() }) + return addRepository( + id, + name, + url, + snapshots, + releases, + { domModel.pluginRepositories.pluginRepositories }, + { domModel.pluginRepositories.addPluginRepository() }) } fun addPluginRepository(description: RepositoryDescription) { addPluginRepository(description.id, description.name, description.url, description.isSnapshot, true) } - fun addLibraryRepository(id: String, name: String, url: String, snapshots: Boolean = false, releases: Boolean = true): MavenDomRepository { + private fun addLibraryRepository( + id: String, + name: String, + url: String, + snapshots: Boolean = false, + releases: Boolean = true + ): MavenDomRepository { ensureRepositories() - return addRepository(id, name, url, snapshots, releases, { domModel.repositories.repositories }, { domModel.repositories.addRepository() }) + return addRepository( + id, + name, + url, + snapshots, + releases, + { domModel.repositories.repositories }, + { domModel.repositories.addRepository() }) } fun addLibraryRepository(description: RepositoryDescription) { addLibraryRepository(description.id, description.name, description.url, description.isSnapshot, true) } - private fun addRepository(id: String, name: String, url: String, snapshots: Boolean, releases: Boolean, existing: () -> List, create: () -> MavenDomRepository): MavenDomRepository { + private fun addRepository( + id: String, + name: String, + url: String, + snapshots: Boolean, + releases: Boolean, + existing: () -> List, + create: () -> MavenDomRepository + ): MavenDomRepository { val repository = - existing().firstOrNull { it.id.stringValue == id } ?: - existing().firstOrNull { it.url.stringValue == url } ?: - create() + existing().firstOrNull { it.id.stringValue == id } ?: existing().firstOrNull { it.url.stringValue == url } ?: create() if (repository.id.isEmpty()) { repository.id.stringValue = id @@ -371,42 +414,37 @@ class PomFile private constructor(val xmlFile: XmlFile, val domModel: MavenDomPr return repository } - fun hasPlugin(artifact: MavenId) = domModel.build.plugins.plugins.any { it.matches(artifact) } - - fun hasDependency(artifact: MavenId, scope: MavenArtifactScope? = null) = - domModel.dependencies.dependencies.any { it.matches(artifact, scope) } - fun findDependencies(artifact: MavenId, scope: MavenArtifactScope? = null) = - domModel.dependencies.dependencies.filter { it.matches(artifact, scope) } + domModel.dependencies.dependencies.filter { it.matches(artifact, scope) } - fun ensureBuild(): XmlTag = ensureElement(projectElement, "build") + private fun ensureBuild(): XmlTag = ensureElement(projectElement, "build") - fun ensureDependencies(): XmlTag = ensureElement(projectElement, "dependencies") - fun ensurePluginRepositories(): XmlTag = ensureElement(projectElement, "pluginRepositories") - fun ensureRepositories(): XmlTag = ensureElement(projectElement, "repositories") + private fun ensureDependencies(): XmlTag = ensureElement(projectElement, "dependencies") + private fun ensurePluginRepositories(): XmlTag = ensureElement(projectElement, "pluginRepositories") + private fun ensureRepositories(): XmlTag = ensureElement(projectElement, "repositories") private fun MavenDomPlugin.isKotlinMavenPlugin() = groupId.stringValue == KotlinMavenConfigurator.GROUP_ID - && artifactId.stringValue == KotlinMavenConfigurator.MAVEN_PLUGIN_ID + && artifactId.stringValue == KotlinMavenConfigurator.MAVEN_PLUGIN_ID private fun MavenDomDependency.matches(artifact: MavenId, scope: MavenArtifactScope?) = - this.matches(artifact) && (this.scope.stringValue == scope?.name?.toLowerCase() || scope == null && this.scope.stringValue == "compile") + this.matches(artifact) && (this.scope.stringValue == scope?.name?.toLowerCase() || scope == null && this.scope.stringValue == "compile") private fun MavenDomArtifactCoordinates.matches(artifact: MavenId) = - (artifact.groupId == null || groupId.stringValue == artifact.groupId) - && (artifact.artifactId == null || artifactId.stringValue == artifact.artifactId) - && (artifact.version == null || version.stringValue == artifact.version) + (artifact.groupId == null || groupId.stringValue == artifact.groupId) + && (artifact.artifactId == null || artifactId.stringValue == artifact.artifactId) + && (artifact.version == null || version.stringValue == artifact.version) private fun MavenId.withNoVersion() = MavenId(groupId, artifactId, null) private fun MavenId.withoutJDKSpecificSuffix() = MavenId( - groupId, - artifactId?.substringBeforeLast("-jre")?.substringBeforeLast("-jdk"), - null) + groupId, + artifactId?.substringBeforeLast("-jre")?.substringBeforeLast("-jdk"), + null + ) private fun MavenDomElement.createChildTag(name: String, value: String? = null) = xmlTag.createChildTag(name, value) private fun XmlTag.createChildTag(name: String, value: String? = null) = createChildTag(name, namespace, value, false)!! - tailrec - private fun XmlTag.deleteCascade() { + private tailrec fun XmlTag.deleteCascade() { val oldParent = this.parentTag delete() @@ -451,12 +489,12 @@ class PomFile private constructor(val xmlFile: XmlFile, val domModel: MavenDomPr private fun insertEmptyLines(node: XmlTag) { node.prevSibling?.let { before -> - if (!(before.hasEmptyLine() || before.lastChild?.hasEmptyLine() ?: false)) { + if (!(before.hasEmptyLine() || before.lastChild?.hasEmptyLine() == true)) { node.parent.addBefore(createEmptyLine(), node) } } node.nextSibling?.let { after -> - if (!(after.hasEmptyLine() || after.firstChild?.hasEmptyLine() ?: false)) { + if (!(after.hasEmptyLine() || after.firstChild?.hasEmptyLine() == true)) { node.parent.addAfter(createEmptyLine(), node) } } @@ -481,45 +519,47 @@ class PomFile private constructor(val xmlFile: XmlFile, val domModel: MavenDomPr @Suppress("Unused") object DefaultPhases { - val None = "none" - val Validate = "validate" - val Initialize = "initialize" - val GenerateSources = "generate-sources" - val ProcessSources = "process-sources" - val GenerateResources = "generate-resources" - val ProcessResources = "process-resources" - val Compile = "compile" - val ProcessClasses = "process-classes" - val GenerateTestSources = "generate-test-sources" - val ProcessTestSources = "process-test-sources" - val GenerateTestResources = "generate-test-resources" - val ProcessTestResources = "process-test-resources" - val TestCompile = "test-compile" - val ProcessTestClasses = "process-test-classes" - val Test = "test" - val PreparePackage = "prepare-package" - val Package = "package" - val PreIntegrationTest = "pre-integration-test" - val IntegrationTest = "integration-test" - val PostIntegrationTest = "post-integration-test" - val Verify = "verify" - val Install = "install" - val Deploy = "deploy" + const val None = "none" + const val Validate = "validate" + const val Initialize = "initialize" + const val GenerateSources = "generate-sources" + const val ProcessSources = "process-sources" + const val GenerateResources = "generate-resources" + const val ProcessResources = "process-resources" + const val Compile = "compile" + const val ProcessClasses = "process-classes" + const val GenerateTestSources = "generate-test-sources" + const val ProcessTestSources = "process-test-sources" + const val GenerateTestResources = "generate-test-resources" + const val ProcessTestResources = "process-test-resources" + const val TestCompile = "test-compile" + const val ProcessTestClasses = "process-test-classes" + const val Test = "test" + const val PreparePackage = "prepare-package" + const val Package = "package" + const val PreIntegrationTest = "pre-integration-test" + const val IntegrationTest = "integration-test" + const val PostIntegrationTest = "post-integration-test" + const val Verify = "verify" + const val Install = "install" + const val Deploy = "deploy" } object KotlinGoals { - val Compile = "compile" - val TestCompile = "test-compile" - val Js = "js" - val TestJs = "test-js" - val MetaData = "metadata" + const val Compile = "compile" + const val TestCompile = "test-compile" + const val Js = "js" + const val TestJs = "test-js" + const val MetaData = "metadata" } companion object { private val LOG = Logger.getInstance(PomFile::class.java) - fun forFileOrNull(xmlFile: XmlFile): PomFile? = MavenDomUtil.getMavenDomProjectModel(xmlFile.project, xmlFile.virtualFile)?.let { PomFile(xmlFile, it) } + fun forFileOrNull(xmlFile: XmlFile): PomFile? = + MavenDomUtil.getMavenDomProjectModel(xmlFile.project, xmlFile.virtualFile)?.let { PomFile(xmlFile, it) } + @Suppress("DeprecatedCallableAddReplaceWith") @Deprecated("We shouldn't use phase but additional compiler configuration in most cases") fun getPhase(hasJavaFiles: Boolean, isTest: Boolean) = when { hasJavaFiles -> when { @@ -577,18 +617,22 @@ class PomFile private constructor(val xmlFile: XmlFile, val domModel: MavenDomPr """.lines() - .map { it.trim().removePrefix("<").removeSuffix("/>").trim() } - .filter(String::isNotEmpty) - .toCollection(LinkedHashSet()) + .map { it.trim().removePrefix("<").removeSuffix("/>").trim() } + .filter(String::isNotEmpty) + .toCollection(LinkedHashSet()) val recommendedOrderAsList = recommendedElementsOrder.toList() } } fun PomFile.changeLanguageVersion(languageVersion: String?, apiVersion: String?): PsiElement? { - val kotlinPlugin = findPlugin(MavenId(KotlinMavenConfigurator.GROUP_ID, - KotlinMavenConfigurator.MAVEN_PLUGIN_ID, - null)) ?: return null + val kotlinPlugin = findPlugin( + MavenId( + KotlinMavenConfigurator.GROUP_ID, + KotlinMavenConfigurator.MAVEN_PLUGIN_ID, + null + ) + ) ?: return null val languageElement = languageVersion?.let { changeConfigurationOrProperty(kotlinPlugin, "languageVersion", "kotlin.compiler.languageVersion", it) } @@ -598,9 +642,11 @@ fun PomFile.changeLanguageVersion(languageVersion: String?, apiVersion: String?) return languageElement ?: apiElement } -private fun PomFile.changeConfigurationOrProperty(kotlinPlugin: MavenDomPlugin, - configurationTagName: String, - propertyName: String, value: String): XmlTag? { +private fun PomFile.changeConfigurationOrProperty( + kotlinPlugin: MavenDomPlugin, + configurationTagName: String, + propertyName: String, value: String +): XmlTag? { val configuration = kotlinPlugin.configuration if (configuration.exists()) { val subTag = configuration.xmlTag.findFirstSubTag(configurationTagName) @@ -623,8 +669,12 @@ private fun PomFile.changeConfigurationOrProperty(kotlinPlugin: MavenDomPlugin, } fun PomFile.changeCoroutineConfiguration(value: String): PsiElement? { - val kotlinPlugin = findPlugin(MavenId(KotlinMavenConfigurator.GROUP_ID, - KotlinMavenConfigurator.MAVEN_PLUGIN_ID, - null)) ?: return null + val kotlinPlugin = findPlugin( + MavenId( + KotlinMavenConfigurator.GROUP_ID, + KotlinMavenConfigurator.MAVEN_PLUGIN_ID, + null + ) + ) ?: return null return changeConfigurationOrProperty(kotlinPlugin, "experimentalCoroutines", "kotlin.compiler.experimental.coroutines", value) } diff --git a/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/actions/MavenPluginSourcesSwap.kt b/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/actions/MavenPluginSourcesSwap.kt index ebabe1bb9d3..ad3aca11369 100644 --- a/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/actions/MavenPluginSourcesSwap.kt +++ b/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/actions/MavenPluginSourcesSwap.kt @@ -110,7 +110,11 @@ class MavenPluginSourcesMoveToBuild : PsiElementBaseIntentionAction() { } } - private fun tryInvoke(project: Project, element: PsiElement, block: (pom: PomFile, dir: String, execution: MavenDomPluginExecution, build: MavenDomBuild) -> Unit = { _, _, _, _ -> }): Boolean { + private fun tryInvoke( + project: Project, + element: PsiElement, + block: (pom: PomFile, dir: String, execution: MavenDomPluginExecution, build: MavenDomBuild) -> Unit = { _, _, _, _ -> } + ): Boolean { val file = element.containingFile if (file == null || !MavenDomUtil.isMavenFile(file) || (element !is XmlElement && element.parent !is XmlElement)) { @@ -122,9 +126,9 @@ class MavenPluginSourcesMoveToBuild : PsiElementBaseIntentionAction() { val execution = domElement.getParentOfType(MavenDomPluginExecution::class.java, false) ?: return false tag.parentsWithSelf - .takeWhile { it != execution.xmlElement } - .filterIsInstance() - .firstOrNull { it.localName == "sourceDirs" } ?: return false + .takeWhile { it != execution.xmlElement } + .filterIsInstance() + .firstOrNull { it.localName == "sourceDirs" } ?: return false val pom = PomFile.forFileOrNull(element.containingFile as XmlFile) ?: return false val sourceDirsToMove = pom.executionSourceDirs(execution) @@ -137,12 +141,12 @@ class MavenPluginSourcesMoveToBuild : PsiElementBaseIntentionAction() { var couldMove = 0 if (shouldMoveCompileSourceRoot(execution)) { if (!build.sourceDirectory.exists() || build.sourceDirectory.stringValue == sourceDirsToMove.single()) { - couldMove ++ + couldMove++ } } if (shouldMoveTestSourceRoot(execution)) { if (!build.testSourceDirectory.exists() || build.testSourceDirectory.stringValue == sourceDirsToMove.single()) { - couldMove ++ + couldMove++ } } @@ -158,5 +162,5 @@ class MavenPluginSourcesMoveToBuild : PsiElementBaseIntentionAction() { execution.goals.goals.any { it.stringValue == PomFile.KotlinGoals.Compile || it.stringValue == PomFile.KotlinGoals.Js } private fun shouldMoveTestSourceRoot(execution: MavenDomPluginExecution) = - execution.goals.goals.any { it.stringValue == PomFile.KotlinGoals.TestCompile || it.stringValue == PomFile.KotlinGoals.TestJs } + execution.goals.goals.any { it.stringValue == PomFile.KotlinGoals.TestCompile || it.stringValue == PomFile.KotlinGoals.TestJs } } diff --git a/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/actions/MavenPomActions.kt b/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/actions/MavenPomActions.kt index adfaf9a031d..6ecaaef8b4b 100644 --- a/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/actions/MavenPomActions.kt +++ b/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/actions/MavenPomActions.kt @@ -33,11 +33,15 @@ import org.jetbrains.kotlin.idea.maven.configuration.KotlinMavenConfigurator import org.jetbrains.kotlin.idea.versions.MAVEN_STDLIB_ID import org.jetbrains.kotlin.psi.psiUtil.endOffset -class GenerateMavenCompileExecutionAction : PomFileActionBase(KotlinMavenExecutionProvider(PomFile.KotlinGoals.Compile, PomFile.DefaultPhases.Compile)) -class GenerateMavenTestCompileExecutionAction : PomFileActionBase(KotlinMavenExecutionProvider(PomFile.KotlinGoals.TestCompile, PomFile.DefaultPhases.TestCompile)) +class GenerateMavenCompileExecutionAction : + PomFileActionBase(KotlinMavenExecutionProvider(PomFile.KotlinGoals.Compile, PomFile.DefaultPhases.Compile)) + +class GenerateMavenTestCompileExecutionAction : + PomFileActionBase(KotlinMavenExecutionProvider(PomFile.KotlinGoals.TestCompile, PomFile.DefaultPhases.TestCompile)) + class GenerateMavenPluginAction : PomFileActionBase(KotlinMavenPluginProvider()) -private val DefaultKotlinVersion = "\${kotlin.version}" +private const val DefaultKotlinVersion = "\${kotlin.version}" open class PomFileActionBase(generateProvider: AbstractDomGenerateProvider<*>) : GenerateDomElementAction(generateProvider) { override fun isValidForFile(project: Project, editor: Editor, file: PsiFile): Boolean { @@ -47,7 +51,8 @@ open class PomFileActionBase(generateProvider: AbstractDomGenerateProvider<*>) : override fun startInWriteAction() = true } -private class KotlinMavenPluginProvider : AbstractDomGenerateProvider("kotlin-maven-plugin-provider", MavenDomPlugin::class.java) { +private class KotlinMavenPluginProvider : + AbstractDomGenerateProvider("kotlin-maven-plugin-provider", MavenDomPlugin::class.java) { override fun generate(parent: DomElement?, editor: Editor?): MavenDomPlugin? { if (parent !is MavenDomProjectModel) { @@ -82,7 +87,8 @@ private class KotlinMavenPluginProvider : AbstractDomGenerateProvider("kotlin-maven-execution-provider", MavenDomPlugin::class.java) { +private class KotlinMavenExecutionProvider(val goal: String, val phase: String) : + AbstractDomGenerateProvider("kotlin-maven-execution-provider", MavenDomPlugin::class.java) { override fun generate(parent: DomElement?, editor: Editor?): MavenDomPlugin? { if (parent !is MavenDomPlugin) { @@ -99,7 +105,7 @@ private class KotlinMavenExecutionProvider(val goal: String, val phase: String) return parent } - override fun getElementToNavigate(t: MavenDomPlugin?) = null + override fun getElementToNavigate(t: MavenDomPlugin?): DomElement? = null override fun getParentDomElement(project: Project?, editor: Editor?, file: PsiFile?): DomElement? { if (project == null || editor == null || file == null) { @@ -112,8 +118,8 @@ private class KotlinMavenExecutionProvider(val goal: String, val phase: String) override fun isAvailableForElement(contextElement: DomElement): Boolean { val plugin = contextElement.findPlugin() return plugin != null - && plugin.isKotlinMavenPlugin() - && plugin.executions.executions.none { it.goals.goals.any { it.value == goal } } + && plugin.isKotlinMavenPlugin() + && plugin.executions.executions.none { it.goals.goals.any { it.value == goal } } } } @@ -129,11 +135,14 @@ private fun Char.isRangeEnd() = this == ']' || this == ')' private fun String.isRangeVersion() = length > 2 && this[0].isRangeStart() && last().isRangeEnd() -private fun DomElement.findProject(): MavenDomProjectModel? = this as? MavenDomProjectModel ?: DomUtil.getParentOfType(this, MavenDomProjectModel::class.java, true) -private fun DomElement.findPlugin(): MavenDomPlugin? = this as? MavenDomPlugin ?: DomUtil.getParentOfType(this, MavenDomPlugin::class.java, true) +private fun DomElement.findProject(): MavenDomProjectModel? = + this as? MavenDomProjectModel ?: DomUtil.getParentOfType(this, MavenDomProjectModel::class.java, true) + +private fun DomElement.findPlugin(): MavenDomPlugin? = + this as? MavenDomPlugin ?: DomUtil.getParentOfType(this, MavenDomPlugin::class.java, true) private fun MavenDomPlugin.isKotlinMavenPlugin() = groupId.stringValue == KotlinMavenConfigurator.GROUP_ID - && artifactId.stringValue == KotlinMavenConfigurator.MAVEN_PLUGIN_ID + && artifactId.stringValue == KotlinMavenConfigurator.MAVEN_PLUGIN_ID private fun MavenDomDependency.isKotlinStdlib() = groupId.stringValue == KotlinMavenConfigurator.GROUP_ID - && artifactId.stringValue == MAVEN_STDLIB_ID + && artifactId.stringValue == MAVEN_STDLIB_ID diff --git a/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/configuration/KotlinJavaMavenConfigurator.kt b/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/configuration/KotlinJavaMavenConfigurator.kt index 2f015d8e4d3..73e4f58f2f8 100644 --- a/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/configuration/KotlinJavaMavenConfigurator.kt +++ b/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/configuration/KotlinJavaMavenConfigurator.kt @@ -29,16 +29,21 @@ import org.jetbrains.kotlin.idea.versions.getStdlibArtifactId import org.jetbrains.kotlin.resolve.TargetPlatform import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform -class KotlinJavaMavenConfigurator : KotlinMavenConfigurator(KotlinJavaMavenConfigurator.TEST_LIB_ID, false, KotlinJavaMavenConfigurator.NAME, KotlinJavaMavenConfigurator.PRESENTABLE_TEXT) { +class KotlinJavaMavenConfigurator : KotlinMavenConfigurator( + KotlinJavaMavenConfigurator.TEST_LIB_ID, + false, + KotlinJavaMavenConfigurator.NAME, + KotlinJavaMavenConfigurator.PRESENTABLE_TEXT +) { override fun isKotlinModule(module: Module) = - hasKotlinJvmRuntimeInScope(module) + hasKotlinJvmRuntimeInScope(module) override fun isRelevantGoal(goalName: String) = - goalName == PomFile.KotlinGoals.Compile + goalName == PomFile.KotlinGoals.Compile override fun getStdlibArtifactId(module: Module, version: String): String = - getStdlibArtifactId(ModuleRootManager.getInstance(module).sdk, version) + getStdlibArtifactId(ModuleRootManager.getInstance(module).sdk, version) override fun createExecutions(pomFile: PomFile, kotlinPlugin: MavenDomPlugin, module: Module) { createExecution(pomFile, kotlinPlugin, PomFile.DefaultPhases.Compile, PomFile.KotlinGoals.Compile, module, false) @@ -66,8 +71,8 @@ class KotlinJavaMavenConfigurator : KotlinMavenConfigurator(KotlinJavaMavenConfi get() = JvmPlatform companion object { - private val NAME = "maven" - val TEST_LIB_ID = "kotlin-test" - private val PRESENTABLE_TEXT = "Maven" + private const val NAME = "maven" + const val TEST_LIB_ID = "kotlin-test" + private const val PRESENTABLE_TEXT = "Maven" } } diff --git a/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/configuration/KotlinJavascriptMavenConfigurator.kt b/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/configuration/KotlinJavascriptMavenConfigurator.kt index c4f568643ea..ab559032b51 100644 --- a/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/configuration/KotlinJavascriptMavenConfigurator.kt +++ b/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/configuration/KotlinJavascriptMavenConfigurator.kt @@ -24,7 +24,8 @@ import org.jetbrains.kotlin.idea.versions.MAVEN_JS_STDLIB_ID import org.jetbrains.kotlin.js.resolve.JsPlatform import org.jetbrains.kotlin.resolve.TargetPlatform -class KotlinJavascriptMavenConfigurator : KotlinMavenConfigurator(null, false, KotlinJavascriptMavenConfigurator.NAME, KotlinJavascriptMavenConfigurator.PRESENTABLE_TEXT) { +class KotlinJavascriptMavenConfigurator : + KotlinMavenConfigurator(null, false, KotlinJavascriptMavenConfigurator.NAME, KotlinJavascriptMavenConfigurator.PRESENTABLE_TEXT) { override fun getStdlibArtifactId(module: Module, version: String) = MAVEN_JS_STDLIB_ID @@ -47,7 +48,7 @@ class KotlinJavascriptMavenConfigurator : KotlinMavenConfigurator(null, false, K override fun getMinimumSupportedVersion() = "1.1.0" companion object { - private val NAME = "js maven" - private val PRESENTABLE_TEXT = "Maven (JavaScript)" + private const val NAME = "js maven" + private const val PRESENTABLE_TEXT = "Maven (JavaScript)" } } 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 133b84cb9cc..518cb795f44 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 @@ -41,10 +41,12 @@ import org.jetbrains.kotlin.idea.util.application.runReadAction import org.jetbrains.kotlin.idea.versions.LibraryJarDescriptor abstract class KotlinMavenConfigurator - protected constructor(private val testArtifactId: String?, - private val addJunit: Boolean, - override val name: String, - override val presentableText: String) : KotlinProjectConfigurator { +protected constructor( + private val testArtifactId: String?, + private val addJunit: Boolean, + override val name: String, + override val presentableText: String +) : KotlinProjectConfigurator { override fun getStatus(moduleSourceRootGroup: ModuleSourceRootGroup): ConfigureKotlinStatus { val module = moduleSourceRootGroup.baseModule @@ -77,8 +79,8 @@ abstract class KotlinMavenConfigurator val mavenProject = mavenProjectsManager.findProject(module) ?: return ConfigureKotlinStatus.BROKEN val kotlinPluginId = kotlinPluginId(null) - val kotlinPlugin = mavenProject.plugins.find { it.mavenId.equals(kotlinPluginId.groupId, kotlinPluginId.artifactId)} - ?: return ConfigureKotlinStatus.CAN_BE_CONFIGURED + val kotlinPlugin = mavenProject.plugins.find { it.mavenId.equals(kotlinPluginId.groupId, kotlinPluginId.artifactId) } + ?: return ConfigureKotlinStatus.CAN_BE_CONFIGURED if (kotlinPlugin.executions.any { it.goals.any(this::isRelevantGoal) }) { return ConfigureKotlinStatus.CONFIGURED @@ -108,8 +110,7 @@ abstract class KotlinMavenConfigurator if (file != null && canConfigureFile(file)) { configureModule(module, file, dialog.kotlinVersion, collector) OpenFileAction.openFile(file.virtualFile, project) - } - else { + } else { showErrorMessage(project, "Cannot find pom.xml for module " + module.name) } } @@ -126,13 +127,13 @@ abstract class KotlinMavenConfigurator protected abstract fun getStdlibArtifactId(module: Module, version: String): String open fun configureModule(module: Module, file: PsiFile, version: String, collector: NotificationMessageCollector): Boolean = - changePomFile(module, file, version, collector) + changePomFile(module, file, version, collector) private fun changePomFile( - module: Module, - file: PsiFile, - version: String, - collector: NotificationMessageCollector + module: Module, + file: PsiFile, + version: String, + collector: NotificationMessageCollector ): Boolean { val virtualFile = file.virtualFile ?: error("Virtual file should exists for psi file " + file.name) val domModel = MavenDomUtil.getMavenDomProjectModel(module.project, virtualFile) @@ -144,7 +145,13 @@ abstract class KotlinMavenConfigurator val pom = PomFile.forFileOrNull(file as XmlFile) ?: return false pom.addProperty(KOTLIN_VERSION_PROPERTY, version) - pom.addDependency(MavenId(GROUP_ID, getStdlibArtifactId(module, version), "\${$KOTLIN_VERSION_PROPERTY}"), MavenArtifactScope.COMPILE, null, false, null) + pom.addDependency( + MavenId(GROUP_ID, getStdlibArtifactId(module, version), "\${$KOTLIN_VERSION_PROPERTY}"), + MavenArtifactScope.COMPILE, + null, + false, + null + ) if (testArtifactId != null) { pom.addDependency(MavenId(GROUP_ID, testArtifactId, "\${$KOTLIN_VERSION_PROPERTY}"), MavenArtifactScope.TEST, null, false, null) } @@ -174,13 +181,13 @@ abstract class KotlinMavenConfigurator } protected fun createExecution( - pomFile: PomFile, - kotlinPlugin: MavenDomPlugin, - executionId: String, - goalName: String, - module: Module, - isTest: Boolean) { - + pomFile: PomFile, + kotlinPlugin: MavenDomPlugin, + executionId: String, + goalName: String, + module: Module, + isTest: Boolean + ) { pomFile.addKotlinExecution(module, kotlinPlugin, executionId, PomFile.getPhase(false, isTest), isTest, listOf(goalName)) if (hasJavaFiles(module)) { @@ -189,18 +196,19 @@ abstract class KotlinMavenConfigurator } override fun updateLanguageVersion( - module: Module, - languageVersion: String?, - apiVersion: String?, - requiredStdlibVersion: ApiVersion, - forTests: Boolean + module: Module, + languageVersion: String?, + apiVersion: String?, + requiredStdlibVersion: ApiVersion, + forTests: Boolean ) { fun doUpdateMavenLanguageVersion(): PsiElement? { val psi = KotlinMavenConfigurator.findModulePomFile(module) as? XmlFile ?: return null val pom = PomFile.forFileOrNull(psi) ?: return null return pom.changeLanguageVersion( - languageVersion, - apiVersion) + languageVersion, + apiVersion + ) } val runtimeUpdateRequired = getRuntimeLibraryVersion(module)?.let { ApiVersion.parse(it) }?.let { runtimeVersion -> @@ -208,39 +216,49 @@ abstract class KotlinMavenConfigurator } ?: false if (runtimeUpdateRequired) { - Messages.showErrorDialog(module.project, - "This language feature requires version $requiredStdlibVersion or later of the Kotlin runtime library. " + - "Please update the version in your build script.", - "Update Language Version") + Messages.showErrorDialog( + module.project, + "This language feature requires version $requiredStdlibVersion or later of the Kotlin runtime library. " + + "Please update the version in your build script.", + "Update Language Version" + ) return } val element = doUpdateMavenLanguageVersion() if (element == null) { - Messages.showErrorDialog(module.project, - "Failed to update.pom.xml. Please update the file manually.", - "Update Language Version") - } - else { + Messages.showErrorDialog( + module.project, + "Failed to update.pom.xml. Please update the file manually.", + "Update Language Version" + ) + } else { OpenFileDescriptor(module.project, element.containingFile.virtualFile, element.textRange.startOffset).navigate(true) } } - override fun addLibraryDependency(module: Module, element: PsiElement, library: ExternalLibraryDescriptor, libraryJarDescriptors: List) { + override fun addLibraryDependency( + module: Module, + element: PsiElement, + library: ExternalLibraryDescriptor, + libraryJarDescriptors: List + ) { val scope = OrderEntryFix.suggestScopeByLocation(module, element) JavaProjectModelModificationService.getInstance(module.project).addDependency(module, library, scope) } override fun changeCoroutineConfiguration(module: Module, state: LanguageFeature.State) { val runtimeUpdateRequired = state != LanguageFeature.State.DISABLED && - (getRuntimeLibraryVersion(module)?.startsWith("1.0") ?: false) + (getRuntimeLibraryVersion(module)?.startsWith("1.0") ?: false) val messageTitle = ChangeCoroutineSupportFix.getFixText(state) if (runtimeUpdateRequired) { - Messages.showErrorDialog(module.project, - "Coroutines support requires version 1.1 or later of the Kotlin runtime library. " + - "Please update the version in your build script.", - messageTitle) + Messages.showErrorDialog( + module.project, + "Coroutines support requires version 1.1 or later of the Kotlin runtime library. " + + "Please update the version in your build script.", + messageTitle + ) return } @@ -261,19 +279,19 @@ abstract class KotlinMavenConfigurator val element = doChangeMavenCoroutineConfiguration() if (element == null) { - Messages.showErrorDialog(module.project, - "Failed to update.pom.xml. Please update the file manually.", - messageTitle) + Messages.showErrorDialog( + module.project, + "Failed to update.pom.xml. Please update the file manually.", + messageTitle + ) } return element } companion object { - val NAME = "maven" - - val GROUP_ID = "org.jetbrains.kotlin" - val MAVEN_PLUGIN_ID = "kotlin-maven-plugin" - private val KOTLIN_VERSION_PROPERTY = "kotlin.version" + const val GROUP_ID = "org.jetbrains.kotlin" + const val MAVEN_PLUGIN_ID = "kotlin-maven-plugin" + private const val KOTLIN_VERSION_PROPERTY = "kotlin.version" private fun hasJavaFiles(module: Module): Boolean { return !FileTypeIndex.getFiles(JavaFileType.INSTANCE, GlobalSearchScope.moduleScope(module)).isEmpty() @@ -296,11 +314,13 @@ abstract class KotlinMavenConfigurator } private fun showErrorMessage(project: Project, message: String?) { - Messages.showErrorDialog(project, - "Couldn't configure kotlin-maven plugin automatically.
" + - (if (message != null) "$message
" else "") + - "See manual installation instructions here.", - "Configure Kotlin-Maven Plugin") + Messages.showErrorDialog( + project, + "Couldn't configure kotlin-maven plugin automatically.
" + + (if (message != null) "$message
" else "") + + "See manual installation instructions here.", + "Configure Kotlin-Maven Plugin" + ) } } } diff --git a/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/inspections/DeprecatedMavenDependencyInspection.kt b/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/inspections/DeprecatedMavenDependencyInspection.kt index 2153e2b9411..69e42805cb2 100644 --- a/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/inspections/DeprecatedMavenDependencyInspection.kt +++ b/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/inspections/DeprecatedMavenDependencyInspection.kt @@ -41,23 +41,26 @@ class DeprecatedMavenDependencyInspection : DomElementsInspection= 0 - } - .forEach { dependency -> - val xmlElement = dependency.artifactId.xmlElement - if (xmlElement != null) { - val fix = ReplaceStringInDocumentFix(xmlElement, libInfo.old.name, libInfo.new.name) + .filter { it.version?.stringValue != null } + .filter { + val libVersion = + project.findDependencies(libInfo.old.groupId, libInfo.old.name).map { it.version }.distinct().singleOrNull() + libVersion != null && VersionComparatorUtil.COMPARATOR.compare(libVersion, libInfo.outdatedAfterVersion) >= 0 + } + .forEach { dependency -> + val xmlElement = dependency.artifactId.xmlElement + if (xmlElement != null) { + val fix = ReplaceStringInDocumentFix(xmlElement, libInfo.old.name, libInfo.new.name) - holder.createProblem(dependency.artifactId, - ProblemHighlightType.LIKE_DEPRECATED, - libInfo.message, - null, - fix) - } + holder.createProblem( + dependency.artifactId, + ProblemHighlightType.LIKE_DEPRECATED, + libInfo.message, + null, + fix + ) } + } } } } \ No newline at end of file diff --git a/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/inspections/DifferentKotlinMavenVersionInspection.kt b/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/inspections/DifferentKotlinMavenVersionInspection.kt index 95984be8061..62f601e7541 100644 --- a/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/inspections/DifferentKotlinMavenVersionInspection.kt +++ b/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/inspections/DifferentKotlinMavenVersionInspection.kt @@ -28,7 +28,8 @@ import org.jetbrains.kotlin.idea.inspections.PluginVersionDependentInspection import org.jetbrains.kotlin.idea.maven.PomFile import org.jetbrains.kotlin.idea.versions.bundledRuntimeVersion -class DifferentKotlinMavenVersionInspection : DomElementsInspection(MavenDomProjectModel::class.java), PluginVersionDependentInspection { +class DifferentKotlinMavenVersionInspection : DomElementsInspection(MavenDomProjectModel::class.java), + PluginVersionDependentInspection { private val idePluginVersion by lazy { bundledRuntimeVersion() } override var testVersionMessage: String? = null @@ -53,8 +54,11 @@ class DifferentKotlinMavenVersionInspection : DomElementsInspection, val newVersion: String, val versionResolved: String?) : LocalQuickFix { - override fun getName() = if (versionResolved == null) "Change version to $newVersion" else "Change version to $newVersion ($versionResolved)" + private class SetVersionQuickFix(val versionElement: GenericDomValue<*>, val newVersion: String, val versionResolved: String?) : + LocalQuickFix { + override fun getName() = + if (versionResolved == null) "Change version to $newVersion" else "Change version to $newVersion ($versionResolved)" + override fun getFamilyName() = "Change version" override fun applyFix(project: Project, descriptor: ProblemDescriptor) { diff --git a/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/inspections/KotlinMavenPluginPhaseInspection.kt b/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/inspections/KotlinMavenPluginPhaseInspection.kt index a34f6fd0bd5..87b12f4ba0b 100644 --- a/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/inspections/KotlinMavenPluginPhaseInspection.kt +++ b/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/inspections/KotlinMavenPluginPhaseInspection.kt @@ -59,8 +59,8 @@ class KotlinMavenPluginPhaseInspection : DomElementsInspection = executions.flatMapTo(HashSet()) { it.goals } val hasJvmExecution = PomFile.KotlinGoals.Compile in allGoalsSet || PomFile.KotlinGoals.TestCompile in allGoalsSet val hasJsExecution = PomFile.KotlinGoals.Js in allGoalsSet || PomFile.KotlinGoals.TestJs in allGoalsSet @@ -71,45 +71,52 @@ class KotlinMavenPluginPhaseInspection : DomElementsInspection - val javacPlugin = mavenProject.findPlugin("org.apache.maven.plugins", "maven-compiler-plugin") - val existingJavac = pom.domModel.build.plugins.plugins.firstOrNull { - it.groupId.stringValue == "org.apache.maven.plugins" && - it.artifactId.stringValue == "maven-compiler-plugin" - } + pom.findExecutions(kotlinPlugin, PomFile.KotlinGoals.Compile).notAtPhase(PomFile.DefaultPhases.ProcessSources) + .forEach { badExecution -> + val javacPlugin = mavenProject.findPlugin("org.apache.maven.plugins", "maven-compiler-plugin") + val existingJavac = pom.domModel.build.plugins.plugins.firstOrNull { + it.groupId.stringValue == "org.apache.maven.plugins" && + it.artifactId.stringValue == "maven-compiler-plugin" + } - if (existingJavac == null - || !pom.isPluginAfter(existingJavac, kotlinPlugin) - || pom.isExecutionEnabled(javacPlugin, "default-compile") - || pom.isExecutionEnabled(javacPlugin, "default-testCompile") - || pom.isPluginExecutionMissing(javacPlugin, "default-compile", "compile") - || pom.isPluginExecutionMissing(javacPlugin, "default-testCompile", "testCompile")) { + if (existingJavac == null + || !pom.isPluginAfter(existingJavac, kotlinPlugin) + || pom.isExecutionEnabled(javacPlugin, "default-compile") + || pom.isExecutionEnabled(javacPlugin, "default-testCompile") + || pom.isPluginExecutionMissing(javacPlugin, "default-compile", "compile") + || pom.isPluginExecutionMissing(javacPlugin, "default-testCompile", "testCompile")) { - holder.createProblem(badExecution.phase.createStableCopy(), - HighlightSeverity.WARNING, - "Kotlin plugin should run before javac so kotlin classes could be visible from Java", - FixExecutionPhaseLocalFix(badExecution, PomFile.DefaultPhases.ProcessSources), - AddJavaExecutionsLocalFix(module, domFileElement.file, kotlinPlugin)) + holder.createProblem( + badExecution.phase.createStableCopy(), + HighlightSeverity.WARNING, + "Kotlin plugin should run before javac so kotlin classes could be visible from Java", + FixExecutionPhaseLocalFix(badExecution, PomFile.DefaultPhases.ProcessSources), + AddJavaExecutionsLocalFix(module, domFileElement.file, kotlinPlugin) + ) + } } - } pom.findExecutions(kotlinPlugin, PomFile.KotlinGoals.Js, PomFile.KotlinGoals.TestJs).forEach { badExecution -> - holder.createProblem(badExecution.goals.goals.first { it.isJsGoal() }.createStableCopy(), - HighlightSeverity.WARNING, - "JavaScript goal configured for module with Java files") + holder.createProblem( + badExecution.goals.goals.first { it.isJsGoal() }.createStableCopy(), + HighlightSeverity.WARNING, + "JavaScript goal configured for module with Java files" + ) } } @@ -117,16 +124,20 @@ class KotlinMavenPluginPhaseInspection : DomElementsInspection - holder.createProblem(dep.artifactId.createStableCopy(), - HighlightSeverity.WARNING, - "You have ${dep.artifactId} configured but no corresponding plugin execution", - ConfigurePluginExecutionLocalFix(module, domFileElement.file, PomFile.KotlinGoals.Compile, dep.version.rawText)) + holder.createProblem( + dep.artifactId.createStableCopy(), + HighlightSeverity.WARNING, + "You have ${dep.artifactId} configured but no corresponding plugin execution", + ConfigurePluginExecutionLocalFix(module, domFileElement.file, PomFile.KotlinGoals.Compile, dep.version.rawText) + ) } } val stdlibJsDependencies = pom.findDependencies(MavenId(KotlinMavenConfigurator.GROUP_ID, MAVEN_JS_STDLIB_ID, null)) if (!hasJsExecution && stdlibJsDependencies.isNotEmpty()) { stdlibJsDependencies.forEach { dep -> - holder.createProblem(dep.artifactId.createStableCopy(), - HighlightSeverity.WARNING, - "You have ${dep.artifactId} configured but no corresponding plugin execution", - ConfigurePluginExecutionLocalFix(module, domFileElement.file, PomFile.KotlinGoals.Js, dep.version.rawText)) + holder.createProblem( + dep.artifactId.createStableCopy(), + HighlightSeverity.WARNING, + "You have ${dep.artifactId} configured but no corresponding plugin execution", + ConfigurePluginExecutionLocalFix(module, domFileElement.file, PomFile.KotlinGoals.Js, dep.version.rawText) + ) } } pom.findKotlinExecutions().filter { it.goals.goals.any { it.rawText == PomFile.KotlinGoals.Compile || it.rawText == PomFile.KotlinGoals.Js } - && it.goals.goals.any { it.rawText == PomFile.KotlinGoals.TestCompile || it.rawText == PomFile.KotlinGoals.TestJs } + && it.goals.goals.any { it.rawText == PomFile.KotlinGoals.TestCompile || it.rawText == PomFile.KotlinGoals.TestJs } }.forEach { badExecution -> - holder.createProblem(badExecution.goals.createStableCopy(), - HighlightSeverity.WEAK_WARNING, - "It is not recommended to have both test and compile goals in the same execution") - } + holder.createProblem( + badExecution.goals.createStableCopy(), + HighlightSeverity.WEAK_WARNING, + "It is not recommended to have both test and compile goals in the same execution" + ) + } } - private class AddExecutionLocalFix(val file: XmlFile, val module: Module, val kotlinPlugin: MavenDomPlugin, val goal: String) : LocalQuickFix { + private class AddExecutionLocalFix(val file: XmlFile, val module: Module, val kotlinPlugin: MavenDomPlugin, val goal: String) : + LocalQuickFix { override fun getName() = "Create $goal execution" override fun getFamilyName() = "Create kotlin execution" override fun applyFix(project: Project, descriptor: ProblemDescriptor) { - PomFile.forFileOrNull(file)?.addKotlinExecution(module, kotlinPlugin, goal, PomFile.getPhase(module.hasJavaFiles(), false), false, listOf(goal)) + PomFile.forFileOrNull(file) + ?.addKotlinExecution(module, kotlinPlugin, goal, PomFile.getPhase(module.hasJavaFiles(), false), false, listOf(goal)) } } @@ -195,11 +214,13 @@ class KotlinMavenPluginPhaseInspection : DomElementsInspection() { - override fun getReferenceClass(): Class = KtSimpleNameReference::class.java + override fun getReferenceClass(): Class = KtSimpleNameReference::class.java override fun registerFixes(ref: KtSimpleNameReference, registrar: QuickFixActionRegistrar) { val module = ModuleUtilCore.findModuleForPsiElement(ref.expression) ?: return @@ -59,15 +59,14 @@ class KotlinMavenUnresolvedReferenceQuickFixProvider : UnresolvedReferenceQuickF } else { importDirective.importedFqName?.asString() } - } - else { + } else { val typeReference = expression.getParentOfType(true) val referenced = typeReference?.text ?: expression.getReferencedName() expression.containingKtFile - .importDirectives - .firstOrNull { !it.isAllUnder && it.aliasName == referenced || it.importedFqName?.shortName()?.asString() == referenced } - ?.let { it.importedFqName?.asString() } + .importDirectives + .firstOrNull { !it.isAllUnder && it.aliasName == referenced || it.importedFqName?.shortName()?.asString() == referenced } + ?.let { it.importedFqName?.asString() } ?: referenced } @@ -77,12 +76,16 @@ class KotlinMavenUnresolvedReferenceQuickFixProvider : UnresolvedReferenceQuickF } } -class AddMavenDependencyQuickFix(val className: String, val smartPsiElementPointer: SmartPsiElementPointer) : IntentionAction, LowPriorityAction { +class AddMavenDependencyQuickFix( + val className: String, + private val smartPsiElementPointer: SmartPsiElementPointer +) : + IntentionAction, LowPriorityAction { override fun getText() = "Add Maven dependency..." override fun getFamilyName() = text override fun startInWriteAction() = false override fun isAvailable(project: Project, editor: Editor?, file: PsiFile?) = - smartPsiElementPointer.element.let { it != null && it.isValid } && file != null && MavenDomUtil.findContainingProject(file) != null + smartPsiElementPointer.element.let { it != null && it.isValid } && file != null && MavenDomUtil.findContainingProject(file) != null override fun invoke(project: Project, editor: Editor?, file: PsiFile?) { if (editor == null || file == null) { diff --git a/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/inspections/KotlinTestJUnitInspection.kt b/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/inspections/KotlinTestJUnitInspection.kt index 40031b989fb..dbf9ae6825c 100644 --- a/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/inspections/KotlinTestJUnitInspection.kt +++ b/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/inspections/KotlinTestJUnitInspection.kt @@ -45,14 +45,15 @@ class KotlinTestJUnitInspection : DomElementsInspection(Ma } val kotlinTestDependencies = domFileElement.rootElement.dependencies - .dependencies.filter { it.groupId.rawText == KotlinMavenConfigurator.GROUP_ID && it.artifactId.rawText == KotlinJavaMavenConfigurator.TEST_LIB_ID } + .dependencies.filter { it.groupId.rawText == KotlinMavenConfigurator.GROUP_ID && it.artifactId.rawText == KotlinJavaMavenConfigurator.TEST_LIB_ID } kotlinTestDependencies.forEach { - holder.createProblem(it.artifactId, - HighlightSeverity.WEAK_WARNING, - "kotlin-test-junit is better with junit", - ReplaceToKotlinTest(it) - ) + holder.createProblem( + it.artifactId, + HighlightSeverity.WEAK_WARNING, + "kotlin-test-junit is better with junit", + ReplaceToKotlinTest(it) + ) } } diff --git a/idea/idea-maven/test/org/jetbrains/kotlin/idea/maven/AbstractKotlinMavenInspectionTest.kt b/idea/idea-maven/test/org/jetbrains/kotlin/idea/maven/AbstractKotlinMavenInspectionTest.kt index a54e0993932..aee372b1f74 100644 --- a/idea/idea-maven/test/org/jetbrains/kotlin/idea/maven/AbstractKotlinMavenInspectionTest.kt +++ b/idea/idea-maven/test/org/jetbrains/kotlin/idea/maven/AbstractKotlinMavenInspectionTest.kt @@ -19,7 +19,6 @@ package org.jetbrains.kotlin.idea.maven import com.intellij.codeInspection.CommonProblemDescriptor import com.intellij.codeInspection.ProblemDescriptorBase import com.intellij.codeInspection.QuickFix -import com.intellij.codeInspection.reference.RefEntity import com.intellij.ide.highlighter.JavaFileType import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.application.Result @@ -60,29 +59,32 @@ abstract class AbstractKotlinMavenInspectionTest : MavenImportingTestCase() { mkJavaFile() } - val inspectionClassName = "".toRegex().find(pomText)?.groups?.get(1)?.value ?: KotlinMavenPluginPhaseInspection::class.qualifiedName !! + val inspectionClassName = "".toRegex().find(pomText)?.groups?.get(1)?.value + ?: KotlinMavenPluginPhaseInspection::class.qualifiedName!! val inspectionClass = Class.forName(inspectionClassName) val matcher = "".toRegex() - val expected = pomText.lines().mapNotNull { matcher.find(it) }.map { SimplifiedProblemDescription(it.groups[2]!!.value.trim(), it.groups[1]!!.value.trim()) } + val expected = pomText.lines().mapNotNull { matcher.find(it) } + .map { SimplifiedProblemDescription(it.groups[2]!!.value.trim(), it.groups[1]!!.value.trim()) } val problemElements = runInspection(inspectionClass, myProject).problemElements val actualProblems = problemElements - .keys() - .filter { it.name == "pom.xml" } - .map { problemElements.get(it) } - .flatMap { it.toList() } - .mapNotNull { it as? ProblemDescriptorBase } + .keys() + .filter { it.name == "pom.xml" } + .map { problemElements.get(it) } + .flatMap { it.toList() } + .mapNotNull { it as? ProblemDescriptorBase } val actual = actualProblems - .map { SimplifiedProblemDescription(it.descriptionTemplate, it.psiElement.text.replace("\\s+".toRegex(), "")) to it } - .sortedBy { it.first.text } + .map { SimplifiedProblemDescription(it.descriptionTemplate, it.psiElement.text.replace("\\s+".toRegex(), "")) to it } + .sortedBy { it.first.text } assertEquals(expected.sortedBy { it.text }, actual.map { it.first }) val suggestedFixes = actual.flatMap { p -> p.second.fixes?.sortedBy { it.familyName }?.map { p.second to it } ?: emptyList() } val filenamePrefix = pomFile.nameWithoutExtension + ".fixed." - val fixFiles = pomFile.parentFile.listFiles { _, name -> name.startsWith(filenamePrefix) && name.endsWith(".xml") }.sortedBy { it.name } + val fixFiles = + pomFile.parentFile.listFiles { _, name -> name.startsWith(filenamePrefix) && name.endsWith(".xml") }.sortedBy { it.name } if (fixFiles.size > suggestedFixes.size) { fail("Not all fixes were suggested by the inspection: expected count: ${fixFiles.size}, actual fixes count: ${suggestedFixes.size}") @@ -144,7 +146,8 @@ abstract class AbstractKotlinMavenInspectionTest : MavenImportingTestCase() { } private fun mkJavaFile() { - val sourceFolder = getContentRoots(myProject.allModules().single().name).single().getSourceFolders(JavaSourceRootType.SOURCE).single() + val sourceFolder = + getContentRoots(myProject.allModules().single().name).single().getSourceFolders(JavaSourceRootType.SOURCE).single() ApplicationManager.getApplication().runWriteAction { val javaFile = sourceFolder.file?.toPsiDirectory(myProject)?.createFile("Test.java") ?: throw IllegalStateException() javaFile.viewProvider.document!!.setText("class Test {}\n") diff --git a/idea/idea-maven/test/org/jetbrains/kotlin/idea/maven/KotlinMavenArchetypesProviderTest.kt b/idea/idea-maven/test/org/jetbrains/kotlin/idea/maven/KotlinMavenArchetypesProviderTest.kt index e746598e31e..37b0495536c 100644 --- a/idea/idea-maven/test/org/jetbrains/kotlin/idea/maven/KotlinMavenArchetypesProviderTest.kt +++ b/idea/idea-maven/test/org/jetbrains/kotlin/idea/maven/KotlinMavenArchetypesProviderTest.kt @@ -24,7 +24,9 @@ import org.junit.Test import java.io.File class KotlinMavenArchetypesProviderTest { - private val BASE_PATH = "idea/testData/configuration/" + companion object { + private const val BASE_PATH = "idea/testData/configuration/" + } @Test fun extractVersions() { @@ -38,11 +40,11 @@ class KotlinMavenArchetypesProviderTest { val versions = KotlinMavenArchetypesProvider("1.0.0-Release-Something-1886", false).extractVersions(json) assertEquals( - listOf( - MavenArchetype("org.jetbrains.kotlin", "kotlin-archetype-jvm", "1.0.1-2", null, null), - MavenArchetype("org.jetbrains.kotlin", "kotlin-archetype-js", "1.0.0", null, null) - ).sortedBy { it.artifactId + "." + it.version }, - versions.sortedBy { it.artifactId + "." + it.version } + listOf( + MavenArchetype("org.jetbrains.kotlin", "kotlin-archetype-jvm", "1.0.1-2", null, null), + MavenArchetype("org.jetbrains.kotlin", "kotlin-archetype-js", "1.0.0", null, null) + ).sortedBy { it.artifactId + "." + it.version }, + versions.sortedBy { it.artifactId + "." + it.version } ) } @@ -58,10 +60,10 @@ class KotlinMavenArchetypesProviderTest { val versions = KotlinMavenArchetypesProvider("1.1.0-Next-Release-Something-9999", false).extractVersions(json) assertEquals( - listOf( - MavenArchetype("org.jetbrains.kotlin", "kotlin-archetype-jvm", "1.1.2", null, null) - ).sortedBy { it.artifactId + "." + it.version }, - versions.sortedBy { it.artifactId + "." + it.version } + listOf( + MavenArchetype("org.jetbrains.kotlin", "kotlin-archetype-jvm", "1.1.2", null, null) + ).sortedBy { it.artifactId + "." + it.version }, + versions.sortedBy { it.artifactId + "." + it.version } ) } @@ -77,12 +79,12 @@ class KotlinMavenArchetypesProviderTest { val versions = KotlinMavenArchetypesProvider("1.0.0-Release-Something-1886", true).extractVersions(json) assertEquals( - listOf( - MavenArchetype("org.jetbrains.kotlin", "kotlin-archetype-jvm", "1.0.1-2", null, null), - MavenArchetype("org.jetbrains.kotlin", "kotlin-archetype-jvm", "1.1.2", null, null), - MavenArchetype("org.jetbrains.kotlin", "kotlin-archetype-js", "1.0.0", null, null) - ).sortedBy { it.artifactId + "." + it.version }, - versions.sortedBy { it.artifactId + "." + it.version } + listOf( + MavenArchetype("org.jetbrains.kotlin", "kotlin-archetype-jvm", "1.0.1-2", null, null), + MavenArchetype("org.jetbrains.kotlin", "kotlin-archetype-jvm", "1.1.2", null, null), + MavenArchetype("org.jetbrains.kotlin", "kotlin-archetype-js", "1.0.0", null, null) + ).sortedBy { it.artifactId + "." + it.version }, + versions.sortedBy { it.artifactId + "." + it.version } ) } @@ -98,12 +100,12 @@ class KotlinMavenArchetypesProviderTest { val versions = KotlinMavenArchetypesProvider("1.9.0-Missing-Release-Something-1886", false).extractVersions(json) assertEquals( - listOf( - MavenArchetype("org.jetbrains.kotlin", "kotlin-archetype-jvm", "1.0.1-2", null, null), - MavenArchetype("org.jetbrains.kotlin", "kotlin-archetype-jvm", "1.1.2", null, null), - MavenArchetype("org.jetbrains.kotlin", "kotlin-archetype-js", "1.0.0", null, null) - ).sortedBy { it.artifactId + "." + it.version }, - versions.sortedBy { it.artifactId + "." + it.version } + listOf( + MavenArchetype("org.jetbrains.kotlin", "kotlin-archetype-jvm", "1.0.1-2", null, null), + MavenArchetype("org.jetbrains.kotlin", "kotlin-archetype-jvm", "1.1.2", null, null), + MavenArchetype("org.jetbrains.kotlin", "kotlin-archetype-js", "1.0.0", null, null) + ).sortedBy { it.artifactId + "." + it.version }, + versions.sortedBy { it.artifactId + "." + it.version } ) } @@ -119,12 +121,12 @@ class KotlinMavenArchetypesProviderTest { val versions = KotlinMavenArchetypesProvider("@snapshot@", false).extractVersions(json) assertEquals( - listOf( - MavenArchetype("org.jetbrains.kotlin", "kotlin-archetype-jvm", "1.0.1-2", null, null), - MavenArchetype("org.jetbrains.kotlin", "kotlin-archetype-jvm", "1.1.2", null, null), - MavenArchetype("org.jetbrains.kotlin", "kotlin-archetype-js", "1.0.0", null, null) - ).sortedBy { it.artifactId + "." + it.version }, - versions.sortedBy { it.artifactId + "." + it.version } + listOf( + MavenArchetype("org.jetbrains.kotlin", "kotlin-archetype-jvm", "1.0.1-2", null, null), + MavenArchetype("org.jetbrains.kotlin", "kotlin-archetype-jvm", "1.1.2", null, null), + MavenArchetype("org.jetbrains.kotlin", "kotlin-archetype-js", "1.0.0", null, null) + ).sortedBy { it.artifactId + "." + it.version }, + versions.sortedBy { it.artifactId + "." + it.version } ) } } \ No newline at end of file diff --git a/idea/idea-maven/test/org/jetbrains/kotlin/idea/maven/KotlinMavenImporterTest.kt b/idea/idea-maven/test/org/jetbrains/kotlin/idea/maven/KotlinMavenImporterTest.kt index 5fe37e0d674..af348005800 100644 --- a/idea/idea-maven/test/org/jetbrains/kotlin/idea/maven/KotlinMavenImporterTest.kt +++ b/idea/idea-maven/test/org/jetbrains/kotlin/idea/maven/KotlinMavenImporterTest.kt @@ -33,7 +33,6 @@ import org.jetbrains.kotlin.idea.framework.CommonLibraryKind import org.jetbrains.kotlin.idea.framework.JSLibraryKind import org.jetbrains.kotlin.idea.refactoring.toPsiFile import org.jetbrains.kotlin.psi.KtFile -import org.jetbrains.kotlin.config.LanguageVersion import org.junit.Assert import java.io.File @@ -47,19 +46,21 @@ class KotlinMavenImporterTest : MavenImportingTestCase() { } fun testSimpleKotlinProject() { - importProject(""" - test - project - 1.0.0 + importProject( + """ + test + project + 1.0.0 - - - org.jetbrains.kotlin - kotlin-stdlib - $kotlinVersion - - - """) + + + org.jetbrains.kotlin + kotlin-stdlib + $kotlinVersion + + + """ + ) assertModules("project") assertImporterStatePresent() @@ -69,23 +70,25 @@ class KotlinMavenImporterTest : MavenImportingTestCase() { fun testWithSpecifiedSourceRoot() { createProjectSubDir("src/main/kotlin") - importProject(""" - test - project - 1.0.0 + importProject( + """ + test + project + 1.0.0 - - - org.jetbrains.kotlin - kotlin-stdlib - $kotlinVersion - - + + + org.jetbrains.kotlin + kotlin-stdlib + $kotlinVersion + + - - src/main/kotlin - - """) + + src/main/kotlin + + """ + ) assertModules("project") assertImporterStatePresent() @@ -95,60 +98,62 @@ class KotlinMavenImporterTest : MavenImportingTestCase() { fun testWithCustomSourceDirs() { createProjectSubDirs("src/main/kotlin", "src/main/kotlin.jvm", "src/test/kotlin", "src/test/kotlin.jvm") - importProject(""" - test - project - 1.0.0 + importProject( + """ + test + project + 1.0.0 - - - org.jetbrains.kotlin - kotlin-stdlib - $kotlinVersion - - - - - src/main/kotlin - - - + + org.jetbrains.kotlin - kotlin-maven-plugin + kotlin-stdlib + $kotlinVersion + + - - - compile - compile - - compile - - - - src/main/kotlin - src/main/kotlin.jvm - - - + + src/main/kotlin - - test-compile - test-compile - - test-compile - - - - src/test/kotlin - src/test/kotlin.jvm - - - - - - - - """) + + + org.jetbrains.kotlin + kotlin-maven-plugin + + + + compile + compile + + compile + + + + src/main/kotlin + src/main/kotlin.jvm + + + + + + test-compile + test-compile + + test-compile + + + + src/test/kotlin + src/test/kotlin.jvm + + + + + + + + """ + ) assertModules("project") assertImporterStatePresent() @@ -160,60 +165,62 @@ class KotlinMavenImporterTest : MavenImportingTestCase() { fun testReImportRemoveDir() { createProjectSubDirs("src/main/kotlin", "src/main/kotlin.jvm", "src/test/kotlin", "src/test/kotlin.jvm") - importProject(""" - test - project - 1.0.0 + importProject( + """ + test + project + 1.0.0 - - - org.jetbrains.kotlin - kotlin-stdlib - $kotlinVersion - - - - - src/main/kotlin - - - + + org.jetbrains.kotlin - kotlin-maven-plugin + kotlin-stdlib + $kotlinVersion + + - - - compile - compile - - compile - - - - src/main/kotlin - src/main/kotlin.jvm - - - + + src/main/kotlin - - test-compile - test-compile - - test-compile - - - - src/test/kotlin - src/test/kotlin.jvm - - - - - - - - """) + + + org.jetbrains.kotlin + kotlin-maven-plugin + + + + compile + compile + + compile + + + + src/main/kotlin + src/main/kotlin.jvm + + + + + + test-compile + test-compile + + test-compile + + + + src/test/kotlin + src/test/kotlin.jvm + + + + + + + + """ + ) assertModules("project") assertImporterStatePresent() @@ -222,59 +229,61 @@ class KotlinMavenImporterTest : MavenImportingTestCase() { assertTestSources("project", "src/test/java", "src/test/kotlin", "src/test/kotlin.jvm") // reimport - importProject(""" - test - project - 1.0.0 + importProject( + """ + test + project + 1.0.0 - - - org.jetbrains.kotlin - kotlin-stdlib - $kotlinVersion - - - - - src/main/kotlin - - - + + org.jetbrains.kotlin - kotlin-maven-plugin + kotlin-stdlib + $kotlinVersion + + - - - compile - compile - - compile - - - - src/main/kotlin - - - + + src/main/kotlin - - test-compile - test-compile - - test-compile - - - - src/test/kotlin - src/test/kotlin.jvm - - - - - - - - """) + + + org.jetbrains.kotlin + kotlin-maven-plugin + + + + compile + compile + + compile + + + + src/main/kotlin + + + + + + test-compile + test-compile + + test-compile + + + + src/test/kotlin + src/test/kotlin.jvm + + + + + + + + """ + ) assertSources("project", "src/main/kotlin") assertTestSources("project", "src/test/java", "src/test/kotlin", "src/test/kotlin.jvm") @@ -283,59 +292,61 @@ class KotlinMavenImporterTest : MavenImportingTestCase() { fun testReImportAddDir() { createProjectSubDirs("src/main/kotlin", "src/main/kotlin.jvm", "src/test/kotlin", "src/test/kotlin.jvm") - importProject(""" - test - project - 1.0.0 + importProject( + """ + test + project + 1.0.0 - - - org.jetbrains.kotlin - kotlin-stdlib - $kotlinVersion - - - - - src/main/kotlin - - - + + org.jetbrains.kotlin - kotlin-maven-plugin + kotlin-stdlib + $kotlinVersion + + - - - compile - compile - - compile - - - - src/main/kotlin - - - + + src/main/kotlin - - test-compile - test-compile - - test-compile - - - - src/test/kotlin - src/test/kotlin.jvm - - - - - - - - """) + + + org.jetbrains.kotlin + kotlin-maven-plugin + + + + compile + compile + + compile + + + + src/main/kotlin + + + + + + test-compile + test-compile + + test-compile + + + + src/test/kotlin + src/test/kotlin.jvm + + + + + + + + """ + ) assertModules("project") assertImporterStatePresent() @@ -344,60 +355,62 @@ class KotlinMavenImporterTest : MavenImportingTestCase() { assertTestSources("project", "src/test/java", "src/test/kotlin", "src/test/kotlin.jvm") // reimport - importProject(""" - test - project - 1.0.0 + importProject( + """ + test + project + 1.0.0 - - - org.jetbrains.kotlin - kotlin-stdlib - $kotlinVersion - - - - - src/main/kotlin - - - + + org.jetbrains.kotlin - kotlin-maven-plugin + kotlin-stdlib + $kotlinVersion + + - - - compile - compile - - compile - - - - src/main/kotlin - src/main/kotlin.jvm - - - + + src/main/kotlin - - test-compile - test-compile - - test-compile - - - - src/test/kotlin - src/test/kotlin.jvm - - - - - - - - """) + + + org.jetbrains.kotlin + kotlin-maven-plugin + + + + compile + compile + + compile + + + + src/main/kotlin + src/main/kotlin.jvm + + + + + + test-compile + test-compile + + test-compile + + + + src/test/kotlin + src/test/kotlin.jvm + + + + + + + + """ + ) assertSources("project", "src/main/kotlin", "src/main/kotlin.jvm") assertTestSources("project", "src/test/java", "src/test/kotlin", "src/test/kotlin.jvm") @@ -406,56 +419,58 @@ class KotlinMavenImporterTest : MavenImportingTestCase() { fun testJvmFacetConfiguration() { createProjectSubDirs("src/main/kotlin", "src/main/kotlin.jvm", "src/test/kotlin", "src/test/kotlin.jvm") - importProject(""" - test - project - 1.0.0 + importProject( + """ + test + project + 1.0.0 - - - org.jetbrains.kotlin - kotlin-stdlib - $kotlinVersion - - - - - src/main/kotlin - - - + + org.jetbrains.kotlin - kotlin-maven-plugin + kotlin-stdlib + $kotlinVersion + + - - - compile - compile - - compile - - - - - 1.1 - 1.0 - true - true - - -Xcoroutines=enable - - 1.8 - foobar.jar - - - - - """) + + src/main/kotlin + + + + org.jetbrains.kotlin + kotlin-maven-plugin + + + + compile + compile + + compile + + + + + 1.1 + 1.0 + true + true + + -Xcoroutines=enable + + 1.8 + foobar.jar + + + + + """ + ) assertModules("project") assertImporterStatePresent() - with (facetSettings) { + with(facetSettings) { Assert.assertEquals("1.1", languageLevel!!.versionString) Assert.assertEquals("1.1", compilerArguments!!.languageVersion) Assert.assertEquals("1.0", apiLevel!!.versionString) @@ -467,59 +482,63 @@ class KotlinMavenImporterTest : MavenImportingTestCase() { Assert.assertEquals("JVM 1.8", targetPlatformKind!!.description) Assert.assertEquals("1.8", (compilerArguments as K2JVMCompilerArguments).jvmTarget) Assert.assertEquals("foobar.jar", (compilerArguments as K2JVMCompilerArguments).classpath) - Assert.assertEquals("-Xmulti-platform", - compilerSettings!!.additionalArguments) + Assert.assertEquals( + "-Xmulti-platform", + compilerSettings!!.additionalArguments + ) } } fun testJvmFacetConfigurationFromProperties() { createProjectSubDirs("src/main/kotlin", "src/main/kotlin.jvm", "src/test/kotlin", "src/test/kotlin.jvm") - importProject(""" - test - project - 1.0.0 + importProject( + """ + test + project + 1.0.0 - - - org.jetbrains.kotlin - kotlin-stdlib - $kotlinVersion - - - - - 1.0 - 1.0 - 1.8 - - - - src/main/kotlin - - - + + org.jetbrains.kotlin - kotlin-maven-plugin + kotlin-stdlib + $kotlinVersion + + - - - compile - compile - - compile - - - - - - - """) + + 1.0 + 1.0 + 1.8 + + + + src/main/kotlin + + + + org.jetbrains.kotlin + kotlin-maven-plugin + + + + compile + compile + + compile + + + + + + + """ + ) assertModules("project") assertImporterStatePresent() - with (facetSettings) { + with(facetSettings) { Assert.assertEquals("1.0", languageLevel!!.versionString) Assert.assertEquals("1.0", compilerArguments!!.languageVersion) Assert.assertEquals("1.0", apiLevel!!.versionString) @@ -532,58 +551,60 @@ class KotlinMavenImporterTest : MavenImportingTestCase() { fun testJsFacetConfiguration() { createProjectSubDirs("src/main/kotlin", "src/main/kotlin.jvm", "src/test/kotlin", "src/test/kotlin.jvm") - importProject(""" - test - project - 1.0.0 + importProject( + """ + test + project + 1.0.0 - - - org.jetbrains.kotlin - kotlin-stdlib-js - $kotlinVersion - - - - - src/main/kotlin - - - + + org.jetbrains.kotlin - kotlin-maven-plugin + kotlin-stdlib-js + $kotlinVersion + + - - - compile - compile - - js - - - - - 1.1 - 1.0 - true - true - - -Xcoroutines=enable - - true - test.js - true - commonjs - - - - - """) + + src/main/kotlin + + + + org.jetbrains.kotlin + kotlin-maven-plugin + + + + compile + compile + + js + + + + + 1.1 + 1.0 + true + true + + -Xcoroutines=enable + + true + test.js + true + commonjs + + + + + """ + ) assertModules("project") assertImporterStatePresent() - with (facetSettings) { + with(facetSettings) { Assert.assertEquals("1.1", languageLevel!!.versionString) Assert.assertEquals("1.1", compilerArguments!!.languageVersion) Assert.assertEquals("1.0", apiLevel!!.versionString) @@ -592,13 +613,15 @@ class KotlinMavenImporterTest : MavenImportingTestCase() { Assert.assertFalse(compilerArguments!!.autoAdvanceApiVersion) Assert.assertEquals(true, compilerArguments!!.suppressWarnings) Assert.assertEquals(LanguageFeature.State.ENABLED, coroutineSupport) - Assert.assertTrue(targetPlatformKind is TargetPlatformKind.JavaScript) + Assert.assertTrue(targetPlatformKind == TargetPlatformKind.JavaScript) with(compilerArguments as K2JSCompilerArguments) { Assert.assertEquals(true, sourceMap) Assert.assertEquals("commonjs", moduleKind) } - Assert.assertEquals("-meta-info -output test.js -Xmulti-platform", - compilerSettings!!.additionalArguments) + Assert.assertEquals( + "-meta-info -output test.js -Xmulti-platform", + compilerSettings!!.additionalArguments + ) } val rootManager = ModuleRootManager.getInstance(getModule("project")) @@ -609,58 +632,60 @@ class KotlinMavenImporterTest : MavenImportingTestCase() { fun testFacetSplitConfiguration() { createProjectSubDirs("src/main/kotlin", "src/main/kotlin.jvm", "src/test/kotlin", "src/test/kotlin.jvm") - importProject(""" - test - project - 1.0.0 + importProject( + """ + test + project + 1.0.0 - - - org.jetbrains.kotlin - kotlin-stdlib - $kotlinVersion - - - - - src/main/kotlin - - - + + org.jetbrains.kotlin - kotlin-maven-plugin + kotlin-stdlib + $kotlinVersion + + - - - compile - compile - - compile - - - 1.1 - true - - -Xcoroutines=enable - - foobar.jar - - - - - 1.0 - true - 1.8 - - - - - """) + + src/main/kotlin + + + + org.jetbrains.kotlin + kotlin-maven-plugin + + + + compile + compile + + compile + + + 1.1 + true + + -Xcoroutines=enable + + foobar.jar + + + + + 1.0 + true + 1.8 + + + + + """ + ) assertModules("project") assertImporterStatePresent() - with (facetSettings) { + with(facetSettings) { Assert.assertEquals("1.1", languageLevel!!.versionString) Assert.assertEquals("1.1", compilerArguments!!.languageVersion) Assert.assertEquals("1.0", apiLevel!!.versionString) @@ -677,54 +702,56 @@ class KotlinMavenImporterTest : MavenImportingTestCase() { fun testArgsInFacet() { createProjectSubDirs("src/main/kotlin", "src/main/kotlin.jvm", "src/test/kotlin", "src/test/kotlin.jvm") - importProject(""" - test - project - 1.0.0 + importProject( + """ + test + project + 1.0.0 - - - org.jetbrains.kotlin - kotlin-stdlib - $kotlinVersion - - - - - src/main/kotlin - - - + + org.jetbrains.kotlin - kotlin-maven-plugin + kotlin-stdlib + $kotlinVersion + + - - - compile - compile - - compile - - - - - - -jvm-target - 1.8 - -Xcoroutines=enable - -classpath - c:\program files\jdk1.8 - - - - - - """) + + src/main/kotlin + + + + org.jetbrains.kotlin + kotlin-maven-plugin + + + + compile + compile + + compile + + + + + + -jvm-target + 1.8 + -Xcoroutines=enable + -classpath + c:\program files\jdk1.8 + + + + + + """ + ) assertModules("project") assertImporterStatePresent() - with (facetSettings) { + with(facetSettings) { Assert.assertEquals("JVM 1.8", targetPlatformKind!!.description) Assert.assertEquals("1.8", (compilerArguments as K2JVMCompilerArguments).jvmTarget) Assert.assertEquals(LanguageFeature.State.ENABLED, coroutineSupport) @@ -735,50 +762,52 @@ class KotlinMavenImporterTest : MavenImportingTestCase() { fun testArgsInFacetInSingleElement() { createProjectSubDirs("src/main/kotlin", "src/main/kotlin.jvm", "src/test/kotlin", "src/test/kotlin.jvm") - importProject(""" - test - project - 1.0.0 + importProject( + """ + test + project + 1.0.0 - - - org.jetbrains.kotlin - kotlin-stdlib - $kotlinVersion - - - - - src/main/kotlin - - - + + org.jetbrains.kotlin - kotlin-maven-plugin + kotlin-stdlib + $kotlinVersion + + - - - compile - compile - - compile - - - - - - -jvm-target 1.8 -Xcoroutines=enable -classpath "c:\program files\jdk1.8" - - - - - - """) + + src/main/kotlin + + + + org.jetbrains.kotlin + kotlin-maven-plugin + + + + compile + compile + + compile + + + + + + -jvm-target 1.8 -Xcoroutines=enable -classpath "c:\program files\jdk1.8" + + + + + + """ + ) assertModules("project") assertImporterStatePresent() - with (facetSettings) { + with(facetSettings) { Assert.assertEquals("JVM 1.8", targetPlatformKind!!.description) Assert.assertEquals("1.8", (compilerArguments as K2JVMCompilerArguments).jvmTarget) Assert.assertEquals(LanguageFeature.State.ENABLED, coroutineSupport) @@ -789,44 +818,46 @@ class KotlinMavenImporterTest : MavenImportingTestCase() { fun testJvmDetectionByGoalWithJvmStdlib() { createProjectSubDirs("src/main/kotlin", "src/main/kotlin.jvm", "src/test/kotlin", "src/test/kotlin.jvm") - importProject(""" - test - project - 1.0.0 + importProject( + """ + test + project + 1.0.0 - - - org.jetbrains.kotlin - kotlin-stdlib - $kotlinVersion - - - - - src/main/kotlin - - - + + org.jetbrains.kotlin - kotlin-maven-plugin - - - compile - - compile - - - - test-compile - - test-compile - - - - - - - """) + kotlin-stdlib + $kotlinVersion + + + + + src/main/kotlin + + + + org.jetbrains.kotlin + kotlin-maven-plugin + + + compile + + compile + + + + test-compile + + test-compile + + + + + + + """ + ) assertModules("project") assertImporterStatePresent() @@ -837,44 +868,46 @@ class KotlinMavenImporterTest : MavenImportingTestCase() { fun testJvmDetectionByGoalWithJsStdlib() { createProjectSubDirs("src/main/kotlin", "src/main/kotlin.jvm", "src/test/kotlin", "src/test/kotlin.jvm") - importProject(""" - test - project - 1.0.0 + importProject( + """ + test + project + 1.0.0 - - - org.jetbrains.kotlin - kotlin-stdlib-js - $kotlinVersion - - - - - src/main/kotlin - - - + + org.jetbrains.kotlin - kotlin-maven-plugin - - - compile - - compile - - - - test-compile - - test-compile - - - - - - - """) + kotlin-stdlib-js + $kotlinVersion + + + + + src/main/kotlin + + + + org.jetbrains.kotlin + kotlin-maven-plugin + + + compile + + compile + + + + test-compile + + test-compile + + + + + + + """ + ) assertModules("project") assertImporterStatePresent() @@ -885,44 +918,46 @@ class KotlinMavenImporterTest : MavenImportingTestCase() { fun testJvmDetectionByGoalWithCommonStdlib() { createProjectSubDirs("src/main/kotlin", "src/main/kotlin.jvm", "src/test/kotlin", "src/test/kotlin.jvm") - importProject(""" - test - project - 1.0.0 + importProject( + """ + test + project + 1.0.0 - - - org.jetbrains.kotlin - kotlin-stdlib-common - $kotlinVersion - - - - - src/main/kotlin - - - + + org.jetbrains.kotlin - kotlin-maven-plugin - - - compile - - compile - - - - test-compile - - test-compile - - - - - - - """) + kotlin-stdlib-common + $kotlinVersion + + + + + src/main/kotlin + + + + org.jetbrains.kotlin + kotlin-maven-plugin + + + compile + + compile + + + + test-compile + + test-compile + + + + + + + """ + ) assertModules("project") assertImporterStatePresent() @@ -933,44 +968,46 @@ class KotlinMavenImporterTest : MavenImportingTestCase() { fun testJsDetectionByGoalWithJvmStdlib() { createProjectSubDirs("src/main/kotlin", "src/main/kotlin.jvm", "src/test/kotlin", "src/test/kotlin.jvm") - importProject(""" - test - project - 1.0.0 + importProject( + """ + test + project + 1.0.0 - - - org.jetbrains.kotlin - kotlin-stdlib - $kotlinVersion - - - - - src/main/kotlin - - - + + org.jetbrains.kotlin - kotlin-maven-plugin - - - compile - - js - - - - test-compile - - test-js - - - - - - - """) + kotlin-stdlib + $kotlinVersion + + + + + src/main/kotlin + + + + org.jetbrains.kotlin + kotlin-maven-plugin + + + compile + + js + + + + test-compile + + test-js + + + + + + + """ + ) assertModules("project") assertImporterStatePresent() @@ -981,44 +1018,46 @@ class KotlinMavenImporterTest : MavenImportingTestCase() { fun testJsDetectionByGoalWithJsStdlib() { createProjectSubDirs("src/main/kotlin", "src/main/kotlin.jvm", "src/test/kotlin", "src/test/kotlin.jvm") - importProject(""" - test - project - 1.0.0 + importProject( + """ + test + project + 1.0.0 - - - org.jetbrains.kotlin - kotlin-stdlib-js - $kotlinVersion - - - - - src/main/kotlin - - - + + org.jetbrains.kotlin - kotlin-maven-plugin - - - compile - - js - - - - test-compile - - test-js - - - - - - - """) + kotlin-stdlib-js + $kotlinVersion + + + + + src/main/kotlin + + + + org.jetbrains.kotlin + kotlin-maven-plugin + + + compile + + js + + + + test-compile + + test-js + + + + + + + """ + ) assertModules("project") assertImporterStatePresent() @@ -1029,44 +1068,46 @@ class KotlinMavenImporterTest : MavenImportingTestCase() { fun testJsDetectionByGoalWithCommonStdlib() { createProjectSubDirs("src/main/kotlin", "src/main/kotlin.jvm", "src/test/kotlin", "src/test/kotlin.jvm") - importProject(""" - test - project - 1.0.0 + importProject( + """ + test + project + 1.0.0 - - - org.jetbrains.kotlin - kotlin-stdlib-common - $kotlinVersion - - - - - src/main/kotlin - - - + + org.jetbrains.kotlin - kotlin-maven-plugin - - - compile - - js - - - - test-compile - - test-js - - - - - - - """) + kotlin-stdlib-common + $kotlinVersion + + + + + src/main/kotlin + + + + org.jetbrains.kotlin + kotlin-maven-plugin + + + compile + + js + + + + test-compile + + test-js + + + + + + + """ + ) assertModules("project") assertImporterStatePresent() @@ -1077,49 +1118,51 @@ class KotlinMavenImporterTest : MavenImportingTestCase() { fun testJsAndCommonStdlibKinds() { createProjectSubDirs("src/main/kotlin", "src/main/kotlin.jvm", "src/test/kotlin", "src/test/kotlin.jvm") - importProject(""" - test - project - 1.0.0 + importProject( + """ + test + project + 1.0.0 - - - org.jetbrains.kotlin - kotlin-stdlib-common - $kotlinVersion - - - org.jetbrains.kotlin - kotlin-stdlib-js - $kotlinVersion - - - - - src/main/kotlin - - - + + org.jetbrains.kotlin - kotlin-maven-plugin - - - compile - - js - - - - test-compile - - test-js - - - - - - - """) + kotlin-stdlib-common + $kotlinVersion + + + org.jetbrains.kotlin + kotlin-stdlib-js + $kotlinVersion + + + + + src/main/kotlin + + + + org.jetbrains.kotlin + kotlin-maven-plugin + + + compile + + js + + + + test-compile + + test-js + + + + + + + """ + ) assertModules("project") assertImporterStatePresent() @@ -1127,7 +1170,7 @@ class KotlinMavenImporterTest : MavenImportingTestCase() { Assert.assertEquals(TargetPlatformKind.JavaScript, facetSettings.targetPlatformKind) val rootManager = ModuleRootManager.getInstance(getModule("project")) - val libraries = rootManager.orderEntries.filterIsInstance().mapNotNull { it.library as LibraryEx } + val libraries = rootManager.orderEntries.filterIsInstance().map { it.library as LibraryEx } assertEquals(JSLibraryKind, libraries.single { it.name?.contains("kotlin-stdlib-js") == true }.kind) assertEquals(CommonLibraryKind, libraries.single { it.name?.contains("kotlin-stdlib-common") == true }.kind) } @@ -1135,38 +1178,40 @@ class KotlinMavenImporterTest : MavenImportingTestCase() { fun testCommonDetectionByGoalWithJvmStdlib() { createProjectSubDirs("src/main/kotlin", "src/main/kotlin.jvm", "src/test/kotlin", "src/test/kotlin.jvm") - importProject(""" - test - project - 1.0.0 + importProject( + """ + test + project + 1.0.0 - - - org.jetbrains.kotlin - kotlin-stdlib - $kotlinVersion - - - - - src/main/kotlin - - - + + org.jetbrains.kotlin - kotlin-maven-plugin - - - compile - - metadata - - - - - - - """) + kotlin-stdlib + $kotlinVersion + + + + + src/main/kotlin + + + + org.jetbrains.kotlin + kotlin-maven-plugin + + + compile + + metadata + + + + + + + """ + ) assertModules("project") assertImporterStatePresent() @@ -1177,38 +1222,40 @@ class KotlinMavenImporterTest : MavenImportingTestCase() { fun testCommonDetectionByGoalWithJsStdlib() { createProjectSubDirs("src/main/kotlin", "src/main/kotlin.jvm", "src/test/kotlin", "src/test/kotlin.jvm") - importProject(""" - test - project - 1.0.0 + importProject( + """ + test + project + 1.0.0 - - - org.jetbrains.kotlin - kotlin-stdlib-js - $kotlinVersion - - - - - src/main/kotlin - - - + + org.jetbrains.kotlin - kotlin-maven-plugin - - - compile - - metadata - - - - - - - """) + kotlin-stdlib-js + $kotlinVersion + + + + + src/main/kotlin + + + + org.jetbrains.kotlin + kotlin-maven-plugin + + + compile + + metadata + + + + + + + """ + ) assertModules("project") assertImporterStatePresent() @@ -1219,38 +1266,40 @@ class KotlinMavenImporterTest : MavenImportingTestCase() { fun testCommonDetectionByGoalWithCommonStdlib() { createProjectSubDirs("src/main/kotlin", "src/main/kotlin.jvm", "src/test/kotlin", "src/test/kotlin.jvm") - importProject(""" - test0 - project - 1.0.0 + importProject( + """ + test0 + project + 1.0.0 - - - org.jetbrains.kotlin - kotlin-stdlib-common - $kotlinVersion - - - - - src/main/kotlin - - - + + org.jetbrains.kotlin - kotlin-maven-plugin - - - compile - - metadata - - - - - - - """) + kotlin-stdlib-common + $kotlinVersion + + + + + src/main/kotlin + + + + org.jetbrains.kotlin + kotlin-maven-plugin + + + compile + + metadata + + + + + + + """ + ) assertModules("project") assertImporterStatePresent() @@ -1265,44 +1314,46 @@ class KotlinMavenImporterTest : MavenImportingTestCase() { fun testJvmDetectionByConflictingGoalsAndJvmStdlib() { createProjectSubDirs("src/main/kotlin", "src/main/kotlin.jvm", "src/test/kotlin", "src/test/kotlin.jvm") - importProject(""" - test - project - 1.0.0 + importProject( + """ + test + project + 1.0.0 - - - org.jetbrains.kotlin - kotlin-stdlib - $kotlinVersion - - - - - src/main/kotlin - - - + + org.jetbrains.kotlin - kotlin-maven-plugin - - - compile - - js - - - - test-compile - - test-compile - - - - - - - """) + kotlin-stdlib + $kotlinVersion + + + + + src/main/kotlin + + + + org.jetbrains.kotlin + kotlin-maven-plugin + + + compile + + js + + + + test-compile + + test-compile + + + + + + + """ + ) assertModules("project") assertImporterStatePresent() @@ -1313,44 +1364,46 @@ class KotlinMavenImporterTest : MavenImportingTestCase() { fun testJsDetectionByConflictingGoalsAndJsStdlib() { createProjectSubDirs("src/main/kotlin", "src/main/kotlin.jvm", "src/test/kotlin", "src/test/kotlin.jvm") - importProject(""" - test - project - 1.0.0 + importProject( + """ + test + project + 1.0.0 - - - org.jetbrains.kotlin - kotlin-stdlib-js - $kotlinVersion - - - - - src/main/kotlin - - - + + org.jetbrains.kotlin - kotlin-maven-plugin - - - compile - - js - - - - test-compile - - test-compile - - - - - - - """) + kotlin-stdlib-js + $kotlinVersion + + + + + src/main/kotlin + + + + org.jetbrains.kotlin + kotlin-maven-plugin + + + compile + + js + + + + test-compile + + test-compile + + + + + + + """ + ) assertModules("project") assertImporterStatePresent() @@ -1361,44 +1414,46 @@ class KotlinMavenImporterTest : MavenImportingTestCase() { fun testCommonDetectionByConflictingGoalsAndCommonStdlib() { createProjectSubDirs("src/main/kotlin", "src/main/kotlin.jvm", "src/test/kotlin", "src/test/kotlin.jvm") - importProject(""" - test - project - 1.0.0 + importProject( + """ + test + project + 1.0.0 - - - org.jetbrains.kotlin - kotlin-stdlib-common - $kotlinVersion - - - - - src/main/kotlin - - - + + org.jetbrains.kotlin - kotlin-maven-plugin - - - compile - - js - - - - test-compile - - test-compile - - - - - - - """) + kotlin-stdlib-common + $kotlinVersion + + + + + src/main/kotlin + + + + org.jetbrains.kotlin + kotlin-maven-plugin + + + compile + + js + + + + test-compile + + test-compile + + + + + + + """ + ) assertModules("project") assertImporterStatePresent() @@ -1409,69 +1464,73 @@ class KotlinMavenImporterTest : MavenImportingTestCase() { fun testNoPluginsInAdditionalArgs() { createProjectSubDirs("src/main/kotlin", "src/main/kotlin.jvm", "src/test/kotlin", "src/test/kotlin.jvm") - importProject(""" - test - project - 1.0.0 + importProject( + """ + test + project + 1.0.0 - - - org.jetbrains.kotlin - kotlin-stdlib - $kotlinVersion - - - - - src/main/kotlin - - - + + org.jetbrains.kotlin - kotlin-maven-plugin - - - compile - - js - - - + kotlin-stdlib + $kotlinVersion + + - - - org.jetbrains.kotlin - kotlin-maven-allopen - $kotlinVersion - - + + src/main/kotlin - - - spring - - - - - - """) + + + org.jetbrains.kotlin + kotlin-maven-plugin + + + compile + + js + + + + + + + org.jetbrains.kotlin + kotlin-maven-allopen + $kotlinVersion + + + + + + spring + + + + + + """ + ) assertModules("project") assertImporterStatePresent() with(facetSettings) { Assert.assertEquals( - "-version", - compilerSettings!!.additionalArguments + "-version", + compilerSettings!!.additionalArguments ) Assert.assertEquals( - listOf("plugin:org.jetbrains.kotlin.allopen:annotation=org.springframework.stereotype.Component", - "plugin:org.jetbrains.kotlin.allopen:annotation=org.springframework.transaction.annotation.Transactional", - "plugin:org.jetbrains.kotlin.allopen:annotation=org.springframework.scheduling.annotation.Async", - "plugin:org.jetbrains.kotlin.allopen:annotation=org.springframework.cache.annotation.Cacheable", - "plugin:org.jetbrains.kotlin.allopen:annotation=org.springframework.boot.test.context.SpringBootTest", - "plugin:org.jetbrains.kotlin.allopen:annotation=org.springframework.validation.annotation.Validated"), - compilerArguments!!.pluginOptions!!.toList() + listOf( + "plugin:org.jetbrains.kotlin.allopen:annotation=org.springframework.stereotype.Component", + "plugin:org.jetbrains.kotlin.allopen:annotation=org.springframework.transaction.annotation.Transactional", + "plugin:org.jetbrains.kotlin.allopen:annotation=org.springframework.scheduling.annotation.Async", + "plugin:org.jetbrains.kotlin.allopen:annotation=org.springframework.cache.annotation.Cacheable", + "plugin:org.jetbrains.kotlin.allopen:annotation=org.springframework.boot.test.context.SpringBootTest", + "plugin:org.jetbrains.kotlin.allopen:annotation=org.springframework.validation.annotation.Validated" + ), + compilerArguments!!.pluginOptions!!.toList() ) } } @@ -1479,70 +1538,74 @@ class KotlinMavenImporterTest : MavenImportingTestCase() { fun testNoArgInvokeInitializers() { createProjectSubDirs("src/main/kotlin", "src/main/kotlin.jvm", "src/test/kotlin", "src/test/kotlin.jvm") - importProject(""" - test - project - 1.0.0 + importProject( + """ + test + project + 1.0.0 - - - org.jetbrains.kotlin - kotlin-stdlib - $kotlinVersion - - - - - src/main/kotlin - - - + + org.jetbrains.kotlin - kotlin-maven-plugin - - - compile - - js - - - + kotlin-stdlib + $kotlinVersion + + - - - org.jetbrains.kotlin - kotlin-maven-noarg - $kotlinVersion - - + + src/main/kotlin - - - no-arg - + + + org.jetbrains.kotlin + kotlin-maven-plugin + + + compile + + js + + + - - - - - - - - - """) + + + org.jetbrains.kotlin + kotlin-maven-noarg + $kotlinVersion + + + + + + no-arg + + + + + + + + + + + """ + ) assertModules("project") assertImporterStatePresent() with(facetSettings) { Assert.assertEquals( - "-version", - compilerSettings!!.additionalArguments + "-version", + compilerSettings!!.additionalArguments ) Assert.assertEquals( - listOf("plugin:org.jetbrains.kotlin.noarg:annotation=NoArg", - "plugin:org.jetbrains.kotlin.noarg:invokeInitializers=true"), - compilerArguments!!.pluginOptions!!.toList() + listOf( + "plugin:org.jetbrains.kotlin.noarg:annotation=NoArg", + "plugin:org.jetbrains.kotlin.noarg:invokeInitializers=true" + ), + compilerArguments!!.pluginOptions!!.toList() ) } } @@ -1550,58 +1613,60 @@ class KotlinMavenImporterTest : MavenImportingTestCase() { fun testArgsOverridingInFacet() { createProjectSubDirs("src/main/kotlin", "src/main/kotlin.jvm", "src/test/kotlin", "src/test/kotlin.jvm") - importProject(""" - test - project - 1.0.0 + importProject( + """ + test + project + 1.0.0 - - - org.jetbrains.kotlin - kotlin-stdlib - $kotlinVersion - - - - - src/main/kotlin - - - + + org.jetbrains.kotlin - kotlin-maven-plugin + kotlin-stdlib + $kotlinVersion + + - - - compile - compile - - compile - - - - - 1.6 - 1.0 - 1.0 - - -jvm-target - 1.8 - -language-version - 1.1 - -api-version - 1.1 - - - - - - """) + + src/main/kotlin + + + + org.jetbrains.kotlin + kotlin-maven-plugin + + + + compile + compile + + compile + + + + + 1.6 + 1.0 + 1.0 + + -jvm-target + 1.8 + -language-version + 1.1 + -api-version + 1.1 + + + + + + """ + ) assertModules("project") assertImporterStatePresent() - with (facetSettings) { + with(facetSettings) { Assert.assertEquals("JVM 1.8", targetPlatformKind!!.description) Assert.assertEquals("1.1", languageLevel!!.description) Assert.assertEquals("1.1", apiLevel!!.description) @@ -1612,56 +1677,58 @@ class KotlinMavenImporterTest : MavenImportingTestCase() { fun testSubmoduleArgsInheritance() { createProjectSubDirs("src/main/kotlin", "myModule1/src/main/kotlin", "myModule2/src/main/kotlin", "myModule3/src/main/kotlin") - val mainPom = createProjectPom(""" - test - project - 1.0.0 - pom + val mainPom = createProjectPom( + """ + test + project + 1.0.0 + pom - - - org.jetbrains.kotlin - kotlin-stdlib - $kotlinVersion - - - - - src/main/kotlin - - - + + org.jetbrains.kotlin - kotlin-maven-plugin + kotlin-stdlib + $kotlinVersion + + - - - compile - compile - - compile - - - - - 1.7 - 1.1 - 1.0 - - -java-parameters - -Xdump-declarations-to=dumpDir - -kotlin-home - temp - - - - - - """) + + src/main/kotlin + + + + org.jetbrains.kotlin + kotlin-maven-plugin + + + + compile + compile + + compile + + + + + 1.7 + 1.1 + 1.0 + + -java-parameters + -Xdump-declarations-to=dumpDir + -kotlin-home + temp + + + + + + """ + ) val modulePom1 = createModulePom( - "myModule1", - """ + "myModule1", + """ test @@ -1712,8 +1779,8 @@ class KotlinMavenImporterTest : MavenImportingTestCase() { ) val modulePom2 = createModulePom( - "myModule2", - """ + "myModule2", + """ test @@ -1765,8 +1832,8 @@ class KotlinMavenImporterTest : MavenImportingTestCase() { ) val modulePom3 = createModulePom( - "myModule3", - """ + "myModule3", + """ test @@ -1822,71 +1889,78 @@ class KotlinMavenImporterTest : MavenImportingTestCase() { assertModules("project", "myModule1", "myModule2", "myModule3") assertImporterStatePresent() - with (facetSettings("myModule1")) { + with(facetSettings("myModule1")) { Assert.assertEquals("JVM 1.8", targetPlatformKind!!.description) Assert.assertEquals("1.1", languageLevel!!.description) Assert.assertEquals("1.0", apiLevel!!.description) Assert.assertEquals("1.8", (compilerArguments as K2JVMCompilerArguments).jvmTarget) Assert.assertEquals( - listOf("-Xdump-declarations-to=dumpDir2"), - compilerSettings!!.additionalArgumentsAsList + listOf("-Xdump-declarations-to=dumpDir2"), + compilerSettings!!.additionalArgumentsAsList ) } - with (facetSettings("myModule2")) { + with(facetSettings("myModule2")) { Assert.assertEquals("JVM 1.8", targetPlatformKind!!.description) Assert.assertEquals("1.1", languageLevel!!.description) Assert.assertEquals("1.0", apiLevel!!.description) Assert.assertEquals("1.8", (compilerArguments as K2JVMCompilerArguments).jvmTarget) Assert.assertEquals( - listOf("-Xdump-declarations-to=dumpDir", "-java-parameters", "-kotlin-home", "temp2"), - compilerSettings!!.additionalArgumentsAsList + listOf("-Xdump-declarations-to=dumpDir", "-java-parameters", "-kotlin-home", "temp2"), + compilerSettings!!.additionalArgumentsAsList ) } - with (facetSettings("myModule3")) { + with(facetSettings("myModule3")) { Assert.assertEquals("JVM 1.8", targetPlatformKind!!.description) Assert.assertEquals(LanguageVersion.LATEST_STABLE, languageLevel) Assert.assertEquals(LanguageVersion.LATEST_STABLE, apiLevel) Assert.assertEquals("1.8", (compilerArguments as K2JVMCompilerArguments).jvmTarget) Assert.assertEquals( - listOf("-kotlin-home", "temp2"), - compilerSettings!!.additionalArgumentsAsList + listOf("-kotlin-home", "temp2"), + compilerSettings!!.additionalArgumentsAsList ) } } fun testMultiModuleImport() { - createProjectSubDirs("src/main/kotlin", "my-common-module/src/main/kotlin", "my-jvm-module/src/main/kotlin", "my-js-module/src/main/kotlin") + createProjectSubDirs( + "src/main/kotlin", + "my-common-module/src/main/kotlin", + "my-jvm-module/src/main/kotlin", + "my-js-module/src/main/kotlin" + ) - val mainPom = createProjectPom(""" - test - project - 1.0.0 - pom + val mainPom = createProjectPom( + """ + test + project + 1.0.0 + pom - - my-common-module - my-jvm-module - my-js-module - + + my-common-module + my-jvm-module + my-js-module + - - src/main/kotlin + + src/main/kotlin - - - org.jetbrains.kotlin - kotlin-maven-plugin - $kotlinVersion - - - - """) + + + org.jetbrains.kotlin + kotlin-maven-plugin + $kotlinVersion + + + + """ + ) val commonModule = createModulePom( - "my-common-module", - """ + "my-common-module", + """ test @@ -1928,8 +2002,8 @@ class KotlinMavenImporterTest : MavenImportingTestCase() { ) val jvmModule = createModulePom( - "my-jvm-module", - """ + "my-jvm-module", + """ test @@ -1976,8 +2050,8 @@ class KotlinMavenImporterTest : MavenImportingTestCase() { ) val jsModule = createModulePom( - "my-js-module", - """ + "my-js-module", + """ test @@ -2028,16 +2102,16 @@ class KotlinMavenImporterTest : MavenImportingTestCase() { assertModules("project", "my-common-module", "my-jvm-module", "my-js-module") assertImporterStatePresent() - with (facetSettings("my-common-module")) { + with(facetSettings("my-common-module")) { Assert.assertEquals(TargetPlatformKind.Common.description, targetPlatformKind!!.description) } - with (facetSettings("my-jvm-module")) { + with(facetSettings("my-jvm-module")) { Assert.assertEquals(TargetPlatformKind.Jvm(JvmTarget.JVM_1_6).description, targetPlatformKind!!.description) Assert.assertEquals("my-common-module", implementedModuleName) } - with (facetSettings("my-js-module")) { + with(facetSettings("my-js-module")) { Assert.assertEquals(TargetPlatformKind.JavaScript.description, targetPlatformKind!!.description) Assert.assertEquals("my-common-module", implementedModuleName) } @@ -2054,43 +2128,45 @@ class KotlinMavenImporterTest : MavenImportingTestCase() { try { createProjectSubDirs("src/main/kotlin", "src/main/kotlin.jvm", "src/test/kotlin", "src/test/kotlin.jvm") - importProject(""" - test - project - 1.0.0 + importProject( + """ + test + project + 1.0.0 - - - org.jetbrains.kotlin - kotlin-stdlib - $kotlinVersion - - - - - src/main/kotlin - - - + + org.jetbrains.kotlin - kotlin-maven-plugin + kotlin-stdlib + $kotlinVersion + + - - - compile - compile - - compile - - - - - my/path/to/jdk - - - - - """) + + src/main/kotlin + + + + org.jetbrains.kotlin + kotlin-maven-plugin + + + + compile + compile + + compile + + + + + my/path/to/jdk + + + + + """ + ) assertModules("project") assertImporterStatePresent() @@ -2099,8 +2175,7 @@ class KotlinMavenImporterTest : MavenImportingTestCase() { Assert.assertTrue(moduleSDK.sdkType is JavaSdk) Assert.assertEquals("myJDK", moduleSDK.name) Assert.assertEquals("my/path/to/jdk", moduleSDK.homePath) - } - finally { + } finally { object : WriteAction() { override fun run(result: Result) { val jdkTable = ProjectJdkTable.getInstance() @@ -2112,15 +2187,15 @@ class KotlinMavenImporterTest : MavenImportingTestCase() { fun testProductionOnTestDependency() { createProjectSubDirs( - "module-with-java/src/main/java", - "module-with-java/src/test/java", - "module-with-kotlin/src/main/kotlin", - "module-with-kotlin/src/test/kotlin" + "module-with-java/src/main/java", + "module-with-java/src/test/java", + "module-with-kotlin/src/main/kotlin", + "module-with-kotlin/src/test/kotlin" ) val dummyFile = createProjectSubFile( - "module-with-kotlin/src/main/kotlin/foo/dummy.kt", - """ + "module-with-kotlin/src/main/kotlin/foo/dummy.kt", + """ package foo fun dummy() { @@ -2130,8 +2205,8 @@ class KotlinMavenImporterTest : MavenImportingTestCase() { ) val pomA = createModulePom( - "module-with-java", - """ + "module-with-java", + """ test-group mvnktest @@ -2160,8 +2235,8 @@ class KotlinMavenImporterTest : MavenImportingTestCase() { ) val pomB = createModulePom( - "module-with-kotlin", - """ + "module-with-kotlin", + """ test-group mvnktest @@ -2269,8 +2344,8 @@ class KotlinMavenImporterTest : MavenImportingTestCase() { ) val pomMain = createModulePom( - "", - """ + "", + """ test-group mvnktest 0.0.0.0-SNAPSHOT @@ -2324,50 +2399,52 @@ class KotlinMavenImporterTest : MavenImportingTestCase() { fun testNoArgDuplication() { createProjectSubDirs("src/main/kotlin", "src/main/kotlin.jvm", "src/test/kotlin", "src/test/kotlin.jvm") - importProject(""" - test - project - 1.0.0 + importProject( + """ + test + project + 1.0.0 - - - org.jetbrains.kotlin - kotlin-stdlib - $kotlinVersion - - - - - src/main/kotlin - - - + + org.jetbrains.kotlin - kotlin-maven-plugin + kotlin-stdlib + $kotlinVersion + + - - - compile - compile - - compile - - - - - - -Xjsr305=strict - - - - - - """) + + src/main/kotlin + + + + org.jetbrains.kotlin + kotlin-maven-plugin + + + + compile + compile + + compile + + + + + + -Xjsr305=strict + + + + + + """ + ) assertModules("project") assertImporterStatePresent() - with (facetSettings) { + with(facetSettings) { Assert.assertEquals("-Xjsr305=strict", compilerSettings!!.additionalArguments) } } diff --git a/idea/idea-maven/test/org/jetbrains/kotlin/idea/maven/MavenImportingTestCase.java b/idea/idea-maven/test/org/jetbrains/kotlin/idea/maven/MavenImportingTestCase.java index 802a89334c1..7350f2228db 100644 --- a/idea/idea-maven/test/org/jetbrains/kotlin/idea/maven/MavenImportingTestCase.java +++ b/idea/idea-maven/test/org/jetbrains/kotlin/idea/maven/MavenImportingTestCase.java @@ -217,14 +217,17 @@ public abstract class MavenImportingTestCase extends MavenTestCase { assertModuleLibDepPath(lib, OrderRootType.CLASSES, classesPath == null ? null : Collections.singletonList(classesPath)); assertModuleLibDepPath(lib, OrderRootType.SOURCES, sourcePath == null ? null : Collections.singletonList(sourcePath)); - assertModuleLibDepPath(lib, JavadocOrderRootType.getInstance(), javadocPath == null ? null : Collections.singletonList(javadocPath)); + assertModuleLibDepPath(lib, JavadocOrderRootType.getInstance(), + javadocPath == null ? null : Collections.singletonList(javadocPath)); } - protected void assertModuleLibDep(String moduleName, + protected void assertModuleLibDep( + String moduleName, String depName, List classesPaths, List sourcePaths, - List javadocPaths) { + List javadocPaths + ) { LibraryOrderEntry lib = getModuleLibDep(moduleName, depName); assertModuleLibDepPath(lib, OrderRootType.CLASSES, classesPaths); @@ -255,19 +258,20 @@ public abstract class MavenImportingTestCase extends MavenTestCase { protected void assertExportedDeps(String moduleName, String... expectedDeps) { final List actual = new ArrayList(); - getRootManager(moduleName).orderEntries().withoutSdk().withoutModuleSourceEntries().exportedOnly().process(new RootPolicy() { - @Override - public Object visitModuleOrderEntry(ModuleOrderEntry e, Object value) { - actual.add(e.getModuleName()); - return null; - } + getRootManager(moduleName).orderEntries().withoutSdk().withoutModuleSourceEntries().exportedOnly() + .process(new RootPolicy() { + @Override + public Object visitModuleOrderEntry(ModuleOrderEntry e, Object value) { + actual.add(e.getModuleName()); + return null; + } - @Override - public Object visitLibraryOrderEntry(LibraryOrderEntry e, Object value) { - actual.add(e.getLibraryName()); - return null; - } - }, null); + @Override + public Object visitLibraryOrderEntry(LibraryOrderEntry e, Object value) { + actual.add(e.getLibraryName()); + return null; + } + }, null); assertOrderedElementsAreEqual(actual, expectedDeps); } @@ -305,7 +309,7 @@ public abstract class MavenImportingTestCase extends MavenTestCase { for (OrderEntry e : getRootManager(moduleName).getOrderEntries()) { if (clazz.isInstance(e) && e.getPresentableName().equals(depName)) { - dep = (T)e; + dep = (T) e; } } assertNotNull("Dependency not found: " + depName @@ -507,8 +511,10 @@ public abstract class MavenImportingTestCase extends MavenTestCase { downloadArtifacts(myProjectsManager.getProjects(), null); } - protected MavenArtifactDownloader.DownloadResult downloadArtifacts(Collection projects, - List artifacts) { + protected MavenArtifactDownloader.DownloadResult downloadArtifacts( + Collection projects, + List artifacts + ) { final MavenArtifactDownloader.DownloadResult[] unresolved = new MavenArtifactDownloader.DownloadResult[1]; AsyncResult result = new AsyncResult(); diff --git a/idea/idea-maven/test/org/jetbrains/kotlin/idea/maven/MavenTestCase.java b/idea/idea-maven/test/org/jetbrains/kotlin/idea/maven/MavenTestCase.java index c8918d34553..e8371b514e1 100644 --- a/idea/idea-maven/test/org/jetbrains/kotlin/idea/maven/MavenTestCase.java +++ b/idea/idea-maven/test/org/jetbrains/kotlin/idea/maven/MavenTestCase.java @@ -67,7 +67,7 @@ public abstract class MavenTestCase extends UsefulTestCase { HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection(); urlConnection.setConnectTimeout(1000); int responseCode = urlConnection.getResponseCode(); - if(responseCode < 400) { + if (responseCode < 400) { mirrorDiscoverable = true; } } @@ -137,7 +137,6 @@ public abstract class MavenTestCase extends UsefulTestCase { }); } }); - } private void ensureTempDirCreated() throws IOException { @@ -277,7 +276,9 @@ public abstract class MavenTestCase extends UsefulTestCase { } protected static String getEnvVar() { - if (SystemInfo.isWindows) return "TEMP"; + if (SystemInfo.isWindows) { + return "TEMP"; + } else if (SystemInfo.isLinux) return "HOME"; return "TMPDIR"; } @@ -409,8 +410,9 @@ public abstract class MavenTestCase extends UsefulTestCase { return f; } - @NonNls @Language(value="XML") - public static String createPomXml(@NonNls @Language(value="XML", prefix="", suffix="") String xml) { + @NonNls + @Language(value = "XML") + public static String createPomXml(@NonNls @Language(value = "XML", prefix = "", suffix = "") String xml) { return "" + " void assertUnorderedElementsAreEqual(Collection actual, Collection expected) { assertEquals(new HashSet(expected), new HashSet(actual)); } + protected static void assertUnorderedPathsAreEqual(Collection actual, Collection expected) { assertEquals(new SetWithToString(new THashSet(expected, FileUtil.PATH_HASHING_STRATEGY)), new SetWithToString(new THashSet(actual, FileUtil.PATH_HASHING_STRATEGY))); @@ -641,5 +644,4 @@ public abstract class MavenTestCase extends UsefulTestCase { return myDelegate.hashCode(); } } - } diff --git a/idea/idea-maven/test/org/jetbrains/kotlin/idea/maven/MavenUpdateConfigurationQuickFixTest.kt b/idea/idea-maven/test/org/jetbrains/kotlin/idea/maven/MavenUpdateConfigurationQuickFixTest.kt index 5089be789d0..45e046e226b 100644 --- a/idea/idea-maven/test/org/jetbrains/kotlin/idea/maven/MavenUpdateConfigurationQuickFixTest.kt +++ b/idea/idea-maven/test/org/jetbrains/kotlin/idea/maven/MavenUpdateConfigurationQuickFixTest.kt @@ -33,7 +33,8 @@ import kotlin.reflect.KMutableProperty0 class MavenUpdateConfigurationQuickFixTest : MavenImportingTestCase() { private lateinit var codeInsightTestFixture: CodeInsightTestFixture - fun getTestDataPath() = KotlinTestUtils.getHomeDirectory() + "/idea/idea-maven/testData/languageFeature/" + getTestName(true).substringBefore('_') + private fun getTestDataPath() = + KotlinTestUtils.getHomeDirectory() + "/idea/idea-maven/testData/languageFeature/" + getTestName(true).substringBefore('_') override fun setUpFixtures() { myTestFixture = IdeaTestFixtureFactory.getFixtureFactory().createFixtureBuilder(getName()).fixture @@ -43,31 +44,38 @@ class MavenUpdateConfigurationQuickFixTest : MavenImportingTestCase() { override fun tearDownFixtures() { codeInsightTestFixture.tearDown() + @Suppress("UNCHECKED_CAST") (this::codeInsightTestFixture as KMutableProperty0).set(null) myTestFixture = null } - @Test fun testUpdateLanguageVersion() { + @Test + fun testUpdateLanguageVersion() { doTest("Set module language version to 1.1") } - @Test fun testUpdateLanguageVersionProperty() { + @Test + fun testUpdateLanguageVersionProperty() { doTest("Set module language version to 1.1") } - @Test fun testUpdateApiVersion() { + @Test + fun testUpdateApiVersion() { doTest("Set module API version to 1.1") } - @Test fun testUpdateLanguageAndApiVersion() { + @Test + fun testUpdateLanguageAndApiVersion() { doTest("Set module language version to 1.1") } - @Test fun testEnableCoroutines() { + @Test + fun testEnableCoroutines() { doTest("Enable coroutine support in the current module") } - @Test fun testAddKotlinReflect() { + @Test + fun testAddKotlinReflect() { doTest("Add kotlin-reflect.jar to the classpath") } diff --git a/idea/idea-maven/test/org/jetbrains/kotlin/idea/maven/configuration/AbstractMavenConfigureProjectByChangingFileTest.kt b/idea/idea-maven/test/org/jetbrains/kotlin/idea/maven/configuration/AbstractMavenConfigureProjectByChangingFileTest.kt index f32a0c2bf2b..7896774b98f 100644 --- a/idea/idea-maven/test/org/jetbrains/kotlin/idea/maven/configuration/AbstractMavenConfigureProjectByChangingFileTest.kt +++ b/idea/idea-maven/test/org/jetbrains/kotlin/idea/maven/configuration/AbstractMavenConfigureProjectByChangingFileTest.kt @@ -39,7 +39,13 @@ abstract class AbstractMavenConfigureProjectByChangingFileTest : AbstractConfigu doTest(pathWithFile, pathWithFile.replace("pom", "pom_after"), KotlinJavascriptMavenConfigurator()) } - override fun runConfigurator(module: Module, file: PsiFile, configurator: KotlinMavenConfigurator, version: String, collector: NotificationMessageCollector) { + override fun runConfigurator( + module: Module, + file: PsiFile, + configurator: KotlinMavenConfigurator, + version: String, + collector: NotificationMessageCollector + ) { WriteCommandAction.runWriteCommandAction(module.project) { configurator.configureModule(module, file, version, collector) }