From 6b87574033e53dafdd28e7f026e704e2ea405892 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Radek=20K=C5=AF=C5=BEel?= Date: Mon, 3 Jun 2024 12:27:38 +0200 Subject: [PATCH 1/3] Added file splitting --- build.gradle.kts | 7 +- .../FileContentGeneratorTest.kt | 412 +++++++++--------- .../linguinegenerator/FileParserTest.kt | 60 +-- .../LinguinePluginFunctionalTest.kt | 109 ++--- .../linguinegenerator/FileContentGenerator.kt | 91 ++-- .../linguine/linguinegenerator/FileParser.kt | 21 +- .../linguinegenerator/LinguineConfig.kt | 1 - .../linguinegenerator/LinguinePlugin.kt | 48 +- .../linguinegenerator/LinguinePluginTest.kt | 3 - 9 files changed, 383 insertions(+), 369 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 461f6f9..3733c70 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,5 +1,4 @@ import com.vanniktech.maven.publish.MavenPublishPlugin -import com.vanniktech.maven.publish.SonatypeHost import io.gitlab.arturbosch.detekt.Detekt import org.jetbrains.dokka.gradle.DokkaPlugin @@ -16,11 +15,11 @@ subprojects { apply() group = "io.github.cleverlance.linguine" - version = System.getenv("NEXT_VERSION") ?: "0.1.0" + version = System.getenv("NEXT_VERSION") ?: "0.2.0" mavenPublishing { - publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL, automaticRelease = true) - signAllPublications() +// publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL, automaticRelease = true) +// signAllPublications() pom { name = "Linguine" diff --git a/linguine-generator/src/functionalTest/kotlin/io/github/cleverlance/linguine/linguinegenerator/FileContentGeneratorTest.kt b/linguine-generator/src/functionalTest/kotlin/io/github/cleverlance/linguine/linguinegenerator/FileContentGeneratorTest.kt index 460d002..2fb2613 100644 --- a/linguine-generator/src/functionalTest/kotlin/io/github/cleverlance/linguine/linguinegenerator/FileContentGeneratorTest.kt +++ b/linguine-generator/src/functionalTest/kotlin/io/github/cleverlance/linguine/linguinegenerator/FileContentGeneratorTest.kt @@ -1,15 +1,15 @@ package io.github.cleverlance.linguine.linguinegenerator -import io.kotest.matchers.shouldBe import kotlin.io.path.Path import kotlin.test.Test +import kotlin.test.assertEquals @Suppress("StringLiteralDuplication") class FileContentGeneratorTest { @Test fun `generateFileContent with overlapping key names produces differentiated Kotlin object structures`() { - val filePath = Path("src/main/kotlin/com/example/app/Strings.kt") + val outputDirectory = Path("src/main/kotlin/com/example/app/") val fileContent: Map = mapOf( "settings__privacy__title" to "Title for Privacy Settings", "settings__privacy" to "Privacy Settings", @@ -17,185 +17,184 @@ class FileContentGeneratorTest { ) val root: Map = mapOf( - "Settings" to mapOf( - "privacy" to "settings__privacy", - "title" to "settings__title", - "Privacy" to mapOf( - "title" to "settings__privacy__title", - ), + "Privacy" to mapOf( + "title" to ("settings__privacy__title" to "Title for Privacy Settings"), ), + "privacy" to ("settings__privacy" to "Privacy Settings"), + "title" to ("settings__title" to "Title for Settings"), ) - val generator = FileContentGenerator(filePath, fileContent) + val generator = FileContentGenerator(outputDirectory, fileContent) - val result = generator.generateFileContent(root) + val result = generator.generateFileContent( + outputDirectory.resolve("SettingsStrings.kt"), + "Settings", + root, + ) val expected = """ - package com.example.app - + package presentation + import io.github.cleverlance.linguine.linguineruntime.presentation.Localiser.localise import kotlin.String - - public object Strings { - public object Settings { - public val privacy: String = localise("settings__privacy") - - public val title: String = localise("settings__title") - - public object Privacy { - public val title: String = localise("settings__privacy__title") - } + + public object Settings { + public val privacy: String = localise("settings__privacy") + + public val title: String = localise("settings__title") + + public object Privacy { + public val title: String = localise("settings__privacy__title") } } """ - result.trimIndent() shouldBe expected.trimIndent() + assertEquals(expected.trimIndent(), result.trimIndent()) } @Test fun `generateFileContent with empty values produces valid Kotlin object structures`() { - val filePath = Path("src/main/kotlin/com/example/app/Strings.kt") + val outputDirectory = Path("src/main/kotlin/com/example/app/") val fileContent: Map = mapOf( "section__empty_value" to "", ) val root: Map = mapOf( - "Section" to mapOf( - "emptyValue" to "section__empty_value", - ), + "emptyValue" to ("section__empty_value" to ""), ) - val generator = FileContentGenerator(filePath, fileContent) + val generator = FileContentGenerator(outputDirectory, fileContent) - val result = generator.generateFileContent(root) + val result = generator.generateFileContent( + outputDirectory.resolve("SectionStrings.kt"), + "Section", + root, + ) val expected = """ - package com.example.app - - import io.github.cleverlance.linguine.linguineruntime.presentation.Localiser.localise - import kotlin.String - - public object Strings { - public object Section { - public val emptyValue: String = localise("section__empty_value") - } - } - """ - result.trimIndent() shouldBe expected.trimIndent() + package presentation + + import io.github.cleverlance.linguine.linguineruntime.presentation.Localiser.localise + import kotlin.String + + public object Section { + public val emptyValue: String = localise("section__empty_value") + } + """ + assertEquals(expected.trimIndent(), result.trimIndent()) } @Test fun `generateFileContent with deeply nested structures produces expected Kotlin object structure`() { - val filePath = Path("src/main/kotlin/com/example/app/Strings.kt") + val outputDirectory = Path("src/main/kotlin/com/example/app/") val fileContent: Map = mapOf( "deep__level_one__level_two__level_three__final" to "Deeply Nested Value", ) val root: Map = mapOf( - "Deep" to mapOf( - "LevelOne" to mapOf( - "LevelTwo" to mapOf( - "LevelThree" to mapOf( - "final" to "deep__level_one__level_two__level_three__final", - ), + "LevelOne" to mapOf( + "LevelTwo" to mapOf( + "LevelThree" to mapOf( + "final" to ("deep__level_one__level_two__level_three__final" to "Deeply Nested Value"), ), ), ), ) - val generator = FileContentGenerator(filePath, fileContent) + val generator = FileContentGenerator(outputDirectory, fileContent) - val result = generator.generateFileContent(root) + val result = + generator.generateFileContent(outputDirectory.resolve("DeepStrings.kt"), "Deep", root) val expected = """ - package com.example.app - - import io.github.cleverlance.linguine.linguineruntime.presentation.Localiser.localise - import kotlin.String - - public object Strings { - public object Deep { - public object LevelOne { - public object LevelTwo { - public object LevelThree { - public val `final`: String = - localise("deep__level_one__level_two__level_three__final") - } - } + package presentation + + import io.github.cleverlance.linguine.linguineruntime.presentation.Localiser.localise + import kotlin.String + + public object Deep { + public object LevelOne { + public object LevelTwo { + public object LevelThree { + public val `final`: String = + localise("deep__level_one__level_two__level_three__final") } } } - """ - result.trimIndent() shouldBe expected.trimIndent() + } + """ + assertEquals(expected.trimIndent(), result.trimIndent()) } @Test fun `generateFileContent with simple values produces expected Kotlin properties`() { - val filePath = Path("src/main/kotlin/com/example/app/Strings.kt") + val outputDirectory = Path("src/main/kotlin/com/example/app/") val fileContent: Map = mapOf( "simple__key" to "Simple Value", "another__simple__key" to "Another Simple Value", ) val root: Map = mapOf( - "Simple" to "simple__key", - "AnotherSimple" to "another__simple__key", + "Simple" to ("simple__key" to "Simple Value"), + "AnotherSimple" to ("another__simple__key" to "Another Simple Value"), ) - val generator = FileContentGenerator(filePath, fileContent) + val generator = FileContentGenerator(outputDirectory, fileContent) - val result = generator.generateFileContent(root) + val result = + generator.generateFileContent(outputDirectory.resolve("Strings.kt"), "Strings", root) val expected = """ - package com.example.app - - import io.github.cleverlance.linguine.linguineruntime.presentation.Localiser.localise - import kotlin.String - - public object Strings { - public val Simple: String = localise("simple__key") - - public val AnotherSimple: String = localise("another__simple__key") - } - """ - result.trimIndent() shouldBe expected.trimIndent() + package presentation + + import io.github.cleverlance.linguine.linguineruntime.presentation.Localiser.localise + import kotlin.String + + public object Strings { + public val Simple: String = localise("simple__key") + + public val AnotherSimple: String = localise("another__simple__key") + } + """ + assertEquals(expected.trimIndent(), result.trimIndent()) } @Test fun `generateFileContent with complex function parameterization generates correct function signatures`() { - val filePath = Path("src/main/kotlin/com/example/app/Strings.kt") + val outputDirectory = Path("src/main/kotlin/com/example/app/") val fileContent: Map = mapOf( "error__message__with_parameters" to "Error %1\$s occurred at %2\$d:%3\$d on %4\$s", ) val root: Map = mapOf( "Error" to mapOf( - "messageWithParameters" to "error__message__with_parameters", + "messageWithParameters" to ("error__message__with_parameters" to "Error %1\$s occurred at %2\$d:%3\$d on %4\$s"), ), ) - val generator = FileContentGenerator(filePath, fileContent) + val generator = FileContentGenerator(outputDirectory, fileContent) - val result = generator.generateFileContent(root) + val result = + generator.generateFileContent(outputDirectory.resolve("Strings.kt"), "Strings", root) val expected = """ - package com.example.app - - import io.github.cleverlance.linguine.linguineruntime.presentation.Localiser.localise - import kotlin.Int - import kotlin.String - - public object Strings { - public object Error { - public fun messageWithParameters( - param1: String, - param2: Int, - param3: Int, - param4: String, - ): String = localise("error__message__with_parameters", param1, param2, param3, param4) - } + package presentation + + import io.github.cleverlance.linguine.linguineruntime.presentation.Localiser.localise + import kotlin.Int + import kotlin.String + + public object Strings { + public object Error { + public fun messageWithParameters( + param1: String, + param2: Int, + param3: Int, + param4: String, + ): String = localise("error__message__with_parameters", param1, param2, param3, param4) } - """ - result.trimIndent() shouldBe expected.trimIndent() + } + """ + assertEquals(expected.trimIndent(), result.trimIndent()) } @Test fun `generateFileContent with special characters in keys produces expected Kotlin object structure`() { - val filePath = Path("src/main/kotlin/com/example/app/Strings.kt") + val outputDirectory = Path("src/main/kotlin/com/example/app/") val fileContent: Map = mapOf( "special__char@cters__key!__value" to "Special Value", "another__special__key__with_numbers123" to "Numbered Value", @@ -205,46 +204,47 @@ class FileContentGeneratorTest { "Special" to mapOf( "Characters" to mapOf( "Key" to mapOf( - "value" to "special__char@cters__key!__value", + "value" to ("special__char@cters__key!__value" to "Special Value"), ), ), "AnotherSpecial" to mapOf( - "keyWithNumbers123" to "another__special__key__with_numbers123", + "keyWithNumbers123" to ("another__special__key__with_numbers123" to "Numbered Value"), ), ), ) - val generator = FileContentGenerator(filePath, fileContent) + val generator = FileContentGenerator(outputDirectory, fileContent) - val result = generator.generateFileContent(root) + val result = + generator.generateFileContent(outputDirectory.resolve("Strings.kt"), "Strings", root) val expected = """ - package com.example.app - - import io.github.cleverlance.linguine.linguineruntime.presentation.Localiser.localise - import kotlin.String - - public object Strings { - public object Special { - public object Characters { - public object Key { - public val `value`: String = localise("special__char@cters__key!__value") - } - } - - public object AnotherSpecial { - public val keyWithNumbers123: String = - localise("another__special__key__with_numbers123") + package presentation + + import io.github.cleverlance.linguine.linguineruntime.presentation.Localiser.localise + import kotlin.String + + public object Strings { + public object Special { + public object Characters { + public object Key { + public val `value`: String = localise("special__char@cters__key!__value") } } + + public object AnotherSpecial { + public val keyWithNumbers123: String = + localise("another__special__key__with_numbers123") + } } - """ - result.trimIndent() shouldBe expected.trimIndent() + } + """ + assertEquals(expected.trimIndent(), result.trimIndent()) } @Suppress("LongMethod") @Test fun `generateFileContent with simple map produces expected Kotlin object structure`() { - val filePath = Path("src/main/kotlin/com/example/app/Strings.kt") + val outputDirectory = Path("src/main/kotlin/com/example/app/") val fileContent: Map = mapOf( "activation__forgotten_password__birthdate__cancel_button" to "Cancel", "activation__forgotten_password__email_input" to "Enter your email", @@ -260,89 +260,90 @@ class FileContentGeneratorTest { "Activation" to mapOf( "ForgottenPassword" to mapOf( "Birthdate" to mapOf( - "cancelButton" to "activation__forgotten_password__birthdate__cancel_button", + "cancelButton" to ("activation__forgotten_password__birthdate__cancel_button" to "Cancel"), ), - "emailInput" to "activation__forgotten_password__email_input", + "emailInput" to ("activation__forgotten_password__email_input" to "Enter your email"), ), ), "Home" to mapOf( - "welcomeMessage" to "home__welcome_message", + "welcomeMessage" to ("home__welcome_message" to "Welcome to our application!"), ), "Profile" to mapOf( "Settings" to mapOf( "Privacy" to mapOf( - "title" to "profile__settings__privacy__title", - "description" to "profile__settings__privacy__description", + "title" to ("profile__settings__privacy__title" to "Privacy Settings"), + "description" to ("profile__settings__privacy__description" to "Manage your privacy settings here."), ), ), ), "Checkout" to mapOf( "Payment" to mapOf( "CreditCard" to mapOf( - "numberInput" to "checkout__payment__credit_card__number_input", - "expiryDate" to "checkout__payment__credit_card__expiry_date", - "cvv" to "checkout__payment__credit_card__cvv", + "numberInput" to ("checkout__payment__credit_card__number_input" to "Credit Card Number"), + "expiryDate" to ("checkout__payment__credit_card__expiry_date" to "Expiry Date"), + "cvv" to ("checkout__payment__credit_card__cvv" to "CVV"), ), ), ), ) - val generator = FileContentGenerator(filePath, fileContent) + val generator = FileContentGenerator(outputDirectory, fileContent) - val result = generator.generateFileContent(root) + val result = + generator.generateFileContent(outputDirectory.resolve("Strings.kt"), "Strings", root) val expected = """ - package com.example.app - - import io.github.cleverlance.linguine.linguineruntime.presentation.Localiser.localise - import kotlin.String - - public object Strings { - public object Activation { - public object ForgottenPassword { - public val emailInput: String = localise("activation__forgotten_password__email_input") - - public object Birthdate { - public val cancelButton: String = - localise("activation__forgotten_password__birthdate__cancel_button") - } + package presentation + + import io.github.cleverlance.linguine.linguineruntime.presentation.Localiser.localise + import kotlin.String + + public object Strings { + public object Activation { + public object ForgottenPassword { + public val emailInput: String = localise("activation__forgotten_password__email_input") + + public object Birthdate { + public val cancelButton: String = + localise("activation__forgotten_password__birthdate__cancel_button") } } - - public object Home { - public val welcomeMessage: String = localise("home__welcome_message") - } - - public object Profile { - public object Settings { - public object Privacy { - public val title: String = localise("profile__settings__privacy__title") - - public val description: String = localise("profile__settings__privacy__description") - } + } + + public object Home { + public val welcomeMessage: String = localise("home__welcome_message") + } + + public object Profile { + public object Settings { + public object Privacy { + public val title: String = localise("profile__settings__privacy__title") + + public val description: String = localise("profile__settings__privacy__description") } } - - public object Checkout { - public object Payment { - public object CreditCard { - public val numberInput: String = - localise("checkout__payment__credit_card__number_input") - - public val expiryDate: String = - localise("checkout__payment__credit_card__expiry_date") - - public val cvv: String = localise("checkout__payment__credit_card__cvv") - } + } + + public object Checkout { + public object Payment { + public object CreditCard { + public val numberInput: String = + localise("checkout__payment__credit_card__number_input") + + public val expiryDate: String = + localise("checkout__payment__credit_card__expiry_date") + + public val cvv: String = localise("checkout__payment__credit_card__cvv") } } } - """ - result.trimIndent() shouldBe expected.trimIndent() + } + """ + assertEquals(expected.trimIndent(), result.trimIndent()) } @Test fun `generateFileContent with function parameters generates kotlin object with function parameters`() { - val filePath = Path("src/main/kotlin/com/example/app/Strings.kt") + val outputDirectory = Path("src/main/kotlin/com/example/app/") val fileContent: Map = mapOf( "activation__forgotten_password__birthdate__cancel_button" to "\"%s %d %f %${'$'}s %${'$'}d %${'$'}f\"", ) @@ -351,41 +352,42 @@ class FileContentGeneratorTest { "Activation" to mapOf( "ForgottenPassword" to mapOf( "Birthdate" to mapOf( - "cancelButton" to "activation__forgotten_password__birthdate__cancel_button", + "cancelButton" to ("activation__forgotten_password__birthdate__cancel_button" to "\"%s %d %f %${'$'}s %${'$'}d %${'$'}f\""), ), ), ), ) - val generator = FileContentGenerator(filePath, fileContent) + val generator = FileContentGenerator(outputDirectory, fileContent) - val result = generator.generateFileContent(root) + val result = + generator.generateFileContent(outputDirectory.resolve("Strings.kt"), "Strings", root) val expected = """ - package com.example.app - - import io.github.cleverlance.linguine.linguineruntime.presentation.Localiser.localise - import kotlin.Float - import kotlin.Int - import kotlin.String - - public object Strings { - public object Activation { - public object ForgottenPassword { - public object Birthdate { - public fun cancelButton( - param1: String, - param2: Int, - param3: Float, - param4: String, - param5: Int, - param6: Float, - ): String = localise("activation__forgotten_password__birthdate__cancel_button", - param1, param2, param3, param4, param5, param6) - } + package presentation + + import io.github.cleverlance.linguine.linguineruntime.presentation.Localiser.localise + import kotlin.Float + import kotlin.Int + import kotlin.String + + public object Strings { + public object Activation { + public object ForgottenPassword { + public object Birthdate { + public fun cancelButton( + param1: String, + param2: Int, + param3: Float, + param4: String, + param5: Int, + param6: Float, + ): String = localise("activation__forgotten_password__birthdate__cancel_button", + param1, param2, param3, param4, param5, param6) } } } - """ - result.trimIndent() shouldBe expected.trimIndent() + } + """ + assertEquals(expected.trimIndent(), result.trimIndent()) } } diff --git a/linguine-generator/src/functionalTest/kotlin/io/github/cleverlance/linguine/linguinegenerator/FileParserTest.kt b/linguine-generator/src/functionalTest/kotlin/io/github/cleverlance/linguine/linguinegenerator/FileParserTest.kt index 2738c5c..3649ff5 100644 --- a/linguine-generator/src/functionalTest/kotlin/io/github/cleverlance/linguine/linguinegenerator/FileParserTest.kt +++ b/linguine-generator/src/functionalTest/kotlin/io/github/cleverlance/linguine/linguinegenerator/FileParserTest.kt @@ -14,9 +14,9 @@ class FileParserTest { val expectedOutput = mapOf() - val result = fileParser.generateNestedMapStructure() + val result = fileParser.generateGroupedMapStructure() - result shouldBe expectedOutput + result shouldBe expectedOutput } @Test @@ -27,10 +27,10 @@ class FileParserTest { val fileParser = fileParser(fileContent = mapContent) val expectedOutput = mapOf( - "singleKey" to "singleKey", + "SingleKey" to mapOf("singleKey" to ("singleKey" to "Single Value")), ) - val result = fileParser.generateNestedMapStructure() + val result = fileParser.generateGroupedMapStructure() result shouldBe expectedOutput } @@ -38,19 +38,19 @@ class FileParserTest { @Test fun `generateNestedMapStructure with mixed case keys creates consistent camelCase output`() { val mapContent = mapOf( - "activation__ForgottenPassword__emailInput" to "Enter your email", + "activation__forgottenPassword__emailInput" to "Enter your email", ) val fileParser = fileParser(fileContent = mapContent) val expectedOutput = mapOf( "Activation" to mapOf( "ForgottenPassword" to mapOf( - "emailInput" to "activation__ForgottenPassword__emailInput", - ), - ), + "emailInput" to ("activation__forgottenPassword__emailInput" to "Enter your email") + ) + ) ) - val result = fileParser.generateNestedMapStructure() + val result = fileParser.generateGroupedMapStructure() result shouldBe expectedOutput } @@ -67,14 +67,14 @@ class FileParserTest { "" to mapOf( "ForgottenPassword" to mapOf( "Email" to mapOf( - "input" to "activation____forgotten_password__email__input", + "input" to ("activation____forgotten_password__email__input" to "Email Input"), ), ), ), ), ) - val result = fileParser.generateNestedMapStructure() + val result = fileParser.generateGroupedMapStructure() result shouldBe expectedOutput } @@ -97,34 +97,34 @@ class FileParserTest { "Activation" to mapOf( "ForgottenPassword" to mapOf( "Birthdate" to mapOf( - "cancelButton" to "activation__forgotten_password__birthdate__cancel_button", + "cancelButton" to ("activation__forgotten_password__birthdate__cancel_button" to "Cancel"), ), - "emailInput" to "activation__forgotten_password__email_input", + "emailInput" to ("activation__forgotten_password__email_input" to "Enter your email"), ), ), "Home" to mapOf( - "welcomeMessage" to "home__welcome_message", + "welcomeMessage" to ("home__welcome_message" to "Welcome to our application!"), ), "Profile" to mapOf( "Settings" to mapOf( "Privacy" to mapOf( - "title" to "profile__settings__privacy__title", - "description" to "profile__settings__privacy__description", + "title" to ("profile__settings__privacy__title" to "Privacy Settings"), + "description" to ("profile__settings__privacy__description" to "Manage your privacy settings here."), ), ), ), "Checkout" to mapOf( "Payment" to mapOf( "CreditCard" to mapOf( - "numberInput" to "checkout__payment__credit_card__number_input", - "expiryDate" to "checkout__payment__credit_card__expiry_date", - "cvv" to "checkout__payment__credit_card__cvv", + "numberInput" to ("checkout__payment__credit_card__number_input" to "Credit Card Number"), + "expiryDate" to ("checkout__payment__credit_card__expiry_date" to "Expiry Date"), + "cvv" to ("checkout__payment__credit_card__cvv" to "CVV"), ), ), ), ) - val result = fileParser.generateNestedMapStructure() + val result = fileParser.generateGroupedMapStructure() result shouldBe expectedOutput } @@ -141,16 +141,16 @@ class FileParserTest { "Profile" to mapOf( "Settings" to mapOf( "Privacy" to mapOf( + "privacyPolicy" to ("profile__settings__privacy__privacy_policy" to "Privacy Policy"), "PrivacyPolicy" to mapOf( - "details" to "profile__settings__privacy__privacy_policy__details", - ), - "privacyPolicy" to "profile__settings__privacy__privacy_policy", + "details" to ("profile__settings__privacy__privacy_policy__details" to "Detailed description") + ) ), ), ), ) - val result = fileParser.generateNestedMapStructure() + val result = fileParser.generateGroupedMapStructure() result shouldBe expectedOutput } @@ -168,15 +168,15 @@ class FileParserTest { "Config" to mapOf( "Database" to mapOf( "Settings" to mapOf( - "maxConnections" to "system__config__database__settings__max_connections", - "timeout" to "system__config__database__settings__timeout", + "maxConnections" to ("system__config__database__settings__max_connections" to "100"), + "timeout" to ("system__config__database__settings__timeout" to "30"), ), ), ), ), ) - val result = fileParser.generateNestedMapStructure() + val result = fileParser.generateGroupedMapStructure() result shouldBe expectedOutput } @@ -192,13 +192,13 @@ class FileParserTest { val expectedOutput = mapOf( "User" to mapOf( "Name" to mapOf( - "first name" to "user__name__first name", - "last-name" to "user__name__last-name", + "first name" to ("user__name__first name" to "John"), + "last-name" to ("user__name__last-name" to "Doe"), ), ), ) - val result = fileParser.generateNestedMapStructure() + val result = fileParser.generateGroupedMapStructure() result shouldBe expectedOutput } diff --git a/linguine-generator/src/functionalTest/kotlin/io/github/cleverlance/linguine/linguinegenerator/LinguinePluginFunctionalTest.kt b/linguine-generator/src/functionalTest/kotlin/io/github/cleverlance/linguine/linguinegenerator/LinguinePluginFunctionalTest.kt index 4609f91..e402979 100644 --- a/linguine-generator/src/functionalTest/kotlin/io/github/cleverlance/linguine/linguinegenerator/LinguinePluginFunctionalTest.kt +++ b/linguine-generator/src/functionalTest/kotlin/io/github/cleverlance/linguine/linguinegenerator/LinguinePluginFunctionalTest.kt @@ -1,12 +1,12 @@ package io.github.cleverlance.linguine.linguinegenerator +import org.gradle.testkit.runner.GradleRunner +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.io.TempDir import java.io.File import java.nio.file.Paths import kotlin.io.path.createTempDirectory import kotlin.test.assertTrue -import org.gradle.testkit.runner.GradleRunner -import org.junit.jupiter.api.Test -import org.junit.jupiter.api.io.TempDir class LinguinePluginFunctionalTest { @@ -25,16 +25,10 @@ class LinguinePluginFunctionalTest { plugins { id("io.github.cleverlance.linguine") } - + linguineConfig { inputFilePath = "src/main/resources/string.json" - outputFilePath = "${ - testProjectDir.absolutePath.replace( - '\\', - '/', - ) - }/presentation" - outputFileName = "Strings.kt" + outputFilePath = "${'$'}{projectDir}/presentation" } """.trimIndent(), ) @@ -62,18 +56,17 @@ class LinguinePluginFunctionalTest { testProjectDir.resolve(gradleBuildFileName).apply { writeText( """ - plugins { - id("io.github.cleverlance.linguine") - } - - linguineConfig { - inputFilePath = "src/main/resources/strings.json" - outputFilePath = "${testProjectDir.absolutePath.replace('\\', '/')}/src/main/kotlin/presentation" - outputFileName = "Strings.kt" - majorDelimiter = "__" - minorDelimiter = "_" - } - """.trimIndent(), + plugins { + id("io.github.cleverlance.linguine") + } + + linguineConfig { + inputFilePath = "src/main/resources/strings.json" + outputFilePath = "${'$'}{projectDir}/src/main/kotlin/presentation" + majorDelimiter = "__" + minorDelimiter = "_" + } + """.trimIndent(), ) } @@ -81,11 +74,11 @@ class LinguinePluginFunctionalTest { parentFile.mkdirs() writeText( """ - { - "activation__forgotten_password__birthdate__log_in": "Přihlásit se", - "activation__forgotten_password__birthdate__log_out": "%s %d %f %${'$'}s %${'$'}d %${'$'}f" - } - """.trimIndent(), + { + "activation__forgotten_password__birthdate__log_in": "Přihlásit se", + "activation__forgotten_password__birthdate__log_out": "%s %d %f %${'$'}s %${'$'}d %${'$'}f" + } + """.trimIndent(), ) } @@ -93,12 +86,17 @@ class LinguinePluginFunctionalTest { .withProjectDir(testProjectDir) .withArguments(generateTaskName) .withPluginClasspath() + .forwardOutput() .build() + println(result.output) + assertTrue(result.output.contains(buildSuccessOutput), "Build should be successful") - val generatedFile = File(testProjectDir, "src/main/kotlin/presentation/Strings.kt") + val generatedFile = + File(testProjectDir, "src/main/kotlin/presentation/ActivationStrings.kt") assertTrue(generatedFile.exists(), "Generated file should exist") + val actualContent = generatedFile.readText() val expectedContent = """ package presentation @@ -108,28 +106,26 @@ class LinguinePluginFunctionalTest { import kotlin.Int import kotlin.String - public object Strings { - public object Activation { - public object ForgottenPassword { - public object Birthdate { - public val logIn: String = - localise("activation__forgotten_password__birthdate__log_in") - - public fun logOut( - param1: String, - param2: Int, - param3: Float, - param4: String, - param5: Int, - param6: Float, - ): String = localise("activation__forgotten_password__birthdate__log_out", param1, - param2, param3, param4, param5, param6) - } + public object Activation { + public object ForgottenPassword { + public object Birthdate { + public val logIn: String = localise("activation__forgotten_password__birthdate__log_in") + + public fun logOut( + param1: String, + param2: Int, + param3: Float, + param4: String, + param5: Int, + param6: Float, + ): String = localise("activation__forgotten_password__birthdate__log_out", param1, + param2, param3, param4, param5, param6) } } } """.trimIndent() + kotlin.test.assertEquals( expectedContent, actualContent, @@ -154,7 +150,6 @@ class LinguinePluginFunctionalTest { linguineConfig { inputFilePath = "src/main/resources/strings.json" outputFilePath = "$projectDirPath/presentation" - outputFileName = "Strings.kt" } """.trimIndent() @@ -181,17 +176,23 @@ class LinguinePluginFunctionalTest { assertTrue(result.output.contains(buildSuccessOutput), "Build should be successful") + val expectedSuccessMessagePart = + "File ActivationStrings.kt has been successfully created in the directory" assertTrue( - result.output.contains("File Strings.kt has been successfully created in the directory"), - "Success message was not printed", + result.output.contains(expectedSuccessMessagePart), + "Success message was not printed correctly", ) val expectedOutputPath = - Paths.get(testProjectDir.path, "presentation", "Strings.kt").toString() + Paths.get(testProjectDir.path, "presentation", "ActivationStrings.kt").toString() + .replace('\\', '/') assertTrue(File(expectedOutputPath).exists(), "Output file should exist") - assertTrue( - result.output.contains(expectedOutputPath), - "Expected output file path '$expectedOutputPath' was not found in the build output.", - ) + val outputPathComponents = expectedOutputPath.split('/') + outputPathComponents.forEach { component -> + assertTrue( + result.output.contains(component), + "Expected output path component '$component' was not found in the build output.", + ) + } } } diff --git a/linguine-generator/src/main/kotlin/io/github/cleverlance/linguine/linguinegenerator/FileContentGenerator.kt b/linguine-generator/src/main/kotlin/io/github/cleverlance/linguine/linguinegenerator/FileContentGenerator.kt index e4de1d2..4320635 100644 --- a/linguine-generator/src/main/kotlin/io/github/cleverlance/linguine/linguinegenerator/FileContentGenerator.kt +++ b/linguine-generator/src/main/kotlin/io/github/cleverlance/linguine/linguinegenerator/FileContentGenerator.kt @@ -5,28 +5,35 @@ import com.squareup.kotlinpoet.FunSpec import com.squareup.kotlinpoet.ParameterSpec import com.squareup.kotlinpoet.PropertySpec import com.squareup.kotlinpoet.TypeSpec +import java.io.File import java.nio.file.Path -import kotlin.io.path.isDirectory -import kotlin.io.path.name -import kotlin.io.path.relativeTo +import java.util.Locale import kotlin.reflect.KClass class FileContentGenerator( - private val filePath: Path, - private val fileContent: Map, + private val outputDirectory: Path, + private val fileContent: Map ) { - private val filePackage: String by lazy { getFilePackage(filePath) } + fun generateFileContents(groupedMap: Map>): Map { + return groupedMap.map { (fileName, content) -> + val capitalizedFileName = fileName.replaceFirstChar { + if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() + } + val filePath = outputDirectory.resolve("${capitalizedFileName}Strings.kt") + filePath to generateFileContent(filePath, capitalizedFileName, content) + }.toMap() + } - fun generateFileContent(root: Map): String { - return FileSpec.builder(filePackage, "") + fun generateFileContent(filePath: Path, fileName: String, root: Map): String { + return FileSpec.builder(getFilePackage(filePath), fileName) .indent(DEFAULT_INDENT) .addImport( "io.github.cleverlance.linguine.linguineruntime.presentation", "Localiser.localise", ) .addType( - TypeSpec.objectBuilder("Strings") + TypeSpec.objectBuilder(fileName) .addObjectContent(root) .build(), ) @@ -35,67 +42,61 @@ class FileContentGenerator( } private fun getFilePackage(filePath: Path): String { - fun Path.isSourceDirectory(): Boolean = isDirectory() && - (name == "kotlin" || name == "java") && - parent?.parent?.name == "src" - - var sourcePath: Path? = filePath - while (sourcePath != null && !sourcePath.isSourceDirectory()) { - sourcePath = sourcePath.parent - } - - if (sourcePath == null) return "" // no package - - val relativeDirectoryPath = filePath.parent.relativeTo(sourcePath) - return relativeDirectoryPath.joinToString(separator = ".") { path -> path.name } + val relativePath = outputDirectory.relativize(filePath.parent).toString().replace(File.separatorChar, '.') + return relativePath.ifBlank { "presentation" } } private fun TypeSpec.Builder.addObjectContent(root: Map): TypeSpec.Builder { @Suppress("UNCHECKED_CAST") // presuming the structure of the map root.forEach { (key, value) -> when (value) { - is Map<*, *> -> addObject(key, value as Map) - else -> addFunctionOrProperty(key, value.toString()) + is Map<*, *> -> addType( + TypeSpec.objectBuilder(key.replaceFirstChar { + if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() + }) + .addObjectContent(value as Map) + .build() + ) + is Pair<*, *> -> { + val originalKey = value.first as String + value.second as String + addFunctionOrProperty(key, originalKey) + } } } return this } - private fun TypeSpec.Builder.addObject(key: String, value: Map) { - addType( - TypeSpec.objectBuilder(key) - .addObjectContent(value) - .build(), - ) - } - - private fun TypeSpec.Builder.addFunctionOrProperty(key: String, value: String) { - val translation = fileContent.filter { it.key == value }.toString() - val dataTypes = determineDataTypes(translation) + private fun TypeSpec.Builder.addFunctionOrProperty(key: String, originalKey: String) { + val translation = fileContent[originalKey] + val dataTypes = determineDataTypes(translation ?: "") if (dataTypes.isNotEmpty()) { val parameters = dataTypes.mapIndexed { index, type -> - ParameterSpec.builder("param${index + 1}", type) - .build() + ParameterSpec.builder("param${index + 1}", type).build() } - val parametersCall = parameters.joinToString { it.name } + addFunction( FunSpec.builder(key) - .addParameters(parameters) + .apply { + parameters.forEach { addParameter(it) } + } .returns(String::class) - .addStatement("""return localise("$value", $parametersCall)""") - .build(), + .addStatement( + """return localise("%L", ${parameters.joinToString(", ") { it.name }})""", + originalKey + ) + .build() ) } else { addProperty( PropertySpec.builder(key, String::class) - .initializer("""localise("$value")""") - .build(), + .initializer("""localise("%L")""", originalKey) + .build() ) } } - // %s - valid parameter, can be without $ private fun determineDataTypes(formatString: String): List> { val formatSpecifiers = FORMAT_SPECIFIER_REGEX.findAll(formatString) return formatSpecifiers.map { determineDataType(it.value) }.toList() @@ -115,6 +116,6 @@ class FileContentGenerator( private companion object { const val DEFAULT_INDENT = " " - val FORMAT_SPECIFIER_REGEX = Regex("%[0-9]*\\\$[sdf]|%[sdf]") + val FORMAT_SPECIFIER_REGEX = Regex("%[0-9]*\\$?[sdf]") } } diff --git a/linguine-generator/src/main/kotlin/io/github/cleverlance/linguine/linguinegenerator/FileParser.kt b/linguine-generator/src/main/kotlin/io/github/cleverlance/linguine/linguinegenerator/FileParser.kt index 1a1a063..fbf3554 100644 --- a/linguine-generator/src/main/kotlin/io/github/cleverlance/linguine/linguinegenerator/FileParser.kt +++ b/linguine-generator/src/main/kotlin/io/github/cleverlance/linguine/linguinegenerator/FileParser.kt @@ -5,11 +5,22 @@ class FileParser( private val minorDelimiter: String, private val majorDelimiter: String, ) { - fun generateNestedMapStructure(): Map { + fun generateGroupedMapStructure(): Map> { + val groupedMap = mutableMapOf>>() + fileContent.forEach { (key, value) -> + val firstSegment = + key.substringBefore(majorDelimiter).replaceFirstChar { it.uppercaseChar() } + val restOfKey = key.substringAfter(majorDelimiter) + groupedMap.computeIfAbsent(firstSegment) { mutableMapOf() }[restOfKey] = key to value + } + return groupedMap.mapValues { (_, map) -> generateNestedMapStructure(map) } + } + + private fun generateNestedMapStructure(map: Map>): Map { val root = mutableMapOf() - fileContent.keys.forEach { key -> + map.forEach { (key, value) -> val parts = transformKeyToCamelCaseSegments(key) - updateNestedMapStructure(root, parts, key) + updateNestedMapStructure(root, parts, value) } return root } @@ -25,14 +36,14 @@ class FileParser( private fun updateNestedMapStructure( root: MutableMap, parts: List, - fullKey: String, + value: Pair, ) { var current = root @Suppress("UNCHECKED_CAST") parts.forEachIndexed { index, part -> val formattedPart = formatPart(part, index < parts.lastIndex) if (index == parts.lastIndex) { - current[formattedPart] = fullKey + current[formattedPart] = value } else { current = current.computeIfAbsent(formattedPart) { mutableMapOf() } as MutableMap diff --git a/linguine-generator/src/main/kotlin/io/github/cleverlance/linguine/linguinegenerator/LinguineConfig.kt b/linguine-generator/src/main/kotlin/io/github/cleverlance/linguine/linguinegenerator/LinguineConfig.kt index 621166c..37bca25 100644 --- a/linguine-generator/src/main/kotlin/io/github/cleverlance/linguine/linguinegenerator/LinguineConfig.kt +++ b/linguine-generator/src/main/kotlin/io/github/cleverlance/linguine/linguinegenerator/LinguineConfig.kt @@ -6,7 +6,6 @@ open class LinguineConfig { var inputFilePath: String = "" var inputFileType: FileType = FileType.JSON var outputFilePath: String = "" - var outputFileName: String = "" var majorDelimiter: String = "__" var minorDelimiter: String = "_" var buildTaskName: String? = null diff --git a/linguine-generator/src/main/kotlin/io/github/cleverlance/linguine/linguinegenerator/LinguinePlugin.kt b/linguine-generator/src/main/kotlin/io/github/cleverlance/linguine/linguinegenerator/LinguinePlugin.kt index cd83340..ec16531 100644 --- a/linguine-generator/src/main/kotlin/io/github/cleverlance/linguine/linguinegenerator/LinguinePlugin.kt +++ b/linguine-generator/src/main/kotlin/io/github/cleverlance/linguine/linguinegenerator/LinguinePlugin.kt @@ -1,17 +1,16 @@ package io.github.cleverlance.linguine.linguinegenerator -import io.github.cleverlance.linguine.linguinegenerator.filereader.FileType as LinguineFileType -import org.gradle.api.provider.Property as GradleProperty import io.github.cleverlance.linguine.linguine_generator.BuildConfig import io.github.cleverlance.linguine.linguinegenerator.filereader.FileReader import org.gradle.api.DefaultTask import org.gradle.api.Plugin import org.gradle.api.Project +import org.gradle.api.file.DirectoryProperty import org.gradle.api.file.RegularFileProperty import org.gradle.api.tasks.CacheableTask import org.gradle.api.tasks.Input import org.gradle.api.tasks.InputFile -import org.gradle.api.tasks.OutputFile +import org.gradle.api.tasks.OutputDirectory import org.gradle.api.tasks.PathSensitive import org.gradle.api.tasks.PathSensitivity import org.gradle.api.tasks.TaskAction @@ -19,6 +18,8 @@ import org.gradle.kotlin.dsl.dependencies import org.gradle.kotlin.dsl.getByType import org.gradle.work.Incremental import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension +import io.github.cleverlance.linguine.linguinegenerator.filereader.FileType as LinguineFileType +import org.gradle.api.provider.Property as GradleProperty @Suppress("unused") class LinguinePlugin : Plugin { @@ -41,10 +42,10 @@ class LinguinePlugin : Plugin { fileType.set(extension.inputFileType) majorDelimiter.set(extension.majorDelimiter) minorDelimiter.set(extension.minorDelimiter) - outputFile.set( - project.layout.projectDirectory.file( - "${extension.outputFilePath}/${extension.outputFileName}", - ), + outputDirectory.set( + (project.layout.projectDirectory.dir( + extension.outputFilePath, + )), ) } } @@ -86,7 +87,8 @@ class LinguinePlugin : Plugin { private companion object { const val GENERATE_STRINGS_TASK_NAME = "generateStrings" - const val RUNTIME_DEPENDENCY = "${BuildConfig.GROUP}:linguine-runtime:${BuildConfig.VERSION}" + const val RUNTIME_DEPENDENCY = + "${BuildConfig.GROUP}:linguine-runtime:${BuildConfig.VERSION}" } } @@ -106,8 +108,8 @@ abstract class GenerateStringsTask : DefaultTask() { @get:Input abstract val majorDelimiter: GradleProperty - @get:OutputFile - abstract val outputFile: RegularFileProperty + @get:OutputDirectory + abstract val outputDirectory: DirectoryProperty @TaskAction fun generate() { @@ -121,23 +123,25 @@ abstract class GenerateStringsTask : DefaultTask() { val fileParser = FileParser( fileContent = fileContent, minorDelimiter = minorDelimiter.get(), - majorDelimiter = majorDelimiter.get(), + majorDelimiter = majorDelimiter.get() ) - val root = fileParser.generateNestedMapStructure() + + val groupedMap = fileParser.generateGroupedMapStructure() // Generate content for the Kotlin Localization File - val fileContentGenerator = FileContentGenerator(outputFile.asFile.get().toPath(), fileContent) - val outputFileContent = fileContentGenerator.generateFileContent(root) + val fileContentGenerator = + FileContentGenerator(outputDirectory.get().asFile.toPath(), fileContent) + val outputFileContent = fileContentGenerator.generateFileContents(groupedMap) // Write built kotlin class and its nested structure into Kotlin File val fileWriter = FileWriter() - fileWriter.writeToFile( - outputFile = outputFile.asFile.get(), - outputFileContent = outputFileContent, - ) - logger.lifecycle( - "Linguine: File ${outputFile.asFile.get().name} " + - "has been successfully created in the directory ${outputFile.asFile.get().path}", - ) + outputFileContent.forEach { (filePath, content) -> + fileWriter.writeToFile(filePath.toFile(), content) + + logger.lifecycle( + "Linguine: File ${filePath.fileName} " + + "has been successfully created in the directory ${filePath.parent}", + ) + } } } diff --git a/linguine-generator/src/test/kotlin/io/github/cleverlance/linguine/linguinegenerator/LinguinePluginTest.kt b/linguine-generator/src/test/kotlin/io/github/cleverlance/linguine/linguinegenerator/LinguinePluginTest.kt index 5fb3865..7e64082 100644 --- a/linguine-generator/src/test/kotlin/io/github/cleverlance/linguine/linguinegenerator/LinguinePluginTest.kt +++ b/linguine-generator/src/test/kotlin/io/github/cleverlance/linguine/linguinegenerator/LinguinePluginTest.kt @@ -16,7 +16,6 @@ class LinguinePluginTest { val extension = project.extensions.getByType(LinguineConfig::class.java) extension.inputFilePath = "src/commonMain/resources/string.json" extension.outputFilePath = "presentation" - extension.outputFileName = "Strings.kt" // Verify the result assertNotNull(project.tasks.findByName("generateStrings")) @@ -30,10 +29,8 @@ class LinguinePluginTest { val extension = project.extensions.getByType(LinguineConfig::class.java) extension.inputFilePath = "src/commonMain/resources/string.json" extension.outputFilePath = "presentation" - extension.outputFileName = "Strings.kt" assertEquals("src/commonMain/resources/string.json", extension.inputFilePath) assertEquals("presentation", extension.outputFilePath) - assertEquals("Strings.kt", extension.outputFileName) } } From fb093278ad20b1fe66b669b9113ed213c9c12e86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Radek=20K=C5=AF=C5=BEel?= Date: Mon, 3 Jun 2024 13:47:11 +0200 Subject: [PATCH 2/3] fix detekt --- .../FileContentGeneratorTest.kt | 9 ++++++--- .../linguine/linguinegenerator/FileParserTest.kt | 8 +++++--- .../LinguinePluginFunctionalTest.kt | 10 +++++----- .../linguinegenerator/FileContentGenerator.kt | 16 +++++++++------- .../linguine/linguinegenerator/LinguinePlugin.kt | 12 ++++++------ 5 files changed, 31 insertions(+), 24 deletions(-) diff --git a/linguine-generator/src/functionalTest/kotlin/io/github/cleverlance/linguine/linguinegenerator/FileContentGeneratorTest.kt b/linguine-generator/src/functionalTest/kotlin/io/github/cleverlance/linguine/linguinegenerator/FileContentGeneratorTest.kt index 2fb2613..09f09fa 100644 --- a/linguine-generator/src/functionalTest/kotlin/io/github/cleverlance/linguine/linguinegenerator/FileContentGeneratorTest.kt +++ b/linguine-generator/src/functionalTest/kotlin/io/github/cleverlance/linguine/linguinegenerator/FileContentGeneratorTest.kt @@ -163,7 +163,8 @@ class FileContentGeneratorTest { val root: Map = mapOf( "Error" to mapOf( - "messageWithParameters" to ("error__message__with_parameters" to "Error %1\$s occurred at %2\$d:%3\$d on %4\$s"), + "messageWithParameters" to ("error__message__with_parameters" to + "Error %1\$s occurred at %2\$d:%3\$d on %4\$s"), ), ) val generator = FileContentGenerator(outputDirectory, fileContent) @@ -272,7 +273,8 @@ class FileContentGeneratorTest { "Settings" to mapOf( "Privacy" to mapOf( "title" to ("profile__settings__privacy__title" to "Privacy Settings"), - "description" to ("profile__settings__privacy__description" to "Manage your privacy settings here."), + "description" to ("profile__settings__privacy__description" to + "Manage your privacy settings here."), ), ), ), @@ -352,7 +354,8 @@ class FileContentGeneratorTest { "Activation" to mapOf( "ForgottenPassword" to mapOf( "Birthdate" to mapOf( - "cancelButton" to ("activation__forgotten_password__birthdate__cancel_button" to "\"%s %d %f %${'$'}s %${'$'}d %${'$'}f\""), + "cancelButton" to ("activation__forgotten_password__birthdate__cancel_button" to + "\"%s %d %f %${'$'}s %${'$'}d %${'$'}f\""), ), ), ), diff --git a/linguine-generator/src/functionalTest/kotlin/io/github/cleverlance/linguine/linguinegenerator/FileParserTest.kt b/linguine-generator/src/functionalTest/kotlin/io/github/cleverlance/linguine/linguinegenerator/FileParserTest.kt index 3649ff5..7fb83e4 100644 --- a/linguine-generator/src/functionalTest/kotlin/io/github/cleverlance/linguine/linguinegenerator/FileParserTest.kt +++ b/linguine-generator/src/functionalTest/kotlin/io/github/cleverlance/linguine/linguinegenerator/FileParserTest.kt @@ -16,7 +16,7 @@ class FileParserTest { val result = fileParser.generateGroupedMapStructure() - result shouldBe expectedOutput + result shouldBe expectedOutput } @Test @@ -109,7 +109,8 @@ class FileParserTest { "Settings" to mapOf( "Privacy" to mapOf( "title" to ("profile__settings__privacy__title" to "Privacy Settings"), - "description" to ("profile__settings__privacy__description" to "Manage your privacy settings here."), + "description" to ("profile__settings__privacy__description" to + "Manage your privacy settings here."), ), ), ), @@ -143,7 +144,8 @@ class FileParserTest { "Privacy" to mapOf( "privacyPolicy" to ("profile__settings__privacy__privacy_policy" to "Privacy Policy"), "PrivacyPolicy" to mapOf( - "details" to ("profile__settings__privacy__privacy_policy__details" to "Detailed description") + "details" to ("profile__settings__privacy__privacy_policy__details" to + "Detailed description") ) ), ), diff --git a/linguine-generator/src/functionalTest/kotlin/io/github/cleverlance/linguine/linguinegenerator/LinguinePluginFunctionalTest.kt b/linguine-generator/src/functionalTest/kotlin/io/github/cleverlance/linguine/linguinegenerator/LinguinePluginFunctionalTest.kt index e402979..279d0e7 100644 --- a/linguine-generator/src/functionalTest/kotlin/io/github/cleverlance/linguine/linguinegenerator/LinguinePluginFunctionalTest.kt +++ b/linguine-generator/src/functionalTest/kotlin/io/github/cleverlance/linguine/linguinegenerator/LinguinePluginFunctionalTest.kt @@ -1,12 +1,12 @@ package io.github.cleverlance.linguine.linguinegenerator -import org.gradle.testkit.runner.GradleRunner -import org.junit.jupiter.api.Test -import org.junit.jupiter.api.io.TempDir import java.io.File import java.nio.file.Paths import kotlin.io.path.createTempDirectory import kotlin.test.assertTrue +import org.gradle.testkit.runner.GradleRunner +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.io.TempDir class LinguinePluginFunctionalTest { @@ -66,7 +66,7 @@ class LinguinePluginFunctionalTest { majorDelimiter = "__" minorDelimiter = "_" } - """.trimIndent(), + """.trimIndent(), ) } @@ -78,7 +78,7 @@ class LinguinePluginFunctionalTest { "activation__forgotten_password__birthdate__log_in": "Přihlásit se", "activation__forgotten_password__birthdate__log_out": "%s %d %f %${'$'}s %${'$'}d %${'$'}f" } - """.trimIndent(), + """.trimIndent(), ) } diff --git a/linguine-generator/src/main/kotlin/io/github/cleverlance/linguine/linguinegenerator/FileContentGenerator.kt b/linguine-generator/src/main/kotlin/io/github/cleverlance/linguine/linguinegenerator/FileContentGenerator.kt index 4320635..3a51644 100644 --- a/linguine-generator/src/main/kotlin/io/github/cleverlance/linguine/linguinegenerator/FileContentGenerator.kt +++ b/linguine-generator/src/main/kotlin/io/github/cleverlance/linguine/linguinegenerator/FileContentGenerator.kt @@ -50,13 +50,15 @@ class FileContentGenerator( @Suppress("UNCHECKED_CAST") // presuming the structure of the map root.forEach { (key, value) -> when (value) { - is Map<*, *> -> addType( - TypeSpec.objectBuilder(key.replaceFirstChar { - if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() - }) - .addObjectContent(value as Map) - .build() - ) + is Map<*, *> -> { + addType( + TypeSpec.objectBuilder(key.replaceFirstChar { + if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() + }) + .addObjectContent(value as Map) + .build() + ) + } is Pair<*, *> -> { val originalKey = value.first as String value.second as String diff --git a/linguine-generator/src/main/kotlin/io/github/cleverlance/linguine/linguinegenerator/LinguinePlugin.kt b/linguine-generator/src/main/kotlin/io/github/cleverlance/linguine/linguinegenerator/LinguinePlugin.kt index ec16531..fff40f4 100644 --- a/linguine-generator/src/main/kotlin/io/github/cleverlance/linguine/linguinegenerator/LinguinePlugin.kt +++ b/linguine-generator/src/main/kotlin/io/github/cleverlance/linguine/linguinegenerator/LinguinePlugin.kt @@ -1,5 +1,7 @@ package io.github.cleverlance.linguine.linguinegenerator +import io.github.cleverlance.linguine.linguinegenerator.filereader.FileType as LinguineFileType +import org.gradle.api.provider.Property as GradleProperty import io.github.cleverlance.linguine.linguine_generator.BuildConfig import io.github.cleverlance.linguine.linguinegenerator.filereader.FileReader import org.gradle.api.DefaultTask @@ -18,8 +20,6 @@ import org.gradle.kotlin.dsl.dependencies import org.gradle.kotlin.dsl.getByType import org.gradle.work.Incremental import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension -import io.github.cleverlance.linguine.linguinegenerator.filereader.FileType as LinguineFileType -import org.gradle.api.provider.Property as GradleProperty @Suppress("unused") class LinguinePlugin : Plugin { @@ -43,9 +43,9 @@ class LinguinePlugin : Plugin { majorDelimiter.set(extension.majorDelimiter) minorDelimiter.set(extension.minorDelimiter) outputDirectory.set( - (project.layout.projectDirectory.dir( + project.layout.projectDirectory.dir( extension.outputFilePath, - )), + ), ) } } @@ -123,7 +123,7 @@ abstract class GenerateStringsTask : DefaultTask() { val fileParser = FileParser( fileContent = fileContent, minorDelimiter = minorDelimiter.get(), - majorDelimiter = majorDelimiter.get() + majorDelimiter = majorDelimiter.get(), ) val groupedMap = fileParser.generateGroupedMapStructure() @@ -140,7 +140,7 @@ abstract class GenerateStringsTask : DefaultTask() { logger.lifecycle( "Linguine: File ${filePath.fileName} " + - "has been successfully created in the directory ${filePath.parent}", + "has been successfully created in the directory ${filePath.parent}", ) } } From c34813e3f0544828d3bb1b74edac44d837262238 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Radek=20K=C5=AF=C5=BEel?= Date: Mon, 10 Jun 2024 14:31:01 +0200 Subject: [PATCH 3/3] added publish to maven and sign all --- build.gradle.kts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 3733c70..94b9e42 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,4 +1,5 @@ import com.vanniktech.maven.publish.MavenPublishPlugin +import com.vanniktech.maven.publish.SonatypeHost import io.gitlab.arturbosch.detekt.Detekt import org.jetbrains.dokka.gradle.DokkaPlugin @@ -18,8 +19,8 @@ subprojects { version = System.getenv("NEXT_VERSION") ?: "0.2.0" mavenPublishing { -// publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL, automaticRelease = true) -// signAllPublications() + publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL, automaticRelease = true) + signAllPublications() pom { name = "Linguine"