2019-12-26 23:01:54 -05:00
|
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
2019-09-05 11:42:11 -04:00
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Xml;
|
2020-12-21 23:07:37 -04:00
|
|
|
using EpicGames.Core;
|
2019-09-05 11:42:11 -04:00
|
|
|
using UnrealBuildTool;
|
|
|
|
|
|
2021-12-10 16:56:09 -05:00
|
|
|
namespace AutomationTool.Tasks
|
2019-09-05 11:42:11 -04:00
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Parameters for a ModifyConfig task
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class ModifyConfigTaskParameters
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Path to the config file
|
|
|
|
|
/// </summary>
|
|
|
|
|
[TaskParameter(ValidationType = TaskParameterValidationType.FileSpec)]
|
2024-05-21 20:54:09 -04:00
|
|
|
public string File { get; set; }
|
2019-09-05 11:42:11 -04:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The section name to modify
|
|
|
|
|
/// </summary>
|
|
|
|
|
[TaskParameter]
|
2024-05-21 20:54:09 -04:00
|
|
|
public string Section { get; set; }
|
2019-09-05 11:42:11 -04:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The property name to set
|
|
|
|
|
/// </summary>
|
|
|
|
|
[TaskParameter]
|
2024-05-21 20:54:09 -04:00
|
|
|
public string Key { get; set; }
|
2019-09-05 11:42:11 -04:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The property value to set
|
|
|
|
|
/// </summary>
|
|
|
|
|
[TaskParameter]
|
2024-05-21 20:54:09 -04:00
|
|
|
public string Value { get; set; }
|
2019-09-05 11:42:11 -04:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Tag to be applied to the extracted files
|
|
|
|
|
/// </summary>
|
|
|
|
|
[TaskParameter(Optional = true, ValidationType = TaskParameterValidationType.TagList)]
|
2024-05-21 20:54:09 -04:00
|
|
|
public string Tag { get; set; }
|
2019-09-05 11:42:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Modifies a config file
|
|
|
|
|
/// </summary>
|
|
|
|
|
[TaskElement("ModifyConfig", typeof(ModifyConfigTaskParameters))]
|
2021-12-10 15:36:47 -05:00
|
|
|
public class ModifyConfigTask : BgTaskImpl
|
2019-09-05 11:42:11 -04:00
|
|
|
{
|
2024-05-22 13:17:22 -04:00
|
|
|
readonly ModifyConfigTaskParameters _parameters;
|
2019-09-05 11:42:11 -04:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Constructor
|
|
|
|
|
/// </summary>
|
2024-05-22 13:17:22 -04:00
|
|
|
/// <param name="parameters">Parameters for this task</param>
|
|
|
|
|
public ModifyConfigTask(ModifyConfigTaskParameters parameters)
|
2019-09-05 11:42:11 -04:00
|
|
|
{
|
2024-05-22 13:17:22 -04:00
|
|
|
_parameters = parameters;
|
2019-09-05 11:42:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2024-05-22 13:17:22 -04:00
|
|
|
/// ExecuteAsync the task.
|
2019-09-05 11:42:11 -04:00
|
|
|
/// </summary>
|
2024-05-22 13:17:22 -04:00
|
|
|
/// <param name="job">Information about the current job</param>
|
|
|
|
|
/// <param name="buildProducts">Set of build products produced by this node.</param>
|
|
|
|
|
/// <param name="tagNameToFileSet">Mapping from tag names to the set of files they include</param>
|
|
|
|
|
public override Task ExecuteAsync(JobContext job, HashSet<FileReference> buildProducts, Dictionary<string, HashSet<FileReference>> tagNameToFileSet)
|
2019-09-05 11:42:11 -04:00
|
|
|
{
|
2024-05-22 13:17:22 -04:00
|
|
|
FileReference configFileLocation = ResolveFile(_parameters.File);
|
2019-09-05 11:42:11 -04:00
|
|
|
|
2024-05-22 13:17:22 -04:00
|
|
|
ConfigFile configFile;
|
|
|
|
|
if (FileReference.Exists(configFileLocation))
|
2019-09-05 11:42:11 -04:00
|
|
|
{
|
2024-05-22 13:17:22 -04:00
|
|
|
configFile = new ConfigFile(configFileLocation);
|
2019-09-05 11:42:11 -04:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2024-05-22 13:17:22 -04:00
|
|
|
configFile = new ConfigFile();
|
2019-09-05 11:42:11 -04:00
|
|
|
}
|
|
|
|
|
|
2024-05-22 13:17:22 -04:00
|
|
|
ConfigFileSection section = configFile.FindOrAddSection(_parameters.Section);
|
|
|
|
|
section.Lines.RemoveAll(x => String.Equals(x.Key, _parameters.Key, StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
section.Lines.Add(new ConfigLine(ConfigLineAction.Set, _parameters.Key, _parameters.Value));
|
2019-09-05 11:42:11 -04:00
|
|
|
|
2024-05-22 13:17:22 -04:00
|
|
|
FileReference.MakeWriteable(configFileLocation);
|
|
|
|
|
configFile.Write(configFileLocation);
|
2019-09-05 11:42:11 -04:00
|
|
|
|
|
|
|
|
// Apply the optional tag to the produced archive
|
2024-05-22 13:17:22 -04:00
|
|
|
foreach (string tagName in FindTagNamesFromList(_parameters.Tag))
|
2019-09-05 11:42:11 -04:00
|
|
|
{
|
2024-05-22 13:17:22 -04:00
|
|
|
FindOrAddTagSet(tagNameToFileSet, tagName).Add(configFileLocation);
|
2019-09-05 11:42:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Add the archive to the set of build products
|
2024-05-22 13:17:22 -04:00
|
|
|
buildProducts.Add(configFileLocation);
|
2021-12-10 15:36:47 -05:00
|
|
|
return Task.CompletedTask;
|
2019-09-05 11:42:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Output this task out to an XML writer.
|
|
|
|
|
/// </summary>
|
2024-05-22 13:17:22 -04:00
|
|
|
public override void Write(XmlWriter writer)
|
2019-09-05 11:42:11 -04:00
|
|
|
{
|
2024-05-22 13:17:22 -04:00
|
|
|
Write(writer, _parameters);
|
2019-09-05 11:42:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Find all the tags which are used as inputs to this task
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>The tag names which are read by this task</returns>
|
|
|
|
|
public override IEnumerable<string> FindConsumedTagNames()
|
|
|
|
|
{
|
2024-05-22 13:17:22 -04:00
|
|
|
return FindTagNamesFromFilespec(_parameters.File);
|
2019-09-05 11:42:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Find all the tags which are modified by this task
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>The tag names which are modified by this task</returns>
|
|
|
|
|
public override IEnumerable<string> FindProducedTagNames()
|
|
|
|
|
{
|
2024-05-22 13:17:22 -04:00
|
|
|
return FindTagNamesFromList(_parameters.Tag);
|
2019-09-05 11:42:11 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|