public void Commit_RunStepsInTheOrderTheDependencySorterDictates()
        {
            var results = new Queue<Tuple<Type, string>>();
            Action<Type, string> capture = (t, s) =>
                results.Enqueue(new Tuple<Type, string>(t, s));

            var buildSteps = new IBuildStep[]
                {
                    new Step1(capture),
                    new Step2(capture),
                };

            var dependencySorter = Substitute.For<IBuildStepDependencySorter>();
            dependencySorter.Sort(Arg.Any<IEnumerable<IBuildStep>>())
                            .Returns(buildSteps.Reverse());

            var sut = new Builder(dependencySorter)
                            .With(buildSteps[0])
                            .With(buildSteps[1]);
            sut.Commit();

            var firstStep = results.Dequeue();
            firstStep.Item1.Should().Be(typeof (Step2));
            firstStep.Item2.Should().Be("Commit");

            var secondStep = results.Dequeue();
            secondStep.Item1.Should().Be(typeof (Step1));
            secondStep.Item2.Should().Be("Commit");

            results.Count.Should().Be(0);
        }
        private void inputBox_TextChanged(object sender, EventArgs e)
        {
            IBuildStep step = (IBuildStep)buildSeqList.SelectedItem;

            if (step is InternalBuildStep)
            {
                FilePath newPath = new FilePath(inputBox.Text);
                step.InputFile = _project.ProjectDirectory.Combine(newPath).NormalizePath();
            }
            else if (step is ExternalBuildStep)
            {
                step.InputFile = new FilePath(inputBox.Text);
            }

            int index       = buildSeqList.SelectedIndex;
            int selectIndex = inputBox.SelectionStart;

            // HACK: forces update of item text
            buildSeqList.Items.Remove(step);
            buildSeqList.Items.Insert(index, step);
            buildSeqList.SelectedIndex = index;
            inputBox.Focus();
            inputBox.SelectionStart = selectIndex;

            _needsSave = true;
        }
Exemple #3
0
        internal static string SerializeStep(IBuildStep step)
        {
            if (step == null)
            {
                return(null);
            }

            var obj = step as UnityEngine.Object;

            if (obj != null)
            {
                string guid;
                long   lfid;
                if (AssetDatabase.TryGetGUIDAndLocalFileIdentifier(obj, out guid, out lfid))
                {
                    return($"@{guid}");
                }
                Debug.LogWarning($"{nameof(IBuildStep)} that are {nameof(UnityEngine.Object)} must be saved to an asset before being added to a {nameof(BuildPipeline)}.");
                return(null);
            }

            var type = step.GetType();

            return($"{type}, {type.Assembly.GetName().Name}");
        }
Exemple #4
0
 static int SortSteps(IBuildStep step1, IBuildStep step2)
 {
     if (step1 == null)
     {
         if (step2 == null)
         {
             return(0);
         }
         else
         {
             return(-1);
         }
     }
     else
     {
         if (step2 == null)
         {
             return(1);
         }
         if (step1.StepNumber == step2.StepNumber)
         {
             return(0);
         }
         if (step1.StepNumber > step2.StepNumber)
         {
             return(1);
         }
         else
         {
             return(-1);
         }
     }
 }
Exemple #5
0
 public void AddStep(IBuildStep step)
 {
     if (_steps.Contains(step))
     {
         throw new ArgumentException("Step is already added");
     }
     _steps.Add(step);
 }
Exemple #6
0
        public void TestOrderCycle()
        {
            var a = new A7();
            var b = new B7();
            var c = new C7();
            var s = new IBuildStep[] { b, a, c };

            Assert.That(() => Builder.SortSteps(s), Throws.ArgumentException);
        }
Exemple #7
0
        public void TestOrderCycle()
        {
            var a = new A7();
            var b = new B7();
            var c = new C7();
            var s = new IBuildStep[] { b, a, c };

            Assert.DoesNotThrow(() => Builder.SortSteps(s));
        }
Exemple #8
0
        public void TestOrderRunAfter()
        {
            var a = new A2();
            var b = new B2();
            var s = new IBuildStep[] { b, a };

            var sorted = Builder.SortSteps(s);

            Assert.That(sorted, Is.EqualTo(new IBuildStep[] { a, b }));
        }
Exemple #9
0
        public void TestOrderDerivedClass()
        {
            var a = new A8();
            var b = new B8D();
            var c = new C8();
            var s = new IBuildStep[] { b, a, c };

            var sorted = Builder.SortSteps(s);

            Assert.That(sorted, Is.EqualTo(new IBuildStep[] { a, b, c }));
        }
Exemple #10
0
        public void TestOrderMultipleRunAfter()
        {
            var a = new A4();
            var b = new B4();
            var c = new C4();
            var s = new IBuildStep[] { b, a, c };

            var sorted = Builder.SortSteps(s);

            Assert.That(sorted, Is.EqualTo(new IBuildStep[] { a, b, c }));
        }
Exemple #11
0
        private static IEnumerable <Type> GetTypeHierarchy(IBuildStep step)
        {
            var type = step.GetType();

            while (type != typeof(object))
            {
                yield return(type);

                type = type.BaseType;
            }
        }
Exemple #12
0
        public void TestOrderTransitiveRunBefore()
        {
            var a = new A5();
            var b = new B5();
            var c = new C5();
            var s = new IBuildStep[] { b, a, c };

            var sorted = Builder.SortSteps(s);

            Assert.That(sorted, Is.EqualTo(new IBuildStep[] { a, b, c }));
        }
Exemple #13
0
        public void Next(MagickImage magickImage)
        {
            if (Step >= Pipeline.Count)
            {
                return;
            }

            IBuildStep step = Pipeline[Step++];

            step.Execute(this, magickImage);
        }
Exemple #14
0
        public void CloneTest()
        {
            int               number      = 0;
            string            commandLine = "test args";
            ExternalBuildStep target      = new ExternalBuildStep(null, number, commandLine);

            IBuildStep expected = target;
            IBuildStep actual   = (IBuildStep)target.Clone();

            Assert.AreEqual(expected, actual);
        }
Exemple #15
0
        /// <summary>
        /// Adds a build step to the pipeline.
        /// </summary>
        /// <param name="step">The step to add.</param>
        public bool AddStep(IBuildStep step)
        {
            var data = SerializeStep(step);

            if (string.IsNullOrEmpty(data))
            {
                return(false);
            }

            serializedStepData.Add(data);
            return(true);
        }
Exemple #16
0
        static void RunNextStep()
        {
            if (s_Steps.Count == 0)
            {
                OnStepsCompleted();
                return;
            }

            s_CurrentStep = s_Steps[0];

            s_CurrentStep.Execute(s_BuildContext, OnStepCompleted);
        }
