Esempio n. 1
0
        public void this_assembly_has_a_valid_AssemblyInformationalVersionAttribute()
        {
            var info = InformationalVersion.ReadFromAssembly(System.Reflection.Assembly.GetExecutingAssembly());

            info.IsValidSyntax.Should().BeTrue();
            info.ParseErrorMessage.Should().BeNull();
        }
Esempio n. 2
0
        public void this_assembly_has_a_valid_FileVersionInfo_ProductVersion()
        {
            var path = System.Reflection.Assembly.GetExecutingAssembly().Location;
            var info = InformationalVersion.ReadFromFile(path);

            info.IsValidSyntax.Should().BeTrue();
            info.ParseErrorMessage.Should().BeNull();
        }
Esempio n. 3
0
        public void InformationalVersion_ReadFromAssembly_only_throws_if_assembly_is_null()
        {
            Assert.Throws <ArgumentNullException>(() => InformationalVersion.ReadFromAssembly(null));
            var info = InformationalVersion.ReadFromAssembly(typeof(string).Assembly);

            info.IsValidSyntax.Should().BeFalse();
            info.ParseErrorMessage.Should().NotBeNull();
        }
Esempio n. 4
0
        public void NuGet_and_SemVer_versions_equivalence_are_not_checked(string v)
        {
            var i = new InformationalVersion(v);

            i.IsValidSyntax.Should().BeTrue();
            i.ParseErrorMessage.Should().BeNull();
            InformationalVersion.Parse(v);
        }
        public void the_long_form_is_now_ignored_when_old_format_is_used(string v)
        {
            var i = new InformationalVersion(v);

            i.IsValidSyntax.Should().BeTrue();
            i.ParseErrorMessage.Should().BeNull();
            InformationalVersion.Parse(v);
        }
Esempio n. 6
0
        public void parsing_invalid_InformationalVersion_carries_a_ParseErrorMessage(string v)
        {
            var i = new InformationalVersion(v);

            i.IsValidSyntax.Should().BeFalse();
            i.ParseErrorMessage.Should().NotBeNullOrWhiteSpace();
            Assert.Throws <ArgumentException>(() => InformationalVersion.Parse(v));
        }
        public void parsing_new_format_normalized_the_version(string v)
        {
            var i = new InformationalVersion(v);

            i.IsValidSyntax.Should().BeTrue(i.ParseErrorMessage);
            i.ParseErrorMessage.Should().BeNull();
            i.Version.AsCSVersion.IsLongForm.Should().BeFalse();
            InformationalVersion.Parse(v);
        }
Esempio n. 8
0
        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));
        }
Esempio n. 9
0
 public void InformationalVersion_ReadFromFile_only_throws_if_path_is_null_or_empty()
 {
     Assert.Throws <ArgumentNullException>(() => InformationalVersion.ReadFromFile(null));
     Assert.Throws <ArgumentNullException>(() => InformationalVersion.ReadFromFile(""));
     Assert.Throws <ArgumentNullException>(() => InformationalVersion.ReadFromFile(" \t "));
     {
         var info = InformationalVersion.ReadFromFile("no way this can be a file.");
         info.IsValidSyntax.Should().BeFalse();
         info.ParseErrorMessage.Should().NotBeNull();
     }
     {
         string path = System.IO.Path.GetTempFileName();
         System.IO.File.WriteAllText(path, "Just a text.");
         var info = InformationalVersion.ReadFromFile(path);
         info.IsValidSyntax.Should().BeFalse();
         info.ParseErrorMessage.Should().NotBeNull();
         System.IO.File.Delete(path);
     }
 }
Esempio n. 10
0
    public static void Should_have_required_version()
    {
        var assembly = Assembly.GetAssembly(typeof(RocksDb));
        var infoAttr = assembly?.GetCustomAttribute <AssemblyInformationalVersionAttribute>();

        Assert.IsNotNull(infoAttr, "RocksDB package metadata not found");

        var versions = infoAttr !.InformationalVersion.Split('.');

        Assert.GreaterOrEqual(versions.Length, 3, "Unexpected RocksDB version format");

        var major = versions[0];
        var minor = versions[1];
        var patch = versions[2];

        // Patch version check is needed
        // until the package includes the binaries for aarch64
        Assert.AreEqual("6.29.3", $"{major}.{minor}.{patch}", "Unexpected RocksDB version");
    }
