public static FileMapping ExpandFileMapping(string baseDirectory, FileMapping fileMapping) { if (fileMapping == null) { return null; } if (fileMapping.Expanded) return fileMapping; var expandedFileMapping = new FileMapping(); foreach (var item in fileMapping.Items) { // Use local variable to avoid different items influencing each other var src = Path.Combine(baseDirectory, item.SourceFolder ?? string.Empty); var options = GetMatchOptionsFromItem(item); var files = FileGlob.GetFiles(src, item.Files, item.Exclude, options).ToArray(); if (files.Length == 0) { var currentSrcFullPath = string.IsNullOrEmpty(src) ? Environment.CurrentDirectory : Path.GetFullPath(src); Logger.LogInfo($"No files are found with glob pattern {item.Files.ToDelimitedString() ?? "<none>"}, excluding {item.Exclude.ToDelimitedString() ?? "<none>"}, under directory \"{currentSrcFullPath}\""); } expandedFileMapping.Add( new FileMappingItem { SourceFolder = src, Files = new FileItems(files), DestinationFolder = item.DestinationFolder }); } expandedFileMapping.Expanded = true; return expandedFileMapping; }
public static FileMapping ExpandFileMapping(string baseDirectory, FileMapping fileMapping) { if (fileMapping == null) { return(null); } if (fileMapping.Expanded) { return(fileMapping); } var expandedFileMapping = new FileMapping(); foreach (var item in fileMapping.Items) { // Use local variable to avoid different items influencing each other var cwd = Path.Combine(baseDirectory, item.CurrentWorkingDirectory ?? string.Empty); var options = GetMatchOptionsFromItem(item); var files = FileGlob.GetFiles(cwd, item.Files, item.Exclude, options).ToArray(); if (files.Length == 0) { Logger.LogInfo($"No files are found with glob pattern {item.Files.ToDelimitedString() ?? "<none>"}, excluding {item.Exclude.ToDelimitedString() ?? "<none>"}, under working directory {baseDirectory ?? "<current>"}"); } expandedFileMapping.Add( new FileMappingItem { CurrentWorkingDirectory = cwd, Files = new FileItems(files), }); } expandedFileMapping.Expanded = true; return(expandedFileMapping); }
public static FileMapping ExpandFileMapping(string baseDirectory, FileMapping fileMapping) { if (fileMapping == null) { return null; } if (fileMapping.Expanded) return fileMapping; var expandedFileMapping = new FileMapping(); foreach (var item in fileMapping.Items) { // Use local variable to avoid different items influencing each other var cwd = Path.Combine(baseDirectory, item.CurrentWorkingDirectory ?? string.Empty); var options = GetMatchOptionsFromItem(item); var files = FileGlob.GetFiles(cwd, item.Files, item.Exclude, options).ToArray(); if (files.Length == 0) { Logger.LogInfo($"No files are found with glob pattern {item.Files.ToDelimitedString() ?? "<none>"}, excluding {item.Exclude.ToDelimitedString() ?? "<none>"}, under working directory {baseDirectory ?? "<current>"}"); } expandedFileMapping.Add( new FileMappingItem { CurrentWorkingDirectory = cwd, Files = new FileItems(files), }); } expandedFileMapping.Expanded = true; return expandedFileMapping; }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { var model = new FileMapping(); var value = reader.Value; IEnumerable <JToken> jItems; if (reader.TokenType == JsonToken.StartArray) { jItems = JArray.Load(reader); } else if (reader.TokenType == JsonToken.String) { jItems = JRaw.Load(reader); } else { jItems = JObject.Load(reader); } if (jItems is JValue) { model.Add(FileModelParser.ParseItem(jItems.ToString())); } else if (jItems is JObject) { model.Add(FileModelParser.ParseItem((JToken)jItems)); } else { foreach (var item in jItems) { FileMappingItem itemModel = FileModelParser.ParseItem(item); model.Add(itemModel); } } return(model); }
/// <summary> /// /// </summary> /// <param name="input"></param> /// <param name="key"></param> /// <returns></returns> /// <exception cref="JsonReaderException"></exception> public static FileMapping Parse(string input, string key) { FileMapping model = new FileMapping(); var value = JObject.Parse(input)[key]; foreach (var item in value) { var itemModel = ParseItem(item); model.Add(itemModel); } return(model); }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { var model = new FileMapping(); var value = reader.Value; IEnumerable<JToken> jItems; if (reader.TokenType == JsonToken.StartArray) { jItems = JArray.Load(reader); } else if (reader.TokenType == JsonToken.StartObject) { jItems = JContainer.Load(reader); } else if (reader.TokenType == JsonToken.String) { jItems = JRaw.Load(reader); } else { jItems = JObject.Load(reader); } if (jItems is JValue) { model.Add(FileModelParser.ParseItem(jItems.ToString())); } else { foreach (var item in jItems) { FileMappingItem itemModel = FileModelParser.ParseItem(item); model.Add(itemModel); } } return model; }
public static FileMapping ExpandFileMapping(string baseDirectory, FileMapping fileMapping) { if (fileMapping == null) { return(null); } if (fileMapping.Expanded) { return(fileMapping); } var expandedFileMapping = new FileMapping(); foreach (var item in fileMapping.Items) { var src = Path.Combine(baseDirectory, item.SourceFolder ?? string.Empty); var options = GetMatchOptionsFromItem(item); var fileItems = new FileItems(FileGlob.GetFiles(src, item.Files, item.Exclude, options)); if (fileItems.Count == 0) { var currentSrcFullPath = string.IsNullOrEmpty(src) ? Directory.GetCurrentDirectory() : Path.GetFullPath(src); Logger.LogInfo($"No files are found with glob pattern {StringExtension.ToDelimitedString(item.Files) ?? "<none>"}, excluding {StringExtension.ToDelimitedString(item.Exclude) ?? "<none>"}, under directory \"{currentSrcFullPath}\""); CheckPatterns(item.Files); } if (item.Exclude != null) { CheckPatterns(item.Exclude); } expandedFileMapping.Add( new FileMappingItem { SourceFolder = src, Files = fileItems, DestinationFolder = item.DestinationFolder }); } expandedFileMapping.Expanded = true; return(expandedFileMapping); }
public static FileMapping ExpandFileMapping(string baseDirectory, FileMapping fileMapping) { if (fileMapping == null) { return(null); } if (fileMapping.Expanded) { return(fileMapping); } var expandedFileMapping = new FileMapping(); foreach (var item in fileMapping.Items) { // Use local variable to avoid different items influencing each other var src = Path.Combine(baseDirectory, item.SourceFolder ?? string.Empty); var options = GetMatchOptionsFromItem(item); var files = FileGlob.GetFiles(src, item.Files, item.Exclude, options).ToArray(); if (files.Length == 0) { var currentSrcFullPath = string.IsNullOrEmpty(src) ? Directory.GetCurrentDirectory() : Path.GetFullPath(src); Logger.LogInfo($"No files are found with glob pattern {item.Files.ToDelimitedString() ?? "<none>"}, excluding {item.Exclude.ToDelimitedString() ?? "<none>"}, under directory \"{currentSrcFullPath}\""); CheckPatterns(item.Files); } expandedFileMapping.Add( new FileMappingItem { SourceFolder = src, Files = new FileItems(files), DestinationFolder = item.DestinationFolder }); } expandedFileMapping.Expanded = true; return(expandedFileMapping); }