Example #1
0
        public AssemblyInfoParserFixture(string version              = "1.2.3.4",
                                         string fileVersion          = "4.3.2.1",
                                         string informationalVersion = "4.2.3.1",
                                         bool createAssemblyInfo     = true)
        {
            FileSystem = new FakeFileSystem(false);

            Environment = Substitute.For <ICakeEnvironment>();
            Environment.WorkingDirectory.Returns("/Working");

            if (createAssemblyInfo)
            {
                // Set the versions.
                var settings = new AssemblyInfoSettings();
                if (version != null)
                {
                    settings.Version = version;
                }
                if (fileVersion != null)
                {
                    settings.FileVersion = fileVersion;
                }
                if (informationalVersion != null)
                {
                    settings.InformationalVersion = informationalVersion;
                }

                // Create the assembly info.
                var creator = new AssemblyInfoCreator(FileSystem, Environment, Substitute.For <ICakeLog>());
                creator.Create("./output.cs", settings);
            }
        }
Example #2
0
        private void CreateAssemblyInfoOnDisk(FilePath path)
        {
            var settings = new AssemblyInfoSettings();

            settings.CLSCompliant = ClsCompliant;
            settings.ComVisible   = ComVisible;

            if (Company != null)
            {
                settings.Company = Company;
            }
            if (Configuration != null)
            {
                settings.Configuration = Configuration;
            }
            if (Copyright != null)
            {
                settings.Copyright = Copyright;
            }
            if (Description != null)
            {
                settings.Description = Description;
            }
            if (FileVersion != null)
            {
                settings.FileVersion = FileVersion;
            }
            if (Guid != null)
            {
                settings.Guid = Guid;
            }
            if (InformationalVersion != null)
            {
                settings.InformationalVersion = InformationalVersion;
            }
            if (InternalsVisibleTo != null)
            {
                settings.InternalsVisibleTo = InternalsVisibleTo;
            }
            if (Product != null)
            {
                settings.Product = Product;
            }
            if (Title != null)
            {
                settings.Title = Title;
            }
            if (Trademark != null)
            {
                settings.Trademark = Trademark;
            }
            if (Version != null)
            {
                settings.Version = Version;
            }

            var creator = new AssemblyInfoCreator(FileSystem, Environment, Substitute.For <ICakeLog>());

            creator.Create(path, settings);
        }
Example #3
0
            public void Should_Make_Relative_Output_Path_Absolute()
            {
                // Given
                var fixture = new AssemblyInfoFixture();
                var creator = new AssemblyInfoCreator(fixture.FileSystem, fixture.Environment, fixture.Log);

                // When
                creator.Create("AssemblyInfo.cs", new AssemblyInfoSettings());

                // Then
                Assert.True(fixture.FileSystem.Exist((FilePath)"/Working/AssemblyInfo.cs"));
            }
Example #4
0
            public void Should_Throw_If_Settings_Are_Null()
            {
                // Given
                var fixture = new AssemblyInfoFixture();
                var creator = new AssemblyInfoCreator(fixture.FileSystem, fixture.Environment, fixture.Log);

                // When
                var result = Record.Exception(() => creator.Create("A.cs", null));

                // Then
                Assert.IsArgumentNullException(result, "settings");
            }
Example #5
0
            public void Should_Throw_If_Output_Path_Is_Null()
            {
                // Given
                var fixture = new AssemblyInfoFixture();
                var creator = new AssemblyInfoCreator(fixture.FileSystem, fixture.Environment, fixture.Log);

                // When
                var result = Record.Exception(() => creator.Create(null, new AssemblyInfoSettings()));

                // Then
                Assert.IsArgumentNullException(result, "outputPath");
            }
        /**************************************************************/
        /*                        Public
        /**************************************************************/

        internal static void Generate(string[] aFiles) {
            FrmAssemblyInfoBuilderRunner _Frm = new FrmAssemblyInfoBuilderRunner();

            if (_Frm.ShowDialog() == DialogResult.OK) {
                AssemblyInfoCreator _AssemblyInfoCreator = new AssemblyInfoCreator();
                _AssemblyInfoCreator.MessageEvent += new AssemblyInfoCreator.AssemblyInfoCreatorMessageEvent(MessageEvent);

                fMessages.Clear();
                _AssemblyInfoCreator.CreateAssemblyInfo(_Frm.Language, aFiles);
                FrmAssemblyInfoMessage _FrmAssemblyInfoMessage = new FrmAssemblyInfoMessage(fMessages);
                _FrmAssemblyInfoMessage.ShowDialog();
            }
        }
Example #7
0
        public string CreateAndReturnContent()
        {
            var creator = new AssemblyInfoCreator(FileSystem, Environment, Log);

            creator.Create(Path, Settings);

            var file = FileSystem.GetFile(Path.MakeAbsolute(Environment));

            Assert.True(file.Exists, "File was not created.");
            using (var reader = new StreamReader(file.OpenRead()))
            {
                return(reader.ReadToEnd());
            }
        }
Example #8
0
        /**************************************************************/
        /*                     Public
        /**************************************************************/

        private static void Run(CommandLineManager aCommandLineManager) {
            ValueCommandLineOption _InputOptions = (ValueCommandLineOption) aCommandLineManager.GetCommandLineOptionBySwitch(INPUT_FILE_SWITCH);
            ValueCommandLineOption _OutputOption = (ValueCommandLineOption) aCommandLineManager.GetCommandLineOptionBySwitch(OUTPUT_FILE_SWITCH);
            ValueCommandLineOption _LanguageOptions = (ValueCommandLineOption) aCommandLineManager.GetCommandLineOptionBySwitch(LANGUAGE_SWITCH);

            if (_InputOptions == null) {
                Console.WriteLine("No input files specified");
                return;
            }

            if (_LanguageOptions == null) {
                Console.WriteLine("Language not specified");
                return;
            } else if (_LanguageOptions.Values.Count > 1){
                Console.WriteLine("Too many Language specified");
                return;
            }

            string[] _Files = new string[_InputOptions.Values.Count];
            for(int i = 0; i < _InputOptions.Values.Count; i++) {
                _Files[i] = _InputOptions.Values[i];
            }

            AssemblyInfoCreator _AssemblyInfoCreator = new AssemblyInfoCreator();
            _AssemblyInfoCreator.MessageEvent += new AssemblyInfoCreator.AssemblyInfoCreatorMessageEvent(MessageEvent);

            // Get the Language
            Language _Language;

            if (_LanguageOptions.Values[0].ToUpperInvariant() == LANGUAGE_CS.ToUpperInvariant()) {
                _Language = Language.CSharp;
            } else if (_LanguageOptions.Values[0].ToUpperInvariant() == LANGUAGE_DELPHI.ToUpperInvariant()) {
                _Language = Language.Delphi;
            } else {
                Console.WriteLine("Invalid language specified");
                return;
            }

            if (_OutputOption != null && _OutputOption.Values.Count > 0) {
                if (_OutputOption.Values.Count > 1) {
                    Console.WriteLine("Too many output specified");
                    return;
                }

                _AssemblyInfoCreator.CreateAssemblyInfo(_Language, _Files, _OutputOption.Values[0]);
            } else {
                _AssemblyInfoCreator.CreateAssemblyInfo(_Language, _Files);
            }
        }
Example #9
0
        public void PatchAllAssemblyInfo(VersionResult versionInfo, string copyrightText)
        {
            var parser        = new AssemblyInfoParser(_fileSystem, _environment);
            var creator       = new AssemblyInfoCreator(_fileSystem, _environment, _log);
            var assemblyFiles = _globber.GetFiles("./**/AssemblyInfo.cs");

            foreach (var file in assemblyFiles)
            {
                _log.Verbose($"Possibly file to patch:{file}");
                if (file.ToString().Contains("packages/"))
                {
                    continue;
                }
                var assemblyInfo = parser.Parse(file);

                string rootVersion = versionInfo.RootVersion;
                //on AppVeyor, if it is a PullRequest and "pull_requests: do_not_increment_build_number" is true, it will make up a build like 1.0.2-fisiek
                //It does this because it requires unique version numbers.
                //So, what is in RootVersion has this 'prerelease' tag of 'fisiek' or whatever on it.  This is not valid when versioning assembiles!
                //we of course are not going to publish prereleases to nuget, so just make up any version for this.

                //if do_not_increment_build_number is false, then the version does NOT contain the extra tag and it does not matter.
                //of course we do not know if this is true or false.  So we will just look...
                if (IsPullRequest && rootVersion.Contains("-"))
                {
                    rootVersion = "1.0.1";
                }

                _log.Information($"Creating File Version:{rootVersion} Info Version:{versionInfo.FullVersion} for {file} ");

                creator.Create(file, new AssemblyInfoSettings
                {
                    Product              = assemblyInfo.Product,
                    Version              = rootVersion,
                    FileVersion          = rootVersion,
                    InformationalVersion = versionInfo.FullVersion,
                    Copyright            = string.Format(copyrightText, DateTime.Now.Year)
                });
            }
        }
Example #10
0
        public AssemblyInfoParserFixture(bool clsCompliant           = false,
                                         string company              = "Company",
                                         bool comVisible             = false,
                                         string configuration        = "Debug",
                                         string copyright            = "Copyright 2015",
                                         string description          = "Description",
                                         string fileVersion          = "4.3.2.1",
                                         string guid                 = "ABCEDF",
                                         string informationalVersion = "4.2.3.1",
                                         string internalsVisibleTo   = "Cake.Common.Test",
                                         string product              = "Cake",
                                         string title                = "Cake",
                                         string trademark            = "Trademark",
                                         string version              = "1.2.3.4",
                                         bool createAssemblyInfo     = true)
        {
            Environment = Substitute.For <ICakeEnvironment>();
            Environment.WorkingDirectory.Returns("/Working");

            FileSystem = new FakeFileSystem(Environment);
            FileSystem.CreateDirectory(Environment.WorkingDirectory);

            if (createAssemblyInfo)
            {
                // Set the versions.
                var settings = new AssemblyInfoSettings();
                settings.CLSCompliant = clsCompliant;

                if (company != null)
                {
                    settings.Company = company;
                }

                settings.ComVisible = comVisible;

                if (configuration != null)
                {
                    settings.Configuration = configuration;
                }
                if (copyright != null)
                {
                    settings.Copyright = copyright;
                }
                if (description != null)
                {
                    settings.Description = description;
                }
                if (fileVersion != null)
                {
                    settings.FileVersion = fileVersion;
                }
                if (guid != null)
                {
                    settings.Guid = guid;
                }
                if (informationalVersion != null)
                {
                    settings.InformationalVersion = informationalVersion;
                }
                if (internalsVisibleTo != null)
                {
                    settings.InternalsVisibleTo = new List <string>()
                    {
                        internalsVisibleTo
                    };
                }
                if (product != null)
                {
                    settings.Product = product;
                }
                if (title != null)
                {
                    settings.Title = title;
                }
                if (trademark != null)
                {
                    settings.Trademark = trademark;
                }
                if (version != null)
                {
                    settings.Version = version;
                }

                // Create the assembly info.
                var creator = new AssemblyInfoCreator(FileSystem, Environment, Substitute.For <ICakeLog>());
                creator.Create("./output.cs", settings);
            }
        }