Example #1
0
        public void TestSucceed1()
        {
            var p = new Project {
                Filename = @"C:\1"
            };

            _graph.Add(p, new BuildEnvironment());

            Project          next;
            BuildEnvironment unused;

            _graph.TryGetNextProject(out next, out unused).Should().BeTrue("because the only added project has not dependencies and thus should be ready to be built");

            _graph.IsFinished.Should().BeFalse("Because the only project has neither succeeded, nor failed (yet)");
            _graph.FinishedEvent.Wait(TimeSpan.Zero).Should().BeFalse();


            _graph.MarkAsSuccess(p);
            _graph.IsFinished.Should().BeTrue("Because we've succeeded building the only project");
            _graph.FinishedEvent.Wait(TimeSpan.Zero).Should().BeTrue();
        }
Example #2
0
        private void Run()
        {
            try
            {
                while (true)
                {
                    Project          project;
                    BuildEnvironment environment;
                    if (_graph.TryGetNextProject(out project, out environment))
                    {
                        var logger = _buildLog.CreateLogger();
                        try
                        {
                            _taskEngine.Run(project,
                                            _target,
                                            environment,
                                            _graph,
                                            logger);

                            if (logger.HasErrors)
                            {
                                _graph.MarkAsFailed(project);
                            }
                            else
                            {
                                _graph.MarkAsSuccess(project);
                            }
                        }
                        catch (BuildException e)
                        {
                            logger.WriteLine(Verbosity.Quiet, "error: {0}", e.Message);

                            Log.ErrorFormat("Cauhgt exception while building project '{0}': {1}",
                                            project.Filename,
                                            e);

                            _graph.MarkAsFailed(project);
                        }
                        catch (Exception e)
                        {
                            logger.WriteLine(Verbosity.Quiet, "error: Internal build error: {0}", e);

                            Log.ErrorFormat("Cauhgt unexpected exception while building project '{0}': {1}",
                                            project.Filename,
                                            e);

                            _graph.MarkAsFailed(project);
                        }
                    }
                    else
                    {
                        if (_graph.FinishedEvent.Wait(TimeSpan.FromSeconds(100)))
                        {
                            break;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Log.FatalFormat("Caught unexpected exception: {0}", e);
            }
            finally
            {
                _isFinished = true;
            }
        }