Esempio n. 11
0
        /// <summary>
        ///
        /// </summary>
        /// <exception cref="InvalidOperationException">Thrown if a TorchBase instance already exists.</exception>
        protected TorchBase(ITorchConfig config)
        {
            RegisterCoreAssembly(GetType().Assembly);
            if (Instance != null)
            {
                throw new InvalidOperationException("A TorchBase instance already exists.");
            }

            Instance = this;
            Config   = config;

            var versionString = Assembly.GetEntryAssembly()
                                .GetCustomAttribute <AssemblyInformationalVersionAttribute>()
                                .InformationalVersion;

            if (!InformationalVersion.TryParse(versionString, out InformationalVersion version))
            {
                throw new TypeLoadException("Unable to parse the Torch version from the assembly.");
            }

            TorchVersion = version;

            RunArgs = new string[0];

            Managers = new DependencyManager();

            Plugins = new PluginManager(this);

            var sessionManager = new TorchSessionManager(this);

            sessionManager.AddFactory((x) => Sync.IsServer ? new ChatManagerServer(this) : new ChatManagerClient(this));
            sessionManager.AddFactory((x) => Sync.IsServer ? new CommandManager(this) : null);
            sessionManager.AddFactory((x) => new EntityManager(this));

            Managers.AddManager(sessionManager);
            Managers.AddManager(new PatchManager(this));
            Managers.AddManager(new FilesystemManager(this));
            Managers.AddManager(new UpdateManager(this));
            Managers.AddManager(new EventManager(this));
            Managers.AddManager(Plugins);
            TorchAPI.Instance = this;

            GameStateChanged += (game, state) =>
            {
                if (state == TorchGameState.Created)
                {
                    // If the attached assemblies change (MySandboxGame.ctor => MySandboxGame.ParseArgs => MyPlugins.RegisterFromArgs)
                    // attach assemblies to object factories again.
                    ObjectFactoryInitPatch.ForceRegisterAssemblies();
                    // safe to commit here; all important static ctors have run
                    PatchManager.CommitInternal();
                }
            };

            sessionManager.SessionStateChanged += (session, state) =>
            {
                switch (state)
                {
                case TorchSessionState.Loading:
                    SessionLoading?.Invoke();
                    break;

                case TorchSessionState.Loaded:
                    SessionLoaded?.Invoke();
                    break;

                case TorchSessionState.Unloading:
                    SessionUnloading?.Invoke();
                    break;

                case TorchSessionState.Unloaded:
                    SessionUnloaded?.Invoke();
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(state), state, null);
                }
            };
        }
