Exemplo n.º 1
0
        public void PerformUpdate(string fl, FileUpdateType fut)
        {
            string versonToWrite = cv.GetVersionString(cv.GetDisplayType(fut));

            Bilge.VerboseLog($"Perform update requested {versonToWrite} using {fut.ToString()}", fl);

            switch (fut)
            {
            case FileUpdateType.Assembly4:
            case FileUpdateType.Assembly2:
                UpdateCSFileWithAttribute(fl, ASMFILE_VER_TAG, versonToWrite);
                break;

            case FileUpdateType.AssemblyInformational:
                UpdateCSFileWithAttribute(fl, ASMFILE_INFVER_TAG, versonToWrite);
                break;

            case FileUpdateType.AssemblyFile:
                UpdateCSFileWithAttribute(fl, ASMFILE_FILEVER_TAG, versonToWrite);
                break;

            case FileUpdateType.Wix:
                Bilge.Log("Wix Updates NOT SUPPORTED");
                break;

            default:
                break;
            }
        }
Exemplo n.º 2
0
        public void VersionUnit_ChangeBehavour_ExceptionIfNotIncrementable()
        {
            Bilge.Log(nameof(VersionUnit_ChangeBehavour_ExceptionIfNotIncrementable) + " Entered");
            var sut = new VersionUnit("monkey");


            Assert.Throws <InvalidOperationException>(() => { sut.SetBehaviour(VersionIncrementBehaviour.AutoIncrementWithReset); });
        }
Exemplo n.º 3
0
 public VersioningTask()
 {
     Bilge.CurrentTraceLevel = System.Diagnostics.TraceLevel.Verbose;
     Bilge.Log("PliskyVersioning Online.");
     Bilge.QueueMessages               = false;
     Bilge.EnableEnhancements          = true;
     Bilge.CustomTagReplacementHandler = LogMessageIntercept;
 }
Exemplo n.º 4
0
 public CompleteVersion()
 {
     Bilge.Log("Complete Version Created");
     displayTypes = new DisplayType[NUMBERDISPLAYTYPES];
     displayTypes[(int)FileUpdateType.Assembly4]             = DisplayType.Full;
     displayTypes[(int)FileUpdateType.AssemblyInformational] = DisplayType.FullIncludeText;
     displayTypes[(int)FileUpdateType.AssemblyFile]          = DisplayType.Full;
     displayTypes[(int)FileUpdateType.Wix]       = DisplayType.FullIncludeText;
     displayTypes[(int)FileUpdateType.Assembly2] = DisplayType.Short;
 }
Exemplo n.º 5
0
        private static void Main()
        {
            Bilge.Log("Test Console app online");

            VersionStorage mvs = new PDirtyStorage("http://localhost/PSDirty/home/getversioninfo?id=ddb172c4-f37e-49d3-9841-586cb0ace48d");

            var sut = new VersioningTask();

            sut.InjectStore(mvs);
            sut.BaseSearchDir = @"D:\Temp\_Deleteme\aaaVersioningTestFolder";
            sut.AddUpdateType("**\\Properties\\commonassemblyinfo.cs", FileUpdateType.Assembly2);
            sut.AddUpdateType("**\\Properties\\commonassemblyinfo.cs", FileUpdateType.AssemblyInformational);
            sut.AddUpdateType("**\\Properties\\assemblyinfo.cs", FileUpdateType.AssemblyFile);

            sut.IncrementAndUpdateAll();

            /* sut.VersionNumberKey = vn.ToString();
             * sut.RootPath = @"D:\Files\Git2015\Plisky.net\PliskyVersioning\_Dependencies\TestData\TestFileStructure";
             * sut.AssemblyFilesToUpdate = "**\\Properties\\assemblyinfo.cs";
             * sut.AssemblyFilesUseBuildVersionNumber = false;
             * sut.FileVersionFilesToUpdate = "**\\Properties\\assemblyinfo.cs";
             * sut.FileFilesUseBuildVersionNumber = true;
             * sut.IncrementAndApplyVersion();*/


            /*  var mvs = new MockVersionService();
             * var vn = Guid.NewGuid();
             * var vn2 = Guid.NewGuid();
             * mvs.RegisterVersion(vn, "default", new VersionNumber(3, 1, 1, 1));
             * mvs.RegisterVersion(vn2, "default", new VersionNumber(4, 1, 1, 1));
             *
             * var sut = new BuildVersioner(mvs);
             *
             * sut.VersionNumberKey = vn.ToString();
             * sut.RootPath = @"D:\Files\Git2015\Plisky.net\PliskyVersioning\_Dependencies\TestData\TestFileStructure";
             * sut.AssemblyFilesToUpdate = "**\\Properties\\assemblyinfo.cs";
             * sut.AssemblyFilesUseBuildVersionNumber = false;
             * sut.FileVersionFilesToUpdate = "**\\Properties\\assemblyinfo.cs";
             * sut.FileFilesUseBuildVersionNumber = true;
             * sut.IncrementAndApplyVersion();*/

            Console.WriteLine("done");
            Console.ReadLine();
        }
