diff --git a/build.gradle b/build.gradle index 029dd6f..c87c70b 100644 --- a/build.gradle +++ b/build.gradle @@ -13,12 +13,11 @@ plugins { id "java" id "java-test-fixtures" } - apply plugin: "maven-publish" +version = "0.26.3-SNAPSHOT" group = "org.domaindrivenarchitecture.provs" -version = "0.26.2" repositories { diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/domain/DesktopService.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/domain/DesktopService.kt index 7b1787e..26bd3c8 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/domain/DesktopService.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/domain/DesktopService.kt @@ -16,14 +16,21 @@ import org.domaindrivenarchitecture.provs.framework.ubuntu.user.base.whoami internal fun Prov.provisionDesktopCommand(cmd: DesktopCliCommand, conf: DesktopConfig) = task { - provisionDesktop( - cmd.type, - conf.ssh?.keyPair(), - conf.gpg?.keyPair(), - conf.gitUserName, - conf.gitEmail, - cmd.onlyModules - ) + + validatePrecondition() + + val only = cmd.onlyModules + if (only == null) { + provisionDesktop( + cmd.type, + conf.ssh?.keyPair(), + conf.gpg?.keyPair(), + conf.gitUserName, + conf.gitEmail, + ) + } else { + provisionOnlyModules(cmd.type, only) + } } @@ -41,33 +48,35 @@ internal fun Prov.provisionDesktop( gpg: KeyPair? = null, gitUserName: String? = null, gitEmail: String? = null, - onlyModules: List? ) = task { - validatePrecondition() - if (onlyModules == null) { - provisionBasicDesktop(gpg, ssh, gitUserName, gitEmail) + provisionBasicDesktop(gpg, ssh, gitUserName, gitEmail) + if (desktopType == DesktopType.OFFICE) { + provisionOfficeDesktop() + verifyOfficeSetup() + } + if (desktopType == DesktopType.IDE) { + provisionOfficeDesktop() + provisionIdeDesktop() + verifyIdeSetup() + } +} + +internal fun Prov.provisionOnlyModules( + desktopType: DesktopType = DesktopType.BASIC, + onlyModules: List +) = task { + + if (FIREFOX.isIn(onlyModules)) { + installPpaFirefox() + } + if (VERIFY.isIn(onlyModules)) { if (desktopType == DesktopType.OFFICE) { - provisionOfficeDesktop() verifyOfficeSetup() - } - if (desktopType == DesktopType.IDE) { - provisionOfficeDesktop() - provisionIdeDesktop() + } else if (desktopType == DesktopType.IDE) { verifyIdeSetup() } - } else { - if (FIREFOX.isIn(onlyModules)) { - installPpaFirefox() - } - if (VERIFY.isIn(onlyModules)) { - if (desktopType == DesktopType.OFFICE) { - verifyOfficeSetup() - } else if (desktopType == DesktopType.IDE) { - verifyIdeSetup() - } - } } } diff --git a/src/test/kotlin/org/domaindrivenarchitecture/provs/desktop/application/ApplicationKtTest.kt b/src/test/kotlin/org/domaindrivenarchitecture/provs/desktop/application/ApplicationKtTest.kt index 3971e23..cae0bb7 100644 --- a/src/test/kotlin/org/domaindrivenarchitecture/provs/desktop/application/ApplicationKtTest.kt +++ b/src/test/kotlin/org/domaindrivenarchitecture/provs/desktop/application/ApplicationKtTest.kt @@ -40,7 +40,7 @@ internal class ApplicationKtTest { val dummyProv = Prov.newInstance(DummyProcessor()) mockkObject(Prov) - every { Prov.newInstance(any(), any(), any(), any(), ) } returns dummyProv + every { Prov.newInstance(any(), any(), any(), any()) } returns dummyProv mockkStatic(::local) every { local() } returns dummyProv @@ -52,7 +52,7 @@ internal class ApplicationKtTest { every { getConfig("testconfig.yaml") } returns testConfig mockkStatic(Prov::provisionDesktop) - every { any().provisionDesktop(any(), any(), any(), any(), any(),any()) } returns ProvResult( + every { any().provisionDesktop(any(), any(), any(), any(), any()) } returns ProvResult( true, cmd = "mocked command" ) @@ -85,7 +85,6 @@ internal class ApplicationKtTest { null, testConfig.gitUserName, testConfig.gitEmail, - null ) } } @@ -119,7 +118,7 @@ internal class ApplicationKtTest { "Error: File\u001B[31m idontexist.yaml \u001B[0m was not found.Pls copy file \u001B[31m desktop-config-example.yaml \u001B[0m to file \u001B[31m idontexist.yaml \u001B[0m and change the content according to your needs.No suitable config found." assertEquals(expectedOutput, outContent.toString().replace("\r", "").replace("\n", "")) - verify(exactly = 0) { any().provisionDesktop(any(), any(), any(), any(), any(), any()) } + verify(exactly = 0) { any().provisionDesktop(any(), any(), any(), any(), any()) } unmockkStatic(::quit) } @@ -153,7 +152,7 @@ internal class ApplicationKtTest { "Error: File \"src/test/resources/invalid-desktop-config.yaml\" has an invalid format and or invalid data.No suitable config found." assertEquals(expectedOutput, outContent.toString().replace("\r", "").replace("\n", "")) - verify(exactly = 0) { any().provisionDesktop(any(), any(), any(), any(), any(), any()) } + verify(exactly = 0) { any().provisionDesktop(any(), any(), any(), any(), any()) } unmockkStatic(::quit) } diff --git a/src/test/kotlin/org/domaindrivenarchitecture/provs/desktop/domain/DesktopServiceKtTest.kt b/src/test/kotlin/org/domaindrivenarchitecture/provs/desktop/domain/DesktopServiceKtTest.kt index 05eaef2..852084a 100644 --- a/src/test/kotlin/org/domaindrivenarchitecture/provs/desktop/domain/DesktopServiceKtTest.kt +++ b/src/test/kotlin/org/domaindrivenarchitecture/provs/desktop/domain/DesktopServiceKtTest.kt @@ -41,7 +41,6 @@ internal class DesktopServiceKtTest { DesktopType.BASIC, gitUserName = "testuser", gitEmail = "testuser@test.org", - onlyModules = null ) } } @@ -54,7 +53,7 @@ internal class DesktopServiceKtTest { every { any().installPpaFirefox() } returns ProvResult(true, cmd = "mocked") // when - prov.provisionDesktop(DesktopType.IDE, onlyModules = listOf("firefox")) + prov.provisionOnlyModules(DesktopType.IDE, onlyModules = listOf("firefox")) // then verify(exactly = 1) { any().installPpaFirefox() } @@ -75,7 +74,7 @@ internal class DesktopServiceKtTest { every { any().provisionBasicDesktop(any(), any(), any(), any()) } // when - prov.provisionDesktop(DesktopType.IDE, onlyModules = listOf("verify")) + prov.provisionOnlyModules(DesktopType.IDE, onlyModules = listOf("verify")) // then verify(exactly = 1) { any().verifyIdeSetup() } @@ -98,7 +97,7 @@ internal class DesktopServiceKtTest { every { any().provisionBasicDesktop(any(), any(), any(), any()) } // when - prov.provisionDesktop(DesktopType.OFFICE, onlyModules = listOf("verify")) + prov.provisionOnlyModules(DesktopType.OFFICE, onlyModules = listOf("verify")) // then verify(exactly = 0) { any().verifyIdeSetup() } @@ -122,7 +121,6 @@ internal class DesktopServiceKtTest { DesktopType.BASIC, gitUserName = "testuser", gitEmail = "testuser@test.org", - onlyModules = null ) // then @@ -147,7 +145,6 @@ internal class DesktopServiceKtTest { DesktopType.IDE, gitUserName = "testuser", gitEmail = "testuser@test.org", - onlyModules = null ) // then