/// <summary> /// Ensures the dependency is added if not present. /// </summary> /// <param name="dependency">The dependency.</param> /// <remarks></remarks> public void EnsureDependency(NuSpecDependency dependency) { XElement dependencyElement = DependenciesElement.Elements() .FirstOrDefault( e => e != null && e.Name == DependencyXName && e.Attributes("id").FirstOrDefault( a => a.Value.Equals(dependency.Id, StringComparison.OrdinalIgnoreCase)) != null); if (dependencyElement == null) { // Add the dependency element dependencyElement = new XElement( DependencyXName, new XAttribute("id", dependency.Id), String.IsNullOrWhiteSpace(dependency.Version) ? null : new XAttribute("version", dependency.Version)); DependenciesElement.Add(dependencyElement); HasChanges = true; return; } // We already have a matching dependency, check the version if necessary. if (dependency.Version == null) { return; } XAttribute versionAttribute = dependencyElement.Attributes("version").SingleOrDefault(); if (versionAttribute == null) { versionAttribute = new XAttribute("version", dependency.Version); dependencyElement.Add(versionAttribute); } else { if (versionAttribute.Value.Equals(dependency.Version, StringComparison.OrdinalIgnoreCase)) { return; } versionAttribute.SetValue(dependency.Version); } HasChanges = true; }
public virtual void DeleteSnapshotDependency(string dependencyBuildConfigId) { Log.Trace($"XML DeleteSnapshotDependency for: {BuildConfigId}, to: {dependencyBuildConfigId}"); var dependOnElement = Xml.SelectSingleNode("/build-type/settings/dependencies/depend-on[@sourceBuildTypeId='" + dependencyBuildConfigId + "']"); if (dependOnElement == null) { Log.WarnFormat("Attempted to delete {0} snapshot dependency from {1}, which doesn't exist", dependencyBuildConfigId, BuildConfigId); } else { DependenciesElement.RemoveChild(dependOnElement); } _buildConfigXmlClient.Commit(this, $"TCC {BuildConfigId} Delete Snapshot Dependency to {dependencyBuildConfigId}"); }
public virtual void CreateSnapshotDependency(CreateSnapshotDependency dependency) { Log.Debug($"XML CreateSnapshotDependency for: {dependency.TargetBuildConfigId}, to: {dependency.DependencyBuildConfigId}"); var dependOnElement = (XmlElement)DependenciesElement.AppendChild(Xml.CreateElement("depend-on")); dependOnElement.SetAttribute("sourceBuildTypeId", dependency.DependencyBuildConfigId); var optionsElement = (XmlElement)dependOnElement.AppendChild(Xml.CreateElement("options")); var option1Element = (XmlElement)optionsElement.AppendChild(Xml.CreateElement("option")); option1Element.SetAttribute("name", "take-started-build-with-same-revisions"); option1Element.SetAttribute("value", dependency.TakeStartedBuildWithSameRevisions.ToString().ToLower()); var option2Element = (XmlElement)optionsElement.AppendChild(Xml.CreateElement("option")); option2Element.SetAttribute("name", "take-successful-builds-only"); option2Element.SetAttribute("value", dependency.TakeSuccessFulBuildsOnly.ToString().ToLower()); _buildConfigXmlClient.Commit(this, $"TCC {BuildConfigId} Create Snapshot Dependency to {dependency.DependencyBuildConfigId}"); }
public virtual void DeleteAllSnapshotDependencies() { Log.Debug($"XML DeleteAllSnapshotDependencies for: {BuildConfigId}"); DependenciesElement.RemoveAll(); _buildConfigXmlClient.Commit(this, $"TCC {BuildConfigId} Delete all snapshot dependencies"); }