From ce7dd337dca3cd21cc8174f2b49cb81c92a16045 Mon Sep 17 00:00:00 2001 From: pedrojesus-work Date: Tue, 30 Apr 2024 18:20:35 -0300 Subject: [PATCH 1/9] chore: add svg as content --- .../Resizetizer.Extensions.Sample/Assets/SVG/back.svg | 3 +++ .../Resizetizer.Extensions.Sample.csproj | 7 +++++++ 2 files changed, 10 insertions(+) create mode 100644 samples/NewTemplate/Resizetizer.Extensions.Sample/Assets/SVG/back.svg diff --git a/samples/NewTemplate/Resizetizer.Extensions.Sample/Assets/SVG/back.svg b/samples/NewTemplate/Resizetizer.Extensions.Sample/Assets/SVG/back.svg new file mode 100644 index 00000000..bcd7851b --- /dev/null +++ b/samples/NewTemplate/Resizetizer.Extensions.Sample/Assets/SVG/back.svg @@ -0,0 +1,3 @@ + + + diff --git a/samples/NewTemplate/Resizetizer.Extensions.Sample/Resizetizer.Extensions.Sample.csproj b/samples/NewTemplate/Resizetizer.Extensions.Sample/Resizetizer.Extensions.Sample.csproj index 51551afb..9be80d49 100644 --- a/samples/NewTemplate/Resizetizer.Extensions.Sample/Resizetizer.Extensions.Sample.csproj +++ b/samples/NewTemplate/Resizetizer.Extensions.Sample/Resizetizer.Extensions.Sample.csproj @@ -60,6 +60,13 @@ + + + + PreserveNewest + + + From 325b80238b24d1a970dabaff9432174560a06886 Mon Sep 17 00:00:00 2001 From: pedrojesus-work Date: Tue, 30 Apr 2024 18:21:48 -0300 Subject: [PATCH 2/9] fix: rework RemoveSvgFromContentTask to work with UnoImage collection --- src/.nuspec/Uno.Resizetizer.targets | 3 +- .../src/RemoveSvgFromContentTask.cs | 35 +++++++++---------- 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/src/.nuspec/Uno.Resizetizer.targets b/src/.nuspec/Uno.Resizetizer.targets index 29e3905f..af968c6e 100644 --- a/src/.nuspec/Uno.Resizetizer.targets +++ b/src/.nuspec/Uno.Resizetizer.targets @@ -355,7 +355,8 @@ BeforeTargets="_UnoAddAssetsFilesToCopyLocal" AfterTargets="ContentFilesProjectOutputGroup"> - + diff --git a/src/Resizetizer/src/RemoveSvgFromContentTask.cs b/src/Resizetizer/src/RemoveSvgFromContentTask.cs index 607b4289..c65abb29 100644 --- a/src/Resizetizer/src/RemoveSvgFromContentTask.cs +++ b/src/Resizetizer/src/RemoveSvgFromContentTask.cs @@ -2,6 +2,7 @@ using Microsoft.Build.Utilities; using System; using System.Collections.Generic; +using System.Diagnostics; using System.IO; using System.Linq; @@ -12,6 +13,8 @@ public class RemoveSvgFromContentTask_v0 : Task [Required] public ITaskItem[] CollectionToRemove { get; set; } = Array.Empty(); + public ITaskItem[] UnoImages { get; set; } = []; + [Output] public ITaskItem[] RemovedItems { get; set; } = Array.Empty(); @@ -20,9 +23,9 @@ public override bool Execute() try { #if DEBUG_RESIZETIZER - //System.Diagnostics.Debugger.Launch(); + System.Diagnostics.Debugger.Launch(); #endif - RemovedItems = RemoveDuplicateSvgAndPngFiles(CollectionToRemove); + RemovedItems = RemoveUnoImagesSvgFromContent(); return true; } catch (Exception ex) @@ -32,32 +35,26 @@ public override bool Execute() } } - static ITaskItem[] RemoveDuplicateSvgAndPngFiles(ITaskItem[] assets) + ITaskItem[] RemoveUnoImagesSvgFromContent() { var list = new List(); - var count = assets.Length; - for (var i = 0; i < count; i++) + foreach (var asset in CollectionToRemove) { - var item = assets[i].ItemSpec; - var extension = Path.GetExtension(item) ?? string.Empty; - if (!extension.Equals(".svg", StringComparison.OrdinalIgnoreCase)) + var extension2 = Path.GetExtension(asset.ItemSpec) ?? string.Empty; + var isSvg = extension2.Equals(".svg", StringComparison.OrdinalIgnoreCase); + + if (string.IsNullOrEmpty(extension2) || !isSvg) { continue; } - var svgFileName = Path.GetFileNameWithoutExtension(item); - foreach (var item2 in assets) + var assetFullPath = asset.GetMetadata("fullpath"); + foreach (var unoImage in UnoImages) { - var extension2 = Path.GetExtension(item2.ItemSpec) ?? string.Empty; - if (extension2.Equals(".svg", StringComparison.OrdinalIgnoreCase) - || !extension2.Equals(".png", StringComparison.CurrentCultureIgnoreCase)) - { - continue; - } - - if (svgFileName == Path.GetFileNameWithoutExtension(item2.ItemSpec)) + var fullPath = unoImage.GetMetadata("fullpath"); + if (fullPath == assetFullPath) { - list.Add(assets[i]); + list.Add(asset); } } } From ae3946f849f892345f1c743cd8b7899a0a5c9721 Mon Sep 17 00:00:00 2001 From: pedrojesus-work Date: Tue, 30 Apr 2024 18:25:53 -0300 Subject: [PATCH 3/9] test: add tests to validate changes --- .../UnitTests/RemoveSvgFromContentTests.cs | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 src/Resizetizer/test/UnitTests/RemoveSvgFromContentTests.cs diff --git a/src/Resizetizer/test/UnitTests/RemoveSvgFromContentTests.cs b/src/Resizetizer/test/UnitTests/RemoveSvgFromContentTests.cs new file mode 100644 index 00000000..005ca72f --- /dev/null +++ b/src/Resizetizer/test/UnitTests/RemoveSvgFromContentTests.cs @@ -0,0 +1,50 @@ +using Microsoft.Build.Framework; +using Microsoft.Build.Utilities; +using Xunit; + +namespace Uno.Resizetizer.Tests +{ + public class RemoveSvgFromContentTests : MSBuildTaskTestFixture + { + RemoveSvgFromContentTask_v0 GetNewTask(ITaskItem[] collectionToRemove, ITaskItem[] unoImages) + { + return new() + { + CollectionToRemove = collectionToRemove, + UnoImages = unoImages + }; + } + + + [Fact] + public void RemoveSvgContentIfItIsUnoImage() + { + var assetPath = "Assets/Icons/back.svg"; + var unoImage = new TaskItem(assetPath); + var content = new TaskItem(assetPath); + + var task = GetNewTask(new[] { content }, new[] { unoImage }); + + var success = task.Execute(); + + + Assert.True(success); + Assert.True(task.RemovedItems.Length > 0); + } + + [Fact] + public void DoNotRemoveSvgIfHasSameNameButInDifferentLocation() + { + var unoImage = new TaskItem("Assets/Icons/back.svg"); + var content = new TaskItem("Assets/SVG/back.svg"); + + var task = GetNewTask(new[] { content }, new[] { unoImage }); + + var success = task.Execute(); + + + Assert.True(success); + Assert.True(task.RemovedItems.Length is 0); + } + } +} From 354ad1cc335294ed1257c110ed459d9cb9ce62b7 Mon Sep 17 00:00:00 2001 From: pedrojesus-work Date: Tue, 30 Apr 2024 18:27:22 -0300 Subject: [PATCH 4/9] chore: code cleanup --- src/Resizetizer/src/RemoveSvgFromContentTask.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Resizetizer/src/RemoveSvgFromContentTask.cs b/src/Resizetizer/src/RemoveSvgFromContentTask.cs index c65abb29..66a72dd4 100644 --- a/src/Resizetizer/src/RemoveSvgFromContentTask.cs +++ b/src/Resizetizer/src/RemoveSvgFromContentTask.cs @@ -2,9 +2,7 @@ using Microsoft.Build.Utilities; using System; using System.Collections.Generic; -using System.Diagnostics; using System.IO; -using System.Linq; namespace Uno.Resizetizer; @@ -13,7 +11,7 @@ public class RemoveSvgFromContentTask_v0 : Task [Required] public ITaskItem[] CollectionToRemove { get; set; } = Array.Empty(); - public ITaskItem[] UnoImages { get; set; } = []; + public ITaskItem[] UnoImages { get; set; } = Array.Empty(); [Output] public ITaskItem[] RemovedItems { get; set; } = Array.Empty(); From 12db10609439f30006b7fd22c28d24794f26e31e Mon Sep 17 00:00:00 2001 From: pedrojesus-work Date: Thu, 2 May 2024 13:38:52 -0300 Subject: [PATCH 5/9] chore: rename folder --- .../Resizetizer.Extensions.Sample.csproj | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/samples/NewTemplate/Resizetizer.Extensions.Sample/Resizetizer.Extensions.Sample.csproj b/samples/NewTemplate/Resizetizer.Extensions.Sample/Resizetizer.Extensions.Sample.csproj index 9be80d49..a4f9ace9 100644 --- a/samples/NewTemplate/Resizetizer.Extensions.Sample/Resizetizer.Extensions.Sample.csproj +++ b/samples/NewTemplate/Resizetizer.Extensions.Sample/Resizetizer.Extensions.Sample.csproj @@ -61,10 +61,10 @@ - - - PreserveNewest - + + + PreserveNewest + From be182b85e58e2d39329845f17485974d531faf3d Mon Sep 17 00:00:00 2001 From: pedrojesus-work Date: Thu, 2 May 2024 13:54:02 -0300 Subject: [PATCH 6/9] chore: use wild card for svg folder --- .../Resizetizer.Extensions.Sample.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/samples/NewTemplate/Resizetizer.Extensions.Sample/Resizetizer.Extensions.Sample.csproj b/samples/NewTemplate/Resizetizer.Extensions.Sample/Resizetizer.Extensions.Sample.csproj index a4f9ace9..f9642c58 100644 --- a/samples/NewTemplate/Resizetizer.Extensions.Sample/Resizetizer.Extensions.Sample.csproj +++ b/samples/NewTemplate/Resizetizer.Extensions.Sample/Resizetizer.Extensions.Sample.csproj @@ -61,8 +61,8 @@ - - + + PreserveNewest From c1a2e6c0170c70454f76bccc91b69dd7966e135a Mon Sep 17 00:00:00 2001 From: pedrojesus-work Date: Thu, 2 May 2024 14:01:51 -0300 Subject: [PATCH 7/9] test: add verification if the svg isn't handled for Resizetizer --- .../Resizetizer.Extensions.Sample.csproj | 2 ++ 1 file changed, 2 insertions(+) diff --git a/samples/NewTemplate/Resizetizer.Extensions.Sample/Resizetizer.Extensions.Sample.csproj b/samples/NewTemplate/Resizetizer.Extensions.Sample/Resizetizer.Extensions.Sample.csproj index f9642c58..33048bff 100644 --- a/samples/NewTemplate/Resizetizer.Extensions.Sample/Resizetizer.Extensions.Sample.csproj +++ b/samples/NewTemplate/Resizetizer.Extensions.Sample/Resizetizer.Extensions.Sample.csproj @@ -71,7 +71,9 @@ <_ResizetizerAppIconImagesPath>$(_UnoIntermediateImages)Images\dotnet_bot.scale-200.png + <_SvgContent>$(OutputPath)Assets\Svg\back.svg + \ No newline at end of file From b5485fc3ba7c3557497f517219990be8ae0db60b Mon Sep 17 00:00:00 2001 From: pedrojesus-work Date: Mon, 6 May 2024 16:21:20 -0300 Subject: [PATCH 8/9] chore: removing SVG folder --- .../Resizetizer.Extensions.Sample/Assets/SVG/back.svg | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 samples/NewTemplate/Resizetizer.Extensions.Sample/Assets/SVG/back.svg diff --git a/samples/NewTemplate/Resizetizer.Extensions.Sample/Assets/SVG/back.svg b/samples/NewTemplate/Resizetizer.Extensions.Sample/Assets/SVG/back.svg deleted file mode 100644 index bcd7851b..00000000 --- a/samples/NewTemplate/Resizetizer.Extensions.Sample/Assets/SVG/back.svg +++ /dev/null @@ -1,3 +0,0 @@ - - - From 826a90bf777a74c709de52ca5eb1beddb48f2034 Mon Sep 17 00:00:00 2001 From: pedrojesus-work Date: Mon, 6 May 2024 16:23:00 -0300 Subject: [PATCH 9/9] chore: re-adding back.svg --- .../Resizetizer.Extensions.Sample/Assets/{Icons => Svg}/back.svg | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename samples/NewTemplate/Resizetizer.Extensions.Sample/Assets/{Icons => Svg}/back.svg (100%) diff --git a/samples/NewTemplate/Resizetizer.Extensions.Sample/Assets/Icons/back.svg b/samples/NewTemplate/Resizetizer.Extensions.Sample/Assets/Svg/back.svg similarity index 100% rename from samples/NewTemplate/Resizetizer.Extensions.Sample/Assets/Icons/back.svg rename to samples/NewTemplate/Resizetizer.Extensions.Sample/Assets/Svg/back.svg