From d7548044d2ec765e7deb2453cca3ecec5ed01edc Mon Sep 17 00:00:00 2001 From: Damien Date: Tue, 24 Sep 2024 21:09:52 +0200 Subject: [PATCH] [modgen] maxdepth = 3 lors de la recherche d'un fichier de config + fix build pour samples --- TopModel.Core/TopModel.Core.csproj | 1 + .../TopModel.Generator.Core.csproj | 1 + .../TopModel.Generator.Csharp.csproj | 1 + .../TopModel.Generator.Javascript.csproj | 1 + .../TopModel.Generator.Jpa.csproj | 1 + .../TopModel.Generator.Php.csproj | 1 + .../TopModel.Generator.Sql.csproj | 1 + .../TopModel.Generator.Translation.csproj | 1 + TopModel.Generator/Program.cs | 39 ++++++++++++++----- TopModel.Generator/TopModel.Generator.csproj | 1 + .../TopModel.LanguageServer.csproj | 1 + .../TopModel.ModelGenerator.csproj | 1 + TopModel.UI/TopModel.UI.csproj | 1 + TopModel.Utils/TopModel.Utils.csproj | 1 + samples/model/angular.topmodel.lock | 2 + samples/model/csharp.topmodel.lock | 2 + samples/model/focus.topmodel.lock | 2 + samples/model/jpa.topmodel.lock | 2 + samples/model/pg.topmodel.lock | 2 + samples/model/php.topmodel.lock | 2 + samples/model/ssdt.topmodel.lock | 2 + samples/model/translation.topmodel.lock | 2 + 22 files changed, 59 insertions(+), 9 deletions(-) diff --git a/TopModel.Core/TopModel.Core.csproj b/TopModel.Core/TopModel.Core.csproj index 02ef0b09..015d73fd 100644 --- a/TopModel.Core/TopModel.Core.csproj +++ b/TopModel.Core/TopModel.Core.csproj @@ -6,6 +6,7 @@ enable enable true + true diff --git a/TopModel.Generator.Core/TopModel.Generator.Core.csproj b/TopModel.Generator.Core/TopModel.Generator.Core.csproj index c96daf01..8d7a5e04 100644 --- a/TopModel.Generator.Core/TopModel.Generator.Core.csproj +++ b/TopModel.Generator.Core/TopModel.Generator.Core.csproj @@ -6,6 +6,7 @@ enable enable true + true diff --git a/TopModel.Generator.Csharp/TopModel.Generator.Csharp.csproj b/TopModel.Generator.Csharp/TopModel.Generator.Csharp.csproj index 5af6e91f..af0851b0 100644 --- a/TopModel.Generator.Csharp/TopModel.Generator.Csharp.csproj +++ b/TopModel.Generator.Csharp/TopModel.Generator.Csharp.csproj @@ -6,6 +6,7 @@ enable enable true + true diff --git a/TopModel.Generator.Javascript/TopModel.Generator.Javascript.csproj b/TopModel.Generator.Javascript/TopModel.Generator.Javascript.csproj index 80ba8ad0..fc723b58 100644 --- a/TopModel.Generator.Javascript/TopModel.Generator.Javascript.csproj +++ b/TopModel.Generator.Javascript/TopModel.Generator.Javascript.csproj @@ -6,6 +6,7 @@ enable enable true + true diff --git a/TopModel.Generator.Jpa/TopModel.Generator.Jpa.csproj b/TopModel.Generator.Jpa/TopModel.Generator.Jpa.csproj index fb2ad4c0..76a089a3 100644 --- a/TopModel.Generator.Jpa/TopModel.Generator.Jpa.csproj +++ b/TopModel.Generator.Jpa/TopModel.Generator.Jpa.csproj @@ -6,6 +6,7 @@ enable enable true + true diff --git a/TopModel.Generator.Php/TopModel.Generator.Php.csproj b/TopModel.Generator.Php/TopModel.Generator.Php.csproj index e5348634..b8b16dd9 100644 --- a/TopModel.Generator.Php/TopModel.Generator.Php.csproj +++ b/TopModel.Generator.Php/TopModel.Generator.Php.csproj @@ -6,6 +6,7 @@ enable enable true + true diff --git a/TopModel.Generator.Sql/TopModel.Generator.Sql.csproj b/TopModel.Generator.Sql/TopModel.Generator.Sql.csproj index 050f6ac9..4b45c212 100644 --- a/TopModel.Generator.Sql/TopModel.Generator.Sql.csproj +++ b/TopModel.Generator.Sql/TopModel.Generator.Sql.csproj @@ -6,6 +6,7 @@ enable enable true + true diff --git a/TopModel.Generator.Translation/TopModel.Generator.Translation.csproj b/TopModel.Generator.Translation/TopModel.Generator.Translation.csproj index af88750c..e5401ceb 100644 --- a/TopModel.Generator.Translation/TopModel.Generator.Translation.csproj +++ b/TopModel.Generator.Translation/TopModel.Generator.Translation.csproj @@ -6,6 +6,7 @@ enable enable true + true diff --git a/TopModel.Generator/Program.cs b/TopModel.Generator/Program.cs index 0a47aa84..e0cc6e8b 100644 --- a/TopModel.Generator/Program.cs +++ b/TopModel.Generator/Program.cs @@ -5,6 +5,7 @@ using System.Text; using System.Text.Encodings.Web; using System.Text.Json.Nodes; +using System.Text.RegularExpressions; using System.Xml; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; @@ -88,12 +89,30 @@ void HandleFile(FileInfo file) else { var dir = Directory.GetCurrentDirectory(); - var pattern = "topmodel*.config"; - foreach (var fileName in Directory.EnumerateFiles(dir, pattern, SearchOption.AllDirectories)) + var pattern = new Regex("topmodel\\.?([a-zA-Z-_.]*)\\.config$"); + + void SearchConfigFile(string dirName, int depth = 0) { - HandleFile(new FileInfo(fileName)); + if (depth > 3) + { + return; + } + + foreach (var entryName in Directory.EnumerateFileSystemEntries(dirName)) + { + if (Directory.Exists(entryName)) + { + SearchConfigFile(entryName, depth + 1); + } + else if (pattern.IsMatch(entryName)) + { + HandleFile(new FileInfo(entryName)); + } + } } + SearchConfigFile(dir); + if (configs.Count == 0) { var found = false; @@ -102,7 +121,7 @@ void HandleFile(FileInfo file) dir = Directory.GetParent(dir)?.FullName; if (dir != null) { - foreach (var fileName in Directory.EnumerateFiles(dir, pattern)) + foreach (var fileName in Directory.EnumerateFiles(dir).Where(f => pattern.IsMatch(f))) { HandleFile(new FileInfo(fileName)); found = true; @@ -233,6 +252,8 @@ void HandleFile(FileInfo file) foreach (var cg in config.CustomGenerators) { + var customDir = Path.GetFullPath(Path.Combine(new FileInfo(Path.GetFullPath(fullName)).DirectoryName!, cg)); + string GetCgHash() { return GetHash( @@ -243,7 +264,7 @@ string GetCgHash() SearchOption.AllDirectories) .Where(f => !f.Contains($"{Path.DirectorySeparatorChar}obj{Path.DirectorySeparatorChar}"))) .ToList(), - cg) ?? string.Empty; + customDir) ?? string.Empty; } var customHash = GetCgHash(); @@ -254,9 +275,9 @@ string GetCgHash() { CreateNoWindow = true, WindowStyle = ProcessWindowStyle.Hidden, - FileName = "dotnet.exe", - Arguments = "build -v q", - WorkingDirectory = cg, + FileName = "dotnet", + Arguments = "build -v q -p:Deterministic=true", + WorkingDirectory = customDir, RedirectStandardOutput = true, StandardOutputEncoding = Encoding.UTF8 }); @@ -692,7 +713,7 @@ IEnumerable GetCustomAssemblies(string cg, string fullName) var md5 = MD5.Create(); foreach (var file in files) { - var relativePath = file[(path.Length + 1)..]; + var relativePath = file[(path.Length + 1)..].Replace("\\", "/"); var pathBytes = Encoding.UTF8.GetBytes(relativePath.ToLower()); md5.TransformBlock(pathBytes, 0, pathBytes.Length, pathBytes, 0); diff --git a/TopModel.Generator/TopModel.Generator.csproj b/TopModel.Generator/TopModel.Generator.csproj index 7ce59abc..fc51f0b7 100644 --- a/TopModel.Generator/TopModel.Generator.csproj +++ b/TopModel.Generator/TopModel.Generator.csproj @@ -7,6 +7,7 @@ enable enable true + true diff --git a/TopModel.LanguageServer/TopModel.LanguageServer.csproj b/TopModel.LanguageServer/TopModel.LanguageServer.csproj index 40b82e95..077b74cc 100644 --- a/TopModel.LanguageServer/TopModel.LanguageServer.csproj +++ b/TopModel.LanguageServer/TopModel.LanguageServer.csproj @@ -10,6 +10,7 @@ en en true + true diff --git a/TopModel.ModelGenerator/TopModel.ModelGenerator.csproj b/TopModel.ModelGenerator/TopModel.ModelGenerator.csproj index 9a1221bb..2434e0d7 100644 --- a/TopModel.ModelGenerator/TopModel.ModelGenerator.csproj +++ b/TopModel.ModelGenerator/TopModel.ModelGenerator.csproj @@ -7,6 +7,7 @@ enable enable true + true diff --git a/TopModel.UI/TopModel.UI.csproj b/TopModel.UI/TopModel.UI.csproj index cf4f2c21..2c3b8b0e 100644 --- a/TopModel.UI/TopModel.UI.csproj +++ b/TopModel.UI/TopModel.UI.csproj @@ -7,6 +7,7 @@ enable true KTA1200 + true diff --git a/TopModel.Utils/TopModel.Utils.csproj b/TopModel.Utils/TopModel.Utils.csproj index 07366f2c..bb084287 100644 --- a/TopModel.Utils/TopModel.Utils.csproj +++ b/TopModel.Utils/TopModel.Utils.csproj @@ -6,6 +6,7 @@ enable enable true + true diff --git a/samples/model/angular.topmodel.lock b/samples/model/angular.topmodel.lock index 6587c6fc..ac89ff22 100644 --- a/samples/model/angular.topmodel.lock +++ b/samples/model/angular.topmodel.lock @@ -4,6 +4,8 @@ version: 2.1.0 modules: {} +custom: + ../../../TopModel.Generator.Javascript: 38de32b916f64e855318d5ae5a53030c generatedFiles: - ../generators/angular/src/appgenerated/api/securite/profil/profil.service.ts - ../generators/angular/src/appgenerated/api/securite/utilisateur/utilisateur.service.ts diff --git a/samples/model/csharp.topmodel.lock b/samples/model/csharp.topmodel.lock index 307226eb..05b43249 100644 --- a/samples/model/csharp.topmodel.lock +++ b/samples/model/csharp.topmodel.lock @@ -4,6 +4,8 @@ version: 2.1.0 modules: {} +custom: + ../../../TopModel.Generator.Csharp: f5c36f386404169919fcb40cd406806e generatedFiles: - ../generators/csharp/src/Clients/CSharp.Clients.Db/generated/CSharpDbContext.comments.cs - ../generators/csharp/src/Clients/CSharp.Clients.Db/generated/CSharpDbContext.cs diff --git a/samples/model/focus.topmodel.lock b/samples/model/focus.topmodel.lock index a1a64cb8..b55b13d6 100644 --- a/samples/model/focus.topmodel.lock +++ b/samples/model/focus.topmodel.lock @@ -4,6 +4,8 @@ version: 2.1.0 modules: {} +custom: + ../../../TopModel.Generator.Javascript: 38de32b916f64e855318d5ae5a53030c generatedFiles: - ../generators/focus/src/locale/common.ts - ../generators/focus/src/locale/securite.ts diff --git a/samples/model/jpa.topmodel.lock b/samples/model/jpa.topmodel.lock index e118026f..a67ae23c 100644 --- a/samples/model/jpa.topmodel.lock +++ b/samples/model/jpa.topmodel.lock @@ -4,6 +4,8 @@ version: 2.1.0 modules: {} +custom: + ../../../TopModel.Generator.Jpa: 15eb94e09075c832a4bb717dab332570 generatedFiles: - ../generators/jpa/src/main/javagen/topmodel/jpa/sample/demo/api/client/securite/profil/ProfilClient.java - ../generators/jpa/src/main/javagen/topmodel/jpa/sample/demo/api/client/securite/utilisateur/UtilisateurClient.java diff --git a/samples/model/pg.topmodel.lock b/samples/model/pg.topmodel.lock index 4fb106d2..6fdf8e56 100644 --- a/samples/model/pg.topmodel.lock +++ b/samples/model/pg.topmodel.lock @@ -4,6 +4,8 @@ version: 2.1.0 modules: {} +custom: + ../../../TopModel.Generator.Sql: 0398471b3152707903570652ff61c19a generatedFiles: - ../generators/pg/src/01_tables.sql - ../generators/pg/src/02_fk_indexes.sql diff --git a/samples/model/php.topmodel.lock b/samples/model/php.topmodel.lock index 18896a3d..7a88da40 100644 --- a/samples/model/php.topmodel.lock +++ b/samples/model/php.topmodel.lock @@ -4,6 +4,8 @@ version: 2.1.0 modules: {} +custom: + ../../../TopModel.Generator.Php: fe9c9e33a8855c5fca0a5bfa1fb72e6d generatedFiles: - ../generators/php/src/Entity/Securite/Profil/Droit.php - ../generators/php/src/Entity/Securite/Profil/Profil.php diff --git a/samples/model/ssdt.topmodel.lock b/samples/model/ssdt.topmodel.lock index 394af1a8..04d726dd 100644 --- a/samples/model/ssdt.topmodel.lock +++ b/samples/model/ssdt.topmodel.lock @@ -4,6 +4,8 @@ version: 2.1.0 modules: {} +custom: + ../../../TopModel.Generator.Sql: 0398471b3152707903570652ff61c19a generatedFiles: - ../generators/ssdt/src/init/DROIT.insert.sql - ../generators/ssdt/src/init/main.sql diff --git a/samples/model/translation.topmodel.lock b/samples/model/translation.topmodel.lock index fb84e822..4d1f69b9 100644 --- a/samples/model/translation.topmodel.lock +++ b/samples/model/translation.topmodel.lock @@ -4,6 +4,8 @@ version: 2.1.0 modules: {} +custom: + ../../../TopModel.Generator.Translation: 5c92249b4cd896a536d86ffb453218e6 generatedFiles: - ../generators/translation/i18n/de_DE/out/common_de_DE.properties - ../generators/translation/i18n/de_DE/out/securite_de_DE.properties