diff --git a/examples/src/bld/java/com/example/SampleBuild.java b/examples/src/bld/java/com/example/SampleBuild.java index d2e3c19..f4f6603 100644 --- a/examples/src/bld/java/com/example/SampleBuild.java +++ b/examples/src/bld/java/com/example/SampleBuild.java @@ -45,8 +45,8 @@ public class SampleBuild extends Project { public void genver() throws Exception { new GeneratedVersionOperation() .fromProject(this) - .projectName("My App") - .classTemplate("my_app_version.txt") +// .projectName("My App") +// .classTemplate("my_app_version.txt") .execute(); } } diff --git a/examples/src/main/java/com/example/GeneratedVersion.java b/examples/src/main/java/com/example/GeneratedVersion.java index a06f874..e8dbf5f 100644 --- a/examples/src/main/java/com/example/GeneratedVersion.java +++ b/examples/src/main/java/com/example/GeneratedVersion.java @@ -1,28 +1,30 @@ -/* - * This file is automatically generated. - * Do not modify! -- ALL CHANGES WILL BE ERASED! - */ - package com.example; import java.util.Date; -/** - * Provides project version information. - */ -public final class GeneratedVersion { - public static final String PROJECT = "Sample"; - public static final Date BUILD_DATE = new Date(1720056110519L); +public final class GeneratedVersion implements Comparable { + public static final Date BUILD_DATE = new Date(1720371304587L); public static final int MAJOR = 1; public static final int MINOR = 0; - public static final int REVISION = 1; + public static final String PROJECT = "My App"; public static final String QUALIFIER = "rc1"; + public static final int REVISION = 1; public static final String VERSION = "1.0.1-rc1"; - /** - * Disables the default constructor. - */ private GeneratedVersion() { - throw new UnsupportedOperationException("Illegal constructor call."); + // no-op } -} + + @Override + public int compareTo(GeneratedVersion other) { + if (MAJOR != other.MAJOR) { + return Integer.compare(MAJOR, other.MAJOR); + } else if (MINOR != other.MINOR) { + return Integer.compare(MINOR, other.MINOR); + } else if (REVISION != other.REVISION) { + return Integer.compare(REVISION, other.REVISION); + } else { + return QUALIFIER.compareTo(other.QUALIFIER); + } + } +} \ No newline at end of file diff --git a/src/bld/java/rife/bld/extension/GeneratedVersionOperationBuild.java b/src/bld/java/rife/bld/extension/GeneratedVersionOperationBuild.java index dfb8b49..ac920e0 100644 --- a/src/bld/java/rife/bld/extension/GeneratedVersionOperationBuild.java +++ b/src/bld/java/rife/bld/extension/GeneratedVersionOperationBuild.java @@ -35,7 +35,7 @@ public class GeneratedVersionOperationBuild extends Project { public GeneratedVersionOperationBuild() { pkg = "rife.bld.extension"; name = "GeneratedVersionOperation"; - version = version(0, 9, 7); + version = version(0, 9, 8, "SNAPSHOT"); javaRelease = 17; @@ -49,7 +49,7 @@ public class GeneratedVersionOperationBuild extends Project { scope(test) .include(dependency("org.junit.jupiter", "junit-jupiter", version(5, 10, 3))) .include(dependency("org.junit.platform", "junit-platform-console-standalone", version(1, 10, 3))) - .include(dependency("org.assertj", "assertj-core", version(3, 26, 0))); + .include(dependency("org.assertj", "assertj-core", version(3, 26, 3))); precompileOperation() .templateTypes(TXT); diff --git a/src/test/java/rife/bld/extension/GeneratedVersionTest.java b/src/test/java/rife/bld/extension/GeneratedVersionTest.java index af7e864..2c2a35f 100644 --- a/src/test/java/rife/bld/extension/GeneratedVersionTest.java +++ b/src/test/java/rife/bld/extension/GeneratedVersionTest.java @@ -16,8 +16,7 @@ package rife.bld.extension; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.*; import rife.bld.BaseProject; import rife.bld.Project; import rife.bld.dependencies.VersionNumber; @@ -39,6 +38,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Erik C. Thauvin * @since 1.0 */ +@TestMethodOrder(MethodOrderer.OrderAnnotation.class) class GeneratedVersionTest { private final BaseProject PROJECT = new Project() { @Override @@ -108,6 +108,7 @@ class GeneratedVersionTest { } @Test + @Order(1) void testBuildTemplate() { var gv = new GeneratedVersion(); gv.setProject(PROJECT); @@ -127,7 +128,7 @@ class GeneratedVersionTest { @Test void testExecute() throws Exception { - var tmpDir = Files.createTempDirectory("bld-generated-version-").toFile(); + var tmpDir = Files.createTempDirectory("bld-generated-version-execute-").toFile(); tmpDir.deleteOnExit(); new GeneratedVersionOperation() @@ -147,7 +148,8 @@ class GeneratedVersionTest { var content = Files.readString(template.toPath()); assertThat(content).contains("class MyVersion") .contains("PROJECT = \"MyExample\";").contains("MAJOR = 2").contains("MINOR = 1") - .contains("REVISION = 3").contains("QUALIFIER = \"\"").contains("private MyVersion"); + .contains("REVISION = 3").contains("QUALIFIER = \"\"").contains("private MyVersion") + .doesNotContain("package"); } @Test @@ -171,8 +173,9 @@ class GeneratedVersionTest { } @Test + @Order(2) void testWriteTemplate() throws IOException { - var tmpDir = Files.createTempDirectory("bld-generated-version-").toFile(); + var tmpDir = Files.createTempDirectory("bld-generated-version-write-").toFile(); tmpDir.deleteOnExit(); var gv = new GeneratedVersion();