Exemplo n.º 1
0
        public void RunningFirstIntegrationWithModificationsShouldBuildAndPublish()
        {
            Modification[] modifications = new Modification[1] {
                new Modification()
            };

            mockStateManager.ExpectAndReturn("HasPreviousState", false, ProjectName);
            mockStateManager.Expect("SaveState", new IsAnything());
            mockLabeller.ExpectAndReturn("Generate", "label", new IsAnything());             // generate new label
            mockSourceControl.ExpectAndReturn("GetModifications", modifications, new IsAnything(), new IsAnything());
            mockSourceControl.Expect("LabelSourceControl", new IsAnything());
            mockSourceControl.Expect("GetSource", new IsAnything());
            mockPublisher.Expect("Run", new IsAnything());
            mockTask.Expect("Run", new AddTaskResultConstraint());

            IIntegrationResult result = project.Integrate(ModificationExistRequest());

            Assert.AreEqual(ProjectName, result.ProjectName);
            Assert.AreEqual(ProjectActivity.Sleeping, project.CurrentActivity);
            Assert.AreEqual(IntegrationStatus.Success, result.Status);
            Assert.AreEqual(IntegrationStatus.Unknown, result.LastIntegrationStatus);
            Assert.AreEqual("label", result.Label);
            Assert.IsTrue(result.HasModifications());
            Assert.AreEqual(project.WorkingDirectory, result.WorkingDirectory);
            Assert.AreEqual(modifications, result.Modifications);
            Assert.IsTrue(result.EndTime >= result.StartTime);
            VerifyAll();
        }
Exemplo n.º 2
0
        public void RunningFirstIntegrationShouldForceBuild()
        {
            mockStateManager.ExpectAndReturn("HasPreviousState", false, ProjectName);                                       // running the first integration (no state file)
            mockStateManager.Expect("SaveState", new IsAnything());
            mockLabeller.ExpectAndReturn("Generate", "label", new IsAnything());                                            // generate new label
            mockSourceControl.ExpectAndReturn("GetModifications", new Modification[0], new IsAnything(), new IsAnything()); // return no modifications found
            mockSourceControl.Expect("GetSource", new IsAnything());
            mockSourceControl.Expect("LabelSourceControl", new IsAnything());
            mockPublisher.Expect("Run", new IsAnything());
            mockTask.Expect("Run", new AddTaskResultConstraint());
            project.ConfiguredWorkingDirectory = @"c:\temp";

            IIntegrationResult result = project.Integrate(ModificationExistRequest());

            Assert.AreEqual(ProjectName, result.ProjectName);
            Assert.AreEqual(null, result.ExceptionResult);
            Assert.AreEqual(ProjectActivity.Sleeping, project.CurrentActivity);
            Assert.AreEqual(IntegrationStatus.Success, result.Status);
            Assert.AreEqual(IntegrationStatus.Unknown, result.LastIntegrationStatus);
            Assert.AreEqual(BuildCondition.ForceBuild, result.BuildCondition);
            Assert.AreEqual(@"c:\temp", result.WorkingDirectory);
            Assert.AreEqual(result, project.CurrentResult);
            Assert.AreEqual("label", result.Label);
            AssertFalse("unexpected modifications were returned", result.HasModifications());
            AssertEqualArrays(new Modification[0], result.Modifications);
            Assert.IsTrue(result.EndTime >= result.StartTime);
            VerifyAll();
        }
Exemplo n.º 3
0
        private XmlElement BuildIntegrationElement(XmlDocument ownerDocument, IIntegrationResult result)
        {
            XmlElement integrationElement = CreateElement(ownerDocument, "item");

            integrationElement.AppendChild(CreateTextElement(integrationElement.OwnerDocument,
                                                             "title",
                                                             "Build {0} : {1}  {2}  {3}",
                                                             result.Label,
                                                             result.Status,
                                                             GetAmountOfModifiedFiles(result),
                                                             GetFirstCommentedModification(result)));
            integrationElement.AppendChild(CreateTextElement(
                                               integrationElement.OwnerDocument, "description", GetAmountOfModifiedFiles(result)));
            integrationElement.AppendChild(CreateTextElement(
                                               integrationElement.OwnerDocument, "guid", System.Guid.NewGuid().ToString()));
            integrationElement.AppendChild(CreateTextElement(
                                               integrationElement.OwnerDocument, "pubDate", System.DateTime.Now.ToString("r", CultureInfo.CurrentCulture)));

            if (result.HasModifications())
            {
                XmlElement modsElement = CreateContentElement(
                    integrationElement.OwnerDocument,
                    "encoded");
                XmlCDataSection cdata = integrationElement.OwnerDocument.CreateCDataSection(
                    GetBuildModifications(result));
                modsElement.AppendChild(cdata);
                integrationElement.AppendChild(modsElement);
            }
            return(integrationElement);
        }
Exemplo n.º 4
0
        public bool ShouldRunBuild(IIntegrationResult result)
        {
            if (!this.Condition)
            {
                return(true);
            }

            bool HasTrackers = this.GetQueryCount() != 0;

            bool Modifications = true;

            if (this.WithModifications)
            {
                Modifications = result.HasModifications();
            }

            bool Integratable = HasTrackers && Modifications;

            if (!Integratable)
            {
                Log.Info(string.Format("No trackers were found in query {0}.", this.QueryInforation.Name));
            }

            return(Integratable);
        }
Exemplo n.º 5
0
        public void RunningFirstIntegrationWithModificationsShouldBuildAndPublish()
        {
            Modification[] modifications = new Modification[1] {
                new Modification()
            };

            mockStateManager.Setup(_manager => _manager.HasPreviousState(ProjectName)).Returns(false).Verifiable();
            mockStateManager.Setup(_manager => _manager.SaveState(It.IsAny <IIntegrationResult>())).Verifiable();
            mockLabeller.Setup(labeller => labeller.Generate(It.IsAny <IIntegrationResult>())).Returns("label").Verifiable();            // generate new label
            mockSourceControl.Setup(sourceControl => sourceControl.GetModifications(It.IsAny <IIntegrationResult>(), It.IsAny <IIntegrationResult>())).Returns(modifications).Verifiable();
            mockSourceControl.Setup(sourceControl => sourceControl.LabelSourceControl(It.IsAny <IIntegrationResult>())).Verifiable();
            mockSourceControl.Setup(sourceControl => sourceControl.GetSource(It.IsAny <IIntegrationResult>())).Verifiable();
            mockPublisher.Setup(publisher => publisher.Run(It.IsAny <IIntegrationResult>())).Verifiable();
            mockTask.Setup(task => task.Run(It.IsAny <IntegrationResult>())).Callback <IIntegrationResult>(r => r.AddTaskResult("success")).Verifiable();

            IIntegrationResult result = project.Integrate(ModificationExistRequest());

            Assert.AreEqual(ProjectName, result.ProjectName);
            Assert.AreEqual(ProjectActivity.Sleeping, project.CurrentActivity);
            Assert.AreEqual(IntegrationStatus.Success, result.Status);
            Assert.AreEqual(IntegrationStatus.Unknown, result.LastIntegrationStatus);
            Assert.AreEqual("label", result.Label);
            Assert.IsTrue(result.HasModifications());
            Assert.AreEqual(project.WorkingDirectory, result.WorkingDirectory);
            Assert.AreEqual(modifications, result.Modifications);
            Assert.IsTrue(result.EndTime >= result.StartTime);
            VerifyAll();
        }
Exemplo n.º 6
0
        public void RunningFirstIntegrationShouldForceBuild()
        {
            mockStateManager.Setup(_manager => _manager.HasPreviousState(ProjectName)).Returns(false).Verifiable();                                                                               // running the first integration (no state file)
            mockStateManager.Setup(_manager => _manager.SaveState(It.IsAny <IIntegrationResult>())).Verifiable();
            mockLabeller.Setup(labeller => labeller.Generate(It.IsAny <IIntegrationResult>())).Returns("label").Verifiable();                                                                     // generate new label
            mockSourceControl.Setup(sourceControl => sourceControl.GetModifications(It.IsAny <IIntegrationResult>(), It.IsAny <IIntegrationResult>())).Returns(new Modification[0]).Verifiable(); // return no modifications found
            mockSourceControl.Setup(sourceControl => sourceControl.GetSource(It.IsAny <IIntegrationResult>())).Verifiable();
            mockSourceControl.Setup(sourceControl => sourceControl.LabelSourceControl(It.IsAny <IIntegrationResult>())).Verifiable();
            mockPublisher.Setup(publisher => publisher.Run(It.IsAny <IIntegrationResult>())).Verifiable();
            mockTask.Setup(task => task.Run(It.IsAny <IntegrationResult>())).Callback <IIntegrationResult>(r => r.AddTaskResult("success")).Verifiable();
            project.ConfiguredWorkingDirectory = @"c:\temp";

            IIntegrationResult result = project.Integrate(ModificationExistRequest());

            Assert.AreEqual(ProjectName, result.ProjectName);
            Assert.AreEqual(null, result.ExceptionResult);
            Assert.AreEqual(ProjectActivity.Sleeping, project.CurrentActivity);
            Assert.AreEqual(IntegrationStatus.Success, result.Status);
            Assert.AreEqual(IntegrationStatus.Unknown, result.LastIntegrationStatus);
            Assert.AreEqual(BuildCondition.ForceBuild, result.BuildCondition);
            Assert.AreEqual(@"c:\temp", result.WorkingDirectory);
            Assert.AreEqual(result, project.CurrentResult);
            Assert.AreEqual("label", result.Label);
            AssertFalse("unexpected modifications were returned", result.HasModifications());
            AssertEqualArrays(new Modification[0], result.Modifications);
            Assert.IsTrue(result.EndTime >= result.StartTime);
            VerifyAll();
        }
Exemplo n.º 7
0
        public bool ShouldRunBuild(IIntegrationResult result)
        {
            if (!this.Condition)
            {
                return(true);
            }
            bool ResultHasModifications = result.HasModifications();

            return(ResultHasModifications);
        }
Exemplo n.º 8
0
        private string GetFirstCommentedModification(IIntegrationResult result)
        {
            if (result.HasModifications())
            {
                foreach (Modification modification in result.Modifications)
                {
                    if (!string.IsNullOrEmpty(modification.Comment))
                    {
                        return("First Comment : " + modification.Comment);
                    }
                }
            }

            return(string.Empty);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Gets the source.
        /// </summary>
        /// <param name="result">The result.</param>
        /// <remarks></remarks>
        public override void GetSource(IIntegrationResult result)
        {
            Util.Log.Info(result.HasModifications().ToString(CultureInfo.CurrentCulture));


            ftp = new FtpLib(result.BuildProgressInformation);
            string remoteFolder = FtpFolderName;

            ftp.LogIn(ServerName, UserName, Password.PrivateValue, UseActiveConnectionMode);


            if (!FtpFolderName.StartsWith("/"))
            {
                remoteFolder = System.IO.Path.Combine(ftp.CurrentWorkingFolder(), FtpFolderName);
            }

            ftp.DownloadFolder(LocalFolderName, remoteFolder, RecursiveCopy);

            ftp.DisConnect();
        }
Exemplo n.º 10
0
        public void RunningIntegrationWithNoModificationsShouldNotBuildOrPublish()
        {
            mockStateManager.ExpectAndReturn("HasPreviousState", true, ProjectName);
            mockStateManager.ExpectAndReturn("LoadState", IntegrationResultMother.CreateSuccessful(), ProjectName);
            mockSourceControl.ExpectAndReturn("GetModifications", new Modification[0], new IsAnything(), new IsAnything());             // return no modifications found
            mockPublisher.ExpectNoCall("Run", typeof(IntegrationResult));

            IIntegrationResult result = project.Integrate(ModificationExistRequest());

            Assert.AreEqual(ProjectName, result.ProjectName);
            Assert.AreEqual(null, result.ExceptionResult);
            Assert.AreEqual(ProjectActivity.Sleeping, project.CurrentActivity);
            Assert.AreEqual(IntegrationStatus.Unknown, result.Status);
            Assert.IsNotNull(project.CurrentResult);
            //Assert.AreEqual(IntegrationResult.InitialLabel, result.Label);
            AssertFalse("unexpected modifications were returned", result.HasModifications());
            AssertEqualArrays(new Modification[0], result.Modifications);
            Assert.AreEqual(string.Empty, result.TaskOutput, "no output is expected as builder is not called");
            //			Assert.IsTrue(result.EndTime >= result.StartTime);
            VerifyAll();
        }
Exemplo n.º 11
0
        public void RunningIntegrationWithNoModificationsShouldNotBuildOrPublish()
        {
            mockStateManager.Setup(_manager => _manager.HasPreviousState(ProjectName)).Returns(true).Verifiable();
            mockStateManager.Setup(_manager => _manager.LoadState(ProjectName)).Returns(IntegrationResultMother.CreateSuccessful()).Verifiable();
            mockSourceControl.Setup(sourceControl => sourceControl.GetModifications(It.IsAny <IIntegrationResult>(), It.IsAny <IIntegrationResult>())).Returns(new Modification[0]).Verifiable();           // return no modifications found

            IIntegrationResult result = project.Integrate(ModificationExistRequest());

            Assert.AreEqual(ProjectName, result.ProjectName);
            Assert.AreEqual(null, result.ExceptionResult);
            Assert.AreEqual(ProjectActivity.Sleeping, project.CurrentActivity);
            Assert.AreEqual(IntegrationStatus.Unknown, result.Status);
            Assert.IsNotNull(project.CurrentResult);
            //Assert.AreEqual(IntegrationResult.InitialLabel, result.Label);
            AssertFalse("unexpected modifications were returned", result.HasModifications());
            AssertEqualArrays(new Modification[0], result.Modifications);
            Assert.AreEqual(string.Empty, result.TaskOutput, "no output is expected as builder is not called");
            //			Assert.IsTrue(result.EndTime >= result.StartTime);
            mockPublisher.Verify(publisher => publisher.Run(It.IsAny <IntegrationResult>()), Times.Never);
            VerifyAll();
        }
Exemplo n.º 12
0
        public bool ShouldRunBuild(IIntegrationResult result)
        {
            if (!this.Condition)
                return true;

            bool HasTrackers = this.GetQueryCount() != 0;

            bool Modifications = true;
            if (this.WithModifications)
                Modifications = result.HasModifications();

            bool Integratable = HasTrackers && Modifications;

            if (!Integratable)
                Log.Info(string.Format("No trackers were found in query {0}.", this.QueryInforation.Name));

            return Integratable;
        }
Exemplo n.º 13
0
        public override void GetSource(IIntegrationResult result)
        {
            Util.Log.Info(result.HasModifications().ToString());

            ftp = new FtpLib(result.BuildProgressInformation);
            string remoteFolder = FtpFolderName;

            ftp.LogIn(ServerName, UserName, Password.PrivateValue, UseActiveConnectionMode);

            if (!FtpFolderName.StartsWith("/"))
            {
                remoteFolder = System.IO.Path.Combine(ftp.CurrentWorkingFolder(), FtpFolderName);
            }

            ftp.DownloadFolder( LocalFolderName, remoteFolder, RecursiveCopy);

            ftp.DisConnect();
        }
Exemplo n.º 14
0
        private string GetFirstCommentedModification(IIntegrationResult result)
        {
            if (result.HasModifications())
            {
                foreach (Modification modification in result.Modifications)
                {
                    if (!string.IsNullOrEmpty(modification.Comment) )
                        return "First Comment : " + modification.Comment;
                }
            }

            return string.Empty;
        }
Exemplo n.º 15
0
        private XmlElement BuildIntegrationElement(XmlDocument ownerDocument, IIntegrationResult result)
        {
            XmlElement integrationElement = CreateElement(ownerDocument, "item");
            integrationElement.AppendChild(CreateTextElement(integrationElement.OwnerDocument,
                "title",
                "Build {0} : {1}  {2}  {3}",
                result.Label,
                result.Status,
                GetAmountOfModifiedFiles(result),
                GetFirstCommentedModification(result)));
            integrationElement.AppendChild(CreateTextElement(
                integrationElement.OwnerDocument, "description", GetAmountOfModifiedFiles(result)));
            integrationElement.AppendChild(CreateTextElement(
                integrationElement.OwnerDocument, "guid", System.Guid.NewGuid().ToString()));
            integrationElement.AppendChild(CreateTextElement(
                integrationElement.OwnerDocument, "pubDate", System.DateTime.Now.ToString("r", CultureInfo.CurrentCulture)));

            if (result.HasModifications())
            {
                XmlElement modsElement = CreateContentElement(
                    integrationElement.OwnerDocument,
                    "encoded");
                XmlCDataSection cdata = integrationElement.OwnerDocument.CreateCDataSection(
                    GetBuildModifications(result));
                modsElement.AppendChild(cdata);
                integrationElement.AppendChild(modsElement);
            }
            return integrationElement;
        }
        /// <summary>
        /// Generates the specified integration result.	
        /// </summary>
        /// <param name="integrationResult">The integration result.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        public override string Generate(IIntegrationResult integrationResult)
        {
            Version oldVersion;
            int major, minor, patch, revision = 0;

            // try getting old version
            try
            {
                Log.Debug(string.Concat("[semverCommentLabeller] Old build label is: ", integrationResult.LastIntegration.Label));
                oldVersion = new Version(integrationResult.LastIntegration.Label);
                major = oldVersion.Major;
                minor = oldVersion.Minor;
                patch = oldVersion.Build;
            }
            catch (Exception)
            {
                oldVersion = new Version(0, 0, 0, 0);
                major = minor = patch = 0;
            }

            Log.Debug(string.Concat("[semverCommentLabeller] Old version is: ", oldVersion.ToString()));

            VersionNumberChange change = VersionNumberChange.None;

            if (ResetVersion)
            {
                major = Major;
                minor = Minor;
                patch = Patch;
                revision = Revision;
            }
            else
            {
                if (integrationResult.HasModifications())
                {
                    foreach (var mod in integrationResult.Modifications)
                    {
                        if (String.IsNullOrEmpty(mod.Comment) && mod.Comment.Trim() != String.Empty)
                        {
                            continue;
                        }
                        var comment = mod.Comment.ToUpperInvariant();

                        if (comment.StartsWith(MAJOR_PREFIX))
                        {
                            change = VersionNumberChange.Major;
                            break;
                        }
                        else if (comment.StartsWith(MINOR_PREFIX))
                        {
                            change = VersionNumberChange.Minor;
                        }
                        else if (comment.StartsWith(PATCH_PREFIX) && change == VersionNumberChange.None)
                        {
                            change = VersionNumberChange.Patch;
                        }
                    }
                }

                switch (change)
                {
                    case VersionNumberChange.Major:
                        major++;
                        minor = patch = 0;
                        break;
                    case VersionNumberChange.Minor:
                        minor++;
                        patch = 0;
                        break;
                    case VersionNumberChange.Patch:
                        patch++;
                        break;
                }

                //Calculate revision
                if (int.TryParse(integrationResult.LastChangeNumber, out revision))
                {
                    Log.Debug(
                        string.Format(System.Globalization.CultureInfo.CurrentCulture, "[semverCommentLabeller] LastChangeNumber retrieved: {0}",
                        revision));

                    int modVal = RevisionModulusValue > 0 ? RevisionModulusValue : 10000;
                    revision %= modVal;
                }
                else
                {
                    Log.Debug("[semverCommentLabeller] LastChangeNumber of source control is '{0}', set revision number to '0'.",
                              string.IsNullOrEmpty(integrationResult.LastChangeNumber)
                                  ? "N/A"
                                  : integrationResult.LastChangeNumber);
                }
            }

            // use the revision from last build,
            // because LastChangeNumber is 0 on ForceBuild or other failures
            if (revision <= 0) revision = oldVersion.Revision;

            Log.Debug(string.Format(System.Globalization.CultureInfo.InvariantCulture,
                                    "[semverCommentLabeller] Major: {0} Minor: {1} Patch: {2} Revision: {3}", major, minor, patch, revision));

            string result = string.Concat(major.ToString(MajorLabelFormat), ".", minor.ToString(MinorLabelFormat), ".", patch.ToString(PatchLabelFormat), ".", revision.ToString(RevisionLabelFormat));

            Log.Debug(string.Concat("[semverCommentLabeller] New version is: ", result));

            // return new version string
            return result;
        }