Added directory and extension options
This commit is contained in:
parent
b56f684ac8
commit
f8003c72f0
10 changed files with 130 additions and 54 deletions
3
.idea/libraries/bld.xml
generated
3
.idea/libraries/bld.xml
generated
|
@ -6,6 +6,7 @@
|
||||||
</CLASSES>
|
</CLASSES>
|
||||||
<JAVADOC />
|
<JAVADOC />
|
||||||
<SOURCES>
|
<SOURCES>
|
||||||
|
<root url="file://$PROJECT_DIR$/lib/bld" />
|
||||||
<root url="jar://$USER_HOME$/.bld/dist/bld-1.7.5-sources.jar!/" />
|
<root url="jar://$USER_HOME$/.bld/dist/bld-1.7.5-sources.jar!/" />
|
||||||
</SOURCES>
|
</SOURCES>
|
||||||
<excluded>
|
<excluded>
|
||||||
|
@ -14,4 +15,4 @@
|
||||||
<jarDirectory url="file://$PROJECT_DIR$/lib/bld" recursive="false" />
|
<jarDirectory url="file://$PROJECT_DIR$/lib/bld" recursive="false" />
|
||||||
<jarDirectory url="file://$PROJECT_DIR$/lib/bld" recursive="false" type="SOURCES" />
|
<jarDirectory url="file://$PROJECT_DIR$/lib/bld" recursive="false" type="SOURCES" />
|
||||||
</library>
|
</library>
|
||||||
</component>
|
</component>
|
||||||
|
|
6
.idea/misc.xml
generated
6
.idea/misc.xml
generated
|
@ -13,6 +13,12 @@
|
||||||
<option name="customRuleSets">
|
<option name="customRuleSets">
|
||||||
<list>
|
<list>
|
||||||
<option value="$PROJECT_DIR$/config/pmd.xml" />
|
<option value="$PROJECT_DIR$/config/pmd.xml" />
|
||||||
|
<option value="K:\java\semver\config\pmd.xml" />
|
||||||
|
<option value="$PROJECT_DIR$/../bld-pitest/config/pmd.xml" />
|
||||||
|
<option value="$PROJECT_DIR$/../bld-jacoco-report/config/pmd.xml" />
|
||||||
|
<option value="$PROJECT_DIR$/../bld-checkstyle/config/pmd.xml" />
|
||||||
|
<option value="$PROJECT_DIR$/../bld-exec/config/pmd.xml" />
|
||||||
|
<option value="$PROJECT_DIR$/../bld-testng/config/pmd.xml" />
|
||||||
</list>
|
</list>
|
||||||
</option>
|
</option>
|
||||||
<option name="skipTestSources" value="false" />
|
<option name="skipTestSources" value="false" />
|
||||||
|
|
3
examples/.idea/libraries/bld.xml
generated
3
examples/.idea/libraries/bld.xml
generated
|
@ -6,6 +6,7 @@
|
||||||
</CLASSES>
|
</CLASSES>
|
||||||
<JAVADOC />
|
<JAVADOC />
|
||||||
<SOURCES>
|
<SOURCES>
|
||||||
|
<root url="file://$PROJECT_DIR$/lib/bld" />
|
||||||
<root url="jar://$USER_HOME$/.bld/dist/bld-1.7.5-sources.jar!/" />
|
<root url="jar://$USER_HOME$/.bld/dist/bld-1.7.5-sources.jar!/" />
|
||||||
</SOURCES>
|
</SOURCES>
|
||||||
<excluded>
|
<excluded>
|
||||||
|
@ -14,4 +15,4 @@
|
||||||
<jarDirectory url="file://$PROJECT_DIR$/lib/bld" recursive="false" />
|
<jarDirectory url="file://$PROJECT_DIR$/lib/bld" recursive="false" />
|
||||||
<jarDirectory url="file://$PROJECT_DIR$/lib/bld" recursive="false" type="SOURCES" />
|
<jarDirectory url="file://$PROJECT_DIR$/lib/bld" recursive="false" type="SOURCES" />
|
||||||
</library>
|
</library>
|
||||||
</component>
|
</component>
|
||||||
|
|
5
examples/README.md
Normal file
5
examples/README.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
# Compile and Run Example
|
||||||
|
|
||||||
|
```plain
|
||||||
|
./bld compile run
|
||||||
|
```
|
|
@ -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.2
|
bld.extensions=com.uwyn.rife2:bld-generated-version:0.9.3-SNAPSHOT
|
||||||
bld.repositories=MAVEN_LOCAL,RIFE2_SNAPSHOTS,RIFE2_RELEASES
|
bld.repositories=MAVEN_LOCAL,RIFE2_SNAPSHOTS,RIFE2_RELEASES
|
||||||
bld.downloadLocation=
|
bld.downloadLocation=
|
||||||
bld.version=1.7.5
|
bld.version=1.7.5
|
||||||
|
|
|
@ -28,8 +28,8 @@ public class SampleBuild extends Project {
|
||||||
downloadSources = true;
|
downloadSources = true;
|
||||||
repositories = List.of(MAVEN_CENTRAL, RIFE2_RELEASES);
|
repositories = List.of(MAVEN_CENTRAL, RIFE2_RELEASES);
|
||||||
scope(test)
|
scope(test)
|
||||||
.include(dependency("org.junit.jupiter", "junit-jupiter", version(5, 10, 0)))
|
.include(dependency("org.junit.jupiter", "junit-jupiter", version(5, 10, 1)))
|
||||||
.include(dependency("org.junit.platform", "junit-platform-console-standalone", version(1, 10, 0)));
|
.include(dependency("org.junit.platform", "junit-platform-console-standalone", version(1, 10, 1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
@ -50,4 +50,4 @@ public class SampleBuild extends Project {
|
||||||
// .classTemplate(new File(workDirectory, "myversion.txt"))
|
// .classTemplate(new File(workDirectory, "myversion.txt"))
|
||||||
.execute();
|
.execute();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@ package rife.bld.extension;
|
||||||
|
|
||||||
import rife.bld.BuildCommand;
|
import rife.bld.BuildCommand;
|
||||||
import rife.bld.Project;
|
import rife.bld.Project;
|
||||||
|
import rife.bld.operations.JarOperation;
|
||||||
import rife.bld.publish.PublishDeveloper;
|
import rife.bld.publish.PublishDeveloper;
|
||||||
import rife.bld.publish.PublishLicense;
|
import rife.bld.publish.PublishLicense;
|
||||||
import rife.bld.publish.PublishScm;
|
import rife.bld.publish.PublishScm;
|
||||||
|
@ -35,7 +36,7 @@ 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, 2);
|
version = version(0, 9, 3, "SNAPSHOT");
|
||||||
|
|
||||||
javaRelease = 17;
|
javaRelease = 17;
|
||||||
downloadSources = true;
|
downloadSources = true;
|
||||||
|
@ -45,8 +46,8 @@ public class GeneratedVersionOperationBuild extends Project {
|
||||||
scope(compile)
|
scope(compile)
|
||||||
.include(dependency("com.uwyn.rife2", "bld", version(1, 7, 5)));
|
.include(dependency("com.uwyn.rife2", "bld", version(1, 7, 5)));
|
||||||
scope(test)
|
scope(test)
|
||||||
.include(dependency("org.junit.jupiter", "junit-jupiter", version(5, 10, 0)))
|
.include(dependency("org.junit.jupiter", "junit-jupiter", version(5, 10, 1)))
|
||||||
.include(dependency("org.junit.platform", "junit-platform-console-standalone", version(1, 10, 0)))
|
.include(dependency("org.junit.platform", "junit-platform-console-standalone", version(1, 10, 1)))
|
||||||
.include(dependency("org.assertj", "assertj-core", version(3, 24, 2)));
|
.include(dependency("org.assertj", "assertj-core", version(3, 24, 2)));
|
||||||
|
|
||||||
precompileOperation()
|
precompileOperation()
|
||||||
|
@ -54,6 +55,7 @@ public class GeneratedVersionOperationBuild extends Project {
|
||||||
|
|
||||||
javadocOperation()
|
javadocOperation()
|
||||||
.javadocOptions()
|
.javadocOptions()
|
||||||
|
.author()
|
||||||
.docLint(NO_MISSING)
|
.docLint(NO_MISSING)
|
||||||
.link("https://rife2.github.io/bld/")
|
.link("https://rife2.github.io/bld/")
|
||||||
.link("https://rife2.github.io/rife2/")
|
.link("https://rife2.github.io/rife2/")
|
||||||
|
|
|
@ -30,6 +30,8 @@ import java.io.File;
|
||||||
public class GeneratedVersion {
|
public class GeneratedVersion {
|
||||||
private File classFile;
|
private File classFile;
|
||||||
private String className;
|
private String className;
|
||||||
|
private File directory;
|
||||||
|
private String extension = ".java";
|
||||||
private String packageName;
|
private String packageName;
|
||||||
private BaseProject project;
|
private BaseProject project;
|
||||||
private String projectName;
|
private String projectName;
|
||||||
|
@ -42,13 +44,6 @@ public class GeneratedVersion {
|
||||||
return classFile;
|
return classFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the class file.
|
|
||||||
*/
|
|
||||||
public void setClassFile(File classFile) {
|
|
||||||
this.classFile = classFile;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the class name.
|
* Returns the class name.
|
||||||
*/
|
*/
|
||||||
|
@ -57,10 +52,17 @@ public class GeneratedVersion {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the class name.
|
* Returns the destination directory.
|
||||||
*/
|
*/
|
||||||
public void setClassName(String className) {
|
public File getDirectory() {
|
||||||
this.className = className;
|
return directory;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the file extension.
|
||||||
|
*/
|
||||||
|
public String getExtension() {
|
||||||
|
return extension;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -70,13 +72,6 @@ public class GeneratedVersion {
|
||||||
return packageName;
|
return packageName;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the package name.
|
|
||||||
*/
|
|
||||||
public void setPackageName(String packageName) {
|
|
||||||
this.packageName = packageName;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the project.
|
* Returns the project.
|
||||||
*/
|
*/
|
||||||
|
@ -84,13 +79,6 @@ public class GeneratedVersion {
|
||||||
return project;
|
return project;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the project.
|
|
||||||
*/
|
|
||||||
public void setProject(BaseProject project) {
|
|
||||||
this.project = project;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the project name.
|
* Returns the project name.
|
||||||
*/
|
*/
|
||||||
|
@ -98,13 +86,6 @@ public class GeneratedVersion {
|
||||||
return projectName;
|
return projectName;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the project name.
|
|
||||||
*/
|
|
||||||
public void setProjectName(String projectName) {
|
|
||||||
this.projectName = projectName;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the template.
|
* Returns the template.
|
||||||
*/
|
*/
|
||||||
|
@ -112,6 +93,55 @@ public class GeneratedVersion {
|
||||||
return template;
|
return template;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the class file.
|
||||||
|
*/
|
||||||
|
public void setClassFile(File classFile) {
|
||||||
|
this.classFile = classFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the class name.
|
||||||
|
*/
|
||||||
|
public void setClassName(String className) {
|
||||||
|
this.className = className;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the destination directory.
|
||||||
|
*/
|
||||||
|
public void setDirectory(File directory) {
|
||||||
|
this.directory = directory;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the file extension. (e.g. {@code .java}
|
||||||
|
*/
|
||||||
|
public void setExtension(String extension) {
|
||||||
|
this.extension = extension;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the package name.
|
||||||
|
*/
|
||||||
|
public void setPackageName(String packageName) {
|
||||||
|
this.packageName = packageName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the project.
|
||||||
|
*/
|
||||||
|
public void setProject(BaseProject project) {
|
||||||
|
this.project = project;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the project name.
|
||||||
|
*/
|
||||||
|
public void setProjectName(String projectName) {
|
||||||
|
this.projectName = projectName;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the template file.
|
* Sets the template file.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -115,12 +115,13 @@ public class GeneratedVersionOperation extends AbstractOperation<GeneratedVersio
|
||||||
/**
|
/**
|
||||||
* Writes the project version class in the given directory.
|
* Writes the project version class in the given directory.
|
||||||
*/
|
*/
|
||||||
public static void writeTemplate(Template template, File directory, GeneratedVersion gv) {
|
public static void writeTemplate(Template template, GeneratedVersion gv) {
|
||||||
if (gv.getPackageName() != null) {
|
if (gv.getPackageName() != null) {
|
||||||
gv.setClassFile(Path.of(directory.getAbsolutePath(),
|
gv.setClassFile(Path.of(gv.getDirectory().getAbsolutePath(),
|
||||||
gv.getPackageName().replace(".", File.separator), gv.getClassName() + ".java").toFile());
|
gv.getPackageName().replace(".", File.separator), gv.getClassName()
|
||||||
|
+ gv.getExtension()).toFile());
|
||||||
} else {
|
} else {
|
||||||
gv.setClassFile(Path.of(directory.getAbsolutePath(), gv.getClassName() + ".java").toFile());
|
gv.setClassFile(Path.of(gv.getDirectory().getAbsolutePath(), gv.getClassName() + ".java").toFile());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!gv.getClassFile().getParentFile().exists()) {
|
if (!gv.getClassFile().getParentFile().exists()) {
|
||||||
|
@ -135,8 +136,8 @@ public class GeneratedVersionOperation extends AbstractOperation<GeneratedVersio
|
||||||
var updated = gv.getClassFile().exists();
|
var updated = gv.getClassFile().exists();
|
||||||
FileUtils.writeString(template.getContent(), gv.getClassFile());
|
FileUtils.writeString(template.getContent(), gv.getClassFile());
|
||||||
if (LOGGER.isLoggable(Level.INFO)) {
|
if (LOGGER.isLoggable(Level.INFO)) {
|
||||||
LOGGER.log(Level.INFO, "Generated version class has been {0} to {1}: {2}",
|
LOGGER.log(Level.INFO, "Generated version ({0}) class has been {1}: {2}",
|
||||||
new String[]{updated ? "updated" : "created", gv.getProject().version().toString(),
|
new String[]{gv.getProject().version().toString(), updated ? "updated" : "created",
|
||||||
gv.getClassFile().toString()});
|
gv.getClassFile().toString()});
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
@ -162,6 +163,14 @@ public class GeneratedVersionOperation extends AbstractOperation<GeneratedVersio
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the destination directory.
|
||||||
|
*/
|
||||||
|
public GeneratedVersionOperation directory(File directory) {
|
||||||
|
generatedVersion.setDirectory(directory);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates a version data class for this project.
|
* Generates a version data class for this project.
|
||||||
*/
|
*/
|
||||||
|
@ -172,7 +181,15 @@ public class GeneratedVersionOperation extends AbstractOperation<GeneratedVersio
|
||||||
}
|
}
|
||||||
|
|
||||||
var template = buildTemplate(generatedVersion);
|
var template = buildTemplate(generatedVersion);
|
||||||
writeTemplate(template, generatedVersion.getProject().srcMainJavaDirectory(), generatedVersion);
|
writeTemplate(template, generatedVersion);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the file extension. (e.g. {@code .java})
|
||||||
|
*/
|
||||||
|
public GeneratedVersionOperation extension(String extension) {
|
||||||
|
generatedVersion.setExtension(extension);
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -180,6 +197,7 @@ public class GeneratedVersionOperation extends AbstractOperation<GeneratedVersio
|
||||||
*/
|
*/
|
||||||
public GeneratedVersionOperation fromProject(BaseProject project) {
|
public GeneratedVersionOperation fromProject(BaseProject project) {
|
||||||
generatedVersion.setProject(project);
|
generatedVersion.setProject(project);
|
||||||
|
generatedVersion.setDirectory(project.srcMainJavaDirectory());
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -75,10 +75,21 @@ class GeneratedVersionTest {
|
||||||
gv.setClassName("MyVersion");
|
gv.setClassName("MyVersion");
|
||||||
|
|
||||||
var t = GeneratedVersionOperation.buildTemplate(gv);
|
var t = GeneratedVersionOperation.buildTemplate(gv);
|
||||||
|
assertThat(t.getContent()).isEqualTo("""
|
||||||
assertThat(t.getContent()).contains("package com.example.my;").contains("class MyVersion")
|
package com.example.my;
|
||||||
.contains("MAJOR = 2").contains("MINOR = 1").contains("REVISION = 3").contains("QUALIFIER = \"\"")
|
|
||||||
.contains("private MyVersion").contains("PROJECT = \"My App\"");
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
""");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -101,13 +112,15 @@ class GeneratedVersionTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testWriteTemplate() throws IOException {
|
void testWriteTemplate() throws IOException {
|
||||||
|
var tmpDir = Files.createTempDirectory("bldGeneratedVersion").toFile();
|
||||||
var gv = new GeneratedVersion();
|
var gv = new GeneratedVersion();
|
||||||
|
|
||||||
gv.setProject(PROJECT);
|
gv.setProject(PROJECT);
|
||||||
|
gv.setDirectory(tmpDir);
|
||||||
|
|
||||||
var t = GeneratedVersionOperation.buildTemplate(gv);
|
var t = GeneratedVersionOperation.buildTemplate(gv);
|
||||||
|
|
||||||
var tmpDir = Files.createTempDirectory("bldGeneratedVersion").toFile();
|
GeneratedVersionOperation.writeTemplate(t, gv);
|
||||||
|
|
||||||
GeneratedVersionOperation.writeTemplate(t, tmpDir, gv);
|
|
||||||
|
|
||||||
assertThat(gv.getClassFile()).exists();
|
assertThat(gv.getClassFile()).exists();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue