Skip to content

Commit dea890a

Browse files
committed
Plugin update
1 parent 97cd7c9 commit dea890a

File tree

5 files changed

+21
-23
lines changed

5 files changed

+21
-23
lines changed

CHANGELOG_PLUGIN.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## [2.3.20-Beta2-1.10.0]
44

55
- Compatible with 2.3.20-Beta2-1.10.0
6+
- Plugin now throws when no iOS export configuration is found, instead of defaulting to module name
67

78
---
89

kmp-composeuiviewcontroller-gradle-plugin/src/main/kotlin/com/github/guilhe/kmp/composeuiviewcontroller/gradle/KmpComposeUIViewControllerPlugin.kt

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,7 @@ public class KmpComposeUIViewControllerPlugin : Plugin<Project> {
179179
}
180180
}
181181

182-
// Priority 4: Project name (fallback)
183-
val projectModuleName = name.toPascalCase()
184-
logger.info("\t> $INFO_MODULE_NAME_BY_PROJECT [$projectModuleName]")
185-
return Triple(setOf(projectModuleName), true, flattenConfigured)
182+
throw PluginConfigurationException(ERROR_MISSING_FRAMEWORK_CONFIG_FULL)
186183
}
187184

188185
private fun Project.buildFrameworkPackages(packageNames: Set<String>, frameworkNames: Set<String>): Map<String, Set<String>> {
@@ -300,13 +297,6 @@ public class KmpComposeUIViewControllerPlugin : Plugin<Project> {
300297
}
301298
}
302299

303-
private fun String.toPascalCase(): String {
304-
return split("-")
305-
.joinToString("") { segment ->
306-
segment.replaceFirstChar { it.uppercaseChar() }
307-
}
308-
}
309-
310300
private fun KotlinTarget.fromIosFamily(): Boolean = this is KotlinNativeTarget && konanTarget.family == Family.IOS
311301

312302
private fun ComposeUiViewControllerParameters.toList() =
@@ -338,9 +328,13 @@ public class KmpComposeUIViewControllerPlugin : Plugin<Project> {
338328
internal const val PARAM_GROUP = "group_name"
339329
internal const val ERROR_MISSING_KMP = "$LOG_TAG requires the Kotlin Multiplatform plugin to be applied."
340330
internal const val ERROR_MISSING_PACKAGE = "Could not determine project's package"
331+
internal const val ERROR_MISSING_FRAMEWORK_CONFIG = "No framework configuration found."
332+
internal const val ERROR_MISSING_FRAMEWORK_CONFIG_FULL =
333+
"$ERROR_MISSING_FRAMEWORK_CONFIG Please configure in the exporting module either:\n" +
334+
"\t1. iOS framework baseName, or\n" +
335+
"\t2. SwiftExport with moduleName"
341336
internal const val INFO_MODULE_NAME_BY_FRAMEWORK =
342337
"SwiftExport is NOT configured, will use all iOS targets' framework baseName as frameworkBaseName:"
343338
internal const val INFO_MODULE_NAME_BY_SWIFT_EXPORT = "SwiftExport is configured, will use its moduleName:"
344-
internal const val INFO_MODULE_NAME_BY_PROJECT = "No configurations found for moduleName. Fallback to project module name:"
345339
}
346340
}

kmp-composeuiviewcontroller-gradle-plugin/src/test/kotlin/composeuiviewcontroller/PluginTest.kt

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ import com.github.guilhe.kmp.composeuiviewcontroller.common.FILE_NAME_ARGS
66
import com.github.guilhe.kmp.composeuiviewcontroller.common.ModuleMetadata
77
import com.github.guilhe.kmp.composeuiviewcontroller.common.TEMP_FILES_FOLDER
88
import com.github.guilhe.kmp.composeuiviewcontroller.gradle.KmpComposeUIViewControllerPlugin
9+
import com.github.guilhe.kmp.composeuiviewcontroller.gradle.KmpComposeUIViewControllerPlugin.Companion.ERROR_MISSING_FRAMEWORK_CONFIG
910
import com.github.guilhe.kmp.composeuiviewcontroller.gradle.KmpComposeUIViewControllerPlugin.Companion.ERROR_MISSING_KMP
1011
import com.github.guilhe.kmp.composeuiviewcontroller.gradle.KmpComposeUIViewControllerPlugin.Companion.ERROR_MISSING_PACKAGE
1112
import com.github.guilhe.kmp.composeuiviewcontroller.gradle.KmpComposeUIViewControllerPlugin.Companion.FILE_NAME_SCRIPT_TEMP
1213
import com.github.guilhe.kmp.composeuiviewcontroller.gradle.KmpComposeUIViewControllerPlugin.Companion.INFO_MODULE_NAME_BY_FRAMEWORK
13-
import com.github.guilhe.kmp.composeuiviewcontroller.gradle.KmpComposeUIViewControllerPlugin.Companion.INFO_MODULE_NAME_BY_PROJECT
1414
import com.github.guilhe.kmp.composeuiviewcontroller.gradle.KmpComposeUIViewControllerPlugin.Companion.INFO_MODULE_NAME_BY_SWIFT_EXPORT
1515
import com.github.guilhe.kmp.composeuiviewcontroller.gradle.KmpComposeUIViewControllerPlugin.Companion.LIB_ANNOTATIONS_NAME
1616
import com.github.guilhe.kmp.composeuiviewcontroller.gradle.KmpComposeUIViewControllerPlugin.Companion.LIB_GROUP
@@ -307,7 +307,7 @@ class PluginTest {
307307
}
308308

