[xharness] Add nullability to the TestProject class. (#13489)

Also simplify some code elsewhere to make that easier.
This commit is contained in:
Rolf Bjarne Kvinge 2021-12-03 18:24:03 +01:00 коммит произвёл GitHub
Родитель 598261e73d
Коммит d2383796d4
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 33 добавлений и 40 удалений

Просмотреть файл

@ -32,10 +32,6 @@ namespace Xharness {
public string Platform = "x86";
public MacTestProject () : base ()
{
}
public MacTestProject (string path, bool isExecutableProject = true, MacFlavors targetFrameworkFlavor = MacFlavors.Full | MacFlavors.Modern) : base (path, isExecutableProject)
{
TargetFrameworkFlavors = targetFrameworkFlavor;
@ -43,10 +39,14 @@ namespace Xharness {
public override TestProject Clone ()
{
var rv = (MacTestProject) base.Clone ();
rv.TargetFrameworkFlavors = TargetFrameworkFlavors;
return CompleteClone (new MacTestProject (Path, IsExecutableProject, TargetFrameworkFlavors));
}
protected override TestProject CompleteClone (TestProject project)
{
var rv = (MacTestProject) project;
rv.Platform = Platform;
return rv;
return base.CompleteClone (rv);
}
public override string ToString ()

Просмотреть файл

@ -1,3 +1,5 @@
#nullable enable
using System;
using System.Collections.Generic;
using System.Diagnostics;
@ -13,32 +15,28 @@ using Xharness.Jenkins.TestTasks;
namespace Xharness {
public class TestProject {
XmlDocument xml;
XmlDocument? xml;
bool generate_variations = true;
public TestPlatform TestPlatform;
public string Path;
public string SolutionPath;
public string Name;
public string? SolutionPath;
public string? Name;
public bool IsExecutableProject;
public bool IsNUnitProject;
public bool IsDotNetProject;
public string [] Configurations;
public Func<Task> Dependency;
public string FailureMessage;
public string []? Configurations;
public Func<Task>? Dependency;
public string? FailureMessage;
public bool RestoreNugetsInProject = true;
public string MTouchExtraArgs;
public string? MTouchExtraArgs;
public double TimeoutMultiplier = 1;
public bool? Ignore;
public IEnumerable<TestProject> ProjectReferences;
public IEnumerable<TestProject>? ProjectReferences;
// Optional
public MonoNativeInfo MonoNativeInfo { get; set; }
public TestProject ()
{
}
public MonoNativeInfo? MonoNativeInfo { get; set; }
public TestProject (string path, bool isExecutableProject = true)
{
@ -60,7 +58,11 @@ namespace Xharness {
public virtual TestProject Clone ()
{
TestProject rv = (TestProject) Activator.CreateInstance (GetType ());
return CompleteClone (new TestProject (Path, IsExecutableProject));
}
protected virtual TestProject CompleteClone (TestProject rv)
{
rv.Path = Path;
rv.IsExecutableProject = IsExecutableProject;
rv.IsDotNetProject = IsDotNetProject;
@ -73,13 +75,6 @@ namespace Xharness {
return rv;
}
internal async Task<TestProject> CreateCloneAsync (ILog log, IProcessManager processManager, ITestTask test, string rootDirectory)
{
var rv = Clone ();
await rv.CreateCopyAsync (log, processManager, test, rootDirectory);
return rv;
}
public Task CreateCopyAsync (ILog log, IProcessManager processManager, ITestTask test, string rootDirectory)
{
var pr = new Dictionary<string, TestProject> ();
@ -88,7 +83,7 @@ namespace Xharness {
async Task CreateCopyAsync (ILog log, IProcessManager processManager, ITestTask test, string rootDirectory, Dictionary<string, TestProject> allProjectReferences)
{
var directory = Cache.CreateTemporaryDirectory (test?.TestName ?? System.IO.Path.GetFileNameWithoutExtension (Path));
var directory = Cache.CreateTemporaryDirectory (test.TestName ?? System.IO.Path.GetFileNameWithoutExtension (Path));
Directory.CreateDirectory (directory);
var original_path = Path;
Path = System.IO.Path.Combine (directory, System.IO.Path.GetFileName (Path));
@ -244,7 +239,7 @@ namespace Xharness {
public override string ToString ()
{
return Name;
return Name ?? base.ToString ();
}
}

Просмотреть файл

@ -52,10 +52,7 @@ namespace Xharness {
return null;
if (extensions.Count () != 1)
throw new NotImplementedException ();
return new TestProject
{
Path = Path.GetFullPath (Path.Combine (Path.GetDirectoryName (self.Path), Target.ProjectsDir, "today-extension", extensions.First ().Replace ('\\', '/'))),
};
return new TestProject (Path.GetFullPath (Path.Combine (Path.GetDirectoryName (self.Path), Target.ProjectsDir, "today-extension", extensions.First ().Replace ('\\', '/'))));
}
}
}

Просмотреть файл

@ -12,10 +12,6 @@ namespace Xharness {
public bool SkipDeviceVariations;
public bool BuildOnly;
public iOSTestProject ()
{
}
public iOSTestProject (string path, bool isExecutableProject = true)
: base (path, isExecutableProject)
{
@ -32,7 +28,12 @@ namespace Xharness {
public override TestProject Clone ()
{
var rv = (iOSTestProject) base.Clone ();
return CompleteClone (new iOSTestProject (Path, IsExecutableProject));
}
protected override TestProject CompleteClone (TestProject project)
{
var rv = (iOSTestProject) project;
rv.SkipiOSVariation = SkipiOSVariation;
rv.SkipwatchOSVariation = SkipwatchOSVariation;
rv.SkipwatchOSARM64_32Variation = SkipwatchOSARM64_32Variation;
@ -41,7 +42,7 @@ namespace Xharness {
rv.SkipTodayExtensionVariation = SkipTodayExtensionVariation;
rv.SkipDeviceVariations = SkipDeviceVariations;
rv.BuildOnly = BuildOnly;
return rv;
return base.CompleteClone (rv);
}
}
}