private FilePath ProcessXml(FilePath nuspecFilePath, ChocolateyPackSettings settings, XmlDocument xml) { // Process the XML. _log.Debug("Transforming nuspec..."); ChocolateyNuSpecTransformer.Transform(xml, settings); // Return the file of the new nuspec. _log.Debug("Writing temporary nuspec..."); return(SaveNuspecXml(nuspecFilePath, xml)); }
public FilePath Process(ChocolateyPackSettings settings) { var nuspecFilePath = _environment.WorkingDirectory .CombineWithFilePath(string.Concat(settings.Id, ".nuspec")) .MakeAbsolute(_environment); var xml = LoadEmptyNuSpec(); return(ProcessXml(nuspecFilePath, settings, xml)); }
public static void Transform(XmlDocument document, ChocolateyPackSettings settings) { // Create the namespace manager. var namespaceManager = new XmlNamespaceManager(document.NameTable); namespaceManager.AddNamespace("nu", ChocolateyNuSpecXsd); foreach (var elementName in _mappings.Keys) { var content = _mappings[elementName](settings); if (content != null) { // Replace the node content. var node = FindOrCreateElement(document, namespaceManager, elementName); if (_cdataElements.Contains(elementName)) { node.AppendChild(document.CreateCDataSection(content)); } else { node.InnerText = content; } } } if (settings.Files != null && settings.Files.Count > 0) { var filesPath = string.Format(CultureInfo.InvariantCulture, "//*[local-name()='package']//*[local-name()='files']"); var filesElement = document.SelectSingleNode(filesPath, namespaceManager); if (filesElement == null) { // Get the package element. var package = GetPackageElement(document); filesElement = document.CreateAndAppendElement(package, "files"); } // Add the files filesElement.RemoveAll(); foreach (var file in settings.Files) { var fileElement = document.CreateAndAppendElement(filesElement, "file"); fileElement.AddAttributeIfSpecified(file.Source, "src"); fileElement.AddAttributeIfSpecified(file.Exclude, "exclude"); fileElement.AddAttributeIfSpecified(file.Target, "target"); } } }
public FilePath Process(FilePath nuspecFilePath, ChocolateyPackSettings settings) { // Make the nuspec file path absolute. nuspecFilePath = nuspecFilePath.MakeAbsolute(_environment); // Make sure the nuspec file exist. var nuspecFile = _fileSystem.GetFile(nuspecFilePath); if (!nuspecFile.Exists) { const string format = "Could not find nuspec file '{0}'."; throw new CakeException(string.Format(CultureInfo.InvariantCulture, format, nuspecFilePath.FullPath)); } // Load the content of the nuspec file. _log.Debug("Parsing nuspec..."); var xml = LoadNuspecXml(nuspecFile); return(ProcessXml(nuspecFilePath, settings, xml)); }