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