PR Feedback:
- Use 'archive' rather than 'tarball' - Remove dead code - Discard unused return values
This commit is contained in:
parent
9ffe5c200d
commit
7632ab4d74
4 changed files with 60 additions and 95 deletions
|
@ -1,23 +1,23 @@
|
|||
<Project>
|
||||
<UsingTask AssemblyFile="$(SdkArchiveDiffTasksAssembly)" TaskName="FindArchiveDiffs" />
|
||||
<UsingTask AssemblyFile="$(SdkArchiveDiffTasksAssembly)" TaskName="GetClosestOfficialSdk" />
|
||||
<UsingTask AssemblyFile="$(SdkArchiveDiffTasksAssembly)" TaskName="GetSingleTarballItem" />
|
||||
<UsingTask AssemblyFile="$(SdkArchiveDiffTasksAssembly)" TaskName="GetSingleArchiveItem" />
|
||||
|
||||
<Target Name="ReportSdkArchiveDiffs"
|
||||
AfterTargets="Build"
|
||||
DependsOnTargets="DetermineSourceBuiltSdkVersion" >
|
||||
|
||||
<GetSingleTarballItem SdkTarballItems="@(SdkTarballItem)">
|
||||
<Output TaskParameter="BestSdkTarballItem" PropertyName="_TestSdkArchivePath"/>
|
||||
</GetSingleTarballItem>
|
||||
<GetSingleArchiveItem SdkArchiveItems="@(SdkTarballItem)">
|
||||
<Output TaskParameter="BestSdkArchiveItem" PropertyName="_BuiltSdkArchivePath"/>
|
||||
</GetSingleArchiveItem>
|
||||
|
||||
<GetClosestOfficialSdk BuiltSdkPath="$(_TestSdkArchivePath)" Condition="'$(_TestSdkArchivePath)' != ''">
|
||||
<GetClosestOfficialSdk BuiltSdkPath="$(_BuiltSdkArchivePath)" Condition="'$(_BuiltSdkArchivePath)' != ''">
|
||||
<Output TaskParameter="ClosestOfficialSdkPath" PropertyName="ClosestOfficialSdkPath" />
|
||||
</GetClosestOfficialSdk>
|
||||
|
||||
<Message Text="Failed to find closest official SDK archive." Importance="High" Condition="'$(_TestSdkArchivePath)' != '' AND '$(ClosestOfficialSdkPath)' == ''" />
|
||||
<Message Text="Failed to find closest official SDK archive." Importance="High" Condition="'$(_BuiltSdkArchivePath)' != '' AND '$(ClosestOfficialSdkPath)' == ''" />
|
||||
|
||||
<FindArchiveDiffs BaselineArchive="$(_TestSdkArchivePath)" TestArchive="$(ClosestOfficialSdkPath)" Condition="'$(_TestSdkArchivePath)' != '' AND '$(ClosestOfficialSdkPath)' != ''">
|
||||
<FindArchiveDiffs BaselineArchive="$(_BuiltSdkArchivePath)" TestArchive="$(ClosestOfficialSdkPath)" Condition="'$(_BuiltSdkArchivePath)' != '' AND '$(ClosestOfficialSdkPath)' != ''">
|
||||
<Output TaskParameter="ContentDifferences" ItemName="ContentDifferences" />
|
||||
</FindArchiveDiffs>
|
||||
|
||||
|
|
|
@ -21,13 +21,9 @@ public abstract class Archive : IDisposable
|
|||
throw new NotSupportedException("Unsupported archive type");
|
||||
}
|
||||
|
||||
public abstract bool Contains(string relativePath);
|
||||
|
||||
public abstract string[] GetFileNames();
|
||||
|
||||
public abstract string[] GetFileLines(string relativePath);
|
||||
|
||||
public abstract Task<byte[]> GetFileBytesAsync(string relativePath);
|
||||
public abstract bool Contains(string relativePath);
|
||||
|
||||
public abstract void Dispose();
|
||||
|
||||
|
@ -61,19 +57,6 @@ public abstract class Archive : IDisposable
|
|||
return Directory.GetFiles(_extractedFolder, "*", SearchOption.AllDirectories).Select(f => f.Substring(_extractedFolder.Length + 1)).ToArray();
|
||||
}
|
||||
|
||||
public override string[] GetFileLines(string relativePath)
|
||||
{
|
||||
return File.ReadAllLines(Path.Combine(_extractedFolder, relativePath));
|
||||
}
|
||||
|
||||
public override Task<byte[]> GetFileBytesAsync(string relativePath)
|
||||
{
|
||||
var filePath = Path.Combine(_extractedFolder, relativePath);
|
||||
if (!File.Exists(filePath))
|
||||
return Task.FromResult<byte[]>([]);
|
||||
return File.ReadAllBytesAsync(Path.Combine(_extractedFolder, relativePath));
|
||||
}
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
if (Directory.Exists(_extractedFolder))
|
||||
|
@ -105,25 +88,6 @@ public abstract class Archive : IDisposable
|
|||
return _archive.Entries.Select(e => e.FullName).ToArray();
|
||||
}
|
||||
|
||||
public override string[] GetFileLines(string relativePath)
|
||||
{
|
||||
var entry = _archive.GetEntry(relativePath);
|
||||
if (entry == null)
|
||||
throw new ArgumentException("File not found");
|
||||
return entry.Lines();
|
||||
}
|
||||
public override Task<byte[]> GetFileBytesAsync(string relativePath)
|
||||
{
|
||||
using (var entry = _archive.GetEntry(relativePath)?.Open())
|
||||
{
|
||||
if (entry == null)
|
||||
{
|
||||
return Task.FromResult<byte[]>([]);
|
||||
}
|
||||
return entry.ReadToEndAsync();
|
||||
}
|
||||
}
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
_archive.Dispose();
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.Build.Framework;
|
||||
|
||||
public class GetSingleArchiveItem : Microsoft.Build.Utilities.Task
|
||||
{
|
||||
[Required]
|
||||
public required ITaskItem[] SdkArchiveItems { get; init; }
|
||||
|
||||
[Output]
|
||||
public string BestSdkArchiveItem { get; set; } = "";
|
||||
|
||||
public override bool Execute()
|
||||
{
|
||||
List<string> archiveItems = new ();
|
||||
foreach(var item in SdkArchiveItems)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Ensure the version and RID info can be parsed from the item
|
||||
_ = Archive.GetInfoFromArchivePath(item.ItemSpec);
|
||||
archiveItems.Add(item.ItemSpec);
|
||||
}
|
||||
catch (ArgumentException e)
|
||||
{
|
||||
Log.LogMessage(MessageImportance.High, e.Message);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
switch (archiveItems.Count){
|
||||
case 0:
|
||||
Log.LogMessage(MessageImportance.High, "No valid archive items found");
|
||||
BestSdkArchiveItem = "";
|
||||
break;
|
||||
case 1:
|
||||
Log.LogMessage(MessageImportance.High, $"{archiveItems[0]} is the only valid archive item found");
|
||||
BestSdkArchiveItem = archiveItems[0];
|
||||
break;
|
||||
default:
|
||||
archiveItems.Sort((a,b) => a.Length - b.Length);
|
||||
Log.LogMessage(MessageImportance.High, $"Multiple valid archive items found: '{string.Join("', '", archiveItems)}'");
|
||||
BestSdkArchiveItem = archiveItems[0];
|
||||
Log.LogMessage(MessageImportance.High, $"Choosing '{BestSdkArchiveItem}");
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,51 +0,0 @@
|
|||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.Build.Framework;
|
||||
|
||||
public class GetSingleTarballItem : Microsoft.Build.Utilities.Task
|
||||
{
|
||||
[Required]
|
||||
public required ITaskItem[] SdkTarballItems { get; init; }
|
||||
|
||||
[Output]
|
||||
public string BestSdkTarballItem { get; set; } = "";
|
||||
|
||||
public override bool Execute()
|
||||
{
|
||||
List<string> tarballItems = new ();
|
||||
foreach(var item in SdkTarballItems)
|
||||
{
|
||||
try
|
||||
{
|
||||
var (versionString, rid, extension) = Archive.GetInfoFromArchivePath(item.ItemSpec);
|
||||
tarballItems.Add(item.ItemSpec);
|
||||
}
|
||||
catch (ArgumentException e)
|
||||
{
|
||||
Log.LogMessage(MessageImportance.High, e.Message);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
switch (tarballItems.Count){
|
||||
case 0:
|
||||
Log.LogMessage(MessageImportance.High, "No valid tarball items found");
|
||||
BestSdkTarballItem = "";
|
||||
break;
|
||||
case 1:
|
||||
Log.LogMessage(MessageImportance.High, $"{tarballItems[0]} is the only valid tarball item found");
|
||||
BestSdkTarballItem = tarballItems[0];
|
||||
break;
|
||||
default:
|
||||
tarballItems.Sort((a,b) => a.Length - b.Length);
|
||||
Log.LogMessage(MessageImportance.High, $"Multiple valid tarball items found: '{string.Join("', '", tarballItems)}'");
|
||||
BestSdkTarballItem = tarballItems[0];
|
||||
Log.LogMessage(MessageImportance.High, $"Choosing '{BestSdkTarballItem}");
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue