Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error handling for missing 'supported.ij.version' #175

Merged
merged 3 commits into from
Oct 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 using local.properties file or -Psupported.ij.version 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')"
)
}
}
}