From 99d4f935003ae651b9b4ac4c239f190146bdd641 Mon Sep 17 00:00:00 2001 From: pedrojesus-work Date: Thu, 21 Mar 2024 13:43:10 -0300 Subject: [PATCH 01/10] chore: configure apps to build just for android --- .../Resizetizer.Extensions.Sample.Mobile.csproj | 4 ++-- .../Resizetizer.Extensions.Sample.csproj | 9 +++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/samples/NewTemplate/Resizetizer.Extensions.Sample.Mobile/Resizetizer.Extensions.Sample.Mobile.csproj b/samples/NewTemplate/Resizetizer.Extensions.Sample.Mobile/Resizetizer.Extensions.Sample.Mobile.csproj index db2846de..15a3c47d 100644 --- a/samples/NewTemplate/Resizetizer.Extensions.Sample.Mobile/Resizetizer.Extensions.Sample.Mobile.csproj +++ b/samples/NewTemplate/Resizetizer.Extensions.Sample.Mobile/Resizetizer.Extensions.Sample.Mobile.csproj @@ -1,6 +1,6 @@ - + - net7.0-android;net7.0-ios;net7.0-maccatalyst + net8.0-android; true Exe diff --git a/samples/NewTemplate/Resizetizer.Extensions.Sample/Resizetizer.Extensions.Sample.csproj b/samples/NewTemplate/Resizetizer.Extensions.Sample/Resizetizer.Extensions.Sample.csproj index 51551afb..d85181ff 100644 --- a/samples/NewTemplate/Resizetizer.Extensions.Sample/Resizetizer.Extensions.Sample.csproj +++ b/samples/NewTemplate/Resizetizer.Extensions.Sample/Resizetizer.Extensions.Sample.csproj @@ -1,7 +1,8 @@ - + - $(TargetFrameworks);net7.0-windows10.0.19041 - $(TargetFrameworks);net7.0;net7.0-ios;net7.0-android;net7.0-maccatalyst + + net8.0-android; true @@ -44,7 +45,7 @@ %(Filename) - + From 7e0a0f78e01f289b5f76680e4bc1ddb42dc5f3a7 Mon Sep 17 00:00:00 2001 From: pedrojesus-work Date: Thu, 21 Mar 2024 13:43:23 -0300 Subject: [PATCH 02/10] fix: remove UnoImage from Content and AndroidAsset --- src/.nuspec/Uno.Resizetizer.targets | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/.nuspec/Uno.Resizetizer.targets b/src/.nuspec/Uno.Resizetizer.targets index 7f68d35d..0c49e0b0 100644 --- a/src/.nuspec/Uno.Resizetizer.targets +++ b/src/.nuspec/Uno.Resizetizer.targets @@ -309,6 +309,22 @@ + + + + <_MyFileBefore Include="@(Content)" /> + + <_MyFile Include="@(Content)" /> + + <_Temp Include="@(AndroidAssets)"> + <_MyAssetsBefore Include="@(AndroidAsset)" /> + + <_MyAssetsAfter Include="@(AndroidAsset)" /> + + + Date: Thu, 21 Mar 2024 16:15:25 -0300 Subject: [PATCH 03/10] chore: Run Cleanup afeter UnoAssetsGeneration --- src/.nuspec/Uno.Resizetizer.targets | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/.nuspec/Uno.Resizetizer.targets b/src/.nuspec/Uno.Resizetizer.targets index 0c49e0b0..0e84eb96 100644 --- a/src/.nuspec/Uno.Resizetizer.targets +++ b/src/.nuspec/Uno.Resizetizer.targets @@ -310,18 +310,14 @@ + AfterTargets="UnoAssetsGeneration"> - <_MyFileBefore Include="@(Content)" /> - <_MyFile Include="@(Content)" /> - - <_Temp Include="@(AndroidAssets)"> - <_MyAssetsBefore Include="@(AndroidAsset)" /> + + + - <_MyAssetsAfter Include="@(AndroidAsset)" /> From 9f1dd423ac161207b8e858dc46c213c29fa6d466 Mon Sep 17 00:00:00 2001 From: pedrojesus-work Date: Thu, 21 Mar 2024 18:16:11 -0300 Subject: [PATCH 04/10] chore: revert commit to build just for android This reverts commit 2b037f9aeaaffd90591d8a6a778a7e401be499c2. --- .../Resizetizer.Extensions.Sample.Mobile.csproj | 4 ++-- .../Resizetizer.Extensions.Sample.csproj | 9 ++++----- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/samples/NewTemplate/Resizetizer.Extensions.Sample.Mobile/Resizetizer.Extensions.Sample.Mobile.csproj b/samples/NewTemplate/Resizetizer.Extensions.Sample.Mobile/Resizetizer.Extensions.Sample.Mobile.csproj index 15a3c47d..db2846de 100644 --- a/samples/NewTemplate/Resizetizer.Extensions.Sample.Mobile/Resizetizer.Extensions.Sample.Mobile.csproj +++ b/samples/NewTemplate/Resizetizer.Extensions.Sample.Mobile/Resizetizer.Extensions.Sample.Mobile.csproj @@ -1,6 +1,6 @@ - + - net8.0-android; + net7.0-android;net7.0-ios;net7.0-maccatalyst true Exe diff --git a/samples/NewTemplate/Resizetizer.Extensions.Sample/Resizetizer.Extensions.Sample.csproj b/samples/NewTemplate/Resizetizer.Extensions.Sample/Resizetizer.Extensions.Sample.csproj index d85181ff..51551afb 100644 --- a/samples/NewTemplate/Resizetizer.Extensions.Sample/Resizetizer.Extensions.Sample.csproj +++ b/samples/NewTemplate/Resizetizer.Extensions.Sample/Resizetizer.Extensions.Sample.csproj @@ -1,8 +1,7 @@ - + - - net8.0-android; + $(TargetFrameworks);net7.0-windows10.0.19041 + $(TargetFrameworks);net7.0;net7.0-ios;net7.0-android;net7.0-maccatalyst true @@ -45,7 +44,7 @@ %(Filename) - + From 19e294ad6b955f3e899a8d28a9f8883d51fdea5e Mon Sep 17 00:00:00 2001 From: pedrojesus-work Date: Tue, 26 Mar 2024 15:36:40 -0300 Subject: [PATCH 05/10] feat: create CleanupAssetsTask to handle duplicated assets --- src/.nuspec/Uno.Resizetizer.targets | 19 ++++++-- src/Resizetizer/src/CleanupAssetsTask.cs | 61 ++++++++++++++++++++++++ 2 files changed, 77 insertions(+), 3 deletions(-) create mode 100644 src/Resizetizer/src/CleanupAssetsTask.cs diff --git a/src/.nuspec/Uno.Resizetizer.targets b/src/.nuspec/Uno.Resizetizer.targets index 0e84eb96..b8ed24fc 100644 --- a/src/.nuspec/Uno.Resizetizer.targets +++ b/src/.nuspec/Uno.Resizetizer.targets @@ -52,6 +52,10 @@ AssemblyFile="$(_UnoResizetizerTaskAssemblyName)" TaskName="Uno.Resizetizer.WindowIconGeneratorTask_V0"/> + + $(CleanDependsOn); @@ -310,14 +314,23 @@ + BeforeTargets="UnoAssetsGeneration;_UnoAddAssetsFilesToCopyLocal"> + + + + + - + + - + + diff --git a/src/Resizetizer/src/CleanupAssetsTask.cs b/src/Resizetizer/src/CleanupAssetsTask.cs new file mode 100644 index 00000000..896b901c --- /dev/null +++ b/src/Resizetizer/src/CleanupAssetsTask.cs @@ -0,0 +1,61 @@ +using Microsoft.Build.Framework; +using Microsoft.Build.Utilities; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace Uno.Resizetizer; + +public class CleanupAssetsTask_v0 : Task +{ + [Required] + [Output] + public ITaskItem[] UnoImagesCollection { get; set; } = Array.Empty(); + + [Required] + [Output] + public ITaskItem[] ContentCollection { get; set; } = Array.Empty(); + + // This is just available on Android target, because of that isn't Required + [Output] + public ITaskItem[] AndroidAssetCollection { get; set; } = Array.Empty(); + + public override bool Execute() + { +#if DEBUG_RESIZETIZER + // System.Diagnostics.Debugger.Launch(); +#endif + try + { + ContentCollection = RemoveUnoImageFrom(UnoImagesCollection, ContentCollection); + AndroidAssetCollection = RemoveUnoImageFrom(UnoImagesCollection, AndroidAssetCollection); + + return true; + } + catch (Exception ex) + { + Log.LogError($"error: {ex} message: {ex.Message}"); + return false; + } + } + + + static ITaskItem[] RemoveUnoImageFrom(ITaskItem[] unoImages, ITaskItem[] assets) + { + var count = assets.Length; + + for (var i = 0; i < count; i++) + { + foreach (var unoImage in unoImages) + { + if (assets[i].ItemSpec == unoImage.ItemSpec) + { + assets[i] = null; + break; + } + } + } + + return assets.Where(x => x is not null).ToArray(); + } +} From 0fa8da6f4c5ef7c3676a89bb95fccdec5db5e10c Mon Sep 17 00:00:00 2001 From: pedrojesus-work Date: Tue, 26 Mar 2024 16:52:14 -0300 Subject: [PATCH 06/10] feat: add RemoveItem collection to indicates what was removed --- src/.nuspec/Uno.Resizetizer.targets | 18 ++++++++++++++++++ src/Resizetizer/src/CleanupAssetsTask.cs | 18 +++++++++++++----- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/src/.nuspec/Uno.Resizetizer.targets b/src/.nuspec/Uno.Resizetizer.targets index b8ed24fc..10c364e4 100644 --- a/src/.nuspec/Uno.Resizetizer.targets +++ b/src/.nuspec/Uno.Resizetizer.targets @@ -56,6 +56,10 @@ AssemblyFile="$(_UnoResizetizerTaskAssemblyName)" TaskName="Uno.Resizetizer.CleanupAssetsTask_v0"/> + + $(CleanDependsOn); @@ -321,6 +325,7 @@ AndroidAssetCollection="@(AndroidAsset)"> + @@ -334,6 +339,19 @@ + + + + + + + + + + + (); + [Output] + public ITaskItem[] RemovedFiles { get; set; } = Array.Empty(); + public override bool Execute() { #if DEBUG_RESIZETIZER - // System.Diagnostics.Debugger.Launch(); + //System.Diagnostics.Debugger.Launch(); #endif try { - ContentCollection = RemoveUnoImageFrom(UnoImagesCollection, ContentCollection); - AndroidAssetCollection = RemoveUnoImageFrom(UnoImagesCollection, AndroidAssetCollection); + var removedItems = new List(); + ContentCollection = RemoveUnoImageFrom(UnoImagesCollection, ContentCollection, removedItems); + + var assetsCount = AndroidAssetCollection.Length; + AndroidAssetCollection = RemoveUnoImageFrom(UnoImagesCollection, AndroidAssetCollection, removedItems); + + RemovedFiles = removedItems.ToArray(); return true; } @@ -39,8 +47,7 @@ public override bool Execute() } } - - static ITaskItem[] RemoveUnoImageFrom(ITaskItem[] unoImages, ITaskItem[] assets) + static ITaskItem[] RemoveUnoImageFrom(ITaskItem[] unoImages, ITaskItem[] assets, List removedItems) { var count = assets.Length; @@ -50,6 +57,7 @@ static ITaskItem[] RemoveUnoImageFrom(ITaskItem[] unoImages, ITaskItem[] assets) { if (assets[i].ItemSpec == unoImage.ItemSpec) { + removedItems.Add(assets[i]); assets[i] = null; break; } From 26b0202851b9d35bc89248dfdd9c0a8633edb1a6 Mon Sep 17 00:00:00 2001 From: pedrojesus-work Date: Tue, 26 Mar 2024 16:52:31 -0300 Subject: [PATCH 07/10] feat: add Task to clean up files to be copied to head --- .../src/RemoveSvgFromContentTask.cs | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 src/Resizetizer/src/RemoveSvgFromContentTask.cs diff --git a/src/Resizetizer/src/RemoveSvgFromContentTask.cs b/src/Resizetizer/src/RemoveSvgFromContentTask.cs new file mode 100644 index 00000000..76e9436b --- /dev/null +++ b/src/Resizetizer/src/RemoveSvgFromContentTask.cs @@ -0,0 +1,68 @@ +using Microsoft.Build.Framework; +using Microsoft.Build.Utilities; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; + +namespace Uno.Resizetizer; + +public class RemoveSvgFromContentTask_v0 : Task +{ + [Required] + public ITaskItem[] CollectionToRemove { get; set; } = Array.Empty(); + + [Output] + public ITaskItem[] RemovedItems { get; set; } = Array.Empty(); + + public override bool Execute() + { + try + { +#if DEBUG_RESIZETIZER + System.Diagnostics.Debugger.Launch(); +#endif + RemovedItems = RemoveDuplicateSvgAndPngFiles(CollectionToRemove); + return true; + } + catch (Exception ex) + { + Log.LogError($"error: {ex} message: {ex.Message}"); + return false; + } + } + + static ITaskItem[] RemoveDuplicateSvgAndPngFiles(ITaskItem[] assets) + { + var list = new List(); + var count = assets.Length; + for (var i = 0; i < count; i++) + { + var item = assets[i].ItemSpec; + var extension = Path.GetExtension(item) ?? string.Empty; + if (!extension.Equals(".svg", StringComparison.CurrentCultureIgnoreCase)) + { + continue; + } + var svgFileName = Path.GetFileNameWithoutExtension(item); + + foreach (var item2 in assets) + { + var extension2 = Path.GetExtension(item2.ItemSpec) ?? string.Empty; + if (extension2.Equals(".svg", StringComparison.CurrentCultureIgnoreCase) + || !extension2.Equals(".png", StringComparison.CurrentCultureIgnoreCase)) + { + continue; + } + + if (svgFileName == Path.GetFileNameWithoutExtension(item2.ItemSpec)) + { + list.Add(assets[i]); + assets[i] = null; + } + } + } + + return list.ToArray(); + } +} \ No newline at end of file From 3ab61d4437ecc56e540a3fdf552e057f8cedae95 Mon Sep 17 00:00:00 2001 From: pedrojesus-work <162186634+pedrojesus-work@users.noreply.github.com> Date: Wed, 27 Mar 2024 14:17:47 -0300 Subject: [PATCH 08/10] chore: Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Jérôme Laban --- src/.nuspec/Uno.Resizetizer.targets | 15 +++++++++++++-- src/Resizetizer/src/CleanupAssetsTask.cs | 2 +- src/Resizetizer/src/RemoveSvgFromContentTask.cs | 4 ++-- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/.nuspec/Uno.Resizetizer.targets b/src/.nuspec/Uno.Resizetizer.targets index 10c364e4..b905d4d1 100644 --- a/src/.nuspec/Uno.Resizetizer.targets +++ b/src/.nuspec/Uno.Resizetizer.targets @@ -317,7 +317,12 @@ - + - + + diff --git a/src/Resizetizer/src/CleanupAssetsTask.cs b/src/Resizetizer/src/CleanupAssetsTask.cs index 4496dba3..13ccda0b 100644 --- a/src/Resizetizer/src/CleanupAssetsTask.cs +++ b/src/Resizetizer/src/CleanupAssetsTask.cs @@ -42,7 +42,7 @@ public override bool Execute() } catch (Exception ex) { - Log.LogError($"error: {ex} message: {ex.Message}"); + Log.LogError($"Failed to remove items: {ex.Message}"); return false; } } diff --git a/src/Resizetizer/src/RemoveSvgFromContentTask.cs b/src/Resizetizer/src/RemoveSvgFromContentTask.cs index 76e9436b..0ca1dc42 100644 --- a/src/Resizetizer/src/RemoveSvgFromContentTask.cs +++ b/src/Resizetizer/src/RemoveSvgFromContentTask.cs @@ -40,7 +40,7 @@ static ITaskItem[] RemoveDuplicateSvgAndPngFiles(ITaskItem[] assets) { var item = assets[i].ItemSpec; var extension = Path.GetExtension(item) ?? string.Empty; - if (!extension.Equals(".svg", StringComparison.CurrentCultureIgnoreCase)) + if (!extension.Equals(".svg", StringComparison.OrdinalIgnoreCase)) { continue; } @@ -49,7 +49,7 @@ static ITaskItem[] RemoveDuplicateSvgAndPngFiles(ITaskItem[] assets) foreach (var item2 in assets) { var extension2 = Path.GetExtension(item2.ItemSpec) ?? string.Empty; - if (extension2.Equals(".svg", StringComparison.CurrentCultureIgnoreCase) + if (extension2.Equals(".svg", StringComparison.OrdinalIgnoreCase) || !extension2.Equals(".png", StringComparison.CurrentCultureIgnoreCase)) { continue; From 6fd69df2d3bc83219c62dc7567c356e6e36bff71 Mon Sep 17 00:00:00 2001 From: pedrojesus-work Date: Wed, 27 Mar 2024 15:11:04 -0300 Subject: [PATCH 09/10] chore: remove set to null on asset collection --- src/Resizetizer/src/RemoveSvgFromContentTask.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Resizetizer/src/RemoveSvgFromContentTask.cs b/src/Resizetizer/src/RemoveSvgFromContentTask.cs index 0ca1dc42..d6b065e8 100644 --- a/src/Resizetizer/src/RemoveSvgFromContentTask.cs +++ b/src/Resizetizer/src/RemoveSvgFromContentTask.cs @@ -58,7 +58,6 @@ static ITaskItem[] RemoveDuplicateSvgAndPngFiles(ITaskItem[] assets) if (svgFileName == Path.GetFileNameWithoutExtension(item2.ItemSpec)) { list.Add(assets[i]); - assets[i] = null; } } } From 1e92627c2e3895ea4cea44d5bc4baf84afa97461 Mon Sep 17 00:00:00 2001 From: pedrojesus-work Date: Wed, 27 Mar 2024 15:11:45 -0300 Subject: [PATCH 10/10] chore: comment debug line --- src/Resizetizer/src/RemoveSvgFromContentTask.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Resizetizer/src/RemoveSvgFromContentTask.cs b/src/Resizetizer/src/RemoveSvgFromContentTask.cs index d6b065e8..607b4289 100644 --- a/src/Resizetizer/src/RemoveSvgFromContentTask.cs +++ b/src/Resizetizer/src/RemoveSvgFromContentTask.cs @@ -20,7 +20,7 @@ public override bool Execute() try { #if DEBUG_RESIZETIZER - System.Diagnostics.Debugger.Launch(); + //System.Diagnostics.Debugger.Launch(); #endif RemovedItems = RemoveDuplicateSvgAndPngFiles(CollectionToRemove); return true;