Skip to content

Commit eb480c3

Browse files
authored
Added DI configuration to new feature option. (#50)
1 parent 7fcbb74 commit eb480c3

File tree

8 files changed

+73
-13
lines changed

8 files changed

+73
-13
lines changed

cli/src/main/kotlin/com/mitteloupe/cag/cli/Main.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ fun main(arguments: Array<String>) {
148148
.enableCompose(true)
149149
.enableKtlint(requestFeature.enableKtlint)
150150
.enableDetekt(requestFeature.enableDetekt)
151+
.setDependencyInjection(requestFeature.dependencyInjection.orDefault(configuration))
151152
.build()
152153
executeAndReport {
153154
setVersionProvider(configuration.existingProjectVersions)

cli/src/main/kotlin/com/mitteloupe/cag/cli/argument/feature/NewFeaturesArgumentsParser.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.mitteloupe.cag.cli.argument.feature
22

33
import com.mitteloupe.cag.cli.argument.ArgumentParser
4+
import com.mitteloupe.cag.cli.argument.feature.mapper.toDependencyInjection
45
import com.mitteloupe.cag.cli.flag.PrimaryFlag.NewFeaturePrimary
56
import com.mitteloupe.cag.cli.flag.SecondaryFlagOptions
67
import com.mitteloupe.cag.cli.request.FeatureRequest
@@ -12,6 +13,7 @@ fun ArgumentParser.parseNewFeaturesArguments(arguments: Array<String>): List<Fea
1213
packageName = secondaries[SecondaryFlagOptions.PACKAGE],
1314
enableKtlint = secondaries.containsKey(SecondaryFlagOptions.KTLINT),
1415
enableDetekt = secondaries.containsKey(SecondaryFlagOptions.DETEKT),
15-
enableGit = secondaries.containsKey(SecondaryFlagOptions.GIT)
16+
enableGit = secondaries.containsKey(SecondaryFlagOptions.GIT),
17+
dependencyInjection = secondaries[SecondaryFlagOptions.DEPENDENCY_INJECTION]?.toDependencyInjection()
1618
)
1719
}

cli/src/main/kotlin/com/mitteloupe/cag/cli/flag/PrimaryFlag.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ interface PrimaryFlag {
100100
SecondaryFlags.packageName,
101101
SecondaryFlags.ktlint,
102102
SecondaryFlags.detekt,
103-
SecondaryFlags.git
103+
SecondaryFlags.git,
104+
SecondaryFlags.dependencyInjection
104105
)
105106
}
106107

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
package com.mitteloupe.cag.cli.request
22

3+
import com.mitteloupe.cag.core.option.DependencyInjection
4+
35
data class FeatureRequest(
46
val featureName: String,
57
val packageName: String?,
68
val enableKtlint: Boolean,
79
val enableDetekt: Boolean,
8-
val enableGit: Boolean = false
10+
val enableGit: Boolean = false,
11+
val dependencyInjection: DependencyInjection?
912
)

cli/src/test/kotlin/com/mitteloupe/cag/cli/argument/AppArgumentProcessorTest.kt

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import org.junit.runners.Suite.SuiteClasses
2020
@SuiteClasses(
2121
AppArgumentProcessorTest.Features::class,
2222
AppArgumentProcessorTest.Help::class,
23+
AppArgumentProcessorTest.NewFeature::class,
2324
AppArgumentProcessorTest.AppArgumentProcessorArchitectureTest::class,
2425
AppArgumentProcessorTest.AppArgumentProcessorDataSourcesTest::class,
2526
AppArgumentProcessorTest.AppArgumentProcessorUseCasesTest::class,
@@ -59,6 +60,15 @@ class AppArgumentProcessorTest {
5960
// Then
6061
assertTrue(result)
6162
}
63+
}
64+
65+
class NewFeature {
66+
private lateinit var classUnderTest: AppArgumentProcessor
67+
68+
@Before
69+
fun setUp() {
70+
classUnderTest = AppArgumentProcessor()
71+
}
6272

6373
@Test
6474
fun `Given --new-feature with --ktlint when getNewFeatures then returns FeatureRequest with ktlint enabled`() {
@@ -70,7 +80,30 @@ class AppArgumentProcessorTest {
7080
featureName = "Quality",
7181
packageName = null,
7282
enableKtlint = true,
73-
enableDetekt = false
83+
enableDetekt = false,
84+
dependencyInjection = null
85+
)
86+
)
87+
88+
// When
89+
val result = classUnderTest.getNewFeatures(givenArguments)
90+
91+
// Then
92+
assertEquals(expectedRequests, result)
93+
}
94+
95+
@Test
96+
fun `Given --new-feature with --dependency-injection=Hilt when getNewFeatures then returns FeatureRequest with Hilt enabled`() {
97+
// Given
98+
val givenArguments = arrayOf("--new-feature", "--name=Quality", "--dependency-injection=Hilt")
99+
val expectedRequests =
100+
listOf(
101+
FeatureRequest(
102+
featureName = "Quality",
103+
packageName = null,
104+
enableKtlint = false,
105+
enableDetekt = false,
106+
dependencyInjection = DependencyInjection.Hilt
74107
)
75108
)
76109

@@ -91,7 +124,8 @@ class AppArgumentProcessorTest {
91124
featureName = "Quality",
92125
packageName = null,
93126
enableKtlint = true,
94-
enableDetekt = true
127+
enableDetekt = true,
128+
dependencyInjection = null
95129
)
96130
)
97131

