Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 0 additions & 52 deletions msbuild/Xamarin.MacDev.Tasks/Tasks/Ditto.cs

This file was deleted.

39 changes: 38 additions & 1 deletion msbuild/Xamarin.MacDev.Tasks/Tasks/DittoTaskBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;

using Xamarin.Messaging.Build.Client;

namespace Xamarin.MacDev.Tasks {
public abstract class DittoTaskBase : XamarinToolTask {
public class Ditto : XamarinToolTask, ITaskCallback {
#region Inputs

public string? AdditionalArguments { get; set; }
Expand Down Expand Up @@ -65,6 +68,14 @@ protected override string GenerateCommandLineCommands ()

public override bool Execute ()
{
if (ShouldExecuteRemotely ()) {
var taskRunner = new TaskRunner (SessionId, BuildEngine4);

taskRunner.FixReferencedItems (new ITaskItem [] { Source! });

return taskRunner.RunAsync (this).Result;
}

if (!base.Execute ())
return false;

Expand All @@ -90,5 +101,31 @@ protected override void LogEventsFromTextOutput (string singleLine, MessageImpor
// TODO: do proper parsing of error messages and such
Log.LogMessage (messageImportance, "{0}", singleLine);
}

public override void Cancel ()
{
base.Cancel ();

if (ShouldExecuteRemotely ())
BuildConnection.CancelAsync (BuildEngine4).Wait ();
}

public IEnumerable<ITaskItem> GetAdditionalItemsToBeCopied ()
{
if (!Directory.Exists (Source!.ItemSpec))
return Enumerable.Empty<ITaskItem> ();

if (!CopyFromWindows)
return Enumerable.Empty<ITaskItem> ();

// TaskRunner doesn't know how to copy directories to Mac but `ditto` can take directories (and that's why we use ditto often).
// If Source is a directory path, let's add each file within it as an TaskItem, as TaskRunner knows how to copy files to Mac.
return Directory.GetFiles (Source.ItemSpec, "*", SearchOption.AllDirectories)
.Select (f => new TaskItem (f));
}

public bool ShouldCopyToBuildServer (ITaskItem item) => true;

public bool ShouldCreateOutputFile (ITaskItem item) => true;
}
}