-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve error handling for missing 'supported.ij.version'
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
Showing
1 changed file
with
24 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')" | ||
) | ||
} | ||
} | ||
} |