@@ -122,13 +156,15 @@ class AppArgumentProcessorTest {
122156
featureName = "First",
123157
packageName = "com.first",
124158
enableKtlint = false,
125-
enableDetekt = false
159+
enableDetekt = false,
160+
dependencyInjection = null
126161
),
127162
FeatureRequest(
128163
featureName = "Second",
129164
packageName = null,
130165
enableKtlint = false,
131-
enableDetekt = false
166+
enableDetekt = false,
167+
dependencyInjection = null
132168
)
133169
)
134170

@@ -149,13 +185,15 @@ class AppArgumentProcessorTest {
149185
featureName = "Third",
150186
packageName = "com.third",
151187
enableKtlint = false,
152-
enableDetekt = false
188+
enableDetekt = false,
189+
dependencyInjection = null
153190
),
154191
FeatureRequest(
155192
featureName = "Fourth",
156193
packageName = "com.fourth",
157194
enableKtlint = false,
158-
enableDetekt = false
195+
enableDetekt = false,
196+
dependencyInjection = null
159197
)
160198
)
161199

@@ -258,7 +296,8 @@ class AppArgumentProcessorTest {
258296
packageName = null,
259297
enableKtlint = false,
260298
enableDetekt = false,
261-
enableGit = true
299+
enableGit = true,
300+
dependencyInjection = null
262301
)
263302

264303
// When

plugin/src/main/kotlin/com/mitteloupe/cag/cleanarchitecturegenerator/CreateCleanArchitectureFeatureAction.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import com.intellij.openapi.components.service
66
import com.intellij.openapi.ui.Messages
77
import com.mitteloupe.cag.cleanarchitecturegenerator.filesystem.GeneratorProvider
88
import com.mitteloupe.cag.cleanarchitecturegenerator.git.GitAddQueueService
9+
import com.mitteloupe.cag.cleanarchitecturegenerator.model.DependencyInjection
10+
import com.mitteloupe.cag.cleanarchitecturegenerator.settings.AppSettingsService
911
import com.mitteloupe.cag.core.AppModuleDirectoryFinder
1012
import com.mitteloupe.cag.core.GenerationException
1113
import com.mitteloupe.cag.core.NamespaceResolver
@@ -16,14 +18,17 @@ class CreateCleanArchitectureFeatureAction : AnAction() {
1618
private val ideBridge = IdeBridge()
1719
private val appModuleDirectoryFinder = AppModuleDirectoryFinder()
1820
private val generatorProvider = GeneratorProvider()
21+
private val appSettingsService = AppSettingsService.getInstance()
1922

2023
override fun actionPerformed(event: AnActionEvent) {
2124
val project = event.project ?: return
2225
val projectModel = IntellijProjectModel(event)
2326
val defaultNamespace = NamespaceResolver().determineBasePackage(projectModel)
2427
val projectRootDirectory = project.basePath?.let { File(it) } ?: File(".")
2528
val appModuleDirectories = appModuleDirectoryFinder.findAndroidAppModuleDirectories(projectRootDirectory)
26-
val dialog = CreateCleanArchitectureFeatureDialog(project, defaultNamespace, appModuleDirectories)
29+
val defaultDependencyInjection = DependencyInjection.fromString(appSettingsService.defaultDependencyInjection)
30+
val dialog =
31+
CreateCleanArchitectureFeatureDialog(project, defaultNamespace, appModuleDirectories, defaultDependencyInjection)
2732
if (dialog.showAndGet()) {
2833
val featureName = dialog.featureName
2934
val featurePackageName = dialog.featurePackageName

plugin/src/main/kotlin/com/mitteloupe/cag/cleanarchitecturegenerator/CreateCleanArchitectureFeatureDialog.kt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ private const val PLACEHOLDER = "FEATURE_NAME"
1919
class CreateCleanArchitectureFeatureDialog(
2020
project: Project?,
2121
private val defaultPackagePrefix: String? = null,
22-
private val appModuleDirectories: List<File>
22+
private val appModuleDirectories: List<File>,
23+
defaultDependencyInjection: DependencyInjection
2324
) : DialogWrapper(project) {
2425
private val featureNameTextField = JBTextField()
2526
private val featurePackageTextField = JBTextField()
@@ -45,7 +46,7 @@ class CreateCleanArchitectureFeatureDialog(
4546
}
4647
}
4748

48-
val dependencyInjection: DependencyInjection = DependencyInjection.None
49+
var dependencyInjection: DependencyInjection = defaultDependencyInjection
4950

5051
val enableCompose: Boolean = true
5152

@@ -120,6 +121,13 @@ class CreateCleanArchitectureFeatureDialog(
120121
row(CleanArchitectureGeneratorBundle.message("dialog.feature.package.label")) {
121122
cell(featurePackageTextField)
122123
}
124+
row(CleanArchitectureGeneratorBundle.message("dialog.feature.dependency.injection.label")) {
125+
comboBox(DependencyInjection.entries)
126+
.bindItem(
127+
{ dependencyInjection },
128+
{ value -> value?.let { dependencyInjection = it } }
129+
)
130+
}
123131
row(CleanArchitectureGeneratorBundle.message("dialog.feature.code.quality.label")) {
124132
checkBox("ktlint").bindSelected(::enableKtlintInternal)
125133
checkBox("detekt").bindSelected(::enableDetektInternal)

plugin/src/main/resources/messages/CleanArchitectureGeneratorBundle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ dialog.feature.name.label=Feature name:
55
dialog.feature.package.label=Feature package:
66
dialog.feature.code.quality.label=Code quality
77
dialog.feature.app.module.label=App module:
8+
dialog.feature.dependency.injection.label=Dependency injection framework
89
validation.feature.name.required=Please enter a feature name.
910
info.feature.generator.confirmation=Generated feature: {0}\n{1}
1011

0 commit comments

Comments
 (0)