Exemple #1
0
        public void TestBuildCommand()
        {
            var cmd = BuildScript.Create("abc", "def ghi", null, null);

            Actions.RunProcess["abc def ghi"] = 1;
            cmd.Run(Actions, StartCallback, EndCallback);
            Assert.Equal("abc def ghi", Actions.RunProcessIn[0]);
            Assert.Equal("abc def ghi", StartCallbackIn[0]);
            Assert.Equal("", EndCallbackIn[0]);
            Assert.Equal(1, EndCallbackReturn[0]);
        }
Exemple #2
0
        public void TestOr1()
        {
            var cmd = BuildScript.Create("odasa", null, null, null) | BuildScript.Create("abc", "def ghi", null, null);

            Actions.RunProcess["abc def ghi"] = 1;
            Actions.RunProcess["odasa "]      = 0;
            cmd.Run(Actions, StartCallback, EndCallback);

            Assert.Equal("odasa ", Actions.RunProcessIn[0]);
            Assert.Equal("odasa ", StartCallbackIn[0]);
            Assert.Equal("", EndCallbackIn[0]);
            Assert.Equal(0, EndCallbackReturn[0]);
            Assert.Equal(1, EndCallbackReturn.Count);
        }
        public override BuildScript GetBuildScript()
        {
            /// <summary>
            /// A script that checks that the C# extractor has been executed.
            /// </summary>
            BuildScript CheckExtractorRun(bool warnOnFailure) =>
            BuildScript.Create(actions =>
            {
                if (actions.FileExists(Extractor.GetCSharpLogPath()))
                {
                    return(0);
                }

                if (warnOnFailure)
                {
                    Log(Severity.Error, "No C# code detected during build.");
                }

                return(1);
            });

            var attempt = BuildScript.Failure;

            switch (GetCSharpBuildStrategy())
            {
            case CSharpBuildStrategy.CustomBuildCommand:
                attempt = new BuildCommandRule(DotNetRule.WithDotNet).Analyse(this, false) & CheckExtractorRun(true);
                break;

            case CSharpBuildStrategy.Buildless:
                // No need to check that the extractor has been executed in buildless mode
                attempt = new StandaloneBuildRule().Analyse(this, false);
                break;

            case CSharpBuildStrategy.MSBuild:
                attempt = new MsBuildRule().Analyse(this, false) & CheckExtractorRun(true);
                break;

            case CSharpBuildStrategy.DotNet:
                attempt = new DotNetRule().Analyse(this, false) & CheckExtractorRun(true);
                break;

            case CSharpBuildStrategy.Auto:
                var cleanTrapFolder =
                    BuildScript.DeleteDirectory(TrapDir);
                var cleanSourceArchive =
                    BuildScript.DeleteDirectory(SourceArchiveDir);
                var tryCleanExtractorArgsLogs =
                    BuildScript.Create(actions =>
                {
                    foreach (var file in Extractor.GetCSharpArgsLogs())
                    {
                        try
                        {
                            actions.FileDelete(file);
                        }
                        catch         // lgtm[cs/catch-of-all-exceptions] lgtm[cs/empty-catch-block]
                        { }
                    }
                    return(0);
                });
                var attemptExtractorCleanup =
                    BuildScript.Try(cleanTrapFolder) &
                    BuildScript.Try(cleanSourceArchive) &
                    tryCleanExtractorArgsLogs &
                    BuildScript.DeleteFile(Extractor.GetCSharpLogPath());

                /// <summary>
                /// Execute script `s` and check that the C# extractor has been executed.
                /// If either fails, attempt to cleanup any artifacts produced by the extractor,
                /// and exit with code 1, in order to proceed to the next attempt.
                /// </summary>
                BuildScript IntermediateAttempt(BuildScript s) =>
                (s & CheckExtractorRun(false)) |
                (attemptExtractorCleanup & BuildScript.Failure);

                attempt =
                    // First try .NET Core
                    IntermediateAttempt(new DotNetRule().Analyse(this, true)) |
                    // Then MSBuild
                    (() => IntermediateAttempt(new MsBuildRule().Analyse(this, true))) |
                    // And finally look for a script that might be a build script
                    (() => new BuildCommandAutoRule(DotNetRule.WithDotNet).Analyse(this, true) & CheckExtractorRun(true)) |
                    // All attempts failed: print message
                    AutobuildFailure();
                break;
            }

            return
                (attempt &
                 (() => new AspBuildRule().Analyse(this, false)) &
                 (() => new XmlBuildRule().Analyse(this, false)));
        }