Revert "Add setting for Kotlin package to codegen (#194)" (#271)

This reverts commit 7f404fff49.

The package is derived from the module name.
Having `module com.example.Foo` in Pkl
will create Kotlin `package com.example`.

Eventually, we may want to introduce a way to map
Pkl names to package names that provides finer
controls to the code generator.
This commit is contained in:
Daniel Chao
2024-03-04 07:51:39 -08:00
committed by GitHub
parent 4f3858aaaf
commit 11f07d1ce8
7 changed files with 8 additions and 145 deletions
@@ -196,15 +196,12 @@ public class PklPlugin implements Plugin<Project> {
configureCodeGenSpec(spec);
spec.getGenerateKdoc().convention(false);
spec.getKotlinPackage().convention("");
createModulesTask(KotlinCodeGenTask.class, spec)
.configure(
task -> {
configureCodeGenTask(task, spec);
task.getGenerateKdoc().set(spec.getGenerateKdoc());
task.getIndent().set(spec.getIndent());
task.getKotlinPackage().set(spec.getKotlinPackage());
});
});
@@ -19,9 +19,5 @@ import org.gradle.api.provider.Property;
/** Configuration options for Kotlin code generators. Documented in user manual. */
public interface KotlinCodeGenSpec extends CodeGenSpec {
Property<String> getIndent();
Property<String> getKotlinPackage();
Property<Boolean> getGenerateKdoc();
}
@@ -25,9 +25,6 @@ public abstract class KotlinCodeGenTask extends CodeGenTask {
@Input
public abstract Property<Boolean> getGenerateKdoc();
@Input
public abstract Property<String> getKotlinPackage();
@Override
protected void doRunTask() {
//noinspection ResultOfMethodCallIgnored
@@ -38,7 +35,6 @@ public abstract class KotlinCodeGenTask extends CodeGenTask {
getCliBaseOptions(),
getProject().file(getOutputDir()).toPath(),
getIndent().get(),
getKotlinPackage().get(),
getGenerateKdoc().get(),
getGenerateSpringBootConfig().get(),
getImplementSerializable().get()))
@@ -65,22 +65,7 @@ class KotlinCodeGeneratorsTest : AbstractTest() {
assertThat(personClassFile).exists()
assertThat(addressClassFile).exists()
}
@Test
fun `compile generated code with custom kotlin package`() {
writeBuildFile(kotlinPackage = "my.cool.pkl.pkg")
writePklFile()
runTask("compileKotlin")
val classesDir = testProjectDir.resolve("build/classes/kotlin/main")
val moduleClassFile = classesDir.resolve("my/cool/pkl/pkg/org/Mod.class")
val personClassFile = classesDir.resolve("my/cool/pkl/pkg/org/Mod\$Person.class")
val addressClassFile = classesDir.resolve("my/cool/pkl/pkg/org/Mod\$Address.class")
assertThat(moduleClassFile).exists()
assertThat(personClassFile).exists()
assertThat(addressClassFile).exists()
}
@Test
fun `no source modules`() {
writeFile(
@@ -103,7 +88,7 @@ class KotlinCodeGeneratorsTest : AbstractTest() {
assertThat(result.output).contains("No source modules specified.")
}
private fun writeBuildFile(kotlinPackage: String? = null) {
private fun writeBuildFile() {
val kotlinVersion = "1.6.0"
writeFile(
@@ -140,7 +125,6 @@ class KotlinCodeGeneratorsTest : AbstractTest() {
sourceModules = ["mod.pkl"]
outputDir = file("build/generated")
settingsModule = "pkl:settings"
${kotlinPackage?.let { "kotlinPackage = \"$it\"" } ?: ""}
}
}
}