diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/ConvertResourcesCases.cs b/src/Xamarin.Android.Build.Tasks/Tasks/ConvertResourcesCases.cs index c17520854f0..9079cd7f285 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/ConvertResourcesCases.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/ConvertResourcesCases.cs @@ -53,18 +53,25 @@ void FixupResources (ITaskItem item, Dictionary acwMap) { var resdir = item.ItemSpec; // Find all the xml and axml files - var xmls = new[] { resdir } - .Concat (Directory.EnumerateDirectories (resdir, "*", SearchOption.AllDirectories) - .Except (Directory.EnumerateDirectories (resdir, "color*", SearchOption.TopDirectoryOnly)) - .Except (Directory.EnumerateDirectories (resdir, "raw*", SearchOption.TopDirectoryOnly))) - .SelectMany (dir => Directory.EnumerateFiles (dir, "*.xml") - .Concat (Directory.EnumerateFiles (dir, "*.axml"))); + var xmls = new List (); + var colorDir = Path.Combine (resdir, "color"); + var rawDir = Path.Combine (resdir, "raw"); + foreach (var file in Directory.GetFiles (resdir, "*.*xml", SearchOption.AllDirectories)) { + if (file.StartsWith (colorDir, StringComparison.Ordinal) || file.StartsWith (rawDir, StringComparison.Ordinal)) + continue; + var ext = Path.GetExtension (file); + if (ext != ".xml" && ext != ".axml") + continue; + xmls.Add (file); + } var lastUpdate = DateTime.MinValue; if (!string.IsNullOrEmpty (AndroidConversionFlagFile) && File.Exists (AndroidConversionFlagFile)) { lastUpdate = File.GetLastWriteTimeUtc (AndroidConversionFlagFile); } Log.LogDebugMessage (" AndroidConversionFlagFile modified: {0}", lastUpdate); + + var resourcedirectories = ResourceDirectories.Where (s => s != item).Select(s => s.ItemSpec).ToArray(); // Fix up each file foreach (string file in xmls) { var srcmodifiedDate = File.GetLastWriteTimeUtc (file); @@ -73,47 +80,35 @@ void FixupResources (ITaskItem item, Dictionary acwMap) continue; } Log.LogDebugMessage (" Processing: {0} {1} > {2}", file, srcmodifiedDate, lastUpdate); - var tmpdest = Path.GetTempFileName (); - File.Copy (file, tmpdest, overwrite: true); - MonoAndroidHelper.SetWriteable (tmpdest); - try { - bool success = AndroidResource.UpdateXmlResource (resdir, tmpdest, acwMap, - ResourceDirectories.Where (s => s != item).Select(s => s.ItemSpec), (t, m) => { - string targetfile = file; - if (targetfile.StartsWith (resdir, StringComparison.InvariantCultureIgnoreCase)) { - targetfile = file.Substring (resdir.Length).TrimStart (Path.DirectorySeparatorChar); - if (resource_name_case_map.TryGetValue (targetfile, out string temp)) - targetfile = temp; - targetfile = Path.Combine ("Resources", targetfile); - } - switch (t) { - case TraceLevel.Error: - Log.LogCodedError ("XA1002", file: targetfile, lineNumber: 0, message: m); - break; - case TraceLevel.Warning: - Log.LogCodedWarning ("XA1001", file: targetfile, lineNumber: 0, message: m); - break; - default: - Log.LogDebugMessage (m); - break; - } - }); - 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 " { + string targetfile = file; + if (targetfile.StartsWith(resdir, StringComparison.InvariantCultureIgnoreCase)) { + targetfile = file.Substring(resdir.Length).TrimStart(Path.DirectorySeparatorChar); + if (resource_name_case_map.TryGetValue(targetfile, out string temp)) + targetfile = temp; + targetfile = Path.Combine("Resources", targetfile); + } + switch (t) { + case TraceLevel.Error: + Log.LogCodedError("XA1002", file: targetfile, lineNumber: 0, message: m); + break; + case TraceLevel.Warning: + Log.LogCodedWarning("XA1001", file: targetfile, lineNumber: 0, message: m); + break; + default: + Log.LogDebugMessage(m); + break; + } + })) + continue; - MonoAndroidHelper.CopyIfChanged (tmpdest, file); - } finally { - File.Delete (tmpdest); - } + // 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 " i.ItemSpec == destfilename)) - modifiedFiles.Add (new TaskItem (destfilename)); - } - } finally { - File.Delete (tmpdest); - } + + if (AndroidResource.UpdateXmlResource (res, filename, acw_map) && !modifiedFiles.Any (i => i.ItemSpec == destfilename)) + modifiedFiles.Add (new TaskItem(destfilename)); } merger.Save (); ModifiedFiles = modifiedFiles.ToArray (); diff --git a/src/Xamarin.Android.Build.Tasks/Utilities/AndroidResource.cs b/src/Xamarin.Android.Build.Tasks/Utilities/AndroidResource.cs index 3fbf06b93ba..625bc8fc6e0 100644 --- a/src/Xamarin.Android.Build.Tasks/Utilities/AndroidResource.cs +++ b/src/Xamarin.Android.Build.Tasks/Utilities/AndroidResource.cs @@ -22,9 +22,9 @@ public static bool UpdateXmlResource (string res, string filename, Dictionary