Added ability to the directory and script template using a String
This commit is contained in:
parent
1e90d059cf
commit
1cfa3a712f
7 changed files with 60 additions and 7 deletions
|
@ -36,11 +36,13 @@ public class GeneratedVersionOperationBuild extends Project {
|
|||
public GeneratedVersionOperationBuild() {
|
||||
pkg = "rife.bld.extension";
|
||||
name = "GeneratedVersionOperation";
|
||||
version = version(0, 9, 6);
|
||||
version = version(0, 9, 7, "SNAPSHOT");
|
||||
|
||||
javaRelease = 17;
|
||||
|
||||
downloadSources = true;
|
||||
autoDownloadPurge = true;
|
||||
|
||||
repositories = List.of(MAVEN_CENTRAL, RIFE2_RELEASES);
|
||||
|
||||
scope(compile)
|
||||
|
|
|
@ -175,6 +175,16 @@ public class GeneratedVersionOperation extends AbstractOperation<GeneratedVersio
|
|||
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.
|
||||
*
|
||||
|
@ -186,6 +196,16 @@ public class GeneratedVersionOperation extends AbstractOperation<GeneratedVersio
|
|||
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.
|
||||
*/
|
||||
|
|
|
@ -75,6 +75,7 @@ class GeneratedVersionTest {
|
|||
gv.setClassName("MyVersion");
|
||||
|
||||
var t = GeneratedVersionOperation.buildTemplate(gv);
|
||||
//noinspection TrailingWhitespacesInTextBlock
|
||||
assertThat(t.getContent()).isEqualTo("""
|
||||
package com.example.my;
|
||||
|
||||
|
@ -110,6 +111,25 @@ class GeneratedVersionTest {
|
|||
.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
|
||||
void testWriteTemplate() throws IOException {
|
||||
var tmpDir = Files.createTempDirectory("bld-generated-version-").toFile();
|
||||
|
|
11
src/test/resources/myversion_test.txt
Normal file
11
src/test/resources/myversion_test.txt
Normal 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
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue