Skip to content

Commit

Permalink
Replace method call with checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Julio Zynger committed Jun 4, 2020
1 parent bc20a99 commit d87d1c9
Showing 1 changed file with 5 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.plugins.ExtensionAware
import java.io.File
import java.lang.IllegalArgumentException

class FloorPlanPlugin: Plugin<Project> {

Expand All @@ -32,8 +31,11 @@ class FloorPlanPlugin: Plugin<Project> {
}

private fun OutputFormatExtension.getFormat(): OutputFormat {
ensureOnlyOneOutputFormatIsEnabled(this)
return when (val output = getEnabledOutputFormats(this).first()) {
val outputFormats = getEnabledOutputFormats(this)
check(outputFormats.isNotEmpty()) { "There are no enabled output formats." }
check(outputFormats.size == 1) { "There can only be one enabled output format." }

return when (val output = outputFormats.first()) {
is DbmlConfigurationExtension -> OutputFormat.DBML(
DbmlConfiguration(
output.creationSqlAsTableNote.get(),
Expand All @@ -46,17 +48,6 @@ class FloorPlanPlugin: Plugin<Project> {
}
}

private fun ensureOnlyOneOutputFormatIsEnabled(outputFormatExtension: OutputFormatExtension) {
val enabled = getEnabledOutputFormats(outputFormatExtension)

if (enabled.isEmpty()) {
throw IllegalArgumentException("There are no enabled output formats.")
}
if (enabled.size != 1) {
throw IllegalArgumentException("There can only be one enabled output format.")
}
}

private fun getEnabledOutputFormats(outputFormatExtension: OutputFormatExtension): List<OutputFormatConfiguration> {
val outputFormats = listOf(
outputFormatExtension.dbmlConfiguration,
Expand Down

0 comments on commit d87d1c9

Please sign in to comment.