309309
@Test
310-
fun `Method retrieveFrameworkBaseNamesFromIosTargets handles SwiftExport with fallback to project name as moduleName`() {
310+
fun `Method retrieveFrameworkBaseNamesFromIosTargets throws exception when no moduleName exists`() {
311311
Templates.createCommonMainSource(projectDir, packageName = "com.test")
312312

313313
val buildFile = Templates.writeBuildGradle(
@@ -322,7 +322,6 @@ class PluginTest {
322322
323323
kotlin {
324324
iosSimulatorArm64()
325-
swiftExport {}
326325
}
327326
"""
328327
)
@@ -331,8 +330,8 @@ class PluginTest {
331330
val settingsFile = Templates.writeSettingsGradle(projectDir, rootProjectName = "testProject")
332331
assertTrue(settingsFile.exists())
333332

334-
val result = Templates.runGradle(projectDir)
335-
assertTrue(result.output.contains("$INFO_MODULE_NAME_BY_PROJECT [TestProject]"))
333+
val result = Templates.runGradle(projectDir, expectFailure = true)
334+
assertTrue(result.output.contains(ERROR_MISSING_FRAMEWORK_CONFIG))
336335
}
337336

338337
@Test
@@ -394,7 +393,7 @@ class PluginTest {
394393
}
395394

396395
@Test
397-
fun `Method retrieveFrameworkBaseNamesFromIosTargets handles SwiftExport with exported module fallback to project name`() {
396+
fun `Method retrieveFrameworkBaseNamesFromIosTargets handles SwiftExport with exported module with explicit moduleName`() {
398397
val commonFile = Templates.createCommonMainSource(projectDir, packageName = "com.test")
399398
assertTrue(commonFile.exists())
400399

@@ -434,7 +433,8 @@ class PluginTest {
434433
swiftExport {
435434
moduleName = "DefaultModule"
436435
export(projects.abc) {
437-
flattenPackage = "com.123"
436+
moduleName = "AbcModule"
437+
flattenPackage = "com.abc"
438438
}
439439
}
440440
}
@@ -452,7 +452,7 @@ class PluginTest {
452452

453453
val result = Templates.runGradle(projectDir)
454454
assertTrue(result.output.contains("$INFO_MODULE_NAME_BY_SWIFT_EXPORT [DefaultModule]"))
455-
assertTrue(result.output.contains("$INFO_MODULE_NAME_BY_PROJECT [Abc]"))
455+
assertTrue(result.output.contains("$INFO_MODULE_NAME_BY_SWIFT_EXPORT [AbcModule]"))
456456
}
457457

458458
@Test
@@ -550,7 +550,9 @@ class PluginTest {
550550
551551
kotlin {
552552
iosSimulatorArm64()
553-
swiftExport {}
553+
swiftExport {
554+
moduleName = "TestModule"
555+
}
554556
}
555557
"""
556558
)

sample/build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,4 @@ plugins {
66

77
tasks.register("exportFrameworkForXcode") {
88
dependsOn(":shared:embedAndSignAppleFrameworkForXcode")
9-
finalizedBy(":shared-models:embedAndSignAppleFrameworkForXcode")
109
}

sample/shared-models/build.gradle.kts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ plugins {
55
}
66

77
kotlin {
8-
listOf(iosArm64(), iosSimulatorArm64()).forEach { target -> target.binaries.framework { baseName = "Models" } }
8+
iosArm64()
9+
iosSimulatorArm64()
10+
911
sourceSets {
1012
commonMain.dependencies {
1113
implementation(local.kotlinx.collections)

0 commit comments

Comments
 (0)