mirror of
https://github.com/apple/pkl.git
synced 2026-06-08 14:52:56 +02:00
Change Gradle property to "rename" (#528)
This changes the property to match the name of the CLI flag.
This commit is contained in:
@@ -36,11 +36,11 @@ Example: `generateSpringBootConfig = true` +
|
|||||||
Whether to generate config classes for use with Spring Boot.
|
Whether to generate config classes for use with Spring Boot.
|
||||||
====
|
====
|
||||||
|
|
||||||
.packageMapping: MapProperty<String, String>
|
.renames: MapProperty<String, String>
|
||||||
[%collapsible]
|
[%collapsible]
|
||||||
====
|
====
|
||||||
Default: `[:]` +
|
Default: `[:]` +
|
||||||
Example: `packageMapping = ["foo.": "com.example.foo.", "bar.Config": "com.example.bar.Config"]` +
|
Example: `renames = ["foo.": "com.example.foo.", "bar.Config": "com.example.bar.Config"]` +
|
||||||
Allows to change default class and package names (derived from Pkl module names) in the generated code.
|
Allows to change default class and package names (derived from Pkl module names) in the generated code.
|
||||||
|
|
||||||
When you need the generated class or package names to be different from the default names derived from the Pkl module names, you can define a rename mapping, where the key is the original Pkl module name prefix, and the value is its replacement.
|
When you need the generated class or package names to be different from the default names derived from the Pkl module names, you can define a rename mapping, where the key is the original Pkl module name prefix, and the value is its replacement.
|
||||||
@@ -49,9 +49,9 @@ When you do, the generated code's `package` declarations, class names, as well a
|
|||||||
The prefixes are replaced literally, which means that dots at the end are important.
|
The prefixes are replaced literally, which means that dots at the end are important.
|
||||||
If you want to rename packages only, in most cases, you must ensure that you have an ending dot on both sides of a mapping (except for an empty mapping, if you use it), otherwise you may get unexpected results:
|
If you want to rename packages only, in most cases, you must ensure that you have an ending dot on both sides of a mapping (except for an empty mapping, if you use it), otherwise you may get unexpected results:
|
||||||
|
|
||||||
....
|
----
|
||||||
// Assuming the following mapping configuration:
|
// Assuming the following mapping configuration:
|
||||||
packageMapping = [
|
renames = [
|
||||||
"com.foo.": "x", // Dot on the left only
|
"com.foo.": "x", // Dot on the left only
|
||||||
"org.bar": "y.", // Dot on the right only
|
"org.bar": "y.", // Dot on the right only
|
||||||
"net.baz": "z" // No dots
|
"net.baz": "z" // No dots
|
||||||
@@ -62,13 +62,13 @@ packageMapping = [
|
|||||||
"org.bar.baz" -> "y..baz" // Double dot, invalid name
|
"org.bar.baz" -> "y..baz" // Double dot, invalid name
|
||||||
"net.baz.qux" -> "z.qux" // Looks okay, but...
|
"net.baz.qux" -> "z.qux" // Looks okay, but...
|
||||||
"net.bazqux" -> "zqux" // ...may cut the name in the middle.
|
"net.bazqux" -> "zqux" // ...may cut the name in the middle.
|
||||||
....
|
----
|
||||||
|
|
||||||
When computing the appropriate target name, the longest matching prefix is used:
|
When computing the appropriate target name, the longest matching prefix is used:
|
||||||
|
|
||||||
....
|
----
|
||||||
// Assuming the following mapping configuration:
|
// Assuming the following mapping configuration:
|
||||||
packageMapping = [
|
renames = [
|
||||||
"com.foo.Main": "w.Main",
|
"com.foo.Main": "w.Main",
|
||||||
"com.foo.": "x.",
|
"com.foo.": "x.",
|
||||||
"com.": "y.",
|
"com.": "y.",
|
||||||
@@ -80,7 +80,7 @@ com.foo.Main -> w.Main
|
|||||||
com.foo.bar -> x.bar
|
com.foo.bar -> x.bar
|
||||||
com.baz.qux -> y.baz.qux
|
com.baz.qux -> y.baz.qux
|
||||||
org.foo.bar -> z.org.foo.bar
|
org.foo.bar -> z.org.foo.bar
|
||||||
....
|
----
|
||||||
|
|
||||||
Keys in this mapping can be arbitrary strings, including an empty string.
|
Keys in this mapping can be arbitrary strings, including an empty string.
|
||||||
Values must be valid dot-separated fully qualifed class name prefixes, possibly terminated by a dot.
|
Values must be valid dot-separated fully qualifed class name prefixes, possibly terminated by a dot.
|
||||||
|
|||||||
@@ -412,7 +412,7 @@ public class PklPlugin implements Plugin<Project> {
|
|||||||
task.getOutputDir().set(spec.getOutputDir());
|
task.getOutputDir().set(spec.getOutputDir());
|
||||||
task.getGenerateSpringBootConfig().set(spec.getGenerateSpringBootConfig());
|
task.getGenerateSpringBootConfig().set(spec.getGenerateSpringBootConfig());
|
||||||
task.getImplementSerializable().set(spec.getImplementSerializable());
|
task.getImplementSerializable().set(spec.getImplementSerializable());
|
||||||
task.getPackageMapping().set(spec.getPackageMapping());
|
task.getRenames().set(spec.getRenames());
|
||||||
}
|
}
|
||||||
|
|
||||||
private <T extends BasePklTask, S extends BasePklSpec> void configureBaseTask(T task, S spec) {
|
private <T extends BasePklTask, S extends BasePklSpec> void configureBaseTask(T task, S spec) {
|
||||||
|
|||||||
@@ -32,5 +32,5 @@ public interface CodeGenSpec extends ModulesSpec {
|
|||||||
|
|
||||||
Property<Boolean> getImplementSerializable();
|
Property<Boolean> getImplementSerializable();
|
||||||
|
|
||||||
MapProperty<String, String> getPackageMapping();
|
MapProperty<String, String> getRenames();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,5 +35,5 @@ public abstract class CodeGenTask extends ModulesTask {
|
|||||||
public abstract Property<Boolean> getImplementSerializable();
|
public abstract Property<Boolean> getImplementSerializable();
|
||||||
|
|
||||||
@Input
|
@Input
|
||||||
public abstract MapProperty<String, String> getPackageMapping();
|
public abstract MapProperty<String, String> getRenames();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ public abstract class JavaCodeGenTask extends CodeGenTask {
|
|||||||
getParamsAnnotation().getOrNull(),
|
getParamsAnnotation().getOrNull(),
|
||||||
getNonNullAnnotation().getOrNull(),
|
getNonNullAnnotation().getOrNull(),
|
||||||
getImplementSerializable().get(),
|
getImplementSerializable().get(),
|
||||||
getPackageMapping().get()))
|
getRenames().get()))
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ public abstract class KotlinCodeGenTask extends CodeGenTask {
|
|||||||
getGenerateKdoc().get(),
|
getGenerateKdoc().get(),
|
||||||
getGenerateSpringBootConfig().get(),
|
getGenerateSpringBootConfig().get(),
|
||||||
getImplementSerializable().get(),
|
getImplementSerializable().get(),
|
||||||
getPackageMapping().get()))
|
getRenames().get()))
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ class JavaCodeGeneratorsTest : AbstractTest() {
|
|||||||
paramsAnnotation = "javax.inject.Named"
|
paramsAnnotation = "javax.inject.Named"
|
||||||
nonNullAnnotation = "javax.annotation.Nonnull"
|
nonNullAnnotation = "javax.annotation.Nonnull"
|
||||||
settingsModule = "pkl:settings"
|
settingsModule = "pkl:settings"
|
||||||
packageMapping = [
|
renames = [
|
||||||
'org': 'foo.bar'
|
'org': 'foo.bar'
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -125,7 +125,7 @@ class KotlinCodeGeneratorsTest : AbstractTest() {
|
|||||||
sourceModules = ["mod.pkl"]
|
sourceModules = ["mod.pkl"]
|
||||||
outputDir = file("build/generated")
|
outputDir = file("build/generated")
|
||||||
settingsModule = "pkl:settings"
|
settingsModule = "pkl:settings"
|
||||||
packageMapping = [
|
renames = [
|
||||||
'org.': 'foo.bar.'
|
'org.': 'foo.bar.'
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user