public override bool Execute() { if (LibraryProjectPropertiesFiles.Length == 0 && LibraryProjectZipFiles.Length == 0) { return(true); } Log.LogDebugMessage("CreateLibraryResourceArchive Task"); Log.LogDebugMessage(" OutputDirectory: {0}", OutputDirectory); Log.LogDebugMessage(" OutputJarsDirectory: {0}", OutputJarsDirectory); Log.LogDebugMessage(" OutputAnnotationsDirectory: {0}", OutputAnnotationsDirectory); Log.LogDebugMessage(" LibraryProjectProperties:"); foreach (var p in LibraryProjectPropertiesFiles) { Log.LogDebugMessage(" " + p.ItemSpec); } Log.LogDebugMessage(" LibraryProjectZip:"); foreach (var z in LibraryProjectZipFiles) { Log.LogDebugMessage(" " + z.ItemSpec); } var outDirInfo = new DirectoryInfo(OutputDirectory); // Copy files into _LibraryProjectImportsDirectoryName (library_project_imports) dir. if (!outDirInfo.Exists) { outDirInfo.Create(); } var projectsResolved = ResolveLibraryProjectReferences(LibraryProjectPropertiesFiles.Select(p => Path.GetFullPath(p.ItemSpec))); var imports = projectsResolved.Concat(LibraryProjectZipFiles.Select(p => p.ItemSpec)); foreach (var p in imports) { // note that imports could contain file name that neither of build items contains // (it may be one of those resolved references in project.properties). // Also non-zip files are now specified in full path. if (!LibraryProjectZipFiles.Any(l => l.ItemSpec == p)) { // project.properties var fileInfo = new FileInfo(p); if (!fileInfo.Exists) { throw new InvalidOperationException(String.Format("Library project properties file '{0}' does not exist.", p)); } var bindir = fileInfo.Directory.FullName; CopyLibraryContent(bindir, false); } else { // zip string tmpname = Path.Combine(Path.GetTempPath(), "monodroid_import_" + Guid.NewGuid().ToString()); try { Directory.CreateDirectory(tmpname); ZipFile.ExtractToDirectory(p, tmpname, new System.Text.UTF8Encoding(false)); if (!CopyLibraryContent(tmpname, p.EndsWith(".aar", StringComparison.OrdinalIgnoreCase))) { return(false); } } finally { Directory.Delete(tmpname, true); } } } // Archive them in a zip. using (var stream = new MemoryStream()) { using (var zip = new ZipArchive(stream, ZipArchiveMode.Create, true, new System.Text.UTF8Encoding(false))) { zip.AddDirectory(OutputDirectory, outDirInfo.Name); } stream.Position = 0; string outpath = Path.Combine(outDirInfo.Parent.FullName, "__AndroidLibraryProjects__.zip"); if (Files.ArchiveZip(outpath, f => { using (var fs = new FileStream(f, FileMode.CreateNew)) { stream.CopyTo(fs); } })) { Log.LogDebugMessage("Saving contents to " + outpath); } } return(true); }
public override bool RunTask() { if (LibraryProjectPropertiesFiles.Length == 0 && LibraryProjectZipFiles.Length == 0) { return(true); } var outDirInfo = new DirectoryInfo(OutputDirectory); // Copy files into _LibraryProjectImportsDirectoryName (library_project_imports) dir. if (!outDirInfo.Exists) { outDirInfo.Create(); } var projectsResolved = ResolveLibraryProjectReferences(LibraryProjectPropertiesFiles.Select(p => Path.GetFullPath(p.ItemSpec))); var imports = projectsResolved.Concat(LibraryProjectZipFiles.Select(p => p.ItemSpec)); foreach (var p in imports) { // note that imports could contain file name that neither of build items contains // (it may be one of those resolved references in project.properties). // Also non-zip files are now specified in full path. if (!LibraryProjectZipFiles.Any(l => l.ItemSpec == p)) { // project.properties var fileInfo = new FileInfo(p); if (!fileInfo.Exists) { throw new InvalidOperationException(String.Format("Library project properties file '{0}' does not exist.", p)); } var bindir = fileInfo.Directory.FullName; CopyLibraryContent(bindir, false); } else { // zip string tmpname = Path.Combine(Path.GetTempPath(), "monodroid_import_" + Guid.NewGuid().ToString()); try { Directory.CreateDirectory(tmpname); var archive = ZipArchive.Open(p, FileMode.Open); archive.ExtractAll(tmpname); if (!CopyLibraryContent(tmpname, p.EndsWith(".aar", StringComparison.OrdinalIgnoreCase))) { return(false); } } finally { Directory.Delete(tmpname, true); } } } var outpath = Path.Combine(outDirInfo.Parent.FullName, "__AndroidLibraryProjects__.zip"); if (Files.ArchiveZip(outpath, f => { using (var zip = new ZipArchiveEx(f)) { zip.AddDirectory(OutputDirectory, "library_project_imports"); } })) { Log.LogDebugMessage("Saving contents to " + outpath); } return(true); }