mirror of
https://github.com/apple/pkl.git
synced 2026-07-10 15:12:43 +02:00
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:
@@ -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\"" } ?: ""}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user