private Dep FindLca(Dep dep1, Dep dep2) { if (dep1.Name != dep2.Name) { throw new BadArgumentException(); } var result = new Dep(dep1.Name, dep1.Treeish ?? dep2.Treeish); var configParser = new ConfigurationYamlParser(new FileInfo(Path.Combine(workspace, dep1.Name))); var configs = configParser.GetConfigurations(); var commonAncestorsList = new List <string>(); foreach (var parent in configs) { var cm = new ConfigurationManager(new[] { new Dep(null, null, parent) }, configParser); if (cm.ProcessedParent(dep1) && cm.ProcessedParent(dep2)) { commonAncestorsList.Add(parent); } } var lowestAncestor = commonAncestorsList.Where( c => !new ConfigurationManager(commonAncestorsList.Select(cc => new Dep(null, null, cc)), configParser).ProcessedChildrenConfigurations(new Dep(null, null, c)).Any()).ToList(); if (!commonAncestorsList.Any() || !lowestAncestor.Any()) { throw new CementException("failed get common ancestor for configurations '" + dep1 + "' and '" + dep2 + "'"); } result.Configuration = lowestAncestor.First(); return(result); }
private void FixChildren(string patchConfiguration) { var parser = new DepsYamlParser(new FileInfo(Directory.GetParent(yamlPath).FullName)); var hadDepsInThisSectionAndParrents = parser.Get(patchConfiguration).Deps.Where(d => d.Name == patchDep.Name).ToList(); if (!hadDepsInThisSectionAndParrents.Any()) { return; } if (hadDepsInThisSectionAndParrents.Count > 1) { ThrowDuplicate(); } var currentSectionDep = hadDepsInThisSectionAndParrents.First(); var childConfigurations = new ConfigurationYamlParser(new FileInfo(Directory.GetParent(yamlPath).FullName)) .GetConfigurationsHierarchy()[patchConfiguration]; foreach (var child in childConfigurations) { FixChild(currentSectionDep, child); } foreach (var child in childConfigurations) { FixChildren(child); } }
public static List <string> GetSmallerCementConfigs(string modulePath, List <string> usedCementConfigs) { var configParser = new ConfigurationYamlParser(new FileInfo(modulePath)); var configManager = new ConfigurationManager(usedCementConfigs.Select(c => new Dep("", null, c)), configParser); return(usedCementConfigs .Where(c => !configManager.ProcessedChildrenConfigurations(new Dep("", null, c)).Any()) .ToList()); }
private string GetDepLine(Dep dep) { var parser = new ConfigurationYamlParser(new FileInfo(Path.Combine(workspace, dep.Name))); if (parser.GetDefaultConfigurationName() == dep.Configuration) { dep.Configuration = null; } return(dep.ToYamlString()); }
private void PatchDfs(string patchConfiguration, HashSet <string> processed) { var childConfigurations = new ConfigurationYamlParser(new FileInfo(Directory.GetParent(yamlPath).FullName)) .GetConfigurationsHierarchy()[patchConfiguration] .Where(c => !processed.Contains(c)).ToList(); foreach (var child in childConfigurations) { PatchConfiguration(child); processed.Add(child); } foreach (var child in childConfigurations) { PatchDfs(child, processed); } }
public void TestSampleContentFromAFile() { using (var tempDir = new TempDirectory()) { using (new DirectoryJumper(tempDir.Path)) { File.WriteAllText("module.yaml", @" default: client: sdk: "); var configurations = new ConfigurationYamlParser(new FileInfo(tempDir.Path)).GetConfigurations(); Assert.AreEqual(2, configurations.Count); } } }