// Copyright 1998-2019 Epic Games, Inc. All Rights Reserved.
using AutomationTool;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using Tools.DotNETCommon;
using UnrealBuildTool;
namespace BuildGraph.Tasks
{
///
/// Parameters for the log task
///
public class LogTaskParameters
{
///
/// Message to print out
///
[TaskParameter(Optional = true)]
public string Message;
///
/// If specified, causes the given list of files to be printed after the given message.
///
[TaskParameter(Optional = true, ValidationType = TaskParameterValidationType.FileSpec)]
public string Files;
///
/// If specified, causes the contents of the given files to be printed out.
///
[TaskParameter(Optional = true)]
public bool IncludeContents;
}
///
/// Print a message (and other optional diagnostic information) to the output log
///
[TaskElement("Log", typeof(LogTaskParameters))]
public class LogTask : CustomTask
{
///
/// Parameters for the task
///
LogTaskParameters Parameters;
///
/// Constructor.
///
/// Parameters for the task
public LogTask(LogTaskParameters InParameters)
{
Parameters = InParameters;
}
///
/// Execute 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 void Execute(JobContext Job, HashSet BuildProducts, Dictionary> TagNameToFileSet)
{
// Print the message
if(!String.IsNullOrEmpty(Parameters.Message))
{
CommandUtils.LogInformation(Parameters.Message);
}
// Print the contents of the given tag, if specified
if(!String.IsNullOrEmpty(Parameters.Files))
{
HashSet Files = ResolveFilespec(CommandUtils.RootDirectory, Parameters.Files, TagNameToFileSet);
foreach(FileReference File in Files.OrderBy(x => x.FullName))
{
CommandUtils.LogInformation(" {0}", File.FullName);
if(Parameters.IncludeContents)
{
foreach(string Line in System.IO.File.ReadAllLines(File.FullName))
{
CommandUtils.LogInformation(" {0}", 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;
}
}
}