diff --git a/src/Luban.Core/GenerationContext.cs b/src/Luban.Core/GenerationContext.cs index 379de905..d5ed24d9 100644 --- a/src/Luban.Core/GenerationContext.cs +++ b/src/Luban.Core/GenerationContext.cs @@ -35,13 +35,13 @@ public class GenerationContext public static LubanConfig GlobalConf { get; set; } - public DefAssembly Assembly { get; } + public DefAssembly Assembly { get; private set; } public RawTarget Target => Assembly.Target; - public List IncludeTags { get; } + public List IncludeTags { get; private set; } - public List ExcludeTags { get; } + public List ExcludeTags { get; private set; } private readonly ConcurrentDictionary _recordsByTables = new(); @@ -49,15 +49,15 @@ public class GenerationContext public List Tables => Assembly.GetAllTables(); - private List ExportTypes { get; } + private List ExportTypes { get; set; } - public List ExportTables { get; } + public List ExportTables { get; private set; } - public List ExportBeans { get; } + public List ExportBeans { get; private set; } - public List ExportEnums { get; } + public List ExportEnums { get; private set; } - public TimeZoneInfo TimeZone { get; } + public TimeZoneInfo TimeZone { get; private set; } private readonly Dictionary _uniqueObjects = new(); @@ -70,9 +70,13 @@ public void LoadDatas() s_logger.Info("load datas end"); } - public GenerationContext(GenerationContextBuilder builder) + public GenerationContext() { Current = this; + } + + public void Init(GenerationContextBuilder builder) + { Assembly = builder.Assembly; IncludeTags = builder.IncludeTags; ExcludeTags = builder.ExcludeTags; @@ -196,6 +200,15 @@ public object GetUniqueObject(string key) } } + public object TryGetUniqueObject(string key) + { + lock (this) + { + _uniqueObjects.TryGetValue(key, out var obj); + return obj; + } + } + public object GetOrAddUniqueObject(string key, Func factory) { lock (this) diff --git a/src/Luban.Core/Pipeline/DefaultPipeline.cs b/src/Luban.Core/Pipeline/DefaultPipeline.cs index f4c3d321..23623da7 100644 --- a/src/Luban.Core/Pipeline/DefaultPipeline.cs +++ b/src/Luban.Core/Pipeline/DefaultPipeline.cs @@ -52,6 +52,7 @@ protected void LoadSchema() protected void PrepareGenerationContext() { s_logger.Debug("prepare generation context"); + _genCtx = new GenerationContext(); _defAssembly = new DefAssembly(_rawAssembly, _args.Target, _args.OutputTables); var generationCtxBuilder = new GenerationContextBuilder @@ -61,7 +62,7 @@ protected void PrepareGenerationContext() ExcludeTags = _args.ExcludeTags, TimeZone = _args.TimeZone, }; - _genCtx = new GenerationContext(generationCtxBuilder); + _genCtx.Init(generationCtxBuilder); } protected void LoadDatas() diff --git a/src/Luban.DataValidator.Builtin/Path/PathValidator.cs b/src/Luban.DataValidator.Builtin/Path/PathValidator.cs index a454b5e3..16ec08e3 100644 --- a/src/Luban.DataValidator.Builtin/Path/PathValidator.cs +++ b/src/Luban.DataValidator.Builtin/Path/PathValidator.cs @@ -10,6 +10,8 @@ namespace Luban.DataValidator.Builtin.Path; public class PathValidator : DataValidatorBase { private static readonly NLog.Logger s_logger = NLog.LogManager.GetCurrentClassLogger(); + + private readonly string _rootDir; private string _rawPattern; @@ -17,6 +19,14 @@ public class PathValidator : DataValidatorBase public PathValidator() { + if (!EnvManager.Current.TryGetOption(BuiltinOptionNames.PathValidatorFamily, BuiltinOptionNames.PathValidatorRootDir, false, out _rootDir)) + { + string key = $"{BuiltinOptionNames.PathValidatorFamily}.{BuiltinOptionNames.PathValidatorRootDir}"; + if (GenerationContext.Current.GetOrAddUniqueObject(key, () => this) == this) + { + s_logger.Warn("don't set option '-x {0}=', path validation is disabled", key); + } + } } public override void Compile(DefField field, TType type) @@ -89,15 +99,18 @@ public override void Compile(DefField field, TType type) public override void Validate(DataValidatorContext ctx, TType type, DType data) { + if (string.IsNullOrEmpty(_rootDir)) + { + return; + } + string value = ((DString)data).Value; if (value == "" && _pathPattern.EmptyAble) { return; } - string rootDir = EnvManager.Current.GetOption(BuiltinOptionNames.PathValidatorFamily, BuiltinOptionNames.PathValidatorRootDir, false); - - if (!_pathPattern.ExistPath(rootDir, value)) + if (!_pathPattern.ExistPath(_rootDir, value)) { s_logger.Error("{}:{} (来自文件:{}) 找不到对应文件", RecordPath, value, Source); GenerationContext.Current.LogValidatorFail(this); diff --git a/src/Luban.L10N/DefaultTextProvider.cs b/src/Luban.L10N/DefaultTextProvider.cs index f2c4fc07..3107f878 100644 --- a/src/Luban.L10N/DefaultTextProvider.cs +++ b/src/Luban.L10N/DefaultTextProvider.cs @@ -23,7 +23,7 @@ public void Load() if (!EnvManager.Current.TryGetOption(BuiltinOptionNames.L10NFamily, BuiltinOptionNames.TextProviderFile, true, out string textProviderFile)) { - s_logger.Error("not found option: '-x {0}.{1}=', text validation is disabled", BuiltinOptionNames.L10NFamily, BuiltinOptionNames.TextProviderFile); + s_logger.Warn("not found option: '-x {0}.{1}=', text validation is disabled", BuiltinOptionNames.L10NFamily, BuiltinOptionNames.TextProviderFile); _enableTextValidation = false; return; }