diff --git a/demo-project/groovy-gen-kotlin/build.gradle b/demo-project/groovy-gen-kotlin/build.gradle index 8aff56e..28dc6df 100644 --- a/demo-project/groovy-gen-kotlin/build.gradle +++ b/demo-project/groovy-gen-kotlin/build.gradle @@ -172,6 +172,10 @@ buildConfig { ) buildConfigField(Map.class, "MAP_GENERIC", expression("mapOf(\"a\" to 1, \"b\" to 2)")) buildConfigField(Map.class, "MAP_GENERIC_PROVIDER", provider { expression("mapOf(\"a\" to 1, \"b\" to 2)") }) + buildConfigField(File.class, "FILE", new File("aFile")) + buildConfigField(File.class, "FILE_PROVIDER", provider { new File("aFile") }) + buildConfigField(URI.class, "URI", uri("https://example.io")) + buildConfigField(URI.class, "URI_PROVIDER", provider { uri("https://example.io") }) buildConfigField( "com.github.gmazzo.buildconfig.demos.groovy.SomeData", "DATA", diff --git a/demo-project/groovy/build.gradle b/demo-project/groovy/build.gradle index 379dd22..5993326 100644 --- a/demo-project/groovy/build.gradle +++ b/demo-project/groovy/build.gradle @@ -172,6 +172,10 @@ buildConfig { ) buildConfigField(Map.class, "MAP_GENERIC", expression("java.util.Map.of(\"a\", 1, \"b\", 2)")) buildConfigField(Map.class, "MAP_GENERIC_PROVIDER", provider { expression("java.util.Map.of(\"a\", 1, \"b\", 2)") }) + buildConfigField(File.class, "FILE", new File("aFile")) + buildConfigField(File.class, "FILE_PROVIDER", provider { new File("aFile") }) + buildConfigField(URI.class, "URI", uri("https://example.io")) + buildConfigField(URI.class, "URI_PROVIDER", provider { uri("https://example.io") }) buildConfigField( "com.github.gmazzo.buildconfig.demos.groovy.SomeData", "DATA", diff --git a/demo-project/groovy/src/testFixtures/java/com/github/gmazzo/buildconfig/demos/groovy/BuildConfigBaseTest.java b/demo-project/groovy/src/testFixtures/java/com/github/gmazzo/buildconfig/demos/groovy/BuildConfigBaseTest.java index b89f258..801c9c7 100644 --- a/demo-project/groovy/src/testFixtures/java/com/github/gmazzo/buildconfig/demos/groovy/BuildConfigBaseTest.java +++ b/demo-project/groovy/src/testFixtures/java/com/github/gmazzo/buildconfig/demos/groovy/BuildConfigBaseTest.java @@ -2,6 +2,8 @@ import org.junit.Test; +import java.io.File; +import java.net.URI; import java.util.Arrays; import java.util.HashSet; import java.util.Map; @@ -178,6 +180,10 @@ public void testCustomTypes() { assertEquals(Map.of("a", 1, "b", 2), BuildConfig.MAP_PROVIDER); assertEquals(Map.of("a", 1, "b", 2), BuildConfig.MAP_GENERIC); assertEquals(Map.of("a", 1, "b", 2), BuildConfig.MAP_GENERIC_PROVIDER); + assertEquals(new File("aFile"), BuildConfig.FILE); + assertEquals(new File("aFile"), BuildConfig.FILE_PROVIDER); + assertEquals(URI.create("https://example.io"), BuildConfig.URI); + assertEquals(URI.create("https://example.io"), BuildConfig.URI_PROVIDER); assertEquals(new SomeData("a", 1), BuildConfig.DATA); assertEquals(new SomeData("a", 1), BuildConfig.DATA_PROVIDER); } diff --git a/demo-project/kts-gen-java/build.gradle.kts b/demo-project/kts-gen-java/build.gradle.kts index 5b83eb6..acecb59 100644 --- a/demo-project/kts-gen-java/build.gradle.kts +++ b/demo-project/kts-gen-java/build.gradle.kts @@ -161,6 +161,10 @@ buildConfig { buildConfigField>("MAP_PROVIDER", provider { expression("java.util.Map.of(\"a\", 1, \"b\", 2)") }) buildConfigField>("MAP_GENERIC", expression("java.util.Map.of(\"a\", 1, \"b\", 2)")) buildConfigField>("MAP_GENERIC_PROVIDER", provider { expression("java.util.Map.of(\"a\", 1, \"b\", 2)") }) + buildConfigField("FILE", File("aFile")) + buildConfigField("FILE_PROVIDER", provider { File("aFile") }) + buildConfigField("URI", uri("https://example.io")) + buildConfigField("URI_PROVIDER", provider { uri("https://example.io") }) buildConfigField( "com.github.gmazzo.buildconfig.demos.kts.SomeData", "DATA", diff --git a/demo-project/kts/build.gradle.kts b/demo-project/kts/build.gradle.kts index d6ec977..91a4789 100644 --- a/demo-project/kts/build.gradle.kts +++ b/demo-project/kts/build.gradle.kts @@ -176,6 +176,10 @@ buildConfig { buildConfigField>("MAP_PROVIDER", provider { expression("mapOf(\"a\" to 1, \"b\" to 2)") }) buildConfigField>("MAP_GENERIC", expression("mapOf(\"a\" to 1, \"b\" to 2)")) buildConfigField>("MAP_GENERIC_PROVIDER", provider { expression("mapOf(\"a\" to 1, \"b\" to 2)") }) + buildConfigField("FILE", File("aFile")) + buildConfigField("FILE_PROVIDER", provider { File("aFile") }) + buildConfigField("URI", uri("https://example.io")) + buildConfigField("URI_PROVIDER", provider { uri("https://example.io") }) buildConfigField( "com.github.gmazzo.buildconfig.demos.kts.SomeData", "DATA", diff --git a/plugin/src/main/kotlin/com/github/gmazzo/buildconfig/generators/BuildConfigJavaGenerator.kt b/plugin/src/main/kotlin/com/github/gmazzo/buildconfig/generators/BuildConfigJavaGenerator.kt index 9f38719..4d1b08c 100644 --- a/plugin/src/main/kotlin/com/github/gmazzo/buildconfig/generators/BuildConfigJavaGenerator.kt +++ b/plugin/src/main/kotlin/com/github/gmazzo/buildconfig/generators/BuildConfigJavaGenerator.kt @@ -15,6 +15,8 @@ import com.squareup.javapoet.TypeSpec import com.squareup.javapoet.WildcardTypeName import org.gradle.api.logging.Logging import org.gradle.api.tasks.Input +import java.io.File +import java.net.URI import javax.lang.model.element.Modifier data class BuildConfigJavaGenerator( @@ -122,6 +124,8 @@ data class BuildConfigJavaGenerator( TypeName.LONG -> "\$LL" TypeName.FLOAT -> "\$Lf" STRING -> "\$S" + FILE -> "new java.io.File(\$S)" + URI -> "java.net.URI.create(\$S)" else -> "\$L" } @@ -165,6 +169,8 @@ data class BuildConfigJavaGenerator( private val STRING = ClassName.get(String::class.java) private val LIST = ClassName.get(List::class.java) private val SET = ClassName.get(Set::class.java) + private val FILE = ClassName.get(File::class.java) + private val URI = ClassName.get(URI::class.java) private val GENERIC_LIST = ClassName.get("", "List") private val GENERIC_SET = ClassName.get("", "Set") } diff --git a/plugin/src/main/kotlin/com/github/gmazzo/buildconfig/generators/BuildConfigKotlinGenerator.kt b/plugin/src/main/kotlin/com/github/gmazzo/buildconfig/generators/BuildConfigKotlinGenerator.kt index 85ea8e2..cb54c7a 100644 --- a/plugin/src/main/kotlin/com/github/gmazzo/buildconfig/generators/BuildConfigKotlinGenerator.kt +++ b/plugin/src/main/kotlin/com/github/gmazzo/buildconfig/generators/BuildConfigKotlinGenerator.kt @@ -34,9 +34,12 @@ import com.squareup.kotlinpoet.STAR import com.squareup.kotlinpoet.STRING import com.squareup.kotlinpoet.TypeName import com.squareup.kotlinpoet.TypeSpec +import com.squareup.kotlinpoet.asClassName import com.squareup.kotlinpoet.asTypeName import org.gradle.api.logging.Logging import org.gradle.api.tasks.Input +import java.io.File +import java.net.URI data class BuildConfigKotlinGenerator( @get:Input var topLevelConstants: Boolean = false, @@ -141,6 +144,8 @@ data class BuildConfigKotlinGenerator( LONG -> "%LL" FLOAT -> "%Lf" STRING -> "%S" + FILE -> "java.io.File(%S)" + URI -> "java.net.URI.create(%S)" else -> "%L" } @@ -198,7 +203,9 @@ data class BuildConfigKotlinGenerator( companion object { private val CONST_TYPES = setOf(STRING, BOOLEAN, BYTE, SHORT, INT, LONG, CHAR, FLOAT, DOUBLE) private val GENERIC_LIST = ClassName("", "List") - private val GENERIC_SET = ClassName("", "SET") + private val GENERIC_SET = ClassName("", "Set") + private val FILE = File::class.asClassName() + private val URI = URI::class.asClassName() } } diff --git a/plugin/src/main/kotlin/org/gradle/kotlin/dsl/BuildConfigClassSpecDSL.kt b/plugin/src/main/kotlin/org/gradle/kotlin/dsl/BuildConfigClassSpecDSL.kt index 3edfbed..0a2a7b9 100644 --- a/plugin/src/main/kotlin/org/gradle/kotlin/dsl/BuildConfigClassSpecDSL.kt +++ b/plugin/src/main/kotlin/org/gradle/kotlin/dsl/BuildConfigClassSpecDSL.kt @@ -74,7 +74,7 @@ inline fun BuildConfigClassSpec.buildConfigField( value: List, ) = buildConfigField(name, Action { it.type(typeOf>()) - it.value(if (value is Serializable) value else ArrayList(value)) + it.value(ArrayList(value)) }) @BuildConfigDsl @@ -84,7 +84,7 @@ inline fun BuildConfigClassSpec.buildConfigField( value: Set, ) = buildConfigField(name, Action { it.type(typeOf>()) - it.value(if (value is Serializable) value else LinkedHashSet(value)) + it.value(LinkedHashSet(value)) }) @BuildConfigDsl