private IEnumerable <ITaskItem> GetIncludedFiles() { var containers = ContainersToSkip.Select(c => c.ItemSpec).ToArray(); var mapCache = File.ReadAllLines(AssemblyIdentityMapFile); foreach (var file in Files) { if (ShouldSkip(file, out var container)) { Log.LogMessage($"Skipping '{file}' because it matched '{container}'."); } else { Log.LogMessage(MessageImportance.Low, $"The file '{file}' did not match any skippable containers."); yield return(file); } } bool ShouldSkip(ITaskItem file, out string container) { container = null; var fullPath = Path.GetFullPath(file.ItemSpec); if (!fullPath.StartsWith(OutputImportDirectory, StringComparison.OrdinalIgnoreCase)) { return(false); } var subDir = fullPath.IndexOf(Path.DirectorySeparatorChar, OutputImportDirectory.Length); if (subDir == -1) { return(false); } var indexStr = fullPath.Substring(OutputImportDirectory.Length, subDir - OutputImportDirectory.Length); if (!int.TryParse(indexStr, out int index) || index < 0 || index >= mapCache.Length) { return(false); } container = mapCache[index]; if (Array.IndexOf(containers, container) == -1) { return(false); } return(true); } }
public override bool Execute() { // load the conainers and cache into memory containers = ContainersToSkip?.Length > 0 ? ContainersToSkip.Select(c => c.ItemSpec).ToArray() : Array.Empty <string>(); mapCache = !string.IsNullOrWhiteSpace(AssemblyIdentityMapFile) && File.Exists(AssemblyIdentityMapFile) ? File.ReadAllLines(AssemblyIdentityMapFile) : Array.Empty <string>(); // try and determine the full "lp" directory if (!string.IsNullOrWhiteSpace(OutputImportDirectory)) { OutputImportDirectory = Path.GetFullPath(OutputImportDirectory); } else if (!string.IsNullOrWhiteSpace(AssemblyIdentityMapFile)) { OutputImportDirectory = Path.GetDirectoryName(AssemblyIdentityMapFile); } else { OutputImportDirectory = null; } if (OutputImportDirectory != null && OutputImportDirectory[OutputImportDirectory.Length - 1] != Path.DirectorySeparatorChar) { OutputImportDirectory += Path.DirectorySeparatorChar; } var output = new List <ITaskItem>(); // look through all the extracted resources if (ResourceDirectories?.Length > 0) { var resources = GetExtractedResources(); output.AddRange(resources); } // go through all the jar files if (JavaLibraries?.Length > 0) { foreach (var library in JavaLibraries) { if (bool.TrueString.Equals(library.GetMetadata("AndroidXSkipAndroidXMigration"), StringComparison.OrdinalIgnoreCase)) { continue; } var lib = library.ItemSpec; if (ShouldSkipResource(lib, out var container) || !File.Exists(lib)) { continue; } library.SetMetadata("InputItemSpec", lib); output.Add(library); } } // go through all the app resources if (Resources?.Length > 0) { foreach (var resource in Resources) { if (bool.TrueString.Equals(resource.GetMetadata("AndroidXSkipAndroidXMigration"), StringComparison.OrdinalIgnoreCase)) { continue; } var ext = Path.GetExtension(resource.ItemSpec); if (ext == null || !ext.Equals(".xml", StringComparison.OrdinalIgnoreCase)) { continue; } resource.SetMetadata("InputItemSpec", resource.GetMetadata("OriginalItemSpec")); output.Add(resource); } } OutputFiles = output.ToArray(); return(true); }