Exemplo n.º 6
0
 public void SetAllVersioningItems(string verItemsSimple)
 {
     Bilge.Log("SetAllVersioningITems");
     if (verItemsSimple.Contains(Environment.NewLine))
     {
         // The TFS build agent uses \n not Environment.Newline for its line separator, however unit tests use Environment.Newline
         // so replacing them with \n to make the two consistant.
         verItemsSimple = verItemsSimple.Replace(Environment.NewLine, "\n");
     }
     string[] allLines = verItemsSimple.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries);
     foreach (var ln in allLines)
     {
         string[] parts = ln.Split('!');
         if (parts.Length != 2)
         {
             throw new InvalidOperationException($"The versioning item string was in the wrong format [{ln}] ");
         }
         FileUpdateType ft = GetFileTypeFromString(parts[1]);
         AddUpdateType(parts[0], ft);
     }
 }
Exemplo n.º 7
0
        private bool CheckAndUpdate(string fl, Minimatcher assemblyMM, string versionValue, Action <string, string> p)
        {
            Bilge.Assert(p != null, "The action used cant be null");

            Bilge.VerboseLog("Checking file :" + fl);

            bool result = assemblyMM.IsMatch(fl);

            if ((result) && (File.Exists(fl)))
            {
                Bilge.Log($"Updating VersioningFile File ({fl}) to ({versionValue})");

                hook?.PreUpdateFileAction(fl); // PreUpdateAllAction?.Invoke(fl);
                //PreUpdateAction?.Invoke(fl);

                p(fl, versionValue);

                hook?.PostUpdateFileAction(fl);
            }
            return(result);
        }
