Skip to content

Commit

Permalink
[Xharness] Enable nullable in the BuildProject class and clean code a…
Browse files Browse the repository at this point in the history
… little. (#14897)
  • Loading branch information
mandel-macaque authored May 11, 2022
1 parent 642b03b commit 22ba05b
Showing 1 changed file with 33 additions and 33 deletions.
66 changes: 33 additions & 33 deletions tests/xharness/Jenkins/TestTasks/BuildProject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@
using Microsoft.DotNet.XHarness.iOS.Shared;
using Microsoft.DotNet.XHarness.iOS.Shared.Logging;
using Microsoft.DotNet.XHarness.iOS.Shared.Utilities;
#nullable enable

namespace Xharness.Jenkins.TestTasks {
public class BuildProject : BuildTool {
public IResourceManager ResourceManager { get; set; }
public IEnvManager EnvironmentManager { get; set; }
public IEventLogger EventLogger { get; set; }
Func<string> msbuildPath;
readonly Func<string> msbuildPath;

public string SolutionPath { get; set; }
public string? SolutionPath { get; set; }

public BuildProject (Func<string> msbuildPath, IProcessManager processManager, IResourceManager resourceManager, IEventLogger eventLogger, IEnvManager envManager) : base (processManager)
{
Expand Down Expand Up @@ -46,42 +47,41 @@ public bool SupportsParallelExecution {

async Task<TestExecutingResult> RestoreNugetsAsync (string projectPath, ILog log)
{
using (var resource = await ResourceManager.NugetResource.AcquireExclusiveAsync ()) {
// we do not want to use xibuild on solutions, we will have some failures with Mac Full
var isSolution = projectPath.EndsWith (".sln", StringComparison.Ordinal);
if (!File.Exists (projectPath))
throw new FileNotFoundException ("Could not find the solution whose nugets to restore.", projectPath);
using var _ = await ResourceManager.NugetResource.AcquireExclusiveAsync ();
if (!File.Exists (projectPath))
throw new FileNotFoundException ("Could not find the solution whose nugets to restore.", projectPath);

using (var nuget = new Process ()) {
nuget.StartInfo.FileName = msbuildPath ();
var args = new List<string> ();
args.Add ("-t");
args.Add ("--");
args.Add ("/Library/Frameworks/Mono.framework/Versions/Current/Commands/nuget");
args.Add ("restore");
args.Add (projectPath);
args.Add ("-Verbosity");
args.Add ("detailed");
nuget.StartInfo.Arguments = StringUtils.FormatArguments (args);
EnvironmentManager.SetEnvironmentVariables (nuget);
EventLogger.LogEvent (log, "Restoring nugets for {0} ({1}) on path {2}", TestName, Mode, projectPath);
using (var nuget = new Process ()) {
nuget.StartInfo.FileName = msbuildPath ();
var args = new List<string> ();
args.Add ("-t");
args.Add ("--");
args.Add ("/Library/Frameworks/Mono.framework/Versions/Current/Commands/nuget");
args.Add ("restore");
args.Add (projectPath);
args.Add ("-Verbosity");
args.Add ("detailed");
nuget.StartInfo.Arguments = StringUtils.FormatArguments (args);
EnvironmentManager.SetEnvironmentVariables (nuget);
EventLogger.LogEvent (log, "Restoring nugets for {0} ({1}) on path {2}", TestName, Mode, projectPath);

var timeout = TimeSpan.FromMinutes (15);
var result = await ProcessManager.RunAsync (nuget, log, timeout);
if (result.TimedOut) {
log.WriteLine ("Nuget restore timed out after {0} seconds.", timeout.TotalSeconds);
return TestExecutingResult.TimedOut;
} else if (!result.Succeeded) {
return TestExecutingResult.Failed;
}
var timeout = TimeSpan.FromMinutes (15);
var result = await ProcessManager.RunAsync (nuget, log, timeout);
if (result.TimedOut) {
log.WriteLine ("Nuget restore timed out after {0} seconds.", timeout.TotalSeconds);
return TestExecutingResult.TimedOut;
}

EventLogger.LogEvent (log, "Restoring nugets completed for {0} ({1}) on path {2}", TestName, Mode, projectPath);
return TestExecutingResult.Succeeded;
if (!result.Succeeded) {
return TestExecutingResult.Failed;
}
}

EventLogger.LogEvent (log, "Restoring nugets completed for {0} ({1}) on path {2}", TestName, Mode, projectPath);
return TestExecutingResult.Succeeded;
}

List<string> GetNestedReferenceProjects (string csproj)
static IEnumerable<string> GetNestedReferenceProjects (string csproj)
{
if (!File.Exists (csproj))
throw new FileNotFoundException ("Could not find the project whose reference projects needed to be found.", csproj);
Expand Down Expand Up @@ -110,8 +110,8 @@ public async Task<TestExecutingResult> RestoreNugetsAsync (ILog log, IAcquiredRe
throw new FileNotFoundException ("Could not find the solution whose nugets to restore.", SolutionPath ?? TestProject.Path);

// might happen that the project does contain reference projects with nugets, grab the reference projects and ensure
// thast they have the nugets restored (usually, watch os test projects
if (SolutionPath == null) {
// that they have the nugets restored (usually, watch os test projects
if (SolutionPath is null) {
var references = GetNestedReferenceProjects (TestProject.Path);
foreach (var referenceProject in references) {
var execResult = await RestoreNugetsAsync (referenceProject, log); // do the replace in case we use win paths
Expand Down

1 comment on commit 22ba05b

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📋 [CI Build] API Diff 📋

API Current PR diff

ℹ️ API Diff (from PR only) (please review changes)

View API diff
View dotnet API diff
View dotnet legacy API diff
View dotnet iOS-MacCatalayst API diff

API diff

✅ API Diff from stable

View API diff
View dotnet API diff
View dotnet legacy API diff
View dotnet iOS-MacCatalayst API diff

Generator diff

Generator Diff (no change)

Pipeline on Agent XAMMINI-055.Monterey
Hash: 22ba05bed52383cb1689fe87e8cd0f2bc0bc7a8e

Please sign in to comment.