Added custom template example

This commit is contained in:
Erik C. Thauvin 2023-04-29 14:00:59 -07:00
parent 7b7ce43626
commit 2fa5864c21

View file

@ -56,13 +56,37 @@ public final class {{v className/}} {
You can specified your own template using some or all of the template value tags, as follows: You can specified your own template using some or all of the template value tags, as follows:
```java ```java
@BuildCommand(summary = "Generates version class") @BuildCommand(summary = "Generates MyAppVersion class")
public void genver() throws Exception { public void genver() throws Exception {
new GeneratedVersionOperation() new GeneratedVersionOperation()
.fromProject(this) .fromProject(this)
.projectName("My App")
.packageName("com.example.myapp")
.className("MyAppVersion")
.classTemplate(new File(workDirectory, "myversion.txt")) .classTemplate(new File(workDirectory, "myversion.txt"))
.execute(); .execute();
} }
``` ```
```java
// myversion.txt
package {{v packageName/}};
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
public final class {{v className/}} {
public static final String PROJECT = "{{v project/}}";
public static final LocalDateTime BUILD_DATE = Instant.ofEpochMilli({{v epoch/}}L)
.atZone(ZoneId.systemDefault()).toLocalDateTime();
public static final String VERSION = "{{v version/}}";
private {{v className/}}() {
// no-op
}
}
```
Please check the [GeneratedVersionOperation documentation](https://rife2.github.io/bld-generated-version/rife/bld/extension/GeneratedVersionOperation.html#method-summary) for all available configuration options. Please check the [GeneratedVersionOperation documentation](https://rife2.github.io/bld-generated-version/rife/bld/extension/GeneratedVersionOperation.html#method-summary) for all available configuration options.