From 78cd90abbac03bd3359271034aa45d251803b2a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gild=C3=A9ric=20DERUETTE?= Date: Tue, 25 Jun 2024 17:42:08 +0200 Subject: [PATCH] =?UTF-8?q?[JPA]=20Donner=20la=20possibilit=C3=A9=20de=20m?= =?UTF-8?q?asque=20l'annotation=20@Generated?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TopModel.Generator.Jpa/JpaConfig.cs | 5 +++++ TopModel.Generator.Jpa/JpaMapperGenerator.cs | 8 ++++++-- TopModel.Generator.Jpa/JpaModelGenerator.cs | 7 +++++-- .../JpaModelInterfaceGenerator.cs | 8 ++++++-- .../SpringClientApiGenerator.cs | 8 ++++++-- .../SpringDataFlowGenerator.cs | 16 ++++++++++++---- .../SpringRestTemplateApiGenerator.cs | 8 ++++++-- .../SpringServerApiGenerator.cs | 8 ++++++-- TopModel.Generator.Jpa/jpa.config.json | 5 +++++ docs/generator/jpa.md | 6 ++++++ 10 files changed, 63 insertions(+), 16 deletions(-) diff --git a/TopModel.Generator.Jpa/JpaConfig.cs b/TopModel.Generator.Jpa/JpaConfig.cs index 1fd320a4..184df3c6 100644 --- a/TopModel.Generator.Jpa/JpaConfig.cs +++ b/TopModel.Generator.Jpa/JpaConfig.cs @@ -75,6 +75,11 @@ public class JpaConfig : GeneratorConfigBase /// public bool AssociationRemovers { get; set; } = false; + /// + /// Option pour générer l'annotation @Generated("TopModel : https://github.com/klee-contrib/topmodel") + /// + public bool GeneratedHint { get; set; } = true; + /// /// Option pour générer une enum des champs des classes persistées /// diff --git a/TopModel.Generator.Jpa/JpaMapperGenerator.cs b/TopModel.Generator.Jpa/JpaMapperGenerator.cs index d8709744..7b0847c9 100644 --- a/TopModel.Generator.Jpa/JpaMapperGenerator.cs +++ b/TopModel.Generator.Jpa/JpaMapperGenerator.cs @@ -54,8 +54,12 @@ protected override void HandleFile(string fileName, string tag, IList<(Class Cla } var javaOrJakarta = Config.PersistenceMode.ToString().ToLower(); - fw.AddImport($"{javaOrJakarta}.annotation.Generated"); - fw.WriteLine("@Generated(\"TopModel : https://github.com/klee-contrib/topmodel\")"); + if (Config.GeneratedHint) + { + fw.AddImport($"{javaOrJakarta}.annotation.Generated"); + fw.WriteLine("@Generated(\"TopModel : https://github.com/klee-contrib/topmodel\")"); + } + fw.WriteLine($@"public class {Config.GetMapperName(mapperNs, modelPath)} {{"); fw.WriteLine(); diff --git a/TopModel.Generator.Jpa/JpaModelGenerator.cs b/TopModel.Generator.Jpa/JpaModelGenerator.cs index dc073e47..85577ee0 100644 --- a/TopModel.Generator.Jpa/JpaModelGenerator.cs +++ b/TopModel.Generator.Jpa/JpaModelGenerator.cs @@ -190,8 +190,11 @@ private void WriteAnnotations(JavaWriter fw, Class classe, string tag) fw.WriteDocStart(0, classe.Comment); fw.WriteDocEnd(0); var javaOrJakarta = Config.PersistenceMode.ToString().ToLower(); - fw.AddImport($"{javaOrJakarta}.annotation.Generated"); - fw.WriteLine("@Generated(\"TopModel : https://github.com/klee-contrib/topmodel\")"); + if (Config.GeneratedHint) + { + fw.AddImport($"{javaOrJakarta}.annotation.Generated"); + fw.WriteLine("@Generated(\"TopModel : https://github.com/klee-contrib/topmodel\")"); + } if (classe.IsPersistent) { diff --git a/TopModel.Generator.Jpa/JpaModelInterfaceGenerator.cs b/TopModel.Generator.Jpa/JpaModelInterfaceGenerator.cs index 91604fbf..e876502e 100644 --- a/TopModel.Generator.Jpa/JpaModelInterfaceGenerator.cs +++ b/TopModel.Generator.Jpa/JpaModelInterfaceGenerator.cs @@ -41,8 +41,12 @@ protected override void HandleClass(string fileName, Class classe, string tag) var extends = Config.GetClassExtends(classe); var implements = Config.GetClassImplements(classe); - fw.AddImport($"{javaOrJakarta}.annotation.Generated"); - fw.WriteLine("@Generated(\"TopModel : https://github.com/klee-contrib/topmodel\")"); + if (Config.GeneratedHint) + { + fw.AddImport($"{javaOrJakarta}.annotation.Generated"); + fw.WriteLine("@Generated(\"TopModel : https://github.com/klee-contrib/topmodel\")"); + } + fw.WriteLine($"public interface {classe.NamePascal} {{"); WriteGetters(fw, classe, tag); diff --git a/TopModel.Generator.Jpa/SpringClientApiGenerator.cs b/TopModel.Generator.Jpa/SpringClientApiGenerator.cs index f6015ffb..cf2e6970 100644 --- a/TopModel.Generator.Jpa/SpringClientApiGenerator.cs +++ b/TopModel.Generator.Jpa/SpringClientApiGenerator.cs @@ -46,8 +46,12 @@ protected override void HandleFile(string filePath, string fileName, string tag, } var javaOrJakarta = Config.PersistenceMode.ToString().ToLower(); - fw.AddImport($"{javaOrJakarta}.annotation.Generated"); - fw.WriteLine("@Generated(\"TopModel : https://github.com/klee-contrib/topmodel\")"); + if (Config.GeneratedHint) + { + fw.AddImport($"{javaOrJakarta}.annotation.Generated"); + fw.WriteLine("@Generated(\"TopModel : https://github.com/klee-contrib/topmodel\")"); + } + fw.WriteLine($"public interface {className} {{"); fw.WriteLine(); diff --git a/TopModel.Generator.Jpa/SpringDataFlowGenerator.cs b/TopModel.Generator.Jpa/SpringDataFlowGenerator.cs index 1a617e7f..f1553ed4 100644 --- a/TopModel.Generator.Jpa/SpringDataFlowGenerator.cs +++ b/TopModel.Generator.Jpa/SpringDataFlowGenerator.cs @@ -304,8 +304,12 @@ private void WriteClassFlow(string fileName, DataFlow dataFlow, string tag) fw.WriteLine(); fw.WriteLine("@Configuration"); var javaOrJakarta = Config.PersistenceMode.ToString().ToLower(); - fw.AddImport($"{javaOrJakarta}.annotation.Generated"); - fw.WriteLine("@Generated(\"TopModel : https://github.com/klee-contrib/topmodel\")"); + if (Config.GeneratedHint) + { + fw.AddImport($"{javaOrJakarta}.annotation.Generated"); + fw.WriteLine("@Generated(\"TopModel : https://github.com/klee-contrib/topmodel\")"); + } + fw.WriteClassDeclaration($"{dataFlow.Name}Flow", null); fw.WriteLine(); fw.WriteLine(1, $@"protected {dataFlow.Name}Flow() {{"); @@ -349,8 +353,12 @@ private void WriteModuleConfig(string module, IEnumerable flows) fw.WriteLine(); fw.WriteLine("@Configuration"); var javaOrJakarta = Config.PersistenceMode.ToString().ToLower(); - fw.AddImport($"{javaOrJakarta}.annotation.Generated"); - fw.WriteLine("@Generated(\"TopModel : https://github.com/klee-contrib/topmodel\")"); + if (Config.GeneratedHint) + { + fw.AddImport($"{javaOrJakarta}.annotation.Generated"); + fw.WriteLine("@Generated(\"TopModel : https://github.com/klee-contrib/topmodel\")"); + } + fw.WriteLine(@$"@Import({{{string.Join(", ", flows.Select(f => $@"{f.Name.ToPascalCase()}Flow.class"))}}})"); var className = configFilePath.Split("\\").Last().Split('.').First(); diff --git a/TopModel.Generator.Jpa/SpringRestTemplateApiGenerator.cs b/TopModel.Generator.Jpa/SpringRestTemplateApiGenerator.cs index 870c7c14..233df35e 100644 --- a/TopModel.Generator.Jpa/SpringRestTemplateApiGenerator.cs +++ b/TopModel.Generator.Jpa/SpringRestTemplateApiGenerator.cs @@ -41,8 +41,12 @@ protected override void HandleFile(string filePath, string fileName, string tag, fw.WriteLine(); var javaOrJakarta = Config.PersistenceMode.ToString().ToLower(); - fw.AddImport($"{javaOrJakarta}.annotation.Generated"); - fw.WriteLine("@Generated(\"TopModel : https://github.com/klee-contrib/topmodel\")"); + if (Config.GeneratedHint) + { + fw.AddImport($"{javaOrJakarta}.annotation.Generated"); + fw.WriteLine("@Generated(\"TopModel : https://github.com/klee-contrib/topmodel\")"); + } + fw.WriteLine($"public abstract class {className} {{"); fw.WriteLine(); diff --git a/TopModel.Generator.Jpa/SpringServerApiGenerator.cs b/TopModel.Generator.Jpa/SpringServerApiGenerator.cs index fe9a6e71..0185e59b 100644 --- a/TopModel.Generator.Jpa/SpringServerApiGenerator.cs +++ b/TopModel.Generator.Jpa/SpringServerApiGenerator.cs @@ -46,8 +46,12 @@ protected override void HandleFile(string filePath, string fileName, string tag, } var javaOrJakarta = Config.PersistenceMode.ToString().ToLower(); - fw.AddImport($"{javaOrJakarta}.annotation.Generated"); - fw.WriteLine("@Generated(\"TopModel : https://github.com/klee-contrib/topmodel\")"); + if (Config.GeneratedHint) + { + fw.AddImport($"{javaOrJakarta}.annotation.Generated"); + fw.WriteLine("@Generated(\"TopModel : https://github.com/klee-contrib/topmodel\")"); + } + fw.WriteLine($"public interface {className} {{"); fw.WriteLine(); diff --git a/TopModel.Generator.Jpa/jpa.config.json b/TopModel.Generator.Jpa/jpa.config.json index 8d46d53d..522285d0 100644 --- a/TopModel.Generator.Jpa/jpa.config.json +++ b/TopModel.Generator.Jpa/jpa.config.json @@ -192,6 +192,11 @@ "description": "Option pour générer des méthodes de suppression pour les associations oneToMany et manyToMany. Ces méthodes permettent de synchroniser les objets supprimés", "default": "false" }, + "generatedHint": { + "type": "boolean", + "description": "Option pour générer l'annotation @Generated('TopModel : https://github.com/klee-contrib/topmodel')", + "default": "true" + }, "fieldsEnum": { "type": "string", "description": "Option pour générer une enum des champs des classes persistées", diff --git a/docs/generator/jpa.md b/docs/generator/jpa.md index 0141f1fd..767d7fc0 100644 --- a/docs/generator/jpa.md +++ b/docs/generator/jpa.md @@ -636,6 +636,12 @@ Le générateur créé un fichier de configuration de job par module. Ce job ord _Valeur par défaut_: `false` +- `generatedHint` + + Option pour générer l'annotation @Generated("TopModel : https://github.com/klee-contrib/topmodel") + + _Valeur par défaut_: `true` + - `persistenceMode` Mode de génération de la persistence (`"javax"` ou `"jakarta"`).