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
10 changes: 7 additions & 3 deletions src/Tasks.UnitTests/ZipDirectory_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public void CanZipDirectory(string? compressionLevel, CompressionSupportKind com
CompressionLevel = compressionLevel,
DestinationFile = new TaskItem(zipFilePath),
SourceDirectory = new TaskItem(sourceFolder.Path),
TaskEnvironment = TaskEnvironmentHelper.CreateForTest(),
};

zipDirectory.Execute().ShouldBeTrue(_mockEngine.Log);
Expand Down Expand Up @@ -109,7 +110,8 @@ public void CanOverwriteExistingFile()
BuildEngine = _mockEngine,
DestinationFile = new TaskItem(file.Path),
Overwrite = true,
SourceDirectory = new TaskItem(sourceFolder.Path)
SourceDirectory = new TaskItem(sourceFolder.Path),
TaskEnvironment = TaskEnvironmentHelper.CreateForTest(),
};

zipDirectory.Execute().ShouldBeTrue(_mockEngine.Log);
Expand Down Expand Up @@ -146,7 +148,8 @@ public void LogsErrorIfDestinationExists()
{
BuildEngine = _mockEngine,
DestinationFile = new TaskItem(file.Path),
SourceDirectory = new TaskItem(folder.Path)
SourceDirectory = new TaskItem(folder.Path),
TaskEnvironment = TaskEnvironmentHelper.CreateForTest(),
};

zipDirectory.Execute().ShouldBeFalse(_mockEngine.Log);
Expand All @@ -161,7 +164,8 @@ public void LogsErrorIfDirectoryDoesNotExist()
ZipDirectory zipDirectory = new ZipDirectory
{
BuildEngine = _mockEngine,
SourceDirectory = new TaskItem(Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N")))
SourceDirectory = new TaskItem(Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N"))),
TaskEnvironment = TaskEnvironmentHelper.CreateForTest(),
};

zipDirectory.Execute().ShouldBeFalse(_mockEngine.Log);
Expand Down
12 changes: 9 additions & 3 deletions src/Tasks/ZipDirectory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

namespace Microsoft.Build.Tasks
{
public sealed class ZipDirectory : TaskExtension, IIncrementalTask
[MSBuildMultiThreadableTask]
public sealed class ZipDirectory : TaskExtension, IIncrementalTask, IMultiThreadableTask
{
public const string CompressionLevelOptimal = "Optimal";
public const string CompressionLevelFastest = "Fastest";
Expand Down Expand Up @@ -57,17 +58,22 @@ public sealed class ZipDirectory : TaskExtension, IIncrementalTask
/// </remarks>
public string? CompressionLevel { get; set; }

/// <inheritdoc />
public TaskEnvironment TaskEnvironment { get; set; } = null!;
Comment thread
SimaTian marked this conversation as resolved.

public override bool Execute()
{
DirectoryInfo sourceDirectory = new DirectoryInfo(SourceDirectory.ItemSpec);
AbsolutePath sourceDirectoryAbsolutePath = TaskEnvironment.GetAbsolutePath(SourceDirectory.ItemSpec);
DirectoryInfo sourceDirectory = new DirectoryInfo(sourceDirectoryAbsolutePath);

if (!sourceDirectory.Exists)
{
Log.LogErrorWithCodeFromResources("ZipDirectory.ErrorDirectoryDoesNotExist", sourceDirectory.FullName);
return false;
}

FileInfo destinationFile = new FileInfo(DestinationFile.ItemSpec);
Comment thread
JanProvaznik marked this conversation as resolved.
AbsolutePath destinationFileAbsolutePath = TaskEnvironment.GetAbsolutePath(DestinationFile.ItemSpec);
FileInfo destinationFile = new FileInfo(destinationFileAbsolutePath);

BuildEngine3.Yield();
Comment thread
JanProvaznik marked this conversation as resolved.

Expand Down
Loading