Exemplo n.º 1
0
        public override bool Execute()
        {
            // ok copy all the files from Cache into dest path
            // then copy over the App Resources
            // emit warnings if we find duplicates.
            Log.LogDebugMessage("MergeResources Task");
            Log.LogDebugTaskItems("  SourceFiles: ", SourceFiles);
            Log.LogDebugTaskItems("  DestinationFiles: ", DestinationFiles);

            List <int> changedFiles = new List <int> ();

            merger = new ResourceMerger()
            {
                CacheFile = CacheFile,
                Log       = Log,
            };
            merger.Load();

            for (int i = 0; i < SourceFiles.Length; i++)
            {
                var src          = SourceFiles [i].ItemSpec;
                var destfilename = DestinationFiles [i].ItemSpec;
                if (File.GetLastWriteTimeUtc(src) > File.GetLastWriteTimeUtc(destfilename))
                {
                    changedFiles.Add(i);
                }
            }

            for (int idx = 0; idx < changedFiles.Count; idx++)
            {
                var i            = changedFiles[idx];
                var src          = SourceFiles [i].ItemSpec;
                var destfilename = Path.GetFullPath(DestinationFiles [i].ItemSpec);
                CopyResource(src, destfilename);
                merger.RemoveResourcesForFile(destfilename);
            }

            merger.Save();

            return(!Log.HasLoggedErrors);
        }
Exemplo n.º 2
0
        public override bool Execute()
        {
            // ok copy all the files from Cache into dest path
            // then copy over the App Resources
            // emit warnings if we find duplicates.
            Log.LogDebugMessage ("MergeResources Task");
            Log.LogDebugTaskItems ("  SourceFiles: ", SourceFiles);
            Log.LogDebugTaskItems ("  DestinationFiles: ", DestinationFiles);

            List<int> changedFiles = new List<int> ();

            merger = new ResourceMerger () {
                CacheFile = CacheFile,
                Log = Log,
            };
            merger.Load ();

            for (int i = 0; i < SourceFiles.Length; i++) {
                var src = SourceFiles [i].ItemSpec;
                var destfilename = DestinationFiles [i].ItemSpec;
                if (File.GetLastWriteTimeUtc (src) > File.GetLastWriteTimeUtc (destfilename)) {
                    changedFiles.Add (i);
                }
            }

            for (int idx = 0; idx < changedFiles.Count; idx++) {
                var i = changedFiles[idx];
                var src = SourceFiles [i].ItemSpec;
                var destfilename = Path.GetFullPath (DestinationFiles [i].ItemSpec);
                CopyResource (src, destfilename);
                merger.RemoveResourcesForFile (destfilename);
            }

            merger.Save ();

            return !Log.HasLoggedErrors;
        }
        public override bool Execute()
        {
            Log.LogDebugMessage ("CopyAndConvertResources Task");
            Log.LogDebugTaskItems ("  SourceFiles:", SourceFiles);
            Log.LogDebugTaskItems ("  DestinationFiles:", DestinationFiles);
            Log.LogDebugMessage ("  AcwMapFile: {0}", AcwMapFile);

            if (SourceFiles.Length != DestinationFiles.Length)
                throw new ArgumentException ("source and destination count mismatch");

            var acw_map = MonoAndroidHelper.LoadAcwMapFile (AcwMapFile);

            var xmlFilesToUpdate = new Dictionary<string,string> ();
            for (int i = 0; i < SourceFiles.Length; i++) {
                var filename = SourceFiles [i].ItemSpec;

                if (File.Exists (filename)) {
                    var ext = Path.GetExtension (filename);
                    var destfilename = DestinationFiles [i].ItemSpec;
                    var srcmodifiedDate = File.GetLastWriteTimeUtc (filename);
                    var dstmodifiedDate = File.Exists (destfilename) ? File.GetLastAccessTimeUtc (destfilename) : DateTime.MinValue;
                    var isXml = ext == ".xml" || ext == ".axml";

                    Directory.CreateDirectory (Path.GetDirectoryName (destfilename));

                    if (isXml) {
                        xmlFilesToUpdate.Add (filename, DestinationFiles [i].ItemSpec);
                        continue;
                    }
                    if (dstmodifiedDate < srcmodifiedDate && MonoAndroidHelper.CopyIfChanged (filename, destfilename)) {
                        MonoAndroidHelper.SetWriteable (destfilename);

                        // If the resource is not part of a raw-folder we strip away an eventual UTF-8 BOM
                        // 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 "<?"). Since there is no way to plug into the file saving mechanism in X.S
                        // we strip those here and point the designer to use resources from obj/
                        if (isXml && !MonoAndroidHelper.IsRawResourcePath (filename))
                            MonoAndroidHelper.CleanBOM (destfilename);

                        MonoAndroidHelper.SetLastAccessAndWriteTimeUtc (destfilename, srcmodifiedDate, Log);
                        modifiedFiles.Add (new TaskItem (destfilename));
                    }
                } else
                    Log.LogMessage ("    Warning: input resource '{0}' was not found", filename);
            }

            var merger = new ResourceMerger () {
                CacheFile = CacheFile,
                Log = Log,
            };
            merger.Load ();

            foreach (var p in xmlFilesToUpdate) {
                string filename = p.Key;
                var destfilename = p.Value;
                var srcmodifiedDate = File.GetLastWriteTimeUtc (filename);
                var dstmodifiedDate = File.Exists (destfilename) ? File.GetLastAccessTimeUtc (destfilename) : DateTime.MinValue;
                var tmpdest = p.Value + ".tmp";
                MonoAndroidHelper.CopyIfChanged (filename, tmpdest);
                MonoAndroidHelper.SetWriteable (tmpdest);
                try {
                    AndroidResource.UpdateXmlResource (tmpdest, acw_map);
                    if (MonoAndroidHelper.CopyIfChanged (tmpdest, destfilename)) {
                        MonoAndroidHelper.SetWriteable (destfilename);
                        MonoAndroidHelper.SetLastAccessAndWriteTimeUtc (destfilename, srcmodifiedDate, Log);
                        if (!modifiedFiles.Any (i => i.ItemSpec == destfilename))
                            modifiedFiles.Add (new TaskItem (destfilename));
                    }
                } finally {
                    File.Delete (tmpdest);
                }
            }
            merger.Save ();
            ModifiedFiles = modifiedFiles.ToArray ();

            Log.LogDebugTaskItems (" ModifiedFiles:", ModifiedFiles);

            return true;
        }
Exemplo n.º 4
0
        public override bool Execute()
        {
            Log.LogDebugMessage("CopyAndConvertResources Task");
            Log.LogDebugTaskItems("  SourceFiles:", SourceFiles);
            Log.LogDebugTaskItems("  DestinationFiles:", DestinationFiles);
            Log.LogDebugMessage("  AcwMapFile: {0}", AcwMapFile);

            if (SourceFiles.Length != DestinationFiles.Length)
            {
                throw new ArgumentException("source and destination count mismatch");
            }

            var acw_map = MonoAndroidHelper.LoadAcwMapFile(AcwMapFile);

            var xmlFilesToUpdate = new Dictionary <string, string> ();

            for (int i = 0; i < SourceFiles.Length; i++)
            {
                var filename = SourceFiles [i].ItemSpec;

                if (File.Exists(filename))
                {
                    var ext             = Path.GetExtension(filename);
                    var destfilename    = DestinationFiles [i].ItemSpec;
                    var srcmodifiedDate = File.GetLastWriteTimeUtc(filename);
                    var dstmodifiedDate = File.Exists(destfilename) ? File.GetLastAccessTimeUtc(destfilename) : DateTime.MinValue;
                    var isXml           = ext == ".xml" || ext == ".axml";

                    Directory.CreateDirectory(Path.GetDirectoryName(destfilename));

                    if (isXml)
                    {
                        xmlFilesToUpdate.Add(filename, DestinationFiles [i].ItemSpec);
                        continue;
                    }
                    if (dstmodifiedDate < srcmodifiedDate && MonoAndroidHelper.CopyIfChanged(filename, destfilename))
                    {
                        MonoAndroidHelper.SetWriteable(destfilename);

                        // If the resource is not part of a raw-folder we strip away an eventual UTF-8 BOM
                        // 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 "<?"). Since there is no way to plug into the file saving mechanism in X.S
                        // we strip those here and point the designer to use resources from obj/
                        if (isXml && !MonoAndroidHelper.IsRawResourcePath(filename))
                        {
                            MonoAndroidHelper.CleanBOM(destfilename);
                        }

                        MonoAndroidHelper.SetLastAccessAndWriteTimeUtc(destfilename, srcmodifiedDate, Log);
                        modifiedFiles.Add(new TaskItem(destfilename));
                    }
                }
                else
                {
                    Log.LogMessage("    Warning: input resource '{0}' was not found", filename);
                }
            }

            var merger = new ResourceMerger()
            {
                CacheFile = CacheFile,
                Log       = Log,
            };

            merger.Load();

            foreach (var p in xmlFilesToUpdate)
            {
                string filename        = p.Key;
                var    destfilename    = p.Value;
                var    srcmodifiedDate = File.GetLastWriteTimeUtc(filename);
                var    dstmodifiedDate = File.Exists(destfilename) ? File.GetLastAccessTimeUtc(destfilename) : DateTime.MinValue;
                var    tmpdest         = p.Value + ".tmp";
                MonoAndroidHelper.CopyIfChanged(filename, tmpdest);
                MonoAndroidHelper.SetWriteable(tmpdest);
                try {
                    AndroidResource.UpdateXmlResource(tmpdest, acw_map);
                    if (MonoAndroidHelper.CopyIfChanged(tmpdest, destfilename))
                    {
                        MonoAndroidHelper.SetWriteable(destfilename);
                        MonoAndroidHelper.SetLastAccessAndWriteTimeUtc(destfilename, srcmodifiedDate, Log);
                        if (!modifiedFiles.Any(i => i.ItemSpec == destfilename))
                        {
                            modifiedFiles.Add(new TaskItem(destfilename));
                        }
                    }
                } finally {
                    File.Delete(tmpdest);
                }
            }
            merger.Save();
            ModifiedFiles = modifiedFiles.ToArray();

            Log.LogDebugTaskItems(" ModifiedFiles:", ModifiedFiles);

            return(true);
        }
        public override bool Execute()
        {
            if (SourceFiles.Length != DestinationFiles.Length)
            {
                throw new ArgumentException("source and destination count mismatch");
            }

            var acw_map = MonoAndroidHelper.LoadAcwMapFile(AcwMapFile);
            var resource_name_case_map = MonoAndroidHelper.LoadResourceCaseMap(ResourceNameCaseMap);

            if (CustomViewMapFile != null)
            {
                customViewMap = Xamarin.Android.Tasks.MonoAndroidHelper.LoadCustomViewMapFile(BuildEngine4, CustomViewMapFile);
            }

            var xmlFilesToUpdate = new Dictionary <string, string> ();

            for (int i = 0; i < SourceFiles.Length; i++)
            {
                var filename = SourceFiles [i].ItemSpec;

                if (File.Exists(filename))
                {
                    var ext             = Path.GetExtension(filename);
                    var destfilename    = DestinationFiles [i].ItemSpec;
                    var srcmodifiedDate = File.GetLastWriteTimeUtc(filename);
                    var dstmodifiedDate = File.Exists(destfilename) ? File.GetLastWriteTimeUtc(destfilename) : DateTime.MinValue;
                    var isXml           = ext == ".xml" || ext == ".axml";

                    Directory.CreateDirectory(Path.GetDirectoryName(destfilename));

                    if (isXml)
                    {
                        xmlFilesToUpdate.Add(filename, DestinationFiles [i].ItemSpec);
                        continue;
                    }
                    if (dstmodifiedDate < srcmodifiedDate && MonoAndroidHelper.CopyIfChanged(filename, destfilename))
                    {
                        // If the resource is not part of a raw-folder we strip away an eventual UTF-8 BOM
                        // 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 "<?"). Since there is no way to plug into the file saving mechanism in X.S
                        // we strip those here and point the designer to use resources from obj/
                        if (isXml && !MonoAndroidHelper.IsRawResourcePath(filename))
                        {
                            MonoAndroidHelper.CleanBOM(destfilename);
                        }

                        modifiedFiles.Add(new TaskItem(destfilename));
                    }
                }
                else
                {
                    Log.LogMessage("    Warning: input resource '{0}' was not found", filename);
                }
            }

            var merger = new ResourceMerger()
            {
                CacheFile = CacheFile,
                Log       = Log,
            };

            merger.Load();

            foreach (var p in xmlFilesToUpdate)
            {
                string filename        = p.Key;
                var    destfilename    = p.Value;
                var    srcmodifiedDate = File.GetLastWriteTimeUtc(filename);
                var    dstmodifiedDate = File.Exists(destfilename) ? File.GetLastWriteTimeUtc(destfilename) : DateTime.MinValue;

                var res = Path.Combine(Path.GetDirectoryName(filename), "..");
                MonoAndroidHelper.CopyIfChanged(filename, destfilename);
                MonoAndroidHelper.SetWriteable(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.FixupResourceFilenameAndLogCodedWarning("XA1001", message, filename, resdir.ItemSpec, resource_name_case_map);
                        break;

                    default:
                        Log.LogDebugMessage(message);
                        break;
                    }
                }, registerCustomView: (e, file) => {
                    if (customViewMap == null)
                    {
                        return;
                    }
                    HashSet <string> set;
                    if (!customViewMap.TryGetValue(e, out set))
                    {
                        customViewMap.Add(e, set = new HashSet <string> ());
                    }
                    set.Add(file);
                });
                if (updated)
                {
                    if (!modifiedFiles.Any(i => i.ItemSpec == destfilename))
                    {
                        modifiedFiles.Add(new TaskItem(destfilename));
                    }
                }
            }
            merger.Save();
            ModifiedFiles = modifiedFiles.ToArray();

            Log.LogDebugTaskItems(" ModifiedFiles:", ModifiedFiles);

            if (customViewMap != null)
            {
                Xamarin.Android.Tasks.MonoAndroidHelper.SaveCustomViewMapFile(BuildEngine4, CustomViewMapFile, customViewMap);
            }

            return(true);
        }