From a0eb0b2f8ea92590d1b8ab1cd238b55ae89125c2 Mon Sep 17 00:00:00 2001 From: Andrea Cavalli Date: Sat, 21 Jan 2023 22:58:31 +0100 Subject: [PATCH] Bugfix --- .../data/generator/plugin/ClassGenerator.java | 5 ++++- .../generator/plugin/SourcesGenerator.java | 18 +++++++++++++----- .../plugin/classgen/GenDataBaseX.java | 5 +++++ 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/data-generator-plugin/src/main/java/it/cavallium/data/generator/plugin/ClassGenerator.java b/data-generator-plugin/src/main/java/it/cavallium/data/generator/plugin/ClassGenerator.java index 655b64e..d5bdaff 100644 --- a/data-generator-plugin/src/main/java/it/cavallium/data/generator/plugin/ClassGenerator.java +++ b/data-generator-plugin/src/main/java/it/cavallium/data/generator/plugin/ClassGenerator.java @@ -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) {} } diff --git a/data-generator-plugin/src/main/java/it/cavallium/data/generator/plugin/SourcesGenerator.java b/data-generator-plugin/src/main/java/it/cavallium/data/generator/plugin/SourcesGenerator.java index 19f0273..cc9d0b1 100644 --- a/data-generator-plugin/src/main/java/it/cavallium/data/generator/plugin/SourcesGenerator.java +++ b/data-generator-plugin/src/main/java/it/cavallium/data/generator/plugin/SourcesGenerator.java @@ -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)); } diff --git a/data-generator-plugin/src/main/java/it/cavallium/data/generator/plugin/classgen/GenDataBaseX.java b/data-generator-plugin/src/main/java/it/cavallium/data/generator/plugin/classgen/GenDataBaseX.java index 8e4ef22..4640d79 100644 --- a/data-generator-plugin/src/main/java/it/cavallium/data/generator/plugin/classgen/GenDataBaseX.java +++ b/data-generator-plugin/src/main/java/it/cavallium/data/generator/plugin/classgen/GenDataBaseX.java @@ -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 -> {