[Harness] Move BuildToolTask to a more general namespace. (#8287)

Move the task and use composition so that we can reuse the code. This
will later allow other projects to use the class without the need of
Jenkins or Harness and just implement the base class.



Co-authored-by: Rolf Bjarne Kvinge <rolf@xamarin.com>
Co-authored-by: Přemek Vysoký <premek.vysoky@microsoft.com>
This commit is contained in:
Manuel de la Pena 2020-04-08 15:03:33 -04:00 коммит произвёл GitHub
Родитель a6955968fa
Коммит 5b99859321
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
7 изменённых файлов: 66 добавлений и 19 удалений

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

@ -1,4 +1,4 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;

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

@ -1,30 +1,40 @@
using System; using System.Threading.Tasks;
using System.Threading.Tasks;
using Microsoft.DotNet.XHarness.iOS.Shared.Execution; using Microsoft.DotNet.XHarness.iOS.Shared.Execution;
namespace Xharness.Jenkins.TestTasks namespace Xharness.Jenkins.TestTasks
{ {
public abstract class BuildToolTask : AppleTestTask public abstract class BuildToolTask : AppleTestTask
{ {
protected readonly IProcessManager ProcessManager; readonly Xharness.TestTasks.BuildToolTask buildToolTask;
public bool SpecifyPlatform = true; public IProcessManager ProcessManager => buildToolTask.ProcessManager;
public bool SpecifyConfiguration = true;
protected BuildToolTask (IProcessManager processManager) public bool SpecifyPlatform {
{ get => buildToolTask.SpecifyPlatform;
ProcessManager = processManager ?? throw new ArgumentNullException (nameof (processManager)); set => buildToolTask.SpecifyPlatform = value;
}
public bool SpecifyConfiguration {
get => buildToolTask.SpecifyConfiguration;
set => buildToolTask.SpecifyConfiguration = value;
}
protected BuildToolTask (IProcessManager processManager)
=> buildToolTask = new Xharness.TestTasks.BuildToolTask (processManager);
public override TestPlatform Platform {
get => base.Platform;
set {
base.Platform = value;
buildToolTask.Platform = value;
}
} }
public override string Mode { public override string Mode {
get { return Platform.ToString (); } get => buildToolTask.Mode;
set { throw new NotSupportedException (); } set => buildToolTask.Mode = value;
} }
public virtual Task CleanAsync () public virtual Task CleanAsync () => buildToolTask.CleanAsync ();
{
Console.WriteLine ("Clean is not implemented for {0}", GetType ().Name);
return Task.CompletedTask;
}
} }
} }

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

@ -1,4 +1,4 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;

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

@ -1,4 +1,4 @@
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.DotNet.XHarness.iOS.Shared; using Microsoft.DotNet.XHarness.iOS.Shared;

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

@ -0,0 +1,36 @@
using System;
using System.Threading.Tasks;
using Microsoft.DotNet.XHarness.iOS.Shared.Execution;
namespace Xharness.TestTasks {
public class BuildToolTask
{
public IProcessManager ProcessManager { get; }
public TestPlatform Platform { get; set; }
public bool SpecifyPlatform { get; set; } = true;
public bool SpecifyConfiguration { get; set; } = true;
public BuildToolTask (IProcessManager processManager)
{
ProcessManager = processManager ?? throw new ArgumentNullException (nameof (processManager));
}
public BuildToolTask (IProcessManager processManager, TestPlatform platform) : this (processManager)
{
Platform = platform;
}
public virtual string Mode {
get { return Platform.ToString (); }
set { throw new NotSupportedException (); }
}
public virtual Task CleanAsync ()
{
Console.WriteLine ("Clean is not implemented for {0}", GetType ().Name);
return Task.CompletedTask;
}
}
}

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

@ -37,7 +37,6 @@ namespace Xharness.TestTasks {
protected static string Timestamp => Helpers.Timestamp; protected static string Timestamp => Helpers.Timestamp;
public string ProjectFile => TestProject?.Path; public string ProjectFile => TestProject?.Path;
public bool HasCustomTestName => test_name != null; public bool HasCustomTestName => test_name != null;
public TestPlatform Platform { get; set; }
public bool NotStarted => (ExecutionResult & TestExecutingResult.StateMask) == TestExecutingResult.NotStarted; public bool NotStarted => (ExecutionResult & TestExecutingResult.StateMask) == TestExecutingResult.NotStarted;
public bool InProgress => (ExecutionResult & TestExecutingResult.InProgress) == TestExecutingResult.InProgress; public bool InProgress => (ExecutionResult & TestExecutingResult.InProgress) == TestExecutingResult.InProgress;
@ -138,6 +137,7 @@ namespace Xharness.TestTasks {
#region Virtual #region Virtual
public virtual TestPlatform Platform { get; set; }
public virtual string ProgressMessage { get; } public virtual string ProgressMessage { get; }
public virtual string Mode { get; set; } public virtual string Mode { get; set; }
public virtual string Variation { get; set; } public virtual string Variation { get; set; }

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

@ -120,6 +120,7 @@
<Compile Include="TestTasks\IAcquiredResource.cs" /> <Compile Include="TestTasks\IAcquiredResource.cs" />
<Compile Include="TestTasks\Resource.cs" /> <Compile Include="TestTasks\Resource.cs" />
<Compile Include="TestTasks\Resources.cs" /> <Compile Include="TestTasks\Resources.cs" />
<Compile Include="TestTasks\BuildToolTask.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="..\..\tools\common\SdkVersions.cs"> <Compile Include="..\..\tools\common\SdkVersions.cs">