Ejemplo n.º 1
0
        static CakeAPI()
        {
            var env        = new CakeEnvironment(new CakePlatform(), new CakeRuntime());
            var fileSystem = new FileSystem();

            var verbosity = Verbosity.Normal;

            if (Startup.HasArgument("cake-verbosity"))
            {
                verbosity = Enum.Parse <Verbosity>(Startup.Argument("cake-verbosity"));
            }
            var cakeLog = new CakeBuildLog(new CakeConsole(env), verbosity);

            var cakeConfiguration = new CakeConfiguration(new Dictionary <string, string>());
            var toolRepos         = new ToolRepository(env);

            Globber = new Globber(fileSystem, env);
            var cakeDataService = new CakeDataService();
            var registry        = new WindowsRegistry();
            var toolLocator     = new ToolLocator(env, toolRepos, new ToolResolutionStrategy(fileSystem, env, Globber, cakeConfiguration, cakeLog));
            var cakeArgs        = new CakeArguments(new List <string>().ToLookup(x => x));
            var procRunner      = new ProcessRunner(fileSystem, env, cakeLog, toolLocator, cakeConfiguration);

            Context = new CakeContext(fileSystem, env, Globber, cakeLog, cakeArgs, procRunner, registry, toolLocator, cakeDataService, cakeConfiguration);
        }
Ejemplo n.º 2
0
        static ProjectReference()
        {
            var platform    = new CakePlatform();
            var runtime     = new CakeRuntime();
            var cakeConsole = new CakeConsole();
            var cakeLog     = new CakeBuildLog(cakeConsole, Verbosity.Diagnostic);

            _environment = new CakeEnvironment(platform, runtime, cakeLog);
            _fileSystem  = new Cake.Core.IO.FileSystem();
        }
Ejemplo n.º 3
0
        static ProjectHelper()
        {
            var platform    = new CakePlatform();
            var runtime     = new CakeRuntime();
            var cakeConsole = new CakeConsole();
            var cakeLog     = new CakeBuildLog(cakeConsole, Verbosity.Quiet);

            _environment = new CakeEnvironment(platform, runtime, cakeLog);
            _fileSystem  = new FileSystem();
        }
Ejemplo n.º 4
0
        internal static IEnumerable <string> GetCSharpFilesFromProject(string csProjFolderPath)
        {
            var csProjFilePath = Directory.EnumerateFiles(csProjFolderPath, "*.csproj", SearchOption.TopDirectoryOnly).SingleOrDefault();

            if (csProjFilePath is null)
            {
                throw new FileNotFoundException();
            }

            var fileSystem  = new Cake.Core.IO.FileSystem();
            var platform    = new CakePlatform();
            var runtime     = new CakeRuntime();
            var cakeConsole = new CakeConsole();
            var cakeLog     = new CakeBuildLog(cakeConsole, Verbosity.Diagnostic);
            var environment = new CakeEnvironment(platform, runtime, cakeLog);

            var projectPath = new Cake.Core.IO.FilePath(csProjFilePath);

            if (projectPath.IsRelative)
            {
                projectPath = projectPath.MakeAbsolute(environment);
            }
            var projectFile = fileSystem.GetFile(projectPath);
            var parseResult = projectFile.ParseProjectFile("Debug");

            // TODO: do not assume all .cs files are included by default?
            // TODO: do not return .cs files that are removed from Compile in the .csproj
            foreach (var sourceFile in GetCSharpFilesFromFolder(csProjFolderPath))
            {
                yield return(sourceFile);
            }

            // TODO: if a project or package is encountered multiple times through recursion, ensure it only gets evaluated once (use HashSet?)
            // TODO: handle the case where a library is referenced as both a projectReference and a packageReference (NuGet gives error when this happens)

            foreach (var projectReference in parseResult.ProjectReferences)
            {
                // TODO: test that this works correctly
                foreach (var sourceFile in GetCSharpFilesFromProject(projectReference.FilePath.FullPath))
                {
                    yield return(sourceFile);
                }
            }

            // Assume package reference is either a .Sources package, or it's not and has no .cs files packed.
            foreach (var packageReference in parseResult.PackageReferences)
            {
                // TODO: try to get source files from package's dependencies (recursively)
                foreach (var sourceFile in DiscoverPackageReferenceSourceFiles(packageReference.Name, packageReference.Version))
                {
                    yield return(sourceFile);
                }
            }
        }
Ejemplo n.º 5
0
            public void Should_Write_Error_Log_Messages_Written_With_A_Lower_Log_Level_Than_Warning(LogLevel logLevel)
            {
                // Given
                var console = new FakeConsole();
                var log     = new CakeBuildLog(console, Verbosity.Diagnostic);

                // When
                log.Write(Verbosity.Diagnostic, logLevel, "Hello World");

                // Then
                Assert.Single(console.ErrorMessages);
            }
Ejemplo n.º 6
0
            public void Should_Write_Log_Messages_Written_With_A_Higher_Verbosity_Than_Allowed(Verbosity logVerbosity, Verbosity messageVerbosity)
            {
                // Given
                var console = new FakeConsole();
                var log     = new CakeBuildLog(console, logVerbosity);

                // When
                log.Write(messageVerbosity, LogLevel.Information, "Hello World");

                // Then
                Assert.Single(console.Messages);
            }
Ejemplo n.º 7
0
                public void Should_Write_Standard_Log_Messages_Written_With_A_Higher_Log_Level_Than_Error(LogLevel logLevel)
                {
                    // Given
                    var console = FakeConsole.CreateAnsiConsole();
                    var log     = new CakeBuildLog(console, Verbosity.Diagnostic);

                    // When
                    log.Write(Verbosity.Diagnostic, logLevel, "Hello World");

                    // Then
                    Assert.Single(console.Messages);
                }
Ejemplo n.º 8
0
                public void Should_Not_Colorize_A_Log_Message_Containg_A_Single_Token()
                {
                    // Given
                    var console = FakeConsole.CreateAnsiConsole();
                    var log     = new CakeBuildLog(console, Verbosity.Diagnostic);

                    // When
                    log.Write(Verbosity.Diagnostic, LogLevel.Information, "{0}", "Hello World");

                    // Then
                    Assert.Single(console.Messages);
                    Assert.Equal("Hello World", console.Messages[0]);
                }
Ejemplo n.º 9
0
                public void Should_Colorize_Error_Tokens_Correctly(LogLevel level, string expected)
                {
                    // Given
                    var console = FakeConsole.CreateAnsiConsole();
                    var log     = new CakeBuildLog(console, Verbosity.Diagnostic);

                    // When
                    log.Write(Verbosity.Diagnostic, level, "Hello, {0}", "World");

                    // Then
                    Assert.Single(console.ErrorMessages);
                    Assert.Equal(expected, console.ErrorMessages[0]);
                }
Ejemplo n.º 10
0
            public void Should_Not_Colorize_A_Log_Message_Containg_A_Single_Token()
            {
                // Given
                var console = Substitute.For <IConsole>();
                var log     = new CakeBuildLog(console, Verbosity.Diagnostic);

                // When
                log.Write(Verbosity.Diagnostic, LogLevel.Information, "{0}", "Hello World");

                // Then
                console.Received().Write("{0}", "Hello World");
                console.DidNotReceive().BackgroundColor = ConsoleColor.DarkBlue;
            }
Ejemplo n.º 11
0
                public void Should_Not_Colorize_A_Log_Message_Containg_A_Single_Token()
                {
                    // Given
                    var console = new FakeConsole();

                    console.OutputConsoleColor = true;
                    var log = new CakeBuildLog(console, Verbosity.Diagnostic);

                    // When
                    log.Write(Verbosity.Diagnostic, LogLevel.Information, "{0}", "Hello World");

                    // Then
                    Assert.Single(console.Messages);
                    Assert.Equal("#[Black|White]Hello World[/]", console.Messages[0]);
                }
Ejemplo n.º 12
0
            public void Should_Drop_Log_Messages_Written_With_A_Lower_Verbosity_Than_Allowed(Verbosity logVerbosity, Verbosity messageVerbosity)
            {
                // Given
                var console = new FakeConsole();
                var log     = new CakeBuildLog(console)
                {
                    Verbosity = logVerbosity
                };

                // When
                log.Write(messageVerbosity, LogLevel.Information, "Hello World");

                // Then
                Assert.Equal(0, console.Messages.Count);
            }
Ejemplo n.º 13
0
            public void Should_Colorize_Tokens_Correctly()
            {
                // Given
                var console = Substitute.For <IConsole>();
                var log     = new CakeBuildLog(console, Verbosity.Diagnostic);

                // When
                log.Write(Verbosity.Diagnostic, LogLevel.Information, "Hello, {0}", "World");

                // Then
                console.Received().Write("{0}", "Hello, ");
                console.Received().Write("{0}", "World");

                // console would have been set to fore/back color for the "World" argument.
                console.Received().BackgroundColor = ConsoleColor.DarkBlue;
                console.Received().ForegroundColor = ConsoleColor.White;
            }
Ejemplo n.º 14
0
    public static IScriptHost GetScriptHost()
    {
        var              console     = new CakeConsole();
        ICakeLog         log         = new CakeBuildLog(console);
        IFileSystem      fileSystem  = new FileSystem();
        ICakeDataService data        = new BridgeDataService();
        ICakeEnvironment environment = new CakeEnvironment(
            new CakePlatform(),
            new CakeRuntime(),
            log
            );
        IGlobber           globber       = new Globber(fileSystem, environment);
        ICakeArguments     arguments     = new BridgeArguments();
        ICakeConfiguration configuration = new BridgeConfiguration();
        IToolLocator       tools         = new ToolLocator(
            environment,
            new ToolRepository(environment),
            new ToolResolutionStrategy(
                fileSystem,
                environment,
                globber,
                configuration
                )
            );
        ICakeContext context = new CakeContext(
            fileSystem,
            environment,
            globber,
            log,
            arguments,
            new ProcessRunner(fileSystem, environment, log, tools, configuration),
            new WindowsRegistry(),
            tools,
            data,
            configuration
            );

        return(new BridgeScriptHost(
                   new CakeEngine(data, log),
                   context,
                   new DefaultExecutionStrategy(log),
                   new CakeReportPrinter(console, context),
                   arguments
                   ));
    }
Ejemplo n.º 15
0
                public void Should_Output_Escaped_Tokens_Correctly(bool ansi, string expected)
                {
                    // Given
                    var message = "Executing: if ($LASTEXITCODE -gt 0) {{ throw \"script failed with exit code $LASTEXITCODE\" }}";
                    var console = ansi
                        ? FakeConsole.CreateAnsiConsole()
                        : new FakeConsole()
                    {
                        OutputConsoleColor = true
                    };
                    var log = new CakeBuildLog(console, Verbosity.Diagnostic);

                    // When
                    log.Debug(Verbosity.Normal, message);

                    // Then
                    Assert.Single(console.Messages);
                    Assert.Equal(expected, console.Messages[0]);
                }
Ejemplo n.º 16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AzurePipelinesLog"/> class.
 /// </summary>
 /// <param name="console">Implementation of <see cref="IConsole"/>.</param>
 /// <param name="verbosity">Default <see cref="Verbosity"/>.</param>
 public AzurePipelinesLog(IConsole console, Verbosity verbosity = Verbosity.Normal)
 {
     _cakeLogImplementation = new CakeBuildLog(console, verbosity);
 }