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
|
@ -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
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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)
|
||||||
|
|
|
@ -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.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -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();
|
||||||
|
|
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