Skip to content

Commit

Permalink
Improve error handling for missing 'supported.ij.version'
Browse files Browse the repository at this point in the history
Updated 'supported.ij.version' property handling in IdeaConfiguration.kt to better manage cases when the property is not set. Instead of throwing an error, it now sets a default value and logs a warning message once, advising the user to provide the missing property.
  • Loading branch information
lamba92 committed Oct 12, 2023
1 parent e718267 commit 4916c40
Showing 1 changed file with 24 additions and 13 deletions.
37 changes: 24 additions & 13 deletions buildSrc/src/main/kotlin/IdeaConfiguration.kt
Original file line number Diff line number Diff line change
@@ -1,26 +1,37 @@
import java.util.concurrent.atomic.AtomicBoolean
import org.gradle.api.Project

enum class SupportedIJVersion {
IJ_232,
IJ_233
}

private var warned = AtomicBoolean(false)

fun Project.supportedIJVersion(): SupportedIJVersion {
val prop = localProperty("supported.ij.version")
?: rootProject.property("supported.ij.version")
?: error(
"'supported.ij.version' gradle property is missing. " +
"Please, provide it using local.properties file or -Psupported.ij.version argument in CLI"
)
val prop = kotlin.runCatching {
localProperty("supported.ij.version")
?: rootProject.property("supported.ij.version")?.toString()
}.getOrNull()

if (prop == null) {
if (!warned.getAndSet(true)) {
logger.warn(
"""
No 'supported.ij.version' property provided. Falling back to IJ 233.
It is recommended to provide it to avoid unexpected behavior.
""".trimIndent()
)
}
return SupportedIJVersion.IJ_233
}

return when (prop) {
"232" -> SupportedIJVersion.IJ_232
"233" -> SupportedIJVersion.IJ_233
else -> {
error(
"Invalid 'supported.ij.version' with value '$prop' is provided. " +
"It should be in set of these values: ('232', '233')"
)
}
else -> error(
"Invalid 'supported.ij.version' with value '$prop' is provided. " +
"It should be in set of these values: ('232', '233')"
)
}
}
}

0 comments on commit 4916c40

Please sign in to comment.