|
| 1 | +package org.assertj.generator.gradle.tasks.config |
| 2 | + |
| 3 | +import org.assertj.assertions.generator.AssertionsEntryPointType |
| 4 | +import java.util.EnumSet |
| 5 | + |
| 6 | +/** |
| 7 | + * Used to represent the different [AssertionsEntryPointType] values in a simpler and more "gradle-like" |
| 8 | + * way when configuring. |
| 9 | + */ |
| 10 | +open class EntryPointGeneratorOptions { |
| 11 | + val entryPoints: Set<AssertionsEntryPointType> get() = _entryPoints |
| 12 | + |
| 13 | + private val _entryPoints = EnumSet.of(AssertionsEntryPointType.STANDARD) |
| 14 | + |
| 15 | + /** |
| 16 | + * An optional package name for the Assertions entry point class. If omitted, the package will be determined |
| 17 | + * heuristically from the generated assertions. |
| 18 | + * @return Package string for entry point classes |
| 19 | + */ |
| 20 | + var classPackage: String? = null |
| 21 | + |
| 22 | + private fun forEnum(value: Boolean, e: AssertionsEntryPointType) { |
| 23 | + if (value) { |
| 24 | + _entryPoints.add(e) |
| 25 | + } else { |
| 26 | + _entryPoints.remove(e) |
| 27 | + } |
| 28 | + } |
| 29 | + |
| 30 | + fun only(vararg rest: AssertionsEntryPointType) { |
| 31 | + _entryPoints.clear() |
| 32 | + _entryPoints.addAll(rest) |
| 33 | + } |
| 34 | + |
| 35 | + fun only(vararg rest: String) { |
| 36 | + val asEnums = rest.asSequence() |
| 37 | + .map { it.uppercase() } |
| 38 | + .map { AssertionsEntryPointType.valueOf(it) } |
| 39 | + .toSet() |
| 40 | + only(rest = asEnums.toTypedArray()) |
| 41 | + } |
| 42 | + |
| 43 | + /** |
| 44 | + * @see AssertionsEntryPointType.STANDARD |
| 45 | + */ |
| 46 | + var standard: Boolean |
| 47 | + get() = entryPoints.contains(AssertionsEntryPointType.STANDARD) |
| 48 | + set(value) { |
| 49 | + forEnum(value, AssertionsEntryPointType.STANDARD) |
| 50 | + } |
| 51 | + |
| 52 | + /** |
| 53 | + * @see AssertionsEntryPointType.BDD |
| 54 | + */ |
| 55 | + var bdd: Boolean |
| 56 | + get() = entryPoints.contains(AssertionsEntryPointType.BDD) |
| 57 | + set(value) { |
| 58 | + forEnum(value, AssertionsEntryPointType.BDD) |
| 59 | + } |
| 60 | + |
| 61 | + /** |
| 62 | + * @see AssertionsEntryPointType.SOFT |
| 63 | + */ |
| 64 | + var soft: Boolean |
| 65 | + get() = entryPoints.contains(AssertionsEntryPointType.SOFT) |
| 66 | + set(value) { |
| 67 | + forEnum(value, AssertionsEntryPointType.SOFT) |
| 68 | + } |
| 69 | + |
| 70 | + /** |
| 71 | + * @see AssertionsEntryPointType.BDD_SOFT |
| 72 | + */ |
| 73 | + var bddSoft: Boolean |
| 74 | + get() = entryPoints.contains(AssertionsEntryPointType.BDD_SOFT) |
| 75 | + set(value) { |
| 76 | + forEnum(value, AssertionsEntryPointType.BDD_SOFT) |
| 77 | + } |
| 78 | + |
| 79 | + /** |
| 80 | + * @see AssertionsEntryPointType.JUNIT_SOFT |
| 81 | + */ |
| 82 | + var junitSoft: Boolean |
| 83 | + get() = entryPoints.contains(AssertionsEntryPointType.JUNIT_SOFT) |
| 84 | + set(value) { |
| 85 | + forEnum(value, AssertionsEntryPointType.JUNIT_SOFT) |
| 86 | + } |
| 87 | + |
| 88 | + /** |
| 89 | + * @see AssertionsEntryPointType.JUNIT_BDD_SOFT |
| 90 | + */ |
| 91 | + var junitBddSoft: Boolean |
| 92 | + get() = entryPoints.contains(AssertionsEntryPointType.JUNIT_BDD_SOFT) |
| 93 | + set(value) { |
| 94 | + forEnum(value, AssertionsEntryPointType.JUNIT_BDD_SOFT) |
| 95 | + } |
| 96 | + |
| 97 | + /** |
| 98 | + * @see AssertionsEntryPointType.AUTO_CLOSEABLE_SOFT |
| 99 | + */ |
| 100 | + var autoCloseableSoft: Boolean |
| 101 | + get() = entryPoints.contains(AssertionsEntryPointType.AUTO_CLOSEABLE_SOFT) |
| 102 | + set(value) { |
| 103 | + forEnum(value, AssertionsEntryPointType.AUTO_CLOSEABLE_SOFT) |
| 104 | + } |
| 105 | + |
| 106 | + /** |
| 107 | + * @see AssertionsEntryPointType.AUTO_CLOSEABLE_BDD_SOFT |
| 108 | + */ |
| 109 | + var autoCloseableBddSoft: Boolean |
| 110 | + get() = entryPoints.contains(AssertionsEntryPointType.AUTO_CLOSEABLE_BDD_SOFT) |
| 111 | + set(value) { |
| 112 | + forEnum(value, AssertionsEntryPointType.AUTO_CLOSEABLE_BDD_SOFT) |
| 113 | + } |
| 114 | +} |
0 commit comments