Esempio n. 12
0
        /// <summary>
        /// Initializes a new <see cref="RepositoryInfo"/> on a <see cref="Repository"/>.
        /// </summary>
        /// <param name="r">The rpository (can be invalid and even null).</param>
        /// <param name="options">Optional options.</param>
        public RepositoryInfo(Repository r, RepositoryInfoOptions options = null)
        {
            Options       = options ?? new RepositoryInfoOptions();
            CommitDateUtc = InformationalVersion.ZeroCommitDate;
            if (r == null)
            {
                RepositoryError = "No Git repository.";
            }
            else
            {
                Commit commit;
                CIBranchVersionMode ciVersionMode;
                string ciBuildName;
                RepositoryError = TryFindCommit(options, r, out commit, out ciVersionMode, out ciBuildName);
                Debug.Assert((ciVersionMode != CIBranchVersionMode.None) == (ciBuildName != null));
                if (commit != null)
                {
                    CommitSha           = commit.Sha;
                    CommitDateUtc       = commit.Author.When.UtcDateTime;
                    IsDirtyExplanations = ComputeIsDirty(r, commit, options);
                    if (!IsDirty || options.IgnoreDirtyWorkingFolder)
                    {
                        StringBuilder errors    = new StringBuilder();
                        TagCollector  collector = new TagCollector(errors,
                                                                   r,
                                                                   options.StartingVersionForCSemVer,
                                                                   options.OverriddenTags,
                                                                   options.SingleMajor);
                        if (errors.Length == 0)
                        {
                            ExistingVersions = collector.ExistingVersions.TagCommits;

                            var info = collector.GetCommitInfo(commit);
                            Debug.Assert(info != null);

                            CommitInfo = info;

                            var rawPossible = info.PossibleVersions;
                            IEnumerable <CSVersion> possibles = rawPossible;
                            if (options.OnlyPatch)
                            {
                                possibles = possibles.Where(v => v.IsPatch);
                            }
                            if (options.SingleMajor.HasValue)
                            {
                                possibles = possibles.Where(v => v.Major == options.SingleMajor.Value);
                            }
                            PossibleVersions = possibles != rawPossible?possibles.ToList() : rawPossible;

                            var rawNextPossible = info.NextPossibleVersions;
                            IEnumerable <CSVersion> nextPossibles = rawNextPossible;
                            if (options.OnlyPatch)
                            {
                                nextPossibles = nextPossibles.Where(v => v.IsPatch);
                            }
                            if (options.SingleMajor.HasValue)
                            {
                                nextPossibles = nextPossibles.Where(v => v.Major == options.SingleMajor.Value);
                            }
                            NextPossibleVersions = nextPossibles != rawNextPossible?nextPossibles.ToList() : rawNextPossible;

                            var thisCommit = info.BasicInfo?.UnfilteredThisCommit;
                            if (info.BasicInfo?.BestCommit?.ThisTag > thisCommit?.ThisTag)
                            {
                                BetterExistingVersion = info.BasicInfo.BestCommit;
                            }
                            if (thisCommit != null)
                            {
                                if (PossibleVersions.Contains(thisCommit.ThisTag))
                                {
                                    ValidReleaseTag = thisCommit.ThisTag;
                                }
                                else
                                {
                                    ReleaseTagIsNotPossibleError = true;
                                    errors.Append("Release tag '")
                                    .Append(thisCommit.ThisTag.ParsedText)
                                    .AppendLine("' is not valid here. ");
                                    errors.Append("Valid tags are: ")
                                    .Append(string.Join(", ", PossibleVersions))
                                    .AppendLine();
                                    if (PossibleVersions != rawPossible &&
                                        rawPossible.Contains(thisCommit.ThisTag))
                                    {
                                        errors.AppendLine("Note: this version is invalid because of <SingleMajor> or <OnlyPatch> setting in RepositoryInfo.xml.");
                                    }
                                }
                            }
                            else
                            {
                                // There is no release tag on the commit point.
                                if (ciBuildName != null)
                                {
                                    CIRelease = CIReleaseInfo.Create(commit, ciVersionMode, ciBuildName, errors, info.BasicInfo);
                                }
                            }
                        }
                        if (errors.Length > 0)
                        {
                            ReleaseTagError = errors.ToString();
                        }
                    }

                    // Conclusion:
                    if (CIRelease != null)
                    {
                        //ContentOrFinalNuGetVersion =
                        FinalNuGetVersion = CIRelease.BuildVersionNuGet;
                        FinalSemVersion   = CIRelease.BuildVersion;
                    }
                    else if (ValidReleaseTag != null)
                    {
                        FinalNuGetVersion = SVersion.Parse(ValidReleaseTag.ToString(CSVersionFormat.NuGetPackage), false);
                        FinalSemVersion   = ValidReleaseTag;
                    }
                }
            }
            // Handles FinalInformationalVersion and SVersion.ZeroVersion for versions if needed.
            if (FinalSemVersion == null)
            {
                FinalSemVersion           = SVersion.ZeroVersion;
                FinalNuGetVersion         = SVersion.ZeroVersion;
                FinalInformationalVersion = InformationalVersion.ZeroInformationalVersion;
            }
            else
            {
                FinalInformationalVersion = InformationalVersion.BuildInformationalVersion(FinalSemVersion.NormalizedText, FinalNuGetVersion.NormalizedText, CommitSha, CommitDateUtc);
            }
        }