public void GenerateFullManifest()
 {
     ManifestGenerator generator = new ManifestGenerator();
     IntegrationRequest request = new IntegrationRequest(BuildCondition.ForceBuild, "Somewhere", null);
     IntegrationSummary summary = new IntegrationSummary(IntegrationStatus.Success, "A Label", "Another Label", new DateTime(2009, 1, 1));
     IntegrationResult result = new IntegrationResult("Test project", "Working directory", "Artifact directory", request, summary);
     Modification modification1 = GenerateModification("first file", "Add");
     Modification modification2 = GenerateModification("second file", "Modify");
     result.Modifications = new Modification[] { modification1, modification2 };
     List<string> files = new List<string>();
     files.Add("first file");
     XmlDocument manifest = generator.Generate(result, files.ToArray());
     Assert.IsNotNull(manifest);
     string actualManifest = manifest.OuterXml;
     string expectedManifest = "<manifest>"  +
             "<header project=\"Test project\" label=\"A Label\" build=\"ForceBuild\" status=\"Unknown\">" +
                 "<modification user=\"johnDoe\" changeNumber=\"1\" time=\"2009-01-01T00:00:00\">" +
                     "<comment>A comment</comment>" +
                     "<file name=\"first file\" type=\"Add\" />" +
                     "<file name=\"second file\" type=\"Modify\" />" +
                 "</modification>" +
             "</header>" +
             "<file name=\"first file\" />" +
         "</manifest>";
     Assert.AreEqual(expectedManifest, actualManifest);
 }
        /// <summary>
        /// Finishes the integration.
        /// </summary>
        /// <remarks></remarks>
        public void FinishIntegration()
        {
            try
            {
                // Put the failed tasks into the appropriate list.
                // Must be done here as it is before the build log is dumped
                var failedTasks = new List <string>();
                project.FindFailedTasks(failedTasks);
                currentIntegration.FailureTasks.AddRange(failedTasks);

                // Save users who may have broken integration so we can email them until it's fixed
                if (currentIntegration.Status == IntegrationStatus.Failure)
                {
                    // Build is broken - add any users who contributed modifications to the existing list of users
                    // who have contributed modifications to failing builds.
                    foreach (Modification modification in currentIntegration.Modifications)
                    {
                        if (!currentIntegration.FailureUsers.Contains(modification.UserName))
                        {
                            currentIntegration.FailureUsers.Add(modification.UserName);
                        }
                    }
                }
                project.StateManager.SaveState(currentIntegration);
            }
            catch (Exception ex)
            {
                // swallow exception???
                Log.Error("Unable to save integration result: " + ex);
            }
            lastResult      = currentIntegration;
            lastIntegration = ConvertResultIntoSummary(currentIntegration);
        }
 /// <summary>
 /// Finishes the integration.
 /// </summary>
 /// <remarks></remarks>
 public void FinishIntegration()
 {
     try
     {
         // Save users who may have broken integration so we can email them until it's fixed
         if (currentIntegration.Status == IntegrationStatus.Failure)
         {
             // Build is broken - add any users who contributed modifications to the existing list of users
             // who have contributed modifications to failing builds.
             foreach (Modification modification in currentIntegration.Modifications)
             {
                 if (!currentIntegration.FailureUsers.Contains(modification.UserName))
                 {
                     currentIntegration.FailureUsers.Add(modification.UserName);
                 }
             }
         }
         project.StateManager.SaveState(currentIntegration);
     }
     catch (Exception ex)
     {
         // swallow exception???
         Log.Error("Unable to save integration result: " + ex);
     }
     lastResult      = currentIntegration;
     lastIntegration = ConvertResultIntoSummary(currentIntegration);
 }
        private static IntegrationSummary ConvertResultIntoSummary(IIntegrationResult integration)
        {
            string             lastSuccessfulIntegrationLabel = (integration.Succeeded) ? integration.Label : integration.LastSuccessfulIntegrationLabel;
            IntegrationSummary newSummary = new IntegrationSummary(integration.Status, integration.Label, lastSuccessfulIntegrationLabel, integration.StartTime);

            newSummary.FailureUsers = integration.FailureUsers;
            return(newSummary);
        }
Ejemplo n.º 5
0
        public void VerifyGoToBranchProcessInfoBasic()
        {
            IntegrationRequest request = new IntegrationRequest(BuildCondition.ForceBuild, "source", null);
            IntegrationSummary lastSummary =
                new IntegrationSummary(IntegrationStatus.Success, "label", "lastlabel", DateTime.Now);
            IntegrationResult result = new IntegrationResult("test", @"c:\workspace", @"c:\artifacts", request, lastSummary);

            PlasticSCM plasticscm = new PlasticSCM();
            NetReflector.Read(PLASTICSCM_XML, plasticscm);
            string expected = @"c:\plastic\client\cm.exe stb br:/main -repository=mainrep";
            ProcessInfo info = plasticscm.GoToBranchProcessInfo(result);
            Assert.AreEqual(expected, info.FileName + " " + info.Arguments);
        }
Ejemplo n.º 6
0
		public void VerifyNewGetSourceProcessInfoBasic()
		{
            IntegrationRequest request = new IntegrationRequest(BuildCondition.ForceBuild, "source", null);
		    IntegrationSummary lastSummary =
		        new IntegrationSummary(IntegrationStatus.Success, "label", "lastlabel", DateTime.Now);
		    IntegrationResult result = new IntegrationResult("test", @"c:\workspace", @"c:\artifacts", request, lastSummary);

		    PlasticSCM plasticscm = new PlasticSCM();
		    NetReflector.Read(PLASTICSCM_BASIC_XML, plasticscm);
		    string expected = @"cm update c:\workspace";
		    ProcessInfo info = plasticscm.NewGetSourceProcessInfo(result);
		    Assert.AreEqual(expected, info.FileName + " " + info.Arguments);
		}
Ejemplo n.º 7
0
        public void VerifyCreateLabelProcessInfoWithAttributes()
        {
            IntegrationRequest request = new IntegrationRequest(BuildCondition.ForceBuild, "source", null);
            IntegrationSummary lastSummary = new IntegrationSummary(IntegrationStatus.Success, "label", "lastlabel", DateTime.Now);
            IntegrationResult result = new IntegrationResult("test", @"c:\workspace", @"c:\artifacts", request, lastSummary);
            result.Label = "1";

            //check with attributes
            PlasticSCM plasticscm = new PlasticSCM();
            NetReflector.Read(PLASTICSCM_XML, plasticscm);
            string expected = @"c:\plastic\client\cm.exe mklb BL1";
            ProcessInfo info = plasticscm.CreateLabelProcessInfo(result);
            Assert.AreEqual (expected, info.FileName + " " + info.Arguments);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Equalses the specified obj.
        /// </summary>
        /// <param name="obj">The obj.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }
            if (obj.GetType() != GetType())
            {
                return(false);
            }

            IntegrationSummary other = (IntegrationSummary)obj;

            return(other.status.Equals(status) && other.label == label);
        }
Ejemplo n.º 9
0
        public IntegrationResult(string projectName, string workingDirectory, string artifactDirectory, IntegrationRequest request, IntegrationSummary lastIntegration)
        {
            ProjectName = projectName;
            WorkingDirectory = workingDirectory;
            ArtifactDirectory = artifactDirectory;
            this.request = (lastIntegration.IsInitial()) ? new IntegrationRequest(BuildCondition.ForceBuild, request.Source, request.UserName) : request;
            this.lastIntegration = lastIntegration;
            if ((lastIntegration.Status == IntegrationStatus.Exception)
                || (lastIntegration.Status == IntegrationStatus.Failure))
                failureUsers = lastIntegration.FailureUsers;       // Inherit the previous build's failureUser list if it failed.

            buildProgressInformation = new BuildProgressInformation(artifactDirectory, projectName);

            this.label = this.LastIntegration.Label;
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="IntegrationResult" /> class.
        /// </summary>
        /// <param name="projectName">Name of the project.</param>
        /// <param name="workingDirectory">The working directory.</param>
        /// <param name="artifactDirectory">The artifact directory.</param>
        /// <param name="request">The request.</param>
        /// <param name="lastIntegration">The last integration.</param>
        /// <remarks></remarks>
        public IntegrationResult(string projectName, string workingDirectory, string artifactDirectory, IntegrationRequest request, IntegrationSummary lastIntegration)
        {
            ProjectName          = projectName;
            WorkingDirectory     = workingDirectory;
            ArtifactDirectory    = artifactDirectory;
            this.request         = (lastIntegration.IsInitial()) ? new IntegrationRequest(BuildCondition.ForceBuild, request.Source, request.UserName) : request;
            this.lastIntegration = lastIntegration;
            if ((lastIntegration.Status == IntegrationStatus.Exception) ||
                (lastIntegration.Status == IntegrationStatus.Failure))
            {
                failureUsers = lastIntegration.FailureUsers;       // Inherit the previous build's failureUser list if it failed.
            }
            buildProgressInformation = new BuildProgressInformation(artifactDirectory, projectName);

            this.label = this.LastIntegration.Label;
        }
        public void EvaluateReturnsTrueIfBeyondTime()
        {
            var condition = new LastBuildTimeTaskCondition
                {
                    Time = new Timeout(1000)
                };
            var status = new IntegrationSummary(IntegrationStatus.Success, "1", "1", DateTime.Now.AddHours(-1));
            var result = this.mocks.StrictMock<IIntegrationResult>();
            Expect.Call(result.IsInitial()).Return(false);
            Expect.Call(result.LastIntegration).Return(status);

            this.mocks.ReplayAll();
            var actual = condition.Eval(result);

            this.mocks.VerifyAll();
            Assert.IsTrue(actual);
        }
        public void EvaluateReturnsFalseIfWithinTime()
        {
            var condition = new LastBuildTimeTaskCondition
                {
                    Time = new Timeout(1000),
                    Description = "Not equal test"
                };
            var status = new IntegrationSummary(IntegrationStatus.Success, "1", "1", DateTime.Now);
            var result = this.mocks.StrictMock<IIntegrationResult>();
            Expect.Call(result.IsInitial()).Return(false);
            Expect.Call(result.LastIntegration).Return(status);

            this.mocks.ReplayAll();
            var actual = condition.Eval(result);

            this.mocks.VerifyAll();
            Assert.IsFalse(actual);
        }
        public void ImportAbsoluteBasedManifest()
        {
            string sourceFile = Path.Combine(Path.GetTempPath(), "ImportManifest.xml");
            string expectedManifest = "<manifest>" +
                    "From a file" +
                "</manifest>";
            if (File.Exists(sourceFile)) File.Delete(sourceFile);
            File.WriteAllText(sourceFile, expectedManifest);

            ManifestImporter generator = new ManifestImporter();
            generator.FileName = sourceFile;
            IntegrationRequest request = new IntegrationRequest(BuildCondition.ForceBuild, "Somewhere", null);
            IntegrationSummary summary = new IntegrationSummary(IntegrationStatus.Success, "A Label", "Another Label", new DateTime(2009, 1, 1));
            IntegrationResult result = new IntegrationResult("Test project", "Working directory", "Artifact directory", request, summary);
            List<string> files = new List<string>();
            XmlDocument manifest = generator.Generate(result, files.ToArray());

            Assert.IsNotNull(manifest);
            string actualManifest = manifest.OuterXml;
            Assert.AreEqual(expectedManifest, actualManifest);
        }
 public IIntegrationResult LoadState(string project)
 {
     var path = this.GeneratePath(project);
     using (var reader = new StreamReader(
         this.fileSystem.OpenInputStream(path)))
     {
         var status = (IntegrationStatus)
             Enum.Parse(typeof(IntegrationStatus), reader.ReadLine());
         var lastSummary = new IntegrationSummary(
             status,
             reader.ReadLine(),
             reader.ReadLine(),
             DateTime.Parse(reader.ReadLine()));
         var result = new IntegrationResult(
             project,
             reader.ReadLine(),
             reader.ReadLine(),
             null,
             lastSummary);
         return result;
     }
 }
Ejemplo n.º 15
0
        /// <summary>
        /// Integrates the specified request.	
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        public IIntegrationResult Integrate(IntegrationRequest request)
        {
            Log.Trace();

            

            this.target.InitialiseForBuild(request);
            var result = this.StartNewIntegration(request);

            IIntegrationResult lastResult = resultManager.LastIntegrationResult;
            CreateDirectoryIfItDoesntExist(result.WorkingDirectory);
            CreateDirectoryIfItDoesntExist(result.ArtifactDirectory);

            Log.Trace("Getting Modifications for project {0}", result.ProjectName);
            try
            {
                result.Modifications = GetModifications(lastResult, result);
            }
            catch (Exception error)
            {
                result.SourceControlError = error;
                result.LastBuildStatus = lastResult.HasSourceControlError ? lastResult.LastBuildStatus : lastResult.Status;
                Log.Warning(string.Format(System.Globalization.CultureInfo.CurrentCulture,"Source control failure (GetModifications): {0}", error.Message));
                if (request.PublishOnSourceControlException)
                {
                    result.ExceptionResult = error;
                    CompleteIntegration(result);
                }
            }

            var runBuild = false;
            try
            {
                // Check whether a build should be performed
                runBuild = (result.SourceControlError == null) && result.ShouldRunBuild();

                if (runBuild)
                {
                    Log.Info("Building: " + request);

                    target.ClearNotNeededMessages();


                    // hack : otherwise all labellers(CCnet and custom) should be altered, better do this in 1 place
                    // labelers only increase version if PREVIOUS result was ok
                    // they should also increase version if previous was exception, and the new
                    // build got past the getmodifications

                    Log.Trace("Creating Label for project {0}", result.ProjectName);

                    if (result.LastIntegrationStatus == IntegrationStatus.Exception)
                    {
                        IntegrationSummary isExceptionFix = new IntegrationSummary(IntegrationStatus.Success, result.LastIntegration.Label, result.LastIntegration.LastSuccessfulIntegrationLabel, result.LastIntegration.StartTime);
                        IIntegrationResult irExceptionFix = new IntegrationResult(result.ProjectName, result.WorkingDirectory, result.ArtifactDirectory, result.IntegrationRequest, isExceptionFix);
                        irExceptionFix.Modifications = result.Modifications;

                        target.CreateLabel(irExceptionFix);
                        result.Label = irExceptionFix.Label;
                    }
                    else
                    {
                        target.CreateLabel(result);
                    }

                    Log.Trace("Running tasks of project {0}", result.ProjectName);
                    this.GenerateSystemParameterValues(result); 
                    Build(result);
                }
                else if (lastResult.HasSourceControlError)
                {
                    // Reset to the last valid status
                    result.Status = lastResult.LastBuildStatus;
                    resultManager.FinishIntegration();
                }
            }
            catch (Exception ex)
            {
                Log.Debug("Exception caught: " + ex.Message);
                result.ExceptionResult = ex;
            }
            finally
            {
                if (runBuild)
                {
                    CompleteIntegration(result);
                }
            }

            this.target.Activity = ProjectActivity.Sleeping;
            return result;
        }
Ejemplo n.º 16
0
 private IntegrationResult GenerateResult(int numberOfModifications)
 {
     IntegrationRequest request = new IntegrationRequest(BuildCondition.ForceBuild, "Somewhere", null);
     IntegrationSummary summary = new IntegrationSummary(IntegrationStatus.Success, "A Label", "Another Label", new DateTime(2009, 1, 1));
     IntegrationResult result = new IntegrationResult("Test project", "Working directory", "Artifact directory", request, summary);
     List<Modification> modifications = new List<Modification>();
     for (int loop = 0; loop < numberOfModifications; loop++)
     {
         modifications.Add(GenerateModification(string.Format(System.Globalization.CultureInfo.CurrentCulture,"modification #{0}", loop + 1), "Add"));
     }
     result.Modifications = modifications.ToArray();
     result.ArtifactDirectory = Path.GetTempPath();
     return result;
 }
Ejemplo n.º 17
0
        private IntegrationResult GetResult()
        {
            IntegrationRequest request = new IntegrationRequest(BuildCondition.ForceBuild, "Somewhere", null);
            IntegrationSummary summary = new IntegrationSummary(IntegrationStatus.Success, "A Label", "Another Label", new DateTime(2009, 1, 1));
            IntegrationResult result = new IntegrationResult("Test project", "Working directory", "Artifact directory", request, summary);
            Modification modification1 = GenerateModification("first file", "Add");
            Modification modification2 = GenerateModification("second file", "Modify");
            result.Modifications = new Modification[] { modification1, modification2 };
            result.Status = IntegrationStatus.Success;
            result.ArtifactDirectory = Path.GetTempPath();

            return result;
        }
 private static IntegrationSummary ConvertResultIntoSummary(IIntegrationResult integration)
 {
     string lastSuccessfulIntegrationLabel = (integration.Succeeded) ? integration.Label : integration.LastSuccessfulIntegrationLabel;
     IntegrationSummary newSummary = new IntegrationSummary(integration.Status, integration.Label, lastSuccessfulIntegrationLabel, integration.StartTime);
     newSummary.FailureUsers = integration.FailureUsers;
     return newSummary;
 }
        public void CanGetPreviousState()
        {
            string workingDir = Path.GetFullPath(Path.Combine(".", "workingdir"));
            string artifactDir = Path.GetFullPath(Path.Combine(".", "artifacts"));

            IntegrationSummary expectedSummary = new IntegrationSummary(IntegrationStatus.Exception, "foo", "foo", DateTime.MinValue);
            result = new IntegrationResult("project", workingDir, artifactDir, IntegrationRequest.NullRequest, expectedSummary);
            Assert.AreEqual(new IntegrationSummary(IntegrationStatus.Exception, "foo", "foo", DateTime.MinValue), result.LastIntegration);
        }
 /// <summary>
 /// Finishes the integration.	
 /// </summary>
 /// <remarks></remarks>
 public void FinishIntegration()
 {
     try
     {
         // Save users who may have broken integration so we can email them until it's fixed
         if (currentIntegration.Status == IntegrationStatus.Failure)
         {
             // Build is broken - add any users who contributed modifications to the existing list of users
             // who have contributed modifications to failing builds.
             foreach (Modification modification in currentIntegration.Modifications)
             {
                 if (!currentIntegration.FailureUsers.Contains(modification.UserName))
                     currentIntegration.FailureUsers.Add(modification.UserName);
             }
         }
         project.StateManager.SaveState(currentIntegration);
     }
     catch (Exception ex)
     {
         // swallow exception???
         Log.Error("Unable to save integration result: " + ex);
     }
     lastResult = currentIntegration;
     lastIntegration = ConvertResultIntoSummary(currentIntegration);
 }
Ejemplo n.º 21
0
        public void VerifyCreateQueryProcessInfoBasic()
        {
            string fromtime = "01/02/2003 00:00:00";
            string totime = "23/02/2006 23:14:05";
            IntegrationRequest request = new IntegrationRequest(BuildCondition.ForceBuild, "source", null);
            IntegrationSummary lastSummary =
                new IntegrationSummary(IntegrationStatus.Success, "label", "lastlabel", DateTime.Now);
            IntegrationResult from =
                new IntegrationResult("test", @"c:\workspace", @"c:\artifacts", request, lastSummary);
            from.StartTime =
                DateTime.ParseExact(fromtime, PlasticSCM.DATEFORMAT, System.Globalization.CultureInfo.InvariantCulture);
            IntegrationResult to = new IntegrationResult("test", @"c:\workspace", @"c:\artifacts", request, lastSummary);
            to.StartTime =
                DateTime.ParseExact(totime, PlasticSCM.DATEFORMAT, System.Globalization.CultureInfo.InvariantCulture);

            PlasticSCM plasticscm = new PlasticSCM();
            NetReflector.Read(PLASTICSCM_BASIC_XML, plasticscm);
            string query = string.Format(
                "cm find revision where branch = 'br:/main' and revno != 'CO' "
                + "and date between '{0}' and '{1}' ", fromtime, totime);
            string dateformat = string.Format("--dateformat=\"{0}\" ", PlasticSCM.DATEFORMAT);
            string format = string.Format("--format=\"{0}\"", PlasticSCM.FORMAT);

            ProcessInfo info = plasticscm.CreateQueryProcessInfo(from, to);
            Assert.AreEqual(query + dateformat + format, info.FileName + " " + info.Arguments);
        }
		public static IntegrationResult Create(IntegrationSummary integrationSummary)
		{
            return new IntegrationResult(DefaultProjectName, Path.GetTempPath(), Path.GetTempPath(), ModificationExistRequest(), integrationSummary);
		}
        public void IncludeManifestInPackage()
        {
            IntegrationRequest request = new IntegrationRequest(BuildCondition.ForceBuild, "Somewhere", null);
            IntegrationSummary summary = new IntegrationSummary(IntegrationStatus.Success, "A Label", "Another Label", new DateTime(2009, 1, 1));
            IntegrationResult result = new IntegrationResult("Test project", "Working directory", "Artifact directory", request, summary);
            Modification modification1 = GenerateModification("first file", "Add");
            Modification modification2 = GenerateModification("second file", "Modify");
            result.Modifications = new Modification[] { modification1, modification2 };
            result.Status = IntegrationStatus.Success;
            result.ArtifactDirectory = Path.GetTempPath();

            XmlDocument manifest = new XmlDocument();
            manifest.AppendChild(manifest.CreateElement("manifest"));
            DynamicMock generatorMock = new DynamicMock(typeof(IManifestGenerator));
            List<string> files = new List<string>();
            files.Add(dataFilePath);
            generatorMock.ExpectAndReturn("Generate", manifest, result, files.ToArray());

            string packageLocation = Path.Combine(Path.GetTempPath(), "Test Package-1");
            string packageName = packageLocation + ".zip";
            if (File.Exists(packageName)) File.Delete(packageName);
            PackagePublisher publisher = new PackagePublisher();
            publisher.PackageName = packageLocation;
            publisher.ManifestGenerator = generatorMock.MockInstance as IManifestGenerator;
            publisher.PackageList = new IPackageItem[] { 
                new PackageFile(dataFilePath) 
            };
            publisher.Run(result);
            Assert.IsTrue(File.Exists(packageName), "Package not generated");
            Assert.IsTrue(
                File.Exists(Path.Combine(Path.GetTempPath(), Path.Combine("A Label", "Test project-packages.xml"))),
                "Project package list not generated");
            generatorMock.Verify();
        }
        /// <summary>
        /// Integrates the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        public IIntegrationResult Integrate(IntegrationRequest request)
        {
            Log.Trace();



            this.target.InitialiseForBuild(request);
            var result = this.StartNewIntegration(request);

            IIntegrationResult lastResult = resultManager.LastIntegrationResult;

            CreateDirectoryIfItDoesntExist(result.WorkingDirectory);
            CreateDirectoryIfItDoesntExist(result.ArtifactDirectory);

            Log.Trace("Getting Modifications for project {0}", result.ProjectName);
            try
            {
                result.Modifications = GetModifications(lastResult, result);
            }
            catch (Exception error)
            {
                result.SourceControlError = error;
                result.LastBuildStatus    = lastResult.HasSourceControlError ? lastResult.LastBuildStatus : lastResult.Status;
                Log.Warning(string.Format(System.Globalization.CultureInfo.CurrentCulture, "Source control failure (GetModifications): {0}", error.Message));
                if (request.PublishOnSourceControlException)
                {
                    result.ExceptionResult = error;
                    CompleteIntegration(result);
                }
            }

            var runBuild = false;

            try
            {
                // Check whether a build should be performed
                runBuild = (result.SourceControlError == null) && result.ShouldRunBuild();

                if (runBuild)
                {
                    Log.Info("Building: " + request);

                    target.ClearNotNeededMessages();


                    // hack : otherwise all labellers(CCnet and custom) should be altered, better do this in 1 place
                    // labelers only increase version if PREVIOUS result was ok
                    // they should also increase version if previous was exception, and the new
                    // build got past the getmodifications

                    Log.Trace("Creating Label for project {0}", result.ProjectName);

                    if (result.LastIntegrationStatus == IntegrationStatus.Exception)
                    {
                        IntegrationSummary isExceptionFix = new IntegrationSummary(IntegrationStatus.Success, result.LastIntegration.Label, result.LastIntegration.LastSuccessfulIntegrationLabel, result.LastIntegration.StartTime);
                        IIntegrationResult irExceptionFix = new IntegrationResult(result.ProjectName, result.WorkingDirectory, result.ArtifactDirectory, result.IntegrationRequest, isExceptionFix);
                        irExceptionFix.Modifications = result.Modifications;

                        target.CreateLabel(irExceptionFix);
                        result.Label = irExceptionFix.Label;
                    }
                    else
                    {
                        target.CreateLabel(result);
                    }

                    Log.Trace("Running tasks of project {0}", result.ProjectName);
                    this.GenerateSystemParameterValues(result);
                    Build(result);
                }
                else if (lastResult.HasSourceControlError)
                {
                    // Reset to the last valid status
                    result.Status = lastResult.LastBuildStatus;
                    resultManager.FinishIntegration();
                }
            }
            catch (Exception ex)
            {
                Log.Debug("Exception caught: " + ex.Message);
                result.ExceptionResult = ex;
            }
            finally
            {
                if (runBuild)
                {
                    CompleteIntegration(result);
                }
            }

            this.target.Activity = ProjectActivity.Sleeping;
            return(result);
        }
        public void RunForDirectoryWildCard()
        {
            IntegrationRequest request = new IntegrationRequest(BuildCondition.ForceBuild, "Somewhere", null);
            IntegrationSummary summary = new IntegrationSummary(IntegrationStatus.Success, "A Label", "Another Label", new DateTime(2009, 1, 1));
            IntegrationResult result = new IntegrationResult("Test project", "Working directory", "Artifact directory", request, summary);
            Modification modification1 = GenerateModification("first file", "Add");
            Modification modification2 = GenerateModification("second file", "Modify");
            result.Modifications = new Modification[] { modification1, modification2 };
            result.Status = IntegrationStatus.Success;
            result.ArtifactDirectory = Path.GetTempPath();

            string packageLocation = Path.Combine(Path.GetTempPath(), "Test Package-1");
            string packageName = packageLocation + ".zip";
            if (File.Exists(packageName)) File.Delete(packageName);
            PackagePublisher publisher = new PackagePublisher();
            publisher.PackageName = packageLocation;
            publisher.PackageList = new IPackageItem[] { 
                new PackageFile(Path.Combine(Path.GetTempPath(), "**\\datafile.txt"))
            };
            publisher.Run(result);
            Assert.IsTrue(File.Exists(packageName), "Package not generated");
            Assert.IsTrue(
                File.Exists(Path.Combine(Path.GetTempPath(), Path.Combine("A Label", "Test project-packages.xml"))),
                "Project package list not generated");
        }
        /// <summary>
        /// Finishes the integration.	
        /// </summary>
        /// <remarks></remarks>
        public void FinishIntegration()
        {
            try
            {
                // Put the failed tasks into the appropriate list.
                // Must be done here as it is before the build log is dumped
                var failedTasks = new List<string>();
                project.FindFailedTasks(failedTasks);
                currentIntegration.FailureTasks.AddRange(failedTasks);

                // Save users who may have broken integration so we can email them until it's fixed
                if (currentIntegration.Status == IntegrationStatus.Failure)
                {
                    // Build is broken - add any users who contributed modifications to the existing list of users
                    // who have contributed modifications to failing builds.
                    foreach (Modification modification in currentIntegration.Modifications)
                    {
                        if (!currentIntegration.FailureUsers.Contains(modification.UserName))
                            currentIntegration.FailureUsers.Add(modification.UserName);
                    }
                }
                project.StateManager.SaveState(currentIntegration);
            }
            catch (Exception ex)
            {
                // swallow exception???
                Log.Error("Unable to save integration result: " + ex);
            }
            lastResult = currentIntegration;
            lastIntegration = ConvertResultIntoSummary(currentIntegration);
        }