public void ConstructsOk() { var svi = new SemVerInfo("item-2"); var slice = new MissingSlice(svi); Assert.Equal(slice.RelPath, "item-2"); Assert.Equal(slice.Info.NameMajor, 2); }
public Slice(string relPath, SemVerInfo info, IList <string> lines) { RelPath = relPath; Info = info; Sections = new List <SliceSection>(); int lineStart = 0; SliceSection section; while ((section = SliceSection.Parse(lines, lineStart)) != null) { lineStart = section.EndLine > lineStart ? section.EndLine : lineStart + 1; Sections.Add(section); } foreach (var s in Sections.Where(s => s.SectionType == SliceSection.Type.DEP)) { foreach (var line in s.Lines.Where(l => !l.StartsWith("#"))) { var depInfo = new SemVerInfo(line); if (!DepInfos.Contains(depInfo)) { DepInfos.Add(depInfo); } } } }
public SliceDirectory(DirectoryInfo rootDir, DirectoryInfo bunchDir, SemVerInfo bunchInfo) { RootDir = rootDir; BunchDir = bunchDir; OsDir = bunchDir.GetDirectories("_", SearchOption.TopDirectoryOnly).First(); BunchInfo = bunchInfo; }
public void ToStringEqualsLabel() { var sviB = new SemVerInfo("parent-1.2.3-rc.4"); var svi = new SemVerInfo(sviB.NameSemVer, "Name-21.2.234-beta.1"); Assert.Equal(svi.Label, "Name-21.2.234-beta.1"); Assert.Equal(svi.ToString(), "Name-21.2.234-beta.1"); }
public Layer FindLayer(SemVerInfo layerInfo) { var layer = _layers.Find( item => item.Slice.Info.Name == layerInfo.Name && item.Slice.Info.CompareByNameSemVer(layerInfo) >= 0); if (layer == null) { var slice = SliceList.FindSlice(layerInfo); if (slice is MissingSlice) { if (!MissingInfos.Contains(layerInfo)) { MissingInfos.Add(layerInfo); } layer = new MissingLayer(SliceList, (MissingSlice)slice); } else { layer = new Layer(SliceList, slice); } Add(layer); } return(layer); }
public LayerList(SliceList sliceList, IList <SemVerInfo> layerInfos, SemVerInfo osInfo) { SliceList = sliceList; LayerInfos = layerInfos; OsInfo = osInfo; // first put the requested layers into the list foreach (var layerInfo in layerInfos) { FindLayer(layerInfo); } // then add the dependencies foreach (var layerInfo in layerInfos) { FindLayer(layerInfo).FindDependenciesRecursive(this); } // then if there were more than one layers requested // add other layers as the dependencies for the first one for (var i = layerInfos.Count - 1; i > 0; i--) { _layers[0].InsertDependency(0, FindLayer(layerInfos[i])); } // last but not least find the os layer OsLayer = FindLayer(osInfo); }
public void SimpleNameOnly() { var svi = new SemVerInfo("Ruby"); Assert.Equal(svi.Label, "Ruby"); Assert.Equal(svi.Name, "ruby"); Assert.Equal(svi.BunchSemVer, _emptySemVer); Assert.Equal(svi.NameSemVer, _emptySemVer); }
public void OneDigit() { var svi = new SemVerInfo("name-2"); Assert.Equal(svi.Label, "name-2"); Assert.Equal(svi.Name, "name"); Assert.Equal(svi.BunchSemVer, _emptySemVer); Assert.Equal(svi.NameSemVer, new Tuple<int, int, int, int, int, int>(2, 0, 0, 0, 0, 0)); }
public void PreReleaseRc() { var svi = new SemVerInfo("name-21.2.234-rc.11"); Assert.Equal(svi.Label, "name-21.2.234-rc.11"); Assert.Equal(svi.Name, "name"); Assert.Equal(svi.BunchSemVer, _emptySemVer); Assert.Equal(svi.NameSemVer, new Tuple<int, int, int, int, int, int>(21, 2, 234, -1, 11, 0)); }
public void ThreePlaces() { var svi = new SemVerInfo("name-2.1.1"); Assert.Equal(svi.Label, "name-2.1.1"); Assert.Equal(svi.Name, "name"); Assert.Equal(svi.BunchSemVer, _emptySemVer); Assert.Equal(svi.NameSemVer, new Tuple<int, int, int, int, int, int>(2, 1, 1, 0, 0, 0)); }
public void ValueEqual() { var sviB1 = new SemVerInfo("parent-1.2.3-rc.4"); var sviB2 = new SemVerInfo("parent-1.2.3-rc.4"); var svi1 = new SemVerInfo(sviB1.NameSemVer, "name-21.2.234-beta.1"); var svi2 = new SemVerInfo(sviB2.NameSemVer, "name-21.2.234-beta.1"); Assert.Equal(svi1.Value, svi2.Value); }
public void ThreePlaces() { var svi = new SemVerInfo("name-2.1.1"); Assert.Equal(svi.Label, "name-2.1.1"); Assert.Equal(svi.Name, "name"); Assert.Equal(svi.BunchSemVer, _emptySemVer); Assert.Equal(svi.NameSemVer, new Tuple <int, int, int, int, int, int>(2, 1, 1, 0, 0, 0)); }
public void TwoDigitsTwoPlaces() { var svi = new SemVerInfo("name-21.11"); Assert.Equal(svi.Label, "name-21.11"); Assert.Equal(svi.Name, "name"); Assert.Equal(svi.BunchSemVer, _emptySemVer); Assert.Equal(svi.NameSemVer, new Tuple <int, int, int, int, int, int>(21, 11, 0, 0, 0, 0)); }
public void WithDashesAndUnderscoresNameOnly() { var svi = new SemVerInfo("_Name-one_two"); Assert.Equal(svi.Label, "_Name-one_two"); Assert.Equal(svi.Name, "_name-one_two"); Assert.Equal(svi.BunchSemVer, _emptySemVer); Assert.Equal(svi.NameSemVer, _emptySemVer); }
public void WithDashesNameOnly() { var svi = new SemVerInfo("Name-one-two"); Assert.Equal(svi.Label, "Name-one-two"); Assert.Equal(svi.Name, "name-one-two"); Assert.Equal(svi.BunchSemVer, _emptySemVer); Assert.Equal(svi.NameSemVer, _emptySemVer); }
public void OneDigit() { var svi = new SemVerInfo("name-2"); Assert.Equal(svi.Label, "name-2"); Assert.Equal(svi.Name, "name"); Assert.Equal(svi.BunchSemVer, _emptySemVer); Assert.Equal(svi.NameSemVer, new Tuple <int, int, int, int, int, int>(2, 0, 0, 0, 0, 0)); }
public void ThrowsOnDuplicate() { var sviB = new SemVerInfo("slices-1"); var sliceList = new SliceList(); sliceList.Add(new Slice(null, new SemVerInfo(sviB.NameSemVer, "item1-1"), new List<string>())); var ex = Assert.Throws<InvalidOperationException>( () => sliceList.Add(new Slice(null, new SemVerInfo(sviB.NameSemVer, "item1-1"), new List<string>()))); Assert.NotNull(ex); }
public void PreReleaseRc() { var svi = new SemVerInfo("name-21.2.234-rc.11"); Assert.Equal(svi.Label, "name-21.2.234-rc.11"); Assert.Equal(svi.Name, "name"); Assert.Equal(svi.BunchSemVer, _emptySemVer); Assert.Equal(svi.NameSemVer, new Tuple <int, int, int, int, int, int>(21, 2, 234, -1, 11, 0)); }
public void NotFindsSlice() { var sviB = new SemVerInfo("slices-1"); var sliceList = new SliceList(); sliceList.Add(new Slice(null, new SemVerInfo(sviB.NameSemVer, "item1"), new List<string>())); sliceList.Add(new Slice(null, new SemVerInfo(sviB.NameSemVer, "item2"), new List<string>())); sliceList.Add(new Slice(null, new SemVerInfo(sviB.NameSemVer, "item3"), new List<string>())); var slice = sliceList.FindSlice(new SemVerInfo("item4")); Assert.Equal(slice.GetType(), typeof(MissingSlice)); }
public void WithBunchSemVer() { var sviB = new SemVerInfo("parent-1.2.3-rc.4"); var svi = new SemVerInfo(sviB.NameSemVer, "name-21.2.234-beta.1"); Assert.Equal(svi.Label, "name-21.2.234-beta.1"); Assert.Equal(svi.Name, "name"); Assert.Equal(svi.BunchSemVer, new Tuple <int, int, int, int, int, int>(1, 2, 3, -1, 4, 0)); Assert.Equal(svi.NameSemVer, new Tuple <int, int, int, int, int, int>(21, 2, 234, -2, 1, 0)); }
public void ConstructsOk() { var sviB = new SemVerInfo("slices-1"); var svi = new SemVerInfo(sviB.NameSemVer, "item-2"); var slice = new Slice("root", svi, new List<string> {""}); Assert.Equal(slice.RelPath, "root"); Assert.Equal(slice.Info.BunchSemVer.Item1, 1); Assert.Equal(slice.Info.NameSemVer.Item1, 2); Assert.Equal(slice.Info.Name, "item"); }
public void ValueComparesLowerByNameSemVer() { var sviB1 = new SemVerInfo("parent-1.2.3-rc.4"); var sviB2 = new SemVerInfo("parent-1.2.3-rc.4"); var svi1 = new SemVerInfo(sviB1.NameSemVer, "name-21.2.233-beta.1"); var svi2 = new SemVerInfo(sviB2.NameSemVer, "name-21.2.234-beta.1"); var c1 = svi1.CompareTo(svi2); Assert.Equal(c1, -1); }
public void ValueComparesBiggerByName() { var sviB1 = new SemVerInfo("parent-1.2.3-rc.4"); var sviB2 = new SemVerInfo("parent-1.2.3-rc.4"); var svi1 = new SemVerInfo(sviB1.NameSemVer, "name-21.2.234"); var svi2 = new SemVerInfo(sviB2.NameSemVer, "lame-21.2.234"); var c1 = svi1.CompareTo(svi2); Assert.Equal(c1, 1); }
public void ThrowsOnDuplicate() { var sviB = new SemVerInfo("slices-1"); var sliceList = new SliceList(); sliceList.Add(new Slice(null, new SemVerInfo(sviB.NameSemVer, "item1-1"), new List <string>())); var ex = Assert.Throws <InvalidOperationException>( () => sliceList.Add(new Slice(null, new SemVerInfo(sviB.NameSemVer, "item1-1"), new List <string>()))); Assert.NotNull(ex); }
public void NotFindsSlice() { var sviB = new SemVerInfo("slices-1"); var sliceList = new SliceList(); sliceList.Add(new Slice(null, new SemVerInfo(sviB.NameSemVer, "item1"), new List <string>())); sliceList.Add(new Slice(null, new SemVerInfo(sviB.NameSemVer, "item2"), new List <string>())); sliceList.Add(new Slice(null, new SemVerInfo(sviB.NameSemVer, "item3"), new List <string>())); var slice = sliceList.FindSlice(new SemVerInfo("item4")); Assert.Equal(slice.GetType(), typeof(MissingSlice)); }
public void SortsOneBunch() { var sviB = new SemVerInfo("slices-1"); var sliceList = new SliceList(); sliceList.Add(new Slice(null, new SemVerInfo(sviB.NameSemVer, "item1-1"), new List<string>())); sliceList.Add(new Slice(null, new SemVerInfo(sviB.NameSemVer, "item1-2"), new List<string>())); sliceList.Add(new Slice(null, new SemVerInfo(sviB.NameSemVer, "item2"), new List<string>())); sliceList.Add(new Slice(null, new SemVerInfo(sviB.NameSemVer, "item3"), new List<string>())); sliceList.Sort(); Assert.Equal(sliceList[0].Info.NameMajor, 2); }
public void ConstructsOk() { var sviB = new SemVerInfo("slices-1"); var svi = new SemVerInfo(sviB.NameSemVer, "item-2"); var slice = new Slice("root", svi, new List <string> { "" }); Assert.Equal(slice.RelPath, "root"); Assert.Equal(slice.Info.BunchSemVer.Item1, 1); Assert.Equal(slice.Info.NameSemVer.Item1, 2); Assert.Equal(slice.Info.Name, "item"); }
public SliceList Scan(SemVerInfo osInfo) { var list = new SliceList(); foreach (var directory in _directories) { var slices = directory.Scan(osInfo); foreach (var slice in slices) { list.Add(slice); } } return list; }
public void SortsOneBunch() { var sviB = new SemVerInfo("slices-1"); var sliceList = new SliceList(); sliceList.Add(new Slice(null, new SemVerInfo(sviB.NameSemVer, "item1-1"), new List <string>())); sliceList.Add(new Slice(null, new SemVerInfo(sviB.NameSemVer, "item1-2"), new List <string>())); sliceList.Add(new Slice(null, new SemVerInfo(sviB.NameSemVer, "item2"), new List <string>())); sliceList.Add(new Slice(null, new SemVerInfo(sviB.NameSemVer, "item3"), new List <string>())); sliceList.Sort(); Assert.Equal(sliceList[0].Info.NameMajor, 2); }
public SliceDirectoryList(string root, int versionMajor) { var rootDir = new DirectoryInfo(root); foreach (var bunchDir in rootDir.EnumerateDirectories()) { // Only add slices from the directories with same major version var bunchInfo = new SemVerInfo(bunchDir.Name); if (bunchInfo.NameMajor == versionMajor) { _directories.Add(new SliceDirectory(rootDir, bunchDir, bunchInfo)); } } }
public SliceList Scan(SemVerInfo osInfo) { var list = new SliceList(); foreach (var directory in _directories) { var slices = directory.Scan(osInfo); foreach (var slice in slices) { list.Add(slice); } } return(list); }
public Slice FindSlice(SemVerInfo info) { var slice = _slices.Find(item => item.Info.Name == info.Name && item.Info.CompareByNameSemVer(info) >= 0); if (slice == null) { if (!MissingInfos.Contains(info)) { MissingInfos.Add(info); } slice = new MissingSlice(info); } return(slice); }
/// <summary> /// Finds all slices requested on the cmd line and /// build the layers into a list /// </summary> /// <returns></returns> protected virtual LayerList BuildLayers() { var layerParams = Args.GetLayerParams(); var osParam = Args.GetOsParam(); var layerInfos = layerParams.Select(layerParam => new SemVerInfo(layerParam)).ToList(); var osInfo = new SemVerInfo(osParam); var dirList = new SliceDirectoryList(Args.SlicesDir, Args.VersionInfo.FileMajorPart); var sliceList = dirList.Scan(osInfo); sliceList.CheckDepInfos(); var layerList = new LayerList(sliceList, layerInfos, osInfo); return layerList; }
private IList<Slice> FindOsSlices(SemVerInfo osInfo) { var list = new List<Slice>(); foreach (var fi in OsDir.GetFiles()) { var info = new SemVerInfo(fi.Name); // load os slices with the higher or equal version that was requested if (info.Name == osInfo.Name && info.CompareByNameSemVer(osInfo) >= 0) { var osSlice = LoadSlice(fi); if (osSlice != null) list.Add(osSlice); } } return list; }
/// <summary> /// Fetches the latest version with the same MAJOR part as the executable /// </summary> /// <returns></returns> private string FetchLatestBranchName() { var list = new List <SemVerInfo>(); var branches = FetchBranches(); foreach (var branch in branches.Where(b => b != "master")) { var svi = new SemVerInfo(branch); if (svi.NameMajor == Args.VersionInfo.FileMajorPart) { list.Add(svi); } } list.Sort((x, y) => y.CompareTo(x)); return(list[0].ToString()); }
public void TracksMissing() { var sviB = new SemVerInfo("slices-1"); var sliceList = new SliceList(); sliceList.Add(new Slice(null, new SemVerInfo(sviB.NameSemVer, "item1-1"), new List <string>())); sliceList.Add(new Slice(null, new SemVerInfo(sviB.NameSemVer, "item1-2"), new List <string>())); sliceList.Add(new Slice(null, new SemVerInfo(sviB.NameSemVer, "item2"), new List <string>())); sliceList.Add(new Slice(null, new SemVerInfo(sviB.NameSemVer, "item3"), new List <string>())); sliceList.Sort(); var svi = new SemVerInfo("item1-2.1"); var slice = sliceList.FindSlice(svi); Assert.Equal(slice.GetType(), typeof(MissingSlice)); Assert.Equal(sliceList.MissingInfos[0], svi); }
/// <summary> /// Finds all slices requested on the cmd line and /// build the layers into a list /// </summary> /// <returns></returns> protected virtual LayerList BuildLayers() { var layerParams = Args.GetLayerParams(); var osParam = Args.GetOsParam(); var layerInfos = layerParams.Select(layerParam => new SemVerInfo(layerParam)).ToList(); var osInfo = new SemVerInfo(osParam); var dirList = new SliceDirectoryList(Args.SlicesDir, Args.VersionInfo.FileMajorPart); var sliceList = dirList.Scan(osInfo); sliceList.CheckDepInfos(); var layerList = new LayerList(sliceList, layerInfos, osInfo); return(layerList); }
public IList<Slice> Scan(SemVerInfo osInfo) { // first find suitable os slices in the underscore dir var list = FindOsSlices(osInfo); if (list.Count != 0) { // now loop over subdirectories (bunch root directory is excluded now) foreach (var dir in Directory.EnumerateDirectories(BunchDir.FullName, "*.*", SearchOption.AllDirectories)) { // skip already processed underscore directory with os slices // and skip hidden directories if (dir == OsDir.FullName || dir.StartsWith(".")) continue; LoadSlices(new DirectoryInfo(dir), list); } } return list; }
private IList <Slice> FindOsSlices(SemVerInfo osInfo) { var list = new List <Slice>(); foreach (var fi in OsDir.GetFiles()) { var info = new SemVerInfo(fi.Name); // load os slices with the higher or equal version that was requested if (info.Name == osInfo.Name && info.CompareByNameSemVer(osInfo) >= 0) { var osSlice = LoadSlice(fi); if (osSlice != null) { list.Add(osSlice); } } } return(list); }
public void SortsTwoBunches() { var sviB1 = new SemVerInfo("slices-1"); var sviB2 = new SemVerInfo("slices-2"); var sliceList = new SliceList(); sliceList.Add(new Slice(null, new SemVerInfo(sviB1.NameSemVer, "item1-1"), new List <string>())); sliceList.Add(new Slice(null, new SemVerInfo(sviB1.NameSemVer, "item1-2"), new List <string>())); sliceList.Add(new Slice(null, new SemVerInfo(sviB1.NameSemVer, "item2"), new List <string>())); sliceList.Add(new Slice(null, new SemVerInfo(sviB1.NameSemVer, "item3"), new List <string>())); sliceList.Add(new Slice(null, new SemVerInfo(sviB2.NameSemVer, "item1-1"), new List <string>())); sliceList.Add(new Slice(null, new SemVerInfo(sviB2.NameSemVer, "item1-2"), new List <string>())); sliceList.Add(new Slice(null, new SemVerInfo(sviB2.NameSemVer, "item2"), new List <string>())); sliceList.Add(new Slice(null, new SemVerInfo(sviB2.NameSemVer, "item3"), new List <string>())); sliceList.Sort(); Assert.Equal(sliceList[0].Info.BunchSemVer.Item1, 2); Assert.Equal(sliceList[0].Info.NameMajor, 2); }
public void SortsTwoBunches() { var sviB1 = new SemVerInfo("slices-1"); var sviB2 = new SemVerInfo("slices-2"); var sliceList = new SliceList(); sliceList.Add(new Slice(null, new SemVerInfo(sviB1.NameSemVer, "item1-1"), new List<string>())); sliceList.Add(new Slice(null, new SemVerInfo(sviB1.NameSemVer, "item1-2"), new List<string>())); sliceList.Add(new Slice(null, new SemVerInfo(sviB1.NameSemVer, "item2"), new List<string>())); sliceList.Add(new Slice(null, new SemVerInfo(sviB1.NameSemVer, "item3"), new List<string>())); sliceList.Add(new Slice(null, new SemVerInfo(sviB2.NameSemVer, "item1-1"), new List<string>())); sliceList.Add(new Slice(null, new SemVerInfo(sviB2.NameSemVer, "item1-2"), new List<string>())); sliceList.Add(new Slice(null, new SemVerInfo(sviB2.NameSemVer, "item2"), new List<string>())); sliceList.Add(new Slice(null, new SemVerInfo(sviB2.NameSemVer, "item3"), new List<string>())); sliceList.Sort(); Assert.Equal(sliceList[0].Info.BunchSemVer.Item1, 2); Assert.Equal(sliceList[0].Info.NameMajor, 2); }
private Slice LoadSlice(FileInfo fi) { if (fi.Name.StartsWith(".")) { return(null); } var ext = Path.GetExtension(fi.Name); if (ext == ".md" || ext == ".txt") { return(null); } var relPath = fi.FullName.Replace(RootDir.FullName + Path.DirectorySeparatorChar, ""); var sliceInfo = new SemVerInfo(BunchInfo.NameSemVer, fi.Name); var lines = File.ReadAllLines(fi.FullName); var slice = new Slice(relPath, sliceInfo, lines); return(slice); }
public Slice(string relPath, SemVerInfo info, IList<string> lines) { RelPath = relPath; Info = info; Sections = new List<SliceSection>(); int lineStart = 0; SliceSection section; while ((section = SliceSection.Parse(lines, lineStart)) != null) { lineStart = section.EndLine > lineStart ? section.EndLine : lineStart + 1; Sections.Add(section); } foreach (var s in Sections.Where(s => s.SectionType == SliceSection.Type.DEP)) { foreach (var line in s.Lines.Where(l => !l.StartsWith("#"))) { var depInfo = new SemVerInfo(line); if (!DepInfos.Contains(depInfo)) DepInfos.Add(depInfo); } } }
private Slice LoadSlice(FileInfo fi) { if (fi.Name.StartsWith(".")) return null; var ext = Path.GetExtension(fi.Name); if (ext == ".md" || ext == ".txt") return null; var relPath = fi.FullName.Replace(RootDir.FullName + Path.DirectorySeparatorChar, ""); var sliceInfo = new SemVerInfo(BunchInfo.NameSemVer, fi.Name); var lines = File.ReadAllLines(fi.FullName); var slice = new Slice(relPath, sliceInfo, lines); return slice; }
public MissingSlice(SemVerInfo svi) : base(svi.Label, svi, new string[0]) { }
public void TracksMissing() { var sviB = new SemVerInfo("slices-1"); var sliceList = new SliceList(); sliceList.Add(new Slice(null, new SemVerInfo(sviB.NameSemVer, "item1-1"), new List<string>())); sliceList.Add(new Slice(null, new SemVerInfo(sviB.NameSemVer, "item1-2"), new List<string>())); sliceList.Add(new Slice(null, new SemVerInfo(sviB.NameSemVer, "item2"), new List<string>())); sliceList.Add(new Slice(null, new SemVerInfo(sviB.NameSemVer, "item3"), new List<string>())); sliceList.Sort(); var svi = new SemVerInfo("item1-2.1"); var slice = sliceList.FindSlice(svi); Assert.Equal(slice.GetType(), typeof(MissingSlice)); Assert.Equal(sliceList.MissingInfos[0], svi); }
public void TwoDigitsThreePlaces() { var svi = new SemVerInfo("name-21.2.234"); Assert.Equal(svi.Label, "name-21.2.234"); Assert.Equal(svi.Name, "name"); Assert.Equal(svi.BunchSemVer, _emptySemVer); Assert.Equal(svi.NameSemVer, new Tuple<int, int, int, int, int, int>(21, 2, 234, 0, 0, 0)); }
public void WithBunchSemVer() { var sviB = new SemVerInfo("parent-1.2.3-rc.4"); var svi = new SemVerInfo(sviB.NameSemVer, "name-21.2.234-beta.1"); Assert.Equal(svi.Label, "name-21.2.234-beta.1"); Assert.Equal(svi.Name, "name"); Assert.Equal(svi.BunchSemVer, new Tuple<int, int, int, int, int, int>(1, 2, 3, -1, 4, 0)); Assert.Equal(svi.NameSemVer, new Tuple<int, int, int, int, int, int>(21, 2, 234, -2, 1, 0)); }
/// <summary> /// Fetches the latest version with the same MAJOR part as the executable /// </summary> /// <returns></returns> private string FetchLatestBranchName() { var list = new List<SemVerInfo>(); var branches = FetchBranches(); foreach (var branch in branches.Where(b => b != "master")) { var svi = new SemVerInfo(branch); if (svi.NameMajor == Args.VersionInfo.FileMajorPart) list.Add(svi); } list.Sort((x, y) => y.CompareTo(x)); return list[0].ToString(); }