// Copyright Epic Games, Inc. All Rights Reserved. using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using System.Xml; using EpicGames.Core; using Microsoft.Extensions.Logging; using UnrealBuildBase; namespace AutomationTool.Tasks { /// /// Parameters for the log task /// public class LogTaskParameters { /// /// Message to print out. /// [TaskParameter(Optional = true)] public string Message { get; set; } /// /// If specified, causes the given list of files to be printed after the given message. /// [TaskParameter(Optional = true, ValidationType = TaskParameterValidationType.FileSpec)] public string Files { get; set; } /// /// If specified, causes the contents of the given files to be printed out. /// [TaskParameter(Optional = true)] public bool IncludeContents { get; set; } } /// /// Print a message (and other optional diagnostic information) to the output log. /// [TaskElement("Log", typeof(LogTaskParameters))] public class LogTask : BgTaskImpl { /// /// Parameters for the task /// readonly LogTaskParameters _parameters; /// /// Constructor. /// /// Parameters for the task public LogTask(LogTaskParameters parameters) { _parameters = parameters; } /// /// ExecuteAsync the task. /// /// Information about the current job /// Set of build products produced by this node. /// Mapping from tag names to the set of files they include public override async Task ExecuteAsync(JobContext job, HashSet buildProducts, Dictionary> tagNameToFileSet) { // Print the message if (!String.IsNullOrEmpty(_parameters.Message)) { Logger.LogInformation("{Text}", _parameters.Message); } // Print the contents of the given tag, if specified if (!String.IsNullOrEmpty(_parameters.Files)) { HashSet files = ResolveFilespec(Unreal.RootDirectory, _parameters.Files, tagNameToFileSet); foreach (FileReference file in files.OrderBy(x => x.FullName)) { Logger.LogInformation(" {Arg0}", file.FullName); if (_parameters.IncludeContents) { string[] lines = await System.IO.File.ReadAllLinesAsync(file.FullName); foreach (string line in lines) { Logger.LogInformation(" {Line}", line); } } } } } /// /// Output this task out to an XML writer. /// public override void Write(XmlWriter writer) { Write(writer, _parameters); } /// /// Find all the tags which are used as inputs to this task /// /// The tag names which are read by this task public override IEnumerable FindConsumedTagNames() { return FindTagNamesFromFilespec(_parameters.Files); } /// /// Find all the tags which are modified by this task /// /// The tag names which are modified by this task public override IEnumerable FindProducedTagNames() { yield break; } } }