static PackageDBTests() { T0 = ArtifactType.Register("T0", true); T1 = ArtifactType.Register("T1", true, ';'); T2 = ArtifactType.Register("T2", true, ','); PLevel0V1 = Create(SVersion.Parse("1.0.0")); PLevel0V2 = Create(SVersion.Parse("2.0.0")); PLevel0V3 = Create(SVersion.Parse("3.0.0")); PLevel0V4 = Create(SVersion.Parse("4.0.0")); PLevel0 = new PackageInfo[][] { PLevel0V1, PLevel0V2, PLevel0V3, PLevel0V4 }; PackageInfo[] Create(SVersion v) { var result = new PackageInfo[60]; for (int i = 0; i < result.Length; ++i) { var type = i < (result.Length / 3) ? T0 : i < (2 * result.Length / 3) ? T1 : T2; var p = new PackageInfo(); p.Key = new ArtifactInstance(type, $"P{i}", v); p.FeedNames.Add($"F{i / (result.Length / 10)}"); result[i] = p; } return(result); } }
public async Task <ArtifactAvailableInstances> GetVersionsAsync(IActivityMonitor m, string artifactName) { if (_registry == null) { _registry = _registryFactory(); } var v = new ArtifactAvailableInstances(this, artifactName); var result = await _registry.View(m, artifactName); if (result.exist) { JObject body = JObject.Parse(result.viewJson); var versions = (JObject)body["versions"]; foreach (var vK in versions) { var sV = SVersion.TryParse(vK.Key); if (!sV.IsValid) { m.Warn($"Unable to parse version '{vK.Key}' for '{artifactName}': {sV.ErrorMessage}"); } else { v = v.WithVersion(sV); } } } return(v); }
public CClient( TLinkFunc LinkFunc_, TLinkFailFunc LinkFailFunc_, TUnLinkFunc UnLinkFunc_, TRecvFunc RecvFunc_, net.TLinkFunc LinkFuncSoft_, TUnLinkFunc UnLinkSoftFunc_, TCheckFunc CheckFunc_, TCheckFailFunc CheckFailFunc_, SVersion Version_) { _Version = Version_; _NetA = new net.CClient( _LinkA, _LinkFailA, _UnLinkA, _RecvA, false, 1024000, 1024000, TimeSpan.Zero, TimeSpan.Zero, 60); _NetM = new net.CClient( _LinkM, _LinkFailM, _UnLinkM, _RecvM, false, 1024000, 1024000, TimeSpan.Zero, TimeSpan.Zero, 60); _NetS = new net.CClient( _LinkS, _LinkFailS, _UnLinkS, _RecvS, true, 1024000, 1024000, TimeSpan.FromSeconds(120), TimeSpan.FromSeconds(5), 60); _LinkFunc = LinkFunc_; _LinkFailFunc = LinkFailFunc_; _UnLinkFunc = UnLinkFunc_; _UnLinkSoftFunc = UnLinkSoftFunc_; _RecvFunc = RecvFunc_; _CheckFunc = CheckFunc_; _CheckFailFunc = CheckFailFunc_; }
public void collecting_multiple_versions(string versions, string result) { var v = versions.Split(',').Select(x => SVersion.Parse(x.Trim())).ToArray(); var q = new PackageQualityVersions(v, false); q.ToString().Should().Be(result); }
public void WithBuildMetaData_works_on_SVersion_and_CSVersion() { SVersion sv = SVersion.TryParse("1.0.0-not.a.CSemVer.Version"); SVersion svc = SVersion.TryParse("1.0.0-alpha"); SVersion svnc = SVersion.TryParse("1.0.0-pre", handleCSVersion: false); Assert.That(sv, Is.Not.AssignableTo <CSVersion>()); Assert.That(sv.AsCSVersion, Is.Null); Assert.That(svc, Is.AssignableTo <CSVersion>()); Assert.That(svc.AsCSVersion, Is.SameAs(svc)); Assert.That(svnc, Is.Not.AssignableTo <CSVersion>()); Assert.That(svnc.AsCSVersion, Is.Not.Null); SVersion svB = sv.WithBuildMetaData("Test"); Assert.That(svB, Is.Not.AssignableTo <CSVersion>()); Assert.That(svB.AsCSVersion, Is.Null); Assert.That(svB.NormalizedTextWithBuildMetaData, Is.EqualTo("1.0.0-not.a.CSemVer.Version+Test")); SVersion svcB = svc.WithBuildMetaData("Test"); Assert.That(svcB, Is.AssignableTo <CSVersion>()); Assert.That(svcB.AsCSVersion, Is.SameAs(svcB)); Assert.That(svcB.NormalizedTextWithBuildMetaData, Is.EqualTo("1.0.0-alpha+Test")); SVersion svncB = svnc.WithBuildMetaData("Test"); Assert.That(svncB, Is.Not.AssignableTo <CSVersion>()); Assert.That(svncB.AsCSVersion, Is.Not.Null); Assert.That(svncB.NormalizedTextWithBuildMetaData, Is.EqualTo("1.0.0-pre+Test")); Assert.That(svncB.AsCSVersion.NormalizedTextWithBuildMetaData, Is.EqualTo("1.0.0-prerelease+Test")); }
/// <summary> /// Pushes a version lightweight tag to the 'origin' remote. /// </summary> /// <param name="m">The monitor to use.</param> /// <param name="v">The version to push.</param> /// <returns>True on success, false on error.</returns> public bool PushVersionTag(IActivityMonitor m, SVersion v) { var sv = 'v' + v.ToString(); using (m.OpenInfo($"Pushing tag {sv} to remote for {SubPath}.")) { try { Remote remote = Git.Network.Remotes["origin"]; var options = new PushOptions() { CredentialsProvider = (url, user, cred) => ProtoGitFolder.PATCredentialsHandler(m) }; var exists = Git.Tags[sv]; if (exists == null) { m.Error($"Version Tag {sv} does not exist in {SubPath}."); return(false); } Git.Network.Push(remote, exists.CanonicalName, options); return(true); } catch (Exception ex) { m.Error($"PushVersionTags failed ({sv} on {SubPath}).", ex); return(false); } } }
public void union_with_lock_and_MinQuality() { var b10 = new SVersionBound(V100, SVersionLock.LockMinor, PackageQuality.None); var b11 = new SVersionBound(V110, SVersionLock.LockMajor, PackageQuality.Stable); b10.Contains(b11).Should().BeFalse("The 1.0 minor is locked."); b11.Contains(b10).Should().BeFalse("The 1.1 base version is greater than the 1.0 base version."); var u = b10.Union(b11); u.Should().Be(b11.Union(b10)); u.Base.Should().Be(SVersion.Create(1, 0, 0)); u.Lock.Should().Be(SVersionLock.LockMajor); u.MinQuality.Should().Be(PackageQuality.CI); var b21 = new SVersionBound(V210, SVersionLock.LockMajor, PackageQuality.Exploratory); var u2 = b21.Union(b11); u2.Should().Be(b11.Union(b21)); u2.Base.Should().Be(SVersion.Create(1, 1, 0)); u2.Lock.Should().Be(SVersionLock.LockMajor); u2.MinQuality.Should().Be(PackageQuality.Exploratory); }
public void this_is_not_a_csversion(string t) { var v = SVersion.Parse(t); v.AsCSVersion.Should().BeNull(); v.ToNormalizedString().Should().Be(t); }
public void CSemVerSafeCompare_in_action(string left, char op, string right) { SVersion vL = left != null?SVersion.TryParse(left) : null; SVersion vR = right != null?SVersion.TryParse(right) : null; switch (op) { case '>': SVersion.CSemVerSafeCompare(vL, vR).Should().BePositive(); SVersion.CSemVerSafeCompare(vR, vL).Should().BeNegative(); break; case '<': SVersion.CSemVerSafeCompare(vL, vR).Should().BeNegative(); SVersion.CSemVerSafeCompare(vR, vL).Should().BePositive(); break; case '=': SVersion.CSemVerSafeCompare(vL, vR).Should().Be(0); SVersion.CSemVerSafeCompare(vR, vL).Should().Be(0); break; default: throw new ArgumentException(nameof(op)); } }
public void SVersion_can_be_compared_with_operators() { Assert.That(SVersion.Create(0, 0, 0) > SVersion.Create(0, 0, 0, "a")); Assert.That(SVersion.Create(0, 0, 0) >= SVersion.Create(0, 0, 0, "a")); Assert.That(SVersion.Create(0, 0, 0, "a") < SVersion.Create(0, 0, 0)); Assert.That(SVersion.Create(0, 0, 0, "a") <= SVersion.Create(0, 0, 0)); Assert.That(SVersion.Create(0, 0, 0, "a") != SVersion.Create(0, 0, 0)); }
/// <summary> /// Parses a full path and extracts a <see cref="SVersion"/>. /// </summary> /// <param name="fullPath">The full path of the package.</param> /// <returns>The <see cref="SVersion"/> of the package.</returns> static SVersion ParseVersionFromPackagePath(string fullPath) { var fName = Path.GetFileNameWithoutExtension(fullPath); int idxV = Regex.Match(fName, "\\.\\d").Index; var id = fName.Substring(0, idxV); return(SVersion.Parse(fName.Substring(idxV + 1))); }
public NPMDep(string name, NPMVersionDependencyType type, ArtifactDependencyKind kind, string rawDep, SVersion minVersion) { Name = name; Type = type; Kind = kind; RawDep = rawDep; MinVersion = minVersion; }
public void the_Zero_SVersion_is_lower_than_any_other_syntaxically_valid_SVersion(string version) { var v = SVersion.TryParse(version); Assert.That(v.IsValid); Assert.That(v > SVersion.ZeroVersion); Assert.That(v != SVersion.ZeroVersion); }
public void collecting_best_version(string versions, string result) { var v = versions.Split(',').Select(x => SVersion.Parse(x.Trim())).ToArray(); var q = new PackageQualityVector(v, false); q.ToString().Should().Be(result); q.IsValid.Should().Be(result.Length > 0); q.ActualCount.Should().Be(result.Length > 0 ? 1 : 0); }
public CheckRepositoryInfo(SimpleRepositoryInfo gitInfo, IEnumerable <SolutionProject> projectsToPublish) { GitInfo = gitInfo; Version = SVersion.TryParse(gitInfo.SafeNuGetVersion); if (Version.IsValid) { NuGetPackagesToPublish = projectsToPublish.Select(p => new SimplePackageId(p.Name, Version)).ToList(); } }
public void Syntaxically_invalid_SVersion_are_greater_than_null_and_lower_than_the_Zero_one(string invalid) { SVersion notV = SVersion.TryParse(invalid); Assert.That(!notV.IsValid); Assert.That(notV != SVersion.ZeroVersion); Assert.That(SVersion.ZeroVersion > notV); Assert.That(SVersion.ZeroVersion >= notV); }
/// <summary> /// Parses a full path and extracts a <see cref="LocalNPMPackageFile"/>. /// </summary> /// <param name="fullPath">The full path of the package.</param> /// <returns>The local NPM package file.</returns> public static LocalNPMPackageFile Parse(string fullPath) { var fName = Path.GetFileNameWithoutExtension(fullPath); int idxV = Regex.Match(fName, "-\\d").Index; var id = fName.Substring(0, idxV); var v = SVersion.Parse(fName.Substring(idxV + 1)); return(new LocalNPMPackageFile(fullPath, id, v)); }
public TdfReader() { Bitmap = new SBitmap(); Version = new SVersion(); Header = new SHeader { Date = new SDate() }; }
public void parsing_works_on_prefix_and_ParsedText_covers_the_version(string t, string parsedText) { var head = t.AsSpan(); var v = SVersion.TryParse(ref head); v.IsValid.Should().BeTrue(); v.ErrorMessage.Should().BeNull(); v.ParsedText.Should().Be(parsedText); t.Should().StartWith(v.ParsedText); }
public async Task <bool> ExistAsync(IActivityMonitor m, string packageName, SVersion version) { if (RegistryUri.IsFile) { return(File.Exists(Path.Combine(RegistryUri.AbsolutePath, +'-' + version.ToNormalizedString() + ".tgz"))); } (_, bool exist) = await View(m, packageName, version); return(exist); }
/// <summary> /// Set the package version and change the project reference to package reference. /// </summary> /// <param name="p"></param> /// <param name="version"></param> /// <param name="preparePack"></param> /// <param name="packageJsonPreProcessor"></param> /// <returns></returns> public static IDisposable TemporaryReplacePackageVersion( NormalizedPath jsonPath, SVersion version) { (string content, TempFileTextModification temp) = CreateTempFileTextModification(jsonPath); JObject json = JObject.Parse(content); json["version"] = version.ToNormalizedString(); File.WriteAllText(jsonPath, json.ToString()); return(temp); }
static SVersion GetPackageVersion(Assembly a, AssemblyName n) { var info = InformationalVersion.ReadFromAssembly(a); if (info.IsValidSyntax && info.Version !.IsValid) { return(info.Version); } var v = n.Version; return(SVersion.Create(v.Major, v.Minor, v.Build)); }
/// <summary> /// Adds the <see cref="NPMSolution"/> to the <paramref name="globalInfo"/> /// </summary> /// <param name="this">This global info.</param> /// <param name="solution">The NPM solution.</param> /// <returns>This info.</returns> public static StandardGlobalInfo AddNPM(this StandardGlobalInfo globalInfo, NPMSolution solution) { SVersion minmimalNpmVersionRequired = SVersion.Create(6, 7, 0); string npmVersion = globalInfo.Cake.NpmGetNpmVersion(); if (SVersion.Parse(npmVersion) < minmimalNpmVersionRequired) { globalInfo.Cake.TerminateWithError("Outdated npm. Version older than v6.7.0 are known to fail on publish."); } globalInfo.RegisterSolution(solution); return(globalInfo); }
CIReleaseInfo( CSVersion ciBaseTag, int ciBaseDepth, SVersion ciBuildVersion, SVersion ciBuildVersionNuGet, bool isZeroTimed) { BaseTag = ciBaseTag; Depth = ciBaseDepth; BuildVersion = ciBuildVersion; BuildVersionNuGet = ciBuildVersionNuGet; IsZeroTimed = isZeroTimed; }
/// <summary> /// Simple parse of the "Type:Name/Version" format that may return an invalid /// instance (see <see cref="IsValid"/>). /// This never throws. /// </summary> /// <param name="instanceName">The string to parse.</param> /// <returns>The resulting instance that may be invalid.</returns> public static ArtifactInstance TryParse(string instanceName) { int idx = instanceName.LastIndexOf('/'); if (idx > 0 && idx < instanceName.Length - 3 && SVersion.TryParse(instanceName.Substring(idx + 1), out var version) && Core.Artifact.TryParse(instanceName.Substring(0, idx), out var artifact)) { return(new ArtifactInstance(artifact, version)); } return(new ArtifactInstance()); }
/// <summary> /// Initializes a new <see cref="ArtifactInstance"/>. /// </summary> /// <param name="a">The artifact. Must be <see cref="Artifact.IsValid"/>.</param> /// <param name="version">The version. Can not be null and must be <see cref="SVersion.IsValid"/>.</param> public ArtifactInstance(Artifact a, SVersion version) { if (!a.IsValid) { throw new ArgumentException("Artifact must be valid.", nameof(a)); } Artifact = a; if (version == null || !version.IsValid) { throw new ArgumentException("Version must be valid.", nameof(version)); } Version = version; }
static IEnumerable <SVersion> GetAllVersionsFromFeed(string path, string packageId) { // Do not use TryParse here: pattern MUST be a version since we remove // .symbols and "sub packages" (like CK.Text.Virtual for CK.Text by filtering only // suffixes that start with a digit. // If an error occurs here it should be an exception since this should never happen. // Note: Max on reference type returns null on empty source. return(System.IO.Directory.EnumerateFiles(path, packageId + ".*.nupkg") .Select(p => System.IO.Path.GetFileName(p)) .Select(n => n.Substring(packageId.Length + 1, n.Length - packageId.Length - 7)) .Where(n => !n.EndsWith(".symbols") && Char.IsDigit(n, 0)) .Select(v => SVersion.Parse(v))); }
/// <summary> /// Initializes a new <see cref="VFeature"/>. /// </summary> /// <param name="name">The feature name. Can not be null.</param> /// <param name="version"> /// The version. Can not be null and must be <see cref="SVersion.IsValid"/>. /// If it happens to be a <see cref="CSVersion"/>, <see cref="CSVersion.ToNormalizedForm()"/> is called. /// </param> public VFeature(string name, SVersion version) { if (String.IsNullOrWhiteSpace(name)) { throw new ArgumentException("Must not be null or whitespace.", nameof(name)); } Name = name; if (version == null || !version.IsValid) { throw new ArgumentException("Must be a valid SVersion.", nameof(version)); } Version = version.AsCSVersion?.ToNormalizedForm() ?? version; }
static void DumpVersionInfo(CIBuildDescriptor buildInfo, CSVersion t) { var nugetV2Build = t.ToString(CSVersionFormat.Normalized, buildInfo); int nugetV2BuildSNLen = SVersion.Parse(nugetV2Build).Prerelease.Length; Console.WriteLine("{0}, CI = {1}, NuGet = {2}, NuGet CI = {3}, NugetV2Build.SpecialName.Length = {4}", t, t.ToString(CSVersionFormat.Normalized, buildInfo), t.ToString(CSVersionFormat.Normalized), nugetV2Build, nugetV2BuildSNLen ); Assert.That(nugetV2BuildSNLen, Is.LessThanOrEqualTo(20)); }
public void pre_release_with_standard_names_nugetV2_mappings(string tag, string nuget, bool isPrereleasePatch) { CSVersion fromShortForm = CSVersion.Parse(nuget); CSVersion t = CSVersion.TryParse(tag); Assert.That(t, Is.EqualTo(fromShortForm)); Assert.That(t.IsValid); Assert.That(t.IsPrerelease); Assert.That(t.IsPreReleasePatch, Is.EqualTo(isPrereleasePatch)); Assert.That(t.ToString(CSVersionFormat.LongForm), Is.EqualTo(tag)); Assert.That(t.ToString(CSVersionFormat.Normalized), Is.EqualTo(nuget)); Assert.That(SVersion.Parse(nuget).Prerelease.Length, Is.LessThanOrEqualTo(20)); }