Exemple #17
0
        public void AddBefore(string stepName, IBuildStep buildStep)
        {
            var idx = this.steps.FindIndex(step => step.Name.Equals(stepName, StringComparison.OrdinalIgnoreCase));

            if (idx > -1)
            {
                this.steps.Insert(idx, buildStep);
            }
            else
            {
                this.steps.Add(buildStep);
            }
        }
        public void Sort_ThrowsCircularReferenceExceptionFor3StageCircularReference()
        {
            var buildSteps = new IBuildStep[]
                {
                    new Circular1(),
                    new Circular2(),
                    new Circular3()
                };

            var sut = new BuildStepDependencySorter();

            Assert.Throws<CircularDependencyException>(() => sut.Sort(buildSteps));
        }
        private void deleteDirButton_Click(object sender, EventArgs e)
        {
            IBuildStep selectedItem = (IBuildStep)buildSeqList.SelectedItem;

            if (selectedItem == null)
            {
                return;
            }

            _currentConfig.RemoveStep(selectedItem);
            buildSeqList.Items.Remove(selectedItem);
            _needsSave = true;
        }
        /// <summary>
        /// Get the <see cref="BuildStepResult"/> for the specified <see cref="IBuildStep"/>.
        /// </summary>
        /// <param name="buildStep">The build step to search for the result.</param>
        /// <param name="value">The <see cref="BuildStepResult"/> if found, otherwise default(<see cref="BuildStepResult"/>)</param>
        /// <returns><see langword="true"/> if the IBuildStep was found, otherwise <see langword="false"/>.</returns>
        public bool TryGetBuildStepResult(IBuildStep buildStep, out BuildStepResult value)
        {
            foreach (var result in BuildStepsResults)
            {
                if (result.BuildStep == buildStep)
                {
                    value = result;
                    return(true);
                }
            }

            value = default;
            return(false);
        }
        public void CanSetAndGetSteps()
        {
            var pipeline = ScriptableObject.CreateInstance <BuildPipeline>();
            var steps    = new IBuildStep[] { new TestStep1(), new TestStep1(), new TestStep2(), new TestStep1(), new TestStep1() };

            pipeline.SetSteps(steps);
            var stepList = new List <IBuildStep>();
            var result   = pipeline.GetSteps(stepList);

            Assert.True(result);
            Assert.AreEqual(steps.Length, pipeline.StepCount);
            Assert.AreEqual(stepList.Count, pipeline.StepCount);
            Assert.IsAssignableFrom <TestStep1>(pipeline.GetStep(0));
            Assert.IsAssignableFrom <TestStep2>(pipeline.GetStep(2));
        }
        public void Sort_ResolvesASimpleDepdency()
        {
            var buildSteps = new IBuildStep[]
                {
                    new BuildStepA(),
                    new BuildStepB()
                };

            var sut = new BuildStepDependencySorter();

            var result = sut.Sort(buildSteps).ToArray();

            result[0].Should().BeOfType<BuildStepB>();
            result[1].Should().BeOfType<BuildStepA>();
        }
Exemple #23
0
        /// <summary>
        /// Called before a <paramref name="step"/> is executed during a help build.
        /// </summary>
        /// <param name="step">
        /// <see cref="IBuildStep"/> implementation to be executed.
        /// </param>
        /// <param name="context">
        /// Provides information about the build process.
        /// </param>
        /// <returns>
        /// <b>true</b> indicates that the process should continue, otherwise,
        ///   <b>false</b> indicates that the process should skip this step.
        /// </returns>
        public override bool BeforeExecuteStep(IBuildStep step, BuildContext context)
        {
            var dir  = context.ProjectDirectory;
            var file = Path.Combine(dir, "Help\\Sem_Sync_Documentation.hhp");

            string fileContent = File.ReadAllText(file);

            if (String.IsNullOrEmpty(fileContent) == false)
            {
                File.WriteAllText(file, fileContent, new UTF8Encoding(false));
            }

            this.stepStart = DateTime.Now;
            return(true);
        }
Exemple #24
0
        /// <summary>
        /// Executes the DevEnv task logic.
        /// </summary>
        /// <returns>True if the task succeeds, false otherwise.</returns>
        public override bool Execute()
        {
            bool returnValue = false;

            try
            {
                this.buildStep = InformationNodeConverters.AddBuildStep(this.Build, "DevEnv Task BuildStep", "Visual Studio is building " + (string.IsNullOrEmpty(this.Solution) ? this.Project : this.Solution));

                // Execute DevEnv.
                returnValue = base.Execute();

                // Update the final project build step, if we have one.
                this.UpdateProjectBuildStep();

                // Save the configuration summary (errors and warnings, etc.)
                // 25 April 09: If the task is called twice in a build it throws a null ref exception. Adding this temporary workaround.
                // http://social.msdn.microsoft.com/Forums/en-US/tfsbuild/thread/4438059e-078d-4aa8-91d5-447de5756629/
                try
                {
                    this.ConfigurationSummary.Save();
                }
                catch
                {
                    // we intentionally do nothing.
                }

                // Update compilation status if any errors were encountered.
                if (this.errorEncountered)
                {
                    this.Build.CompilationStatus = BuildPhaseStatus.Failed;
                    this.Build.Save();
                }
            }
            catch (Exception e)
            {
                InformationNodeConverters.AddBuildStep(this.Build, "Exception", e.Message, DateTime.Now, BuildStepStatus.Failed);
                throw;
            }
            finally
            {
                // Update our build step.
                this.BuildStep.Status     = returnValue ? BuildStepStatus.Succeeded : BuildStepStatus.Failed;
                this.BuildStep.FinishTime = DateTime.Now;
                this.BuildStep.Save();
            }

            return(returnValue);
        }
Exemple #25
0
        internal static string Serialize(IBuildStep step)
        {
            if (step == null)
            {
                return(null);
            }

            if (step is BuildPipeline pipeline)
            {
                return(GlobalObjectId.GetGlobalObjectIdSlow(pipeline).ToString());
            }
            else
            {
                return(step.GetType().GetFullyQualifedAssemblyTypeName());
            }
        }
        public static BuildStepResult ReturnBuildPlayerResult(BuildContext context, IBuildStep step, BuildReport report)
        {
            var result = new BuildStepResult
            {
                BuildStep = step,
                Succeeded = report.summary.result == BuildResult.Succeeded,
                Message   = report.summary.result != BuildResult.Succeeded ? report.summary.ToString() : null
            };

            if (result.Succeeded)
            {
                var exe = context.GetOrCreate <ExecutableFile>();
                exe.Path = new FileInfo(report.summary.outputPath);
            }
            return(result);
        }
        public int CompareTo(object obj)
        {
            if (obj == null)
            {
                return(-1);
            }

            IBuildStep step = obj as IBuildStep;

            if (step == null)
            {
                return(-1);
            }

            return(StepNumber.CompareTo(step.StepNumber));
        }
Exemple #28
0
        public void TestOrderDerivedClassMultipleAttr()
        {
            var a = new A9D();
            var b = new B9();
            var c = new C9();
            var s = new IBuildStep[] { b, a, c };

            var sorted = Builder.SortSteps(s);

            var aidx = sorted.IndexOf(a);
            var bidx = sorted.IndexOf(b);
            var cidx = sorted.IndexOf(c);

            Assert.That(aidx, Is.LessThan(bidx));
            Assert.That(aidx, Is.LessThan(cidx));
        }
        private void UpdateStepOptions()
        {
            if (buildSeqList.SelectedIndex == -1)
            {
                stepOptionsBox.Enabled = false;
                return;
            }

            stepOptionsBox.Enabled = true;

            if (buildSeqList.SelectedItem is InternalBuildStep)
            {
                stepTypeBox.SelectedIndex = 0;
            }
            else if (buildSeqList.SelectedItem is ExternalBuildStep)
            {
                stepTypeBox.SelectedIndex = 1;
            }

            IBuildStep step = (IBuildStep)buildSeqList.SelectedItem;

            switch (stepTypeBox.SelectedIndex)
            {
            case 0:
                InternalBuildStep intStep = (InternalBuildStep)step;
                inputLabel.Text     = "Input File:";
                outputLabel.Enabled = true;
                outputBox.Enabled   = true;
                actionBox.Visible   = true;
                actionLabel.Visible = true;

                inputBox.Text           = intStep.InputFile;
                outputBox.Text          = intStep.OutputFile;
                actionBox.SelectedIndex = (int)intStep.StepType;
                break;

            case 1:
                inputLabel.Text     = "Command:";
                outputLabel.Enabled = false;
                outputBox.Enabled   = false;
                actionBox.Visible   = false;
                actionLabel.Visible = false;

                inputBox.Text = step.InputFile;
                break;
            }
        }
        public void Sort_ResolvesMultipleDependencies()
        {
            var buildSteps = new IBuildStep[]
                {
                    new MultipleDepdencyStepC(),
                    new MultipleDepdencyStepB(),
                    new MultipleDepdencyStepA()
                };

            var sut = new BuildStepDependencySorter();

            var result = sut.Sort(buildSteps).ToArray();

            Assert.IsTrue((result[0].GetType() == typeof(MultipleDepdencyStepA) && result[1].GetType() == typeof(MultipleDepdencyStepB)) ||
                          (result[1].GetType() == typeof(MultipleDepdencyStepA) && result[0].GetType() == typeof(MultipleDepdencyStepB)));
            result[2].Should().BeOfType<MultipleDepdencyStepC>();
        }
Exemple #31
0
        internal static string Serialize(IBuildStep step)
        {
            if (step == null)
            {
                return(null);
            }

            if (step is BuildPipeline pipeline)
            {
                return(GlobalObjectId.GetGlobalObjectIdSlow(pipeline).ToString());
            }
            else
            {
                var type = step.GetType();
                return($"{type}, {type.Assembly.GetName().Name}");
            }
        }
Exemple #32
0
        private void PipelineFailed(IBuildStep failingStep, IEnumerable<ICommit> commits)
        {
            if (commits.Any())
            {
                string message;
                if (commits.Count() == 1)
                {
                    var commit = commits.Single();
                    message = "Commit " + commit + " failed at step " + failingStep.Name;
                }
                else
                {
                    message = "Commits " + String.Join(", ", commits) + " failed at " + failingStep.Name;
                }

                _notifier.SendNotification("Build pipeline", message);
            }
        }
        public void Sort_ResolvesASequentialDepdency()
        {
            var buildSteps = new IBuildStep[]
                {
                    new SequentialDepdencyStepD(),
                    new SequentialDepdencyStepC(),
                    new SequentialDepdencyStepB(),
                    new SequentialDepdencyStepA()
                };

            var sut = new BuildStepDependencySorter();

            var result = sut.Sort(buildSteps).ToArray();

            result[0].Should().BeOfType<SequentialDepdencyStepA>();
            result[1].Should().BeOfType<SequentialDepdencyStepB>();
            result[2].Should().BeOfType<SequentialDepdencyStepC>();
            result[3].Should().BeOfType<SequentialDepdencyStepD>();
        }
        private void moveUp_Click(object sender, EventArgs e)
        {
            int index = buildSeqList.SelectedIndex;

            if (index == 0)
            {
                return;
            }

            _currentConfig.Steps[index].StepNumber -= 2;
            foreach (IBuildStep step in _currentConfig.Steps)
            {
                step.StepNumber++;
            }

            index--;
            _needsSave = true;
            IBuildStep selectedItem = (IBuildStep)buildSeqList.SelectedItem;

            buildSeqList.Items.Remove(selectedItem);
            buildSeqList.Items.Insert(index, selectedItem);
            buildSeqList.SelectedIndex = index;
        }
        private void stepTypeBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            IBuildStep step = null;

            _currentConfig.RemoveStep((IBuildStep)buildSeqList.SelectedItem);

            int stepNum = ((IBuildStep)buildSeqList.SelectedItem).StepNumber;

            if (buildSeqList.SelectedItem is InternalBuildStep && stepTypeBox.SelectedIndex != 0)
            {
                step = new ExternalBuildStep(buildSeqList.SelectedIndex, new FilePath("cmd.exe"), string.Empty)
                {
                    StepNumber = stepNum
                };
            }
            else if (buildSeqList.SelectedItem is ExternalBuildStep && stepTypeBox.SelectedIndex != 1)
            {
                step = new InternalBuildStep(
                    buildSeqList.SelectedIndex,
                    BuildStepType.Assemble,
                    _project.ProjectFile.ChangeExtension(".asm"),
                    _project.ProjectFile.ChangeExtension(".8xk"))
                {
                    StepNumber = stepNum
                };
            }

            if (step == null)
            {
                return;
            }

            _currentConfig.AddStep(step);
            buildSeqList.Items[buildSeqList.SelectedIndex] = step;
            UpdateStepOptions();
            _needsSave = true;
        }
Exemple #36
0
 public Setter(MemberInfo member, IBuildStep value)
 {
     _member       = member;
     AssignedValue = value;
 }
        /// <summary>
        /// Called before a <paramref name="step" /> is executed during a help build.
        /// </summary>
        /// <param name="step"><see cref="IBuildStep" /> implementation to be executed.</param>
        /// <param name="context">Provides information about the build process.</param>
        /// <returns><b>true</b> indicates that the process should continue, otherwise, 
        /// <b>false</b> indicates that the process should skip this step.</returns>
        public override bool BeforeExecuteStep(IBuildStep step, BuildContext context)
        {
            stepStart = DateTime.Now;

            return true;
        }
 /// <summary>
 /// Called after a <paramref name="step" /> has been executed during a help build.
 /// </summary>
 /// <param name="step"><see cref="IBuildStep" /> implementation that was executed.</param>
 /// <param name="context">Provides information about the build process.</param>
 public override void AfterExecuteStep(IBuildStep step, BuildContext context)
 {
     TraceLine();
     TraceLine("Step {0} Time Elapsed: {1}", context.CurrentStepIndex + 1, DateTime.Now - stepStart);
 }
 public Node(IBuildStep buildStep)
 {
     BuildStep = buildStep;
     IncomingEdges = new List<Edge>();
     OutgoingEdges = new List<Edge>();
 }
        /// <summary>
        /// Executes the DevEnv task logic.
        /// </summary>
        /// <returns>True if the task succeeds, false otherwise.</returns>
        public override bool Execute()
        {
            bool returnValue = false;

            try
            {
                this.buildStep = InformationNodeConverters.AddBuildStep(this.Build, "DevEnv Task BuildStep", "Visual Studio is building " + (string.IsNullOrEmpty(this.Solution) ? this.Project : this.Solution));

                // Execute DevEnv.
                returnValue = base.Execute();

                // Update the final project build step, if we have one.
                this.UpdateProjectBuildStep();

                // Save the configuration summary (errors and warnings, etc.)
                // 25 April 09: If the task is called twice in a build it throws a null ref exception. Adding this temporary workaround.
                // http://social.msdn.microsoft.com/Forums/en-US/tfsbuild/thread/4438059e-078d-4aa8-91d5-447de5756629/
                try
                {
                    this.ConfigurationSummary.Save();
                }
                catch
                {
                    // we intentionally do nothing.
                }

                // Update compilation status if any errors were encountered.
                if (this.errorEncountered)
                {
                    this.Build.CompilationStatus = BuildPhaseStatus.Failed;
                    this.Build.Save();
                }
            }
            catch (Exception e)
            {
                InformationNodeConverters.AddBuildStep(this.Build, "Exception", e.Message, DateTime.Now, BuildStepStatus.Failed);
                throw;
            }
            finally
            {
                // Update our build step.
                this.BuildStep.Status = returnValue ? BuildStepStatus.Succeeded : BuildStepStatus.Failed;
                this.BuildStep.FinishTime = DateTime.Now;
                this.BuildStep.Save();
            }

            return returnValue;
        }
 private static string GetBuildStepMessage(IBuildStep buildStep)
 {
     return String.Format("{0}: {1:dd-MMM-yyyy HH:mm:ss} - {2}",
                          buildStep.Status,
                          buildStep.StartTime,
                          buildStep.Message);
 }