From bdc05ceb3fd2c14b4d6fecefc34b3376722d141b Mon Sep 17 00:00:00 2001 From: Stephane Delcroix Date: Thu, 6 Sep 2018 11:50:40 +0200 Subject: [PATCH] [Xamarin.Android.Build.Tasks] remove try/catch, unused temp file - remove the try clause around `UpdateXmlResource`, it's a duplicate - remove unused `tempfile` variable --- .../Tasks/ConvertResourcesCases.cs | 68 +++++++++---------- .../Tasks/CopyAndConvertResources.cs | 54 +++++++-------- 2 files changed, 56 insertions(+), 66 deletions(-) diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/ConvertResourcesCases.cs b/src/Xamarin.Android.Build.Tasks/Tasks/ConvertResourcesCases.cs index e2c5187d461..a6534a53b99 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/ConvertResourcesCases.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/ConvertResourcesCases.cs @@ -86,44 +86,38 @@ void FixupResources (ITaskItem item, Dictionary acwMap) } Log.LogDebugMessage (" Processing: {0} {1} > {2}", file, srcmodifiedDate, lastUpdate); MonoAndroidHelper.SetWriteable (file); - try { - bool success = AndroidResource.UpdateXmlResource (resdir, file, acwMap, - resourcedirectories, (level, message) => { - switch (level) { - case TraceLevel.Error: - Log.FixupResourceFilenameAndLogCodedError ("XA1002", message, file, resdir, resource_name_case_map); - break; - case TraceLevel.Warning: - Log.FixupResourceFilenameAndLogCodedError ("XA1001", message, file, resdir, resource_name_case_map); - break; - default: - Log.LogDebugMessage (message); - break; - } - }, registerCustomView : (e, filename) => { - if (customViewMap == null) - return; - HashSet set; - if (!customViewMap.TryGetValue (e, out set)) - customViewMap.Add (e, set = new HashSet ()); - set.Add (filename); - }); - if (!success) { - //If we failed to write the file, a warning is logged, we should skip to the next file - continue; - } - - // We strip away an eventual UTF-8 BOM from the XML file. - // This is a requirement for the Android designer because the desktop Java renderer - // doesn't support those type of BOM (it really wants the document to start - // with " { + switch (level) { + case TraceLevel.Error: + Log.FixupResourceFilenameAndLogCodedError ("XA1002", message, file, resdir, resource_name_case_map); + break; + case TraceLevel.Warning: + Log.FixupResourceFilenameAndLogCodedError ("XA1001", message, file, resdir, resource_name_case_map); + break; + default: + Log.LogDebugMessage (message); + break; + } + }, registerCustomView : (e, filename) => { + if (customViewMap == null) + return; + HashSet set; + if (!customViewMap.TryGetValue (e, out set)) + customViewMap.Add (e, set = new HashSet ()); + set.Add (filename); + }); + if (!success) { + //If we failed to write the file, a warning is logged, we should skip to the next file + continue; } + + // We strip away an eventual UTF-8 BOM from the XML file. + // This is a requirement for the Android designer because the desktop Java renderer + // doesn't support those type of BOM (it really wants the document to start + // with " { - ITaskItem resdir = ResourceDirectories?.FirstOrDefault (x => filename.StartsWith (x.ItemSpec)) ?? null; - switch (level) { - case TraceLevel.Error: - Log.FixupResourceFilenameAndLogCodedError ("XA1002", message, filename, resdir.ItemSpec, resource_name_case_map); - break; - case TraceLevel.Warning: - Log.FixupResourceFilenameAndLogCodedError ("XA1001", message, filename, resdir.ItemSpec, resource_name_case_map); - break; - default: - Log.LogDebugMessage (message); - break; - } - }, registerCustomView: (e, file) => { - if (customViewMap == null) - return; - HashSet set; - if (!customViewMap.TryGetValue (e, out set)) - customViewMap.Add (e, set = new HashSet ()); - set.Add (file); - - }); - if (updated) { - if (!modifiedFiles.Any (i => i.ItemSpec == destfilename)) - modifiedFiles.Add (new TaskItem (destfilename)); + var updated = AndroidResource.UpdateXmlResource (res, destfilename, acw_map, logMessage: (level, message) => { + ITaskItem resdir = ResourceDirectories?.FirstOrDefault (x => filename.StartsWith (x.ItemSpec)) ?? null; + switch (level) { + case TraceLevel.Error: + Log.FixupResourceFilenameAndLogCodedError ("XA1002", message, filename, resdir.ItemSpec, resource_name_case_map); + break; + case TraceLevel.Warning: + Log.FixupResourceFilenameAndLogCodedError ("XA1001", message, filename, resdir.ItemSpec, resource_name_case_map); + break; + default: + Log.LogDebugMessage (message); + break; } - } finally { - File.Delete (tmpdest); + }, registerCustomView: (e, file) => { + if (customViewMap == null) + return; + HashSet set; + if (!customViewMap.TryGetValue (e, out set)) + customViewMap.Add (e, set = new HashSet ()); + set.Add (file); + + }); + if (updated) { + if (!modifiedFiles.Any (i => i.ItemSpec == destfilename)) + modifiedFiles.Add (new TaskItem (destfilename)); } } merger.Save ();