A hybrid implementation of SemVer that supports semantic versioning as described at http://semver.org while not strictly enforcing it to allow older 4-digit versioning schemes to continue working.
Inheritance: Octopus.Client.Model.Versioning.StrictSemanticVersion
Exemple #1
0
        public void Add(string stepNameOrPackageIdAndVersion)
        {
            var split = stepNameOrPackageIdAndVersion.Split(Delimiters);

            if (split.Length < 2)
            {
                throw new CommandException("The package argument '" + stepNameOrPackageIdAndVersion + "' does not use expected format of : {Step Name}:{Version}");
            }

            var stepNameOrPackageId  = split[0];
            var packageReferenceName = split.Length > 2 ? split[1] : WildCard;
            var version = split.Length > 2 ? split[2] : split[1];

            if (string.IsNullOrWhiteSpace(stepNameOrPackageId) || string.IsNullOrWhiteSpace(version))
            {
                throw new CommandException("The package argument '" + stepNameOrPackageIdAndVersion + "' does not use expected format of : {Step Name}:{Version}");
            }

            if (!SemanticVersion.TryParse(version, out var parsedVersion))
            {
                throw new CommandException("The version portion of the package constraint '" + stepNameOrPackageIdAndVersion + "' is not a valid semantic version number.");
            }

            Add(stepNameOrPackageId, packageReferenceName, version);
        }
        public static SemanticVersion ApplyMask(string mask, SemanticVersion currentVersion)
        {
            var match = FormatRegex.Match(mask);
            if (!match.Success)
                return SemanticVersion.Parse(mask);

            return currentVersion == null
                ? GenerateVersionFromMask(new MaskMatchedVersion(mask))
                : GenerateVersionFromCurrent(new MaskMatchedVersion(mask), new MaskMatchedVersion(currentVersion.ToString()));
        }
Exemple #3
0
 public void Default(string packageVersion)
 {
     try
     {
         SemanticVersion.Parse(packageVersion);
         defaultVersion = packageVersion;
     }
     catch (ArgumentException)
     {
         if (packageVersion.Contains(":"))
         {
             throw new ArgumentException("Invalid package version format. Use the package parameter if you need to specify the step name and version.");
         }
         throw;
     }
 }
        public OctoRepository(ServerInstanceElement instance)
        {
            ApiUri = instance.ApiUri.TrimEnd('/');

            var endpoint = new OctopusServerEndpoint(ApiUri, instance.ApiKey);
            var client = new OctopusClient(endpoint);
            _repository = new OctopusRepository(client);

            SystemInfoResource systemInfo;

            try
            {
                ServerStatusResource serverStatus = _repository.ServerStatus.GetServerStatus();
                systemInfo = _repository.ServerStatus.GetSystemInfo(serverStatus);
            }
            catch (OctopusException ex)
            {
                throw;
            }

            Version = new SemanticVersion(systemInfo.Version);

            using (var databaseModel = new DatabaseModel())
            {
                OctopusServer octopusServer = databaseModel.OctopusServers.SingleOrDefault(octo => octo.ApiUri == ApiUri);

                if (octopusServer == null)
                {
                    octopusServer = new OctopusServer();
                    octopusServer.ApiUri = ApiUri;
                    octopusServer.DisplayName = ApiUri;
                    databaseModel.OctopusServers.Add(octopusServer);
                    databaseModel.SaveChanges();
                }

                OctopusServerId = octopusServer.Id;
            }
        }
Exemple #5
0
        public void Add(string stepNameOrPackageId, string packageReferenceName, string packageVersion)
        {
            // Double wild card == default value
            if (stepNameOrPackageId == WildCard && packageReferenceName == WildCard)
            {
                Default(packageVersion);
                return;
            }

            var key = new PackageKey(stepNameOrPackageId, packageReferenceName ?? WildCard);

            if (stepNameToVersion.TryGetValue(key, out var current))
            {
                var newVersion     = SemanticVersion.Parse(packageVersion);
                var currentVersion = SemanticVersion.Parse(current);
                if (newVersion < currentVersion)
                {
                    return;
                }
            }

            stepNameToVersion[key] = packageVersion;
        }
 /// <summary>
 /// Creates a NuGetVersion from an existing NuGetVersion
 /// </summary>
 public SemanticVersion(SemanticVersion version)
     : this(version.Version, version.ReleaseLabels, version.Metadata, version.ToString())
 {
 }
        /// <summary>
        /// Parses a version string using loose semantic versioning rules that allows 2-4 version components followed
        /// by an optional special version.
        /// </summary>
        public static bool TryParse(string value, out SemanticVersion version, bool preserveMissingComponents = false)
        {
            version = null;

            if (value != null)
            {
                Version systemVersion = null;

                // trim the value before passing it in since we not strict here
                var sections = ParseSections(value.Trim());

                // null indicates the string did not meet the rules
                if (sections != null
                    && !string.IsNullOrEmpty(sections.Item1))
                {
                    var versionPart = sections.Item1;

                    if (versionPart.IndexOf('.') < 0)
                    {
                        // System.Version requires at least a 2 part version to parse.
                        versionPart += ".0";
                    }

                    if (Version.TryParse(versionPart, out systemVersion))
                    {
                        // labels
                        if (sections.Item2 != null
                            && !sections.Item2.All(s => IsValidPart(s, false)))
                        {
                            return false;
                        }

                        // build metadata
                        if (sections.Item3 != null
                            && !IsValid(sections.Item3, true))
                        {
                            return false;
                        }

                        var ver = preserveMissingComponents  
                            ? systemVersion 
                            : NormalizeVersionValue(systemVersion);

                        var originalVersion = value;

                        if (originalVersion.IndexOf(' ') > -1)
                        {
                            originalVersion = value.Replace(" ", "");
                        }

                        version = new SemanticVersion(version: ver,
                            releaseLabels: sections.Item2,
                            metadata: sections.Item3 ?? string.Empty,
                            originalVersion: originalVersion);

                        return true;
                    }
                }
            }

            return false;
        }
        /// <summary>
        /// Parses a version string using strict SemVer rules.
        /// </summary>
        public static bool TryParseStrict(string value, out SemanticVersion version)
        {
            version = null;

            StrictSemanticVersion semVer = null;
            if (TryParse(value, out semVer))
            {
                version = new SemanticVersion(semVer.Major, semVer.Minor, semVer.Patch, 0, semVer.ReleaseLabels, semVer.Metadata);
            }

            return true;
        }