/// <summary> /// Creates a *.TapPackage file from the definition in this PackageDef. /// </summary> static public void CreatePackage(this PackageDef pkg, string path) { foreach (PackageFile file in pkg.Files) { if (!File.Exists(file.FileName)) { log.Error("{0}: File '{1}' not found", pkg.Name, file.FileName); throw new InvalidDataException(); } } if (pkg.Files.Any(s => s.HasCustomData <MissingPackageData>())) { bool resolved = true; foreach (var file in pkg.Files) { while (file.HasCustomData <MissingPackageData>()) { MissingPackageData missingPackageData = file.GetCustomData <MissingPackageData>().FirstOrDefault(); if (missingPackageData.TryResolve(out ICustomPackageData customPackageData)) { file.CustomData.Add(customPackageData); } else { resolved = false; log.Error($"Missing plugin to handle XML Element '{missingPackageData.XmlElement.Name.LocalName}' on file {file.FileName}. (Line {missingPackageData.GetLine()})"); } file.CustomData.Remove(missingPackageData); } } if (!resolved) { throw new ArgumentException("Missing plugins to handle XML elements specified in input package.xml..."); } } string tempDir = Path.GetTempPath() + Path.GetRandomFileName(); Directory.CreateDirectory(tempDir); log.Debug("Using temporary folder at '{0}'", tempDir); try { UpdateVersionInfo(tempDir, pkg.Files, pkg.Version); // License Inject // Obfuscate // Sign CustomPackageActionHelper.RunCustomActions(pkg, PackageActionStage.Create, new CustomPackageActionArgs(tempDir, false)); // Concat license required from all files. But only if the property has not manually been set. if (string.IsNullOrEmpty(pkg.LicenseRequired)) { var licenses = pkg.Files.Select(f => f.LicenseRequired).Where(l => l != null).ToList(); pkg.LicenseRequired = string.Join(", ", licenses.Distinct().Select(l => LicenseBase.FormatFriendly(l, false)).ToList()); } log.Info("Creating OpenTAP package."); pkg.Compress(path, pkg.Files); } finally { FileSystemHelper.DeleteDirectory(tempDir); } }