161 lines
No EOL
5.8 KiB
C#
161 lines
No EOL
5.8 KiB
C#
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Text.RegularExpressions;
|
|
using JD.Asset.Types.Map;
|
|
using NUnit.Framework;
|
|
using TeaBox.AssetValidation;
|
|
using TeaBox.Macros;
|
|
using TeaBox.MapValidation;
|
|
using TeaBox.QuickBuild;
|
|
using TeaBox.SourceControl;
|
|
using TeaBox.UAF;
|
|
|
|
namespace TeaBox.Data
|
|
{
|
|
[Module(Icon = "Run")]
|
|
public class DataValidationMacro
|
|
{
|
|
// Files to remove, because we don't cook them
|
|
private static IEnumerable<string> exclusions = new List<string>
|
|
{
|
|
// These paths are commented for now to check if they should really be excluded from the preflight data validation
|
|
//".jpg",
|
|
//@"\data\EngineData\CottleTemplates\",
|
|
@"\data\EngineData\Localisation\Saves\ConsoleSave.json" // Data for the Rosetta tool, which is not something to cook
|
|
};
|
|
|
|
[Macro(Icon = "check.png")]
|
|
[System.ComponentModel.Category(@"Test")]
|
|
[System.ComponentModel.Description("Validate Data in changelist, or common files if no changelist is specified")]
|
|
public static void ValidateData(IExecutionContext context, [PerforceChangeListPicker(SourceControl = SourceControlInstance.Data)] ChangeListNumber changelist, [Browsable(false)] string shelvedFilePath = null)
|
|
{
|
|
var filesString = string.Empty;
|
|
var changelistToValidate = changelist.ToString();
|
|
|
|
if (string.IsNullOrEmpty(shelvedFilePath))
|
|
{
|
|
if (string.IsNullOrEmpty(changelistToValidate))
|
|
{
|
|
context.LogWarning(
|
|
"No change list mentioned to extract the files from, hence running the default data validation (covers the files in the common dependencies)");
|
|
}
|
|
else
|
|
{
|
|
var fileList = RemoveExclusions(GetFilesPathsFromCl(changelistToValidate));
|
|
filesString = CreateFilePathString(fileList);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
var fileList = RemoveExclusions(GetFilesPathsFromTxtFile(shelvedFilePath));
|
|
filesString = CreateFilePathString(fileList);
|
|
}
|
|
|
|
// Asset Validation TODO : add the validation and call for SongDescValidation
|
|
List<Map> maps = new List<Map>();
|
|
|
|
// getting all the maps
|
|
foreach (var file in filesString.Split(','))
|
|
{
|
|
var mapName = new Regex(@".*MAPS\\(.*?)\\").Match(file).Value;
|
|
if (!string.IsNullOrEmpty(mapName))
|
|
{
|
|
Map map = Map.FromName(mapName);
|
|
if (!maps.Contains(map))
|
|
maps.Add(map);
|
|
}
|
|
}
|
|
|
|
// running validations for Maps
|
|
var fileValidations = AssetValidationManager<Map>.Instance.AllValidations.OfType<FileValidation>();
|
|
|
|
using (var mapSteps = context.ExecuteSteps(continueOnErroneousStep: true))
|
|
{
|
|
foreach (var map in maps)
|
|
{
|
|
mapSteps.AddStep($"Validating map : {map.Name}", mapStep =>
|
|
{
|
|
using (var validationSteps = mapStep.ExecuteSteps(continueOnErroneousStep: true))
|
|
{
|
|
fileValidations.ForEach(validation =>
|
|
{
|
|
validationSteps.AddStep($"Validating : {validation.GetType().Name}", step =>
|
|
{
|
|
validation.Validate(new FakePlumeLogger(step), map, false);
|
|
});
|
|
});
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
var packagerCommand = new PackagerCommand
|
|
{
|
|
TaskListType = PackagerTaskList.DataValidation,
|
|
FileList = filesString,
|
|
};
|
|
|
|
packagerCommand.Execute(context);
|
|
}
|
|
|
|
internal static string CreateFilePathString(IEnumerable<string> filesList)
|
|
{
|
|
var formattedString = new StringBuilder();
|
|
filesList.ForEach(x =>
|
|
{
|
|
formattedString.Append(x);
|
|
formattedString.Append(',');
|
|
});
|
|
return formattedString.ToString();
|
|
}
|
|
|
|
internal static IEnumerable<string> RemoveExclusions(IEnumerable<string> fileList)
|
|
{
|
|
return fileList.Where(x => !exclusions.Any(x.Contains));
|
|
}
|
|
|
|
|
|
internal static IEnumerable<string> GetFilesPathsFromCl(string changelistToValidate)
|
|
{
|
|
IList<FileStatus> files;
|
|
|
|
var sourceControl = SourceControlService.Instance.Data();
|
|
sourceControl.GetPendingFiles(new Changelist(changelistToValidate), out files);
|
|
|
|
return files.Select(x => x.ClientFilePath);
|
|
}
|
|
|
|
internal static IEnumerable<string> GetFilesPathsFromTxtFile(string txtFile)
|
|
{
|
|
var xml = File.ReadAllText(txtFile);
|
|
var shelveInfo = XmlExtensions.ParseXml<List<ShelvedFileInfo>>(xml);
|
|
|
|
return shelveInfo.Select(x => x.LocalPath);
|
|
}
|
|
}
|
|
|
|
[TestFixture]
|
|
[Ignore("")]
|
|
public class TestDataValidation
|
|
{
|
|
private readonly IEnumerable<string> _filesPathInCl;
|
|
public TestDataValidation()
|
|
{
|
|
_filesPathInCl = DataValidationMacro.GetFilesPathsFromCl("279628");
|
|
}
|
|
|
|
[Test]
|
|
public void test_get_files_from_data_perforce_cl()
|
|
{
|
|
Assert.IsNotEmpty(_filesPathInCl);
|
|
}
|
|
|
|
[Test]
|
|
public void test_format_filepaths_in_single_string()
|
|
{
|
|
Assert.IsNotEmpty(DataValidationMacro.CreateFilePathString(_filesPathInCl));
|
|
}
|
|
}
|
|
} |