Better parsing for external library name (KT-26794)
- Migration notification fixed - Make fix for replacing old coroutines libraries applicable #KT-26794
This commit is contained in:
+2
-1
@@ -24,6 +24,7 @@ import com.intellij.psi.PsiFile
|
|||||||
import com.intellij.util.text.VersionComparatorUtil
|
import com.intellij.util.text.VersionComparatorUtil
|
||||||
import org.jetbrains.kotlin.idea.configuration.allModules
|
import org.jetbrains.kotlin.idea.configuration.allModules
|
||||||
import org.jetbrains.kotlin.idea.configuration.getWholeModuleGroup
|
import org.jetbrains.kotlin.idea.configuration.getWholeModuleGroup
|
||||||
|
import org.jetbrains.kotlin.idea.configuration.parseExternalLibraryName
|
||||||
import org.jetbrains.kotlin.idea.inspections.ReplaceStringInDocumentFix
|
import org.jetbrains.kotlin.idea.inspections.ReplaceStringInDocumentFix
|
||||||
import org.jetbrains.kotlin.idea.inspections.gradle.GradleHeuristicHelper.PRODUCTION_DEPENDENCY_STATEMENTS
|
import org.jetbrains.kotlin.idea.inspections.gradle.GradleHeuristicHelper.PRODUCTION_DEPENDENCY_STATEMENTS
|
||||||
import org.jetbrains.kotlin.idea.versions.DEPRECATED_LIBRARIES_INFORMATION
|
import org.jetbrains.kotlin.idea.versions.DEPRECATED_LIBRARIES_INFORMATION
|
||||||
@@ -104,7 +105,7 @@ class DeprecatedGradleDependencyInspection : GradleBaseInspection() {
|
|||||||
var libVersion: String? = null
|
var libVersion: String? = null
|
||||||
ModuleRootManager.getInstance(moduleInGroup).orderEntries().forEachLibrary { library ->
|
ModuleRootManager.getInstance(moduleInGroup).orderEntries().forEachLibrary { library ->
|
||||||
if (library.name?.contains(libMarker) == true) {
|
if (library.name?.contains(libMarker) == true) {
|
||||||
libVersion = library.name?.substringAfterLast(":")
|
libVersion = parseExternalLibraryName(library)?.version
|
||||||
}
|
}
|
||||||
|
|
||||||
// Continue if nothing is found
|
// Continue if nothing is found
|
||||||
|
|||||||
+3
-18
@@ -223,15 +223,10 @@ private fun maxKotlinLibVersion(project: Project): LibInfo? {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
val libName = library.name ?: continue
|
val libraryInfo = parseExternalLibraryName(library) ?: continue
|
||||||
|
|
||||||
val version = libName.substringAfterLastNullable(":") ?: continue
|
if (maxStdlibInfo == null || VersionComparatorUtil.COMPARATOR.compare(libraryInfo.version, maxStdlibInfo.version) > 0) {
|
||||||
val artifactId = libName.substringBeforeLastNullable(":")?.substringAfterLastNullable(":") ?: continue
|
maxStdlibInfo = LibInfo(KOTLIN_GROUP_ID, libraryInfo.artifactId, libraryInfo.version)
|
||||||
|
|
||||||
if (version.isBlank() || artifactId.isBlank()) continue
|
|
||||||
|
|
||||||
if (maxStdlibInfo == null || VersionComparatorUtil.COMPARATOR.compare(version, maxStdlibInfo.version) > 0) {
|
|
||||||
maxStdlibInfo = LibInfo(KOTLIN_GROUP_ID, artifactId, version)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -258,14 +253,4 @@ private fun collectMaxCompilerSettings(project: Project): LanguageVersionSetting
|
|||||||
|
|
||||||
LanguageVersionSettingsImpl(maxLanguageVersion ?: LanguageVersion.LATEST_STABLE, maxApiVersion ?: ApiVersion.LATEST_STABLE)
|
LanguageVersionSettingsImpl(maxLanguageVersion ?: LanguageVersion.LATEST_STABLE, maxApiVersion ?: ApiVersion.LATEST_STABLE)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fun String.substringBeforeLastNullable(delimiter: String, missingDelimiterValue: String? = null): String? {
|
|
||||||
val index = lastIndexOf(delimiter)
|
|
||||||
return if (index == -1) missingDelimiterValue else substring(0, index)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun String.substringAfterLastNullable(delimiter: String, missingDelimiterValue: String? = null): String? {
|
|
||||||
val index = lastIndexOf(delimiter)
|
|
||||||
return if (index == -1) missingDelimiterValue else substring(index + 1, length)
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
|
* that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.idea.configuration
|
||||||
|
|
||||||
|
import com.intellij.openapi.roots.libraries.Library
|
||||||
|
|
||||||
|
class ExternalLibraryInfo(
|
||||||
|
val artifactId: String,
|
||||||
|
val version: String
|
||||||
|
)
|
||||||
|
|
||||||
|
fun parseExternalLibraryName(library: Library): ExternalLibraryInfo? {
|
||||||
|
val libName = library.name ?: return null
|
||||||
|
|
||||||
|
val versionWithKind = libName.substringAfterLastNullable(":") ?: return null
|
||||||
|
val version = versionWithKind.substringBefore("@")
|
||||||
|
|
||||||
|
val artifactId = libName.substringBeforeLastNullable(":")?.substringAfterLastNullable(":") ?: return null
|
||||||
|
|
||||||
|
if (version.isBlank() || artifactId.isBlank()) return null
|
||||||
|
|
||||||
|
return ExternalLibraryInfo(artifactId, version)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun String.substringBeforeLastNullable(delimiter: String, missingDelimiterValue: String? = null): String? {
|
||||||
|
val index = lastIndexOf(delimiter)
|
||||||
|
return if (index == -1) missingDelimiterValue else substring(0, index)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun String.substringAfterLastNullable(delimiter: String, missingDelimiterValue: String? = null): String? {
|
||||||
|
val index = lastIndexOf(delimiter)
|
||||||
|
return if (index == -1) missingDelimiterValue else substring(index + 1, length)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user