Bugfix
This commit is contained in:
parent
8f8242c0f3
commit
a0eb0b2f8e
@ -27,6 +27,7 @@ public abstract class ClassGenerator {
|
||||
protected final String basePackageName;
|
||||
private final Path outPath;
|
||||
protected final boolean deepCheckBeforeCreatingNewEqualInstances;
|
||||
protected final boolean useRecordBuilders;
|
||||
|
||||
public ClassGenerator(ClassGeneratorParams params) {
|
||||
this.generatedFilesToDelete = params.generatedFilesToDelete;
|
||||
@ -34,6 +35,7 @@ public abstract class ClassGenerator {
|
||||
this.basePackageName = params.basePackageName;
|
||||
this.outPath = params.outPath;
|
||||
this.deepCheckBeforeCreatingNewEqualInstances = params.deepCheckBeforeCreatingNewEqualInstances;
|
||||
this.useRecordBuilders = params.useRecordBuilders;
|
||||
}
|
||||
|
||||
public void run() throws IOException {
|
||||
@ -83,5 +85,6 @@ public abstract class ClassGenerator {
|
||||
DataModel dataModel,
|
||||
String basePackageName,
|
||||
Path outPath,
|
||||
boolean deepCheckBeforeCreatingNewEqualInstances) {}
|
||||
boolean deepCheckBeforeCreatingNewEqualInstances,
|
||||
boolean useRecordBuilders) {}
|
||||
}
|
||||
|
@ -113,14 +113,16 @@ public class SourcesGenerator {
|
||||
var curHash = dataModel.computeHash();
|
||||
if (Files.isRegularFile(hashPath) && Files.isReadable(hashPath)) {
|
||||
var lines = Files.readAllLines(hashPath, StandardCharsets.UTF_8);
|
||||
if (lines.size() >= 3) {
|
||||
if (lines.size() >= 4) {
|
||||
var prevBasePackageName = lines.get(0);
|
||||
var prevRecordBuilders = lines.get(1);
|
||||
var prevHash = lines.get(2);
|
||||
var prevDeepCheckBeforeCreatingNewEqualInstances = lines.get(3);
|
||||
|
||||
if (!force
|
||||
&& prevBasePackageName.equals(basePackageName)
|
||||
&& (prevRecordBuilders.equalsIgnoreCase("true") == useRecordBuilders)
|
||||
&& (prevRecordBuilders.equalsIgnoreCase("true") == useRecordBuilders)
|
||||
&& (prevDeepCheckBeforeCreatingNewEqualInstances.equalsIgnoreCase("true") == deepCheckBeforeCreatingNewEqualInstances)
|
||||
&& prevHash.equals(Integer.toString(curHash))) {
|
||||
logger.info("Skipped sources generation because it didn't change");
|
||||
return;
|
||||
@ -146,7 +148,7 @@ public class SourcesGenerator {
|
||||
.collect(Collectors.toCollection(HashSet::new));
|
||||
}
|
||||
|
||||
var genParams = new ClassGeneratorParams(generatedFilesToDelete, dataModel, basePackageName, outPath, deepCheckBeforeCreatingNewEqualInstances);
|
||||
var genParams = new ClassGeneratorParams(generatedFilesToDelete, dataModel, basePackageName, outPath, deepCheckBeforeCreatingNewEqualInstances, useRecordBuilders);
|
||||
|
||||
// Create the Versions class
|
||||
new GenVersions(genParams).run();
|
||||
@ -194,8 +196,14 @@ public class SourcesGenerator {
|
||||
new GenUpgraderSuperX(genParams).run();
|
||||
|
||||
// Update the hash at the end
|
||||
Files.writeString(hashPath, basePackageName + '\n' + useRecordBuilders + '\n' + curHash + '\n',
|
||||
StandardCharsets.UTF_8, TRUNCATE_EXISTING, WRITE, CREATE);
|
||||
Files.writeString(hashPath,
|
||||
basePackageName + '\n' + useRecordBuilders + '\n' + deepCheckBeforeCreatingNewEqualInstances + '\n' + curHash
|
||||
+ '\n',
|
||||
StandardCharsets.UTF_8,
|
||||
TRUNCATE_EXISTING,
|
||||
WRITE,
|
||||
CREATE
|
||||
);
|
||||
generatedFilesToDelete.remove(outPath.relativize(hashPath));
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@ import com.squareup.javapoet.ClassName;
|
||||
import com.squareup.javapoet.MethodSpec;
|
||||
import com.squareup.javapoet.ParameterSpec;
|
||||
import com.squareup.javapoet.TypeSpec;
|
||||
import io.soabase.recordbuilder.core.RecordBuilder;
|
||||
import it.cavallium.data.generator.plugin.ClassGenerator;
|
||||
import it.cavallium.data.generator.plugin.ComputedTypeBase;
|
||||
import it.cavallium.data.generator.plugin.ComputedVersion;
|
||||
@ -37,6 +38,10 @@ public class GenDataBaseX extends ClassGenerator {
|
||||
|
||||
classBuilder.addModifiers(Modifier.PUBLIC);
|
||||
|
||||
if (useRecordBuilders && base.getVersion().isCurrent()) {
|
||||
classBuilder.addAnnotation(RecordBuilder.class);
|
||||
}
|
||||
|
||||
var baseTypeClass = ClassName.get(dataModel.getRootPackage(basePackageName), "BaseType");
|
||||
|
||||
dataModel.getTypeSameVersions(base).forEach(v -> {
|
||||
|
Loading…
Reference in New Issue
Block a user