Customizable record builders
This commit is contained in:
parent
8a9122447d
commit
1a90b38ff0
@ -21,6 +21,9 @@ public class MavenPlugin extends AbstractMojo {
|
||||
@Parameter( required = true)
|
||||
private String basePackageName;
|
||||
|
||||
@Parameter( required = true, defaultValue = "false")
|
||||
private String useRecordBuilder;
|
||||
|
||||
/**
|
||||
* @parameter default-value="${project}"
|
||||
* @required
|
||||
@ -38,7 +41,7 @@ public class MavenPlugin extends AbstractMojo {
|
||||
|
||||
Path outPath = genRecordsPath.resolve("java");
|
||||
this.project.addCompileSourceRoot(outPath.toString());
|
||||
sourcesGenerator.generateSources(basePackageName, outPath);
|
||||
sourcesGenerator.generateSources(basePackageName, outPath, Boolean.parseBoolean(useRecordBuilder));
|
||||
} catch (IOException e) {
|
||||
throw new MojoExecutionException("Exception while generating classes", e);
|
||||
}
|
||||
|
@ -93,8 +93,9 @@ public class SourcesGenerator {
|
||||
/**
|
||||
* @param basePackageName org.example
|
||||
* @param outPath path/to/output
|
||||
* @param useRecordBuilders if true, the data will have @RecordBuilder annotation
|
||||
*/
|
||||
public void generateSources(String basePackageName, Path outPath) throws IOException {
|
||||
public void generateSources(String basePackageName, Path outPath, boolean useRecordBuilders) throws IOException {
|
||||
|
||||
// Fix the configuration
|
||||
for (Entry<String, InterfaceDataConfiguration> interfacesDatum : configuration.interfacesData.entrySet()) {
|
||||
@ -2117,7 +2118,9 @@ public class SourcesGenerator {
|
||||
typeClass.addModifiers(Modifier.STATIC);
|
||||
typeClass.addModifiers(Modifier.FINAL);
|
||||
typeClass.addSuperinterface(ClassName.get(joinPackage(versionPackage, "data"), "IBasicType"));
|
||||
if (nextVersion.isEmpty() && useRecordBuilders) {
|
||||
typeClass.addAnnotation(RecordBuilder.class);
|
||||
}
|
||||
var getBasicTypeMethod = MethodSpec
|
||||
.methodBuilder("getBasicType$")
|
||||
.addModifiers(Modifier.PUBLIC)
|
||||
|
@ -7,6 +7,6 @@ public class Standalone {
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
SourcesGenerator sourcesGenerator = SourcesGenerator.load(Paths.get(args[0]));
|
||||
sourcesGenerator.generateSources(args[1], Paths.get(args[2]));
|
||||
sourcesGenerator.generateSources(args[1], Paths.get(args[2]), Boolean.parseBoolean(args[3]));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user