Exemplo n.º 8
0
        public void IncrementAndUpdateAll()
        {
            Bilge.VerboseLog("IncrementAndUpdateAll called");
            ValidateForUpdate();
            LoadVersioningComponent();

            Bilge.VerboseLog("Versioning Loaded Ver at " + ver.ToString());
            ver.PerformIncrement();
            Bilge.VerboseLog("Saving Ver At " + ver.ToString());
            SaveVersioningComponent();
            Bilge.VerboseLog($"Searching {BaseSearchDir} there are {pendingUpdates.Count} pends.");
            foreach (var v in Directory.EnumerateFiles(BaseSearchDir, "*.*", SearchOption.AllDirectories))
            {
                // Check every file that we have returned.
                foreach (var chk in pendingUpdates.Keys)
                {
                    var mm = new Minimatcher(chk, new Options {
                        AllowWindowsPaths = true, IgnoreCase = true
                    });

                    // Dump out every file considered. Bilge.VerboseLog($"Checking {chk} against {v}");

                    if (mm.IsMatch(v))
                    {
                        Bilge.Log($"Match...{chk}", v);
                        // TODO Cache this and make it less loopey
                        VersionFileUpdater vfu = new VersionFileUpdater(ver);
                        foreach (var updateType in pendingUpdates[chk])
                        {
                            Bilge.VerboseLog($"Perform update {v} using {updateType.ToString()} as {(int)updateType}");
                            vfu.PerformUpdate(v, updateType);
                        }
                    }
                }
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Either updates an existing version number in a file or creates a new (very basic) assembly info file and adds the verison number to it.  The
        /// version is stored in the attribute that is supplied as the second parameter.
        /// </summary>
        /// <param name="fileName">The full path to the file to either update or create</param>
        /// <param name="targetAttribute">The name of the attribute to write the verison number into</param>
        /// <param name="vn">The verison number to apply to the code</param>
        private void UpdateCSFileWithAttribute(string fileName, string targetAttribute, string versionValue)
        {
            #region entry code

            Bilge.Assert(!string.IsNullOrEmpty(fileName), "fileName is null, internal consistancy error.");
            Bilge.Assert(!string.IsNullOrEmpty(targetAttribute), "target attribute cant be null, internal consistancy error");
            Bilge.Assert(versionValue != null, "vn cant be null, internal consistancy error");

            #endregion (entry code)

            Bilge.Log(string.Format("VersionSupport, Asked to update CS file with the {0} attribute", targetAttribute), "Full Filename:" + fileName);

            var outputFile = new StringBuilder();

            if (!File.Exists(fileName))
            {
                Bilge.VerboseLog("There was no file, creating file and adding attribute");
                outputFile.Append("using System.Reflection;\r\n");
                outputFile.Append($"[assembly: {targetAttribute}(\"{versionValue}\")]\r\n");
            }
            else
            {
                // If it does exist we need to verify that it is not readonly.
                if ((File.GetAttributes(fileName) & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
                {
                    Bilge.Warning("The file is readonly, removing attribs so I can write on it", "fname [" + fileName + "]");
                    File.SetAttributes(fileName, (File.GetAttributes(fileName) ^ FileAttributes.ReadOnly));
                }

                // Put this in to identify if there were duplicate entries discovered in the file, this should not be valid but helps to reassure that its not the verisoner that has
                // introduced a compile error into the code.
                bool replacementMade = false;

                /*
                 * Regex r = new Regex("\\[\\s*assembly\\s*:\\s*" + targetAttribute + "\\s*\\(\\s*\\\"\\s*[0-9*]+.[0-9*]+.[0-9*]+.[0-9*]+\\s*\\\"\\s*\\)\\s*\\]", RegexOptions.IgnoreCase);
                 */

                Regex r = GetRegex(targetAttribute);
                using (StreamReader sr = new StreamReader(fileName)) {
                    string nextLine = null;
                    while ((nextLine = sr.ReadLine()) != null)
                    {
                        if ((!nextLine.Trim().StartsWith("//")) && (r.IsMatch(nextLine)))
                        {
                            if (replacementMade)
                            {
                                // One would hope that this would not occur outside of testing, yet surprisingly enough this is not the case.
                                throw new ArgumentException("Invalid CSharp File, duplicate verison attribute discovered", fileName);
                            }

                            //  its the line we are to replace
                            outputFile.Append("[assembly: " + targetAttribute + "(\"");
                            outputFile.Append(versionValue);
                            outputFile.Append("\")]\r\n");
                            replacementMade = true;
                        }
                        else
                        {
                            // All lines except the one we are interested in are copied across.
                            outputFile.Append(nextLine + "\r\n");
                        }
                    }

                    if (!replacementMade)
                    {
                        Bilge.Warning("No " + targetAttribute + " found in file, appending new one.");
                        outputFile.Append($"\r\n[assembly: {targetAttribute}(\"{versionValue}\")]\r\n");
                    }
                }
            }

            File.WriteAllText(fileName, outputFile.ToString(), Encoding.UTF8);

            Bilge.Log("The attribute " + targetAttribute + " was applied to the file " + fileName + " Successfully.");
        }