Skip to content

Commit 24e3ed2

Browse files
mchernyavskyyopox
authored andcommitted
CLEAN: Introduce parseSemVer
1 parent c93c740 commit 24e3ed2

File tree

15 files changed

+41
-32
lines changed

15 files changed

+41
-32
lines changed

debugger/src/main/kotlin/org/rust/debugger/runconfig/RsDebugProcessConfigurationHelper.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import com.intellij.openapi.diagnostic.logger
1111
import com.intellij.openapi.util.NlsContexts.NotificationContent
1212
import com.intellij.openapi.util.io.FileUtil
1313
import com.intellij.openapi.util.text.StringUtil
14-
import com.intellij.util.text.SemVer
1514
import com.jetbrains.cidr.execution.debugger.CidrDebugProcess
1615
import com.jetbrains.cidr.execution.debugger.backend.DebuggerCommandException
1716
import com.jetbrains.cidr.execution.debugger.backend.DebuggerDriver
@@ -22,6 +21,7 @@ import org.rust.cargo.project.settings.toolchain
2221
import org.rust.cargo.runconfig.command.workingDirectory
2322
import org.rust.cargo.toolchain.tools.rustc
2423
import org.rust.cargo.toolchain.wsl.RsWslToolchain
24+
import org.rust.cargo.util.parseSemVer
2525
import org.rust.debugger.*
2626
import org.rust.debugger.settings.RsDebuggerSettings
2727
import org.rust.ide.notifications.showBalloon
@@ -192,7 +192,7 @@ class RsDebugProcessConfigurationHelper(
192192
private val LOG: Logger = logger<RsDebugProcessConfigurationHelper>()
193193

194194
// BACKCOMPAT: Rust 1.45. Drop this property
195-
private val RUST_1_46 = SemVer.parseFromText("1.46.0")!!
195+
private val RUST_1_46 = "1.46.0".parseSemVer()
196196

197197
/**
198198
* Should be synchronized with `rust_types.py`

src/main/kotlin/org/rust/cargo/project/model/impl/CargoSyncTask.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import org.rust.cargo.toolchain.impl.RustcVersion
4848
import org.rust.cargo.toolchain.tools.*
4949
import org.rust.cargo.util.DownloadResult
5050
import org.rust.cargo.util.UnitTestRustcCacheService
51+
import org.rust.cargo.util.parseSemVer
5152
import org.rust.openapiext.TaskResult
5253
import org.rust.stdext.mapNotNullToSet
5354
import java.nio.file.Path
@@ -507,4 +508,4 @@ private fun CargoSyncTask.SyncContext.warning(
507508
syncProgress.message(title, message, MessageEvent.Kind.WARNING, null)
508509
}
509510

510-
private val RUST_1_51: SemVer = SemVer.parseFromText("1.51.0")!!
511+
private val RUST_1_51: SemVer = "1.51.0".parseSemVer()

src/main/kotlin/org/rust/cargo/runconfig/CargoTestRunState.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ import com.intellij.execution.runners.ProgramRunner
1414
import com.intellij.execution.testframework.autotest.ToggleAutoTestAction
1515
import com.intellij.notification.NotificationType
1616
import com.intellij.openapi.util.SystemInfo
17-
import com.intellij.util.text.SemVer
1817
import org.rust.RsBundle
1918
import org.rust.cargo.runconfig.buildtool.CargoPatch
2019
import org.rust.cargo.runconfig.command.CargoCommandConfiguration
2120
import org.rust.cargo.runconfig.console.CargoTestConsoleBuilder
2221
import org.rust.cargo.toolchain.CargoCommandLine
2322
import org.rust.cargo.toolchain.RustChannel
2423
import org.rust.cargo.toolchain.impl.RustcVersion
24+
import org.rust.cargo.util.parseSemVer
2525
import org.rust.ide.notifications.showBalloon
2626
import java.time.LocalDate
2727

@@ -89,7 +89,7 @@ class CargoTestRunState(
8989
private fun checkShowOutputSupport(ver: RustcVersion?): Boolean {
9090
if (ver == null) return false
9191
// --show-output is supported since 1.39.0-nightly/dev with a build date later than 2019-08-27
92-
val minRelease = SemVer.parseFromText("1.39.0")
92+
val minRelease = "1.39.0".parseSemVer()
9393
val commitDate = LocalDate.of(2019, 8, 27)
9494
return when {
9595
ver.semver > minRelease -> true

src/main/kotlin/org/rust/cargo/runconfig/buildtool/CargoBuildManager.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import org.rust.cargo.runconfig.command.CargoCommandConfiguration
4343
import org.rust.cargo.runconfig.wasmpack.WasmPackBuildTaskProvider
4444
import org.rust.cargo.toolchain.CargoCommandLine
4545
import org.rust.cargo.util.CargoArgsParser.Companion.parseArgs
46+
import org.rust.cargo.util.parseSemVer
4647
import org.rust.ide.experiments.RsExperiments
4748
import org.rust.ide.notifications.RsNotifications
4849
import org.rust.openapiext.isFeatureEnabled
@@ -57,7 +58,7 @@ object CargoBuildManager {
5758
private val CANCELED_BUILD_RESULT: Future<CargoBuildResult> =
5859
FutureResult(CargoBuildResult(succeeded = false, canceled = true, started = 0))
5960

60-
private val MIN_RUSTC_VERSION: SemVer = SemVer.parseFromText("1.48.0")!!
61+
private val MIN_RUSTC_VERSION: SemVer = "1.48.0".parseSemVer()
6162

6263
val RsCommandConfiguration.isBuildToolWindowEnabled: Boolean
6364
get() {

src/main/kotlin/org/rust/cargo/toolchain/RsToolchainBase.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ import com.intellij.execution.wsl.WslPath
1212
import com.intellij.openapi.util.SystemInfo
1313
import com.intellij.util.io.exists
1414
import com.intellij.util.net.HttpConfigurable
15-
import com.intellij.util.text.SemVer
1615
import org.rust.cargo.CargoConstants
1716
import org.rust.cargo.toolchain.flavors.RsToolchainFlavor
1817
import org.rust.cargo.toolchain.tools.Cargo
1918
import org.rust.cargo.toolchain.wsl.getHomePathCandidates
19+
import org.rust.cargo.util.parseSemVer
2020
import org.rust.openapiext.GeneralCommandLine
2121
import org.rust.openapiext.withWorkDirectory
2222
import java.io.File
@@ -119,7 +119,7 @@ abstract class RsToolchainBase(val location: Path) {
119119
}
120120

121121
companion object {
122-
val MIN_SUPPORTED_TOOLCHAIN = SemVer.parseFromText("1.41.0")!!
122+
val MIN_SUPPORTED_TOOLCHAIN = "1.41.0".parseSemVer()
123123

124124
/** Environment variable to unlock unstable features of rustc and cargo.
125125
* It doesn't change real toolchain.

src/main/kotlin/org/rust/cargo/toolchain/tools/Cargo.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ import org.rust.cargo.toolchain.tools.ProjectDescriptionStatus.BUILD_SCRIPT_EVAL
5050
import org.rust.cargo.toolchain.tools.ProjectDescriptionStatus.OK
5151
import org.rust.cargo.toolchain.tools.Rustup.Companion.checkNeedInstallClippy
5252
import org.rust.cargo.toolchain.wsl.RsWslToolchain
53+
import org.rust.cargo.util.parseSemVer
5354
import org.rust.ide.actions.InstallBinaryCrateAction
5455
import org.rust.ide.experiments.RsExperiments
5556
import org.rust.ide.notifications.showBalloon
@@ -417,7 +418,7 @@ class Cargo(toolchain: RsToolchainBase, useWrapper: Boolean = false)
417418

418419
fun checkNeedInstallCargoGenerate(): Boolean {
419420
val crateName = "cargo-generate"
420-
val minVersion = SemVer.parseFromText("0.9.0")
421+
val minVersion = "0.9.0".parseSemVer()
421422
return checkBinaryCrateIsNotInstalled(crateName, minVersion)
422423
}
423424

@@ -503,7 +504,7 @@ class Cargo(toolchain: RsToolchainBase, useWrapper: Boolean = false)
503504

504505
fun checkNeedInstallGrcov(project: Project): Boolean {
505506
val crateName = "grcov"
506-
val minVersion = SemVer.parseFromText("0.7.0")
507+
val minVersion = "0.7.0".parseSemVer()
507508
return checkNeedInstallBinaryCrate(
508509
project,
509510
crateName,
@@ -515,7 +516,7 @@ class Cargo(toolchain: RsToolchainBase, useWrapper: Boolean = false)
515516

516517
fun checkNeedInstallCargoExpand(project: Project): Boolean {
517518
val crateName = "cargo-expand"
518-
val minVersion = SemVer.parseFromText("1.0.0")
519+
val minVersion = "1.0.0".parseSemVer()
519520
return checkNeedInstallBinaryCrate(
520521
project,
521522
crateName,
@@ -527,7 +528,7 @@ class Cargo(toolchain: RsToolchainBase, useWrapper: Boolean = false)
527528

528529
fun checkNeedInstallEvcxr(project: Project): Boolean {
529530
val crateName = "evcxr_repl"
530-
val minVersion = SemVer.parseFromText("0.10.0")
531+
val minVersion = "0.10.0".parseSemVer()
531532
return checkNeedInstallBinaryCrate(
532533
project,
533534
crateName,
@@ -539,7 +540,7 @@ class Cargo(toolchain: RsToolchainBase, useWrapper: Boolean = false)
539540

540541
fun checkNeedInstallWasmPack(project: Project): Boolean {
541542
val crateName = "wasm-pack"
542-
val minVersion = SemVer.parseFromText("0.9.1")
543+
val minVersion = "0.9.1".parseSemVer()
543544
return checkNeedInstallBinaryCrate(
544545
project,
545546
crateName,

src/main/kotlin/org/rust/cargo/util/ToolchainUtil.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@
66
package org.rust.cargo.util
77

88
import com.intellij.openapi.util.SystemInfo
9+
import com.intellij.util.text.SemVer
910
import org.rust.stdext.isExecutable
1011
import java.nio.file.Path
1112

13+
fun String.parseSemVer(): SemVer = checkNotNull(SemVer.parseFromText(this)) { "Invalid version value: $this" }
14+
1215
fun Path.hasExecutable(toolName: String): Boolean = pathToExecutable(toolName).isExecutable()
1316

1417
fun Path.pathToExecutable(toolName: String): Path {

src/main/kotlin/org/rust/lang/core/CompilerFeature.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import com.intellij.psi.PsiElement
1212
import com.intellij.util.text.SemVer
1313
import org.rust.cargo.project.workspace.PackageOrigin
1414
import org.rust.cargo.toolchain.RustChannel
15+
import org.rust.cargo.util.parseSemVer
1516
import org.rust.ide.annotator.RsAnnotationHolder
1617
import org.rust.ide.annotator.fixes.AddFeatureAttributeFix
1718
import org.rust.lang.core.FeatureAvailability.*
@@ -34,7 +35,7 @@ class CompilerFeature(
3435
state: FeatureState,
3536
since: String,
3637
cache: Boolean = true
37-
) : this(name, state, SemVer.parseFromText(since)!!, cache)
38+
) : this(name, state, since.parseSemVer(), cache)
3839

3940
init {
4041
if (cache) {

src/test/kotlin/org/rust/RsTestBase.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import org.rust.cargo.project.workspace.CargoWorkspace
3333
import org.rust.cargo.project.workspace.PackageFeature
3434
import org.rust.cargo.toolchain.RustChannel
3535
import org.rust.cargo.toolchain.impl.RustcVersion
36+
import org.rust.cargo.util.parseSemVer
3637
import org.rust.lang.core.macros.macroExpansionManager
3738
import org.rust.openapiext.Testmark
3839
import org.rust.openapiext.document
@@ -179,7 +180,7 @@ abstract class RsTestBase : BasePlatformTestCase(), RsTestCase {
179180
val result = versionRe.matchEntire(version) ?: error("$version should match `${versionRe.pattern}` pattern")
180181

181182
val versionText = result.groups[1]?.value ?: error("")
182-
val semVer = SemVer.parseFromText(versionText) ?: error("")
183+
val semVer = versionText.parseSemVer()
183184

184185
val releaseSuffix = result.groups[2]?.value.orEmpty()
185186
val channel = when {

src/test/kotlin/org/rust/RustcVersion.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import com.intellij.findAnnotationInstance
99
import com.intellij.util.text.SemVer
1010
import junit.framework.TestCase
1111
import org.rust.cargo.project.model.CargoProject
12+
import org.rust.cargo.util.parseSemVer
1213
import org.rust.stdext.RsResult
1314

1415
/**
@@ -35,7 +36,7 @@ annotation class MockRustcVersion(val rustcVersion: String)
3536
@Retention(AnnotationRetention.RUNTIME)
3637
annotation class MinRustcVersion(val version: String)
3738

38-
val MinRustcVersion.semver: SemVer get() = SemVer.parseFromText(version) ?: error("Invalid version value: $version")
39+
val MinRustcVersion.semver: SemVer get() = version.parseSemVer()
3940

4041
/**
4142
* Specify maximum rustc version to launch test.
@@ -44,7 +45,7 @@ val MinRustcVersion.semver: SemVer get() = SemVer.parseFromText(version) ?: erro
4445
@Retention(AnnotationRetention.RUNTIME)
4546
annotation class MaxRustcVersion(val version: String)
4647

47-
val MaxRustcVersion.semver: SemVer get() = SemVer.parseFromText(version) ?: error("Invalid version value: $version")
48+
val MaxRustcVersion.semver: SemVer get() = version.parseSemVer()
4849

4950
fun TestCase.checkRustcVersionRequirements(rustcVersionSupplier: () -> RsResult<SemVer, String?>): String? {
5051
val minRustVersion = findAnnotationInstance<MinRustcVersion>()

0 commit comments

Comments
 (0)