Added ability to the directory and script template using a String

This commit is contained in:
Erik C. Thauvin 2024-06-22 20:15:40 -07:00
parent 1e90d059cf
commit 1cfa3a712f
Signed by: erik
GPG key ID: 776702A6A2DA330E
7 changed files with 60 additions and 7 deletions

View file

@ -1,6 +1,6 @@
bld.downloadExtensionJavadoc=false bld.downloadExtensionJavadoc=false
bld.downloadExtensionSources=true bld.downloadExtensionSources=true
bld.extensions=com.uwyn.rife2:bld-generated-version:0.9.6
bld.repositories=MAVEN_LOCAL,RIFE2_SNAPSHOTS,RIFE2_RELEASES
bld.downloadLocation= bld.downloadLocation=
bld.extension-gv=com.uwyn.rife2:bld-generated-version:0.9.7-SNAPSHOT
bld.repositories=MAVEN_LOCAL,RIFE2_SNAPSHOTS,RIFE2_RELEASES
bld.version=1.9.1 bld.version=1.9.1

View file

@ -12,7 +12,7 @@ import java.util.Date;
*/ */
public final class GeneratedVersion { public final class GeneratedVersion {
public static final String PROJECT = "Sample"; public static final String PROJECT = "Sample";
public static final Date BUILD_DATE = new Date(1713398927971L); public static final Date BUILD_DATE = new Date(1719112298450L);
public static final int MAJOR = 1; public static final int MAJOR = 1;
public static final int MINOR = 0; public static final int MINOR = 0;
public static final int REVISION = 1; public static final int REVISION = 1;

View file

@ -1,7 +1,7 @@
bld.downloadExtensionJavadoc=false bld.downloadExtensionJavadoc=false
bld.downloadExtensionSources=true bld.downloadExtensionSources=true
bld.extension-pmd=com.uwyn.rife2:bld-pmd:0.9.9
bld.extension-jacoco=com.uwyn.rife2:bld-jacoco-report:0.9.5
bld.repositories=MAVEN_CENTRAL,MAVEN_LOCAL,RIFE2_SNAPSHOTS,RIFE2_RELEASES
bld.downloadLocation= bld.downloadLocation=
bld.extension-jacoco=com.uwyn.rife2:bld-jacoco-report:0.9.5
bld.extension-pmd=com.uwyn.rife2:bld-pmd:1.1.0
bld.repositories=MAVEN_CENTRAL,MAVEN_LOCAL,RIFE2_SNAPSHOTS,RIFE2_RELEASES
bld.version=1.9.1 bld.version=1.9.1

View file

@ -36,11 +36,13 @@ public class GeneratedVersionOperationBuild extends Project {
public GeneratedVersionOperationBuild() { public GeneratedVersionOperationBuild() {
pkg = "rife.bld.extension"; pkg = "rife.bld.extension";
name = "GeneratedVersionOperation"; name = "GeneratedVersionOperation";
version = version(0, 9, 6); version = version(0, 9, 7, "SNAPSHOT");
javaRelease = 17; javaRelease = 17;
downloadSources = true; downloadSources = true;
autoDownloadPurge = true; autoDownloadPurge = true;
repositories = List.of(MAVEN_CENTRAL, RIFE2_RELEASES); repositories = List.of(MAVEN_CENTRAL, RIFE2_RELEASES);
scope(compile) scope(compile)

View file

@ -175,6 +175,16 @@ public class GeneratedVersionOperation extends AbstractOperation<GeneratedVersio
return this; return this;
} }
/**
* Sets the class template path.
*
* @param template the template path
* @return this operation instance
*/
public GeneratedVersionOperation classTemplate(String template) {
return classTemplate(new File(template));
}
/** /**
* Sets the destination directory. * Sets the destination directory.
* *
@ -186,6 +196,16 @@ public class GeneratedVersionOperation extends AbstractOperation<GeneratedVersio
return this; return this;
} }
/**
* Sets the destination directory.
*
* @param directory the destination directory
* @return this operation instance
*/
public GeneratedVersionOperation directory(String directory) {
return directory(new File(directory));
}
/** /**
* Generates a version data class for this project. * Generates a version data class for this project.
*/ */

View file

@ -75,6 +75,7 @@ class GeneratedVersionTest {
gv.setClassName("MyVersion"); gv.setClassName("MyVersion");
var t = GeneratedVersionOperation.buildTemplate(gv); var t = GeneratedVersionOperation.buildTemplate(gv);
//noinspection TrailingWhitespacesInTextBlock
assertThat(t.getContent()).isEqualTo(""" assertThat(t.getContent()).isEqualTo("""
package com.example.my; package com.example.my;
@ -110,6 +111,25 @@ class GeneratedVersionTest {
.contains("private GeneratedVersion"); .contains("private GeneratedVersion");
} }
@Test
void testExecute() throws IOException {
var tmpDir = Files.createTempDirectory("bld-generated-version-").toFile();
tmpDir.deleteOnExit();
new GeneratedVersionOperation()
.fromProject(PROJECT)
.directory(tmpDir.getAbsolutePath())
.extension(".java")
.classTemplate("src/test/resources/myversion_test.txt")
.packageName("")
.className("MyVersion")
.execute();
deleteOnExit(tmpDir);
assertThat(new File(tmpDir, "MyVersion.java")).exists();
}
@Test @Test
void testWriteTemplate() throws IOException { void testWriteTemplate() throws IOException {
var tmpDir = Files.createTempDirectory("bld-generated-version-").toFile(); var tmpDir = Files.createTempDirectory("bld-generated-version-").toFile();

View file

@ -0,0 +1,11 @@
public final class {{v className/}} {
public static final int PROJECT = "{{v project/}}";
public static final int MAJOR = {{v major/}};
public static final int MINOR = {{v minor/}};
public static final int REVISION = {{v revision/}};
public static final String QUALIFIER = "{{v qualifier/}}";
private {{v className/}}() {
// no-op
}
}