From eabca28d38cdb3298a72beea5dd63d5d173b66dc Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Wed, 28 Aug 2024 00:56:00 -0700 Subject: [PATCH] Cleaned up API to match bld operations aand options APIs --- .idea/bld.xml | 6 ++++ examples/lib/bld/bld-wrapper.properties | 2 +- .../java/com/example/GeneratedVersion.java | 2 +- .../GeneratedVersionOperationBuild.java | 2 +- .../extension/GeneratedVersionOperation.java | 30 +++++++++++++++++++ .../bld/extension/GeneratedVersionTest.java | 20 +++++++++++-- 6 files changed, 56 insertions(+), 6 deletions(-) create mode 100644 .idea/bld.xml diff --git a/.idea/bld.xml b/.idea/bld.xml new file mode 100644 index 0000000..6600cee --- /dev/null +++ b/.idea/bld.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/examples/lib/bld/bld-wrapper.properties b/examples/lib/bld/bld-wrapper.properties index ddf7535..538206d 100644 --- a/examples/lib/bld/bld-wrapper.properties +++ b/examples/lib/bld/bld-wrapper.properties @@ -1,6 +1,6 @@ bld.downloadExtensionJavadoc=false bld.downloadExtensionSources=true bld.downloadLocation= -bld.extension-gv=com.uwyn.rife2:bld-generated-version:0.9.8 +bld.extension-gv=com.uwyn.rife2:bld-generated-version:0.9.9-SNAPSHOT bld.repositories=MAVEN_LOCAL,RIFE2_SNAPSHOTS,RIFE2_RELEASES bld.version=2.0.1 diff --git a/examples/src/main/java/com/example/GeneratedVersion.java b/examples/src/main/java/com/example/GeneratedVersion.java index e9a3abe..10ca76f 100644 --- a/examples/src/main/java/com/example/GeneratedVersion.java +++ b/examples/src/main/java/com/example/GeneratedVersion.java @@ -12,7 +12,7 @@ */ public final class GeneratedVersion { public static final String PROJECT = "Sample"; - public static final Date BUILD_DATE = new Date(1722235624114L); + public static final Date BUILD_DATE = new Date(1724831563821L); public static final int MAJOR = 1; public static final int MINOR = 0; public static final int REVISION = 1; diff --git a/src/bld/java/rife/bld/extension/GeneratedVersionOperationBuild.java b/src/bld/java/rife/bld/extension/GeneratedVersionOperationBuild.java index 40ec39d..5a2131c 100644 --- a/src/bld/java/rife/bld/extension/GeneratedVersionOperationBuild.java +++ b/src/bld/java/rife/bld/extension/GeneratedVersionOperationBuild.java @@ -34,7 +34,7 @@ public class GeneratedVersionOperationBuild extends Project { public GeneratedVersionOperationBuild() { pkg = "rife.bld.extension"; name = "GeneratedVersionOperation"; - version = version(0, 9, 8); + version = version(0, 9, 9, "SNAPSHOT"); javaRelease = 17; diff --git a/src/main/java/rife/bld/extension/GeneratedVersionOperation.java b/src/main/java/rife/bld/extension/GeneratedVersionOperation.java index 04fad54..8968413 100644 --- a/src/main/java/rife/bld/extension/GeneratedVersionOperation.java +++ b/src/main/java/rife/bld/extension/GeneratedVersionOperation.java @@ -22,6 +22,7 @@ import rife.bld.operations.exceptions.ExitStatusException; import java.io.File; +import java.nio.file.Path; import java.util.logging.Level; import java.util.logging.Logger; @@ -67,6 +68,16 @@ public GeneratedVersionOperation classTemplate(String template) { return classTemplate(new File(template)); } + /** + * Sets the class template path. + * + * @param template the template path + * @return this operation instance + */ + public GeneratedVersionOperation classTemplate(Path template) { + return classTemplate(template.toFile()); + } + /** * Sets the destination directory. * @@ -88,6 +99,16 @@ public GeneratedVersionOperation directory(String directory) { return directory(new File(directory)); } + /** + * Sets the destination directory. + * + * @param directory the destination directory + * @return this operation instance + */ + public GeneratedVersionOperation directory(Path directory) { + return directory(directory.toFile()); + } + /** * Generates a version data class for this project. */ @@ -140,6 +161,15 @@ public GeneratedVersionOperation fromProject(BaseProject project) { return this; } + /** + * Retrieves the generated version instance. + * + * @return the generated version + */ + public GeneratedVersion generatedVersion() { + return generatedVersion_; + } + /** * Sets the package name. * diff --git a/src/test/java/rife/bld/extension/GeneratedVersionTest.java b/src/test/java/rife/bld/extension/GeneratedVersionTest.java index 7762290..d4334ff 100644 --- a/src/test/java/rife/bld/extension/GeneratedVersionTest.java +++ b/src/test/java/rife/bld/extension/GeneratedVersionTest.java @@ -91,17 +91,16 @@ void testBuildCustomTemplate() { gv.setClassName("MyVersion"); var t = gv.buildTemplate(); - //noinspection TrailingWhitespacesInTextBlock assertThat(t.getContent()).isEqualTo(""" package com.example.my; - + public final class MyVersion { public static final int PROJECT = "My App"; public static final int MAJOR = 2; public static final int MINOR = 1; public static final int REVISION = 3; public static final String QUALIFIER = ""; - + private MyVersion() { // no-op } @@ -127,6 +126,21 @@ void testBuildTemplate() { .contains("private GeneratedVersion"); } + @Test + void testDirectories() { + var foo = new File("foo"); + var bar = new File("bar"); + + var op = new GeneratedVersionOperation().directory(foo); + assertThat(op.generatedVersion().getDirectory()).as("as file").isEqualTo(foo); + + op = op.directory(bar.toPath()); + assertThat(op.generatedVersion().getDirectory()).as("as path").isEqualTo(bar); + + op = op.directory("foo"); + assertThat(op.generatedVersion().getDirectory()).as("as string").isEqualTo(foo); + } + @Test void testExample() throws Exception { var tmpDir = Files.createTempDirectory("bld-generated-version-example-").toFile();