<commit_before>///////////////////////////////////////////////////////////////////////////////
// ADDINS
///////////////////////////////////////////////////////////////////////////////

#addin "nuget:?package=Polly&version=4.2.0"
#addin "nuget:?package=NuGet.Core&version=2.12.0"
#tool "nuget:https://dotnet.myget.org/F/nuget-build/?package=NuGet.CommandLine&version=4.3.0-preview1-3980&prerelease"
#tool "nuget:?package=JetBrains.dotMemoryUnit&version=2.3.20160517.113140"
#tool "JetBrains.ReSharper.CommandLineTools"
///////////////////////////////////////////////////////////////////////////////
// TOOLS
///////////////////////////////////////////////////////////////////////////////

#tool "nuget:?package=xunit.runner.console&version=2.1.0"
#tool "nuget:?package=OpenCover"

///////////////////////////////////////////////////////////////////////////////
// USINGS
///////////////////////////////////////////////////////////////////////////////

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Polly;
using NuGet;

///////////////////////////////////////////////////////////////////////////////
// SCRIPTS
///////////////////////////////////////////////////////////////////////////////

#load "./parameters.cake"
#load "./packages.cake"

//////////////////////////////////////////////////////////////////////
// PARAMETERS
//////////////////////////////////////////////////////////////////////

Parameters parameters = new Parameters(Context);
Packages packages = new Packages(Context, parameters);

///////////////////////////////////////////////////////////////////////////////
// SETUP
///////////////////////////////////////////////////////////////////////////////

Setup(context =>
{
    Information("Building version {0} of Avalonia ({1}, {2}, {3}) using version {4} of Cake.", 
        parameters.Version,
        parameters.Platform,
        parameters.Configuration,
        parameters.Target,
        typeof(ICakeContext).Assembly.GetName().Version.ToString());

    if (parameters.IsRunningOnAppVeyor)
    {
        Information("Repository Name: " + BuildSystem.AppVeyor.Environment.Repository.Name);
        Information("Repository Branch: " + BuildSystem.AppVeyor.Environment.Repository.Branch);
    }

    Information("Target: " + parameters.Target);
    Information("Platform: " + parameters.Platform);
    Information("Configuration: " + parameters.Configuration);
    Information("IsLocalBuild: " + parameters.IsLocalBuild);
    Information("IsRunningOnUnix: " + parameters.IsRunningOnUnix);
    Information("IsRunningOnWindows: " + parameters.IsRunningOnWindows);
    Information("IsRunningOnAppVeyor: " + parameters.IsRunningOnAppVeyor);
    Information("IsPullRequest: " + parameters.IsPullRequest);
    Information("IsMainRepo: " + parameters.IsMainRepo);
    Information("IsMasterBranch: " + parameters.IsMasterBranch);
    Information("IsTagged: " + parameters.IsTagged);
    Information("IsReleasable: " + parameters.IsReleasable);
    Information("IsMyGetRelease: " + parameters.IsMyGetRelease);
    Information("IsNuGetRelease: " + parameters.IsNuGetRelease);
});

///////////////////////////////////////////////////////////////////////////////
// TEARDOWN
///////////////////////////////////////////////////////////////////////////////

Teardown(context =>
{
    Information("Finished running tasks.");
});

///////////////////////////////////////////////////////////////////////////////
// TASKS
///////////////////////////////////////////////////////////////////////////////

Task("Clean")
    .Does(() =>
{
    CleanDirectories(parameters.BuildDirs);
    CleanDirectory(parameters.ArtifactsDir);
    CleanDirectory(parameters.NugetRoot);
    CleanDirectory(parameters.ZipRoot);
    CleanDirectory(parameters.BinRoot);
    CleanDirectory(parameters.TestsRoot);
});


Task("Restore-NuGet-Packages")
    .IsDependentOn("Clean")
    .WithCriteria(parameters.IsRunningOnWindows)
    .Does(() =>
{
    var maxRetryCount = 5;
    var toolTimeout = 2d;
    Policy
        .Handle<Exception>()
        .Retry(maxRetryCount, (exception, retryCount, context) => {
            if (retryCount == maxRetryCount)
            {
                throw exception;
            }
            else
            {
                Verbose("{0}", exception);
                toolTimeout+=0.5;
            }})
        .Execute(()=> {
                NuGetRestore(parameters.MSBuildSolution, new NuGetRestoreSettings {
                    ToolPath = "./tools/NuGet.CommandLine/tools/NuGet.exe",
                    ToolTimeout = TimeSpan.FromMinutes(toolTimeout)
                });
        });
});

void DotNetCoreBuild()
{
    DotNetCoreRestore("samples\\ControlCatalog.NetCore");
    DotNetBuild("samples\\ControlCatalog.NetCore");
}

Task("DotNetCoreBuild")
    .IsDependentOn("Clean")
    .Does(() => DotNetCoreBuild());

Task("Build")
    .IsDependentOn("Restore-NuGet-Packages")
    .Does(() =>
{
    if(parameters.IsRunningOnWindows)
    {
        MSBuild(parameters.MSBuildSolution, settings => {
            settings.SetConfiguration(parameters.Configuration);
            settings.WithProperty("Platform", "\"" + parameters.Platform + "\"");
            settings.WithProperty("UseRoslynPathHack", "true");
            settings.SetVerbosity(Verbosity.Minimal);
            settings.WithProperty("Windows", "True");
            settings.UseToolVersion(MSBuildToolVersion.VS2017);
            settings.SetNodeReuse(false);
        });
    }
    else
    {
        DotNetCoreBuild();
    }
});

void RunCoreTest(string dir, Parameters parameters, bool net461Only)
{
    Information("Running tests from " + dir);
    DotNetCoreRestore(dir);
    var frameworks = new List<string>(){"netcoreapp1.1"};
    if(parameters.IsRunningOnWindows)
        frameworks.Add("net461");
    foreach(var fw in frameworks)
    {
        if(fw != "net461" && net461Only)
            continue;
        Information("Running for " + fw);
        DotNetCoreTest(System.IO.Path.Combine(dir, System.IO.Path.GetFileName(dir)+".csproj"),
            new DotNetCoreTestSettings{Framework = fw});
    }
}


Task("Run-Net-Core-Unit-Tests")
    .IsDependentOn("Clean")
    .Does(() => {
        RunCoreTest("./tests/Avalonia.Base.UnitTests", parameters, false);
        RunCoreTest("./tests/Avalonia.Controls.UnitTests", parameters, true);
        RunCoreTest("./tests/Avalonia.Input.UnitTests", parameters, true);
        RunCoreTest("./tests/Avalonia.Interactivity.UnitTests", parameters, true);
        RunCoreTest("./tests/Avalonia.Layout.UnitTests", parameters, true);
        //RunCoreTest("./tests/Avalonia.Markup.UnitTests", parameters, true);
        //RunCoreTest("./tests/Avalonia.Markup.Xaml.UnitTests", parameters, true);
        RunCoreTest("./tests/Avalonia.Styling.UnitTests", parameters, true);
        RunCoreTest("./tests/Avalonia.Visuals.UnitTests", parameters, true);
    });

Task("Run-Unit-Tests")
    .IsDependentOn("Run-Net-Core-Unit-Tests")
    .IsDependentOn("Build")
    .WithCriteria(() => !parameters.SkipTests)
    .Does(() =>
{
    if(!parameters.IsRunningOnWindows)
       return;

    var unitTests = GetDirectories("./tests/Avalonia.*.UnitTests")
        .Select(dir => System.IO.Path.GetFileName(dir.FullPath))
        .Where(name => parameters.IsRunningOnWindows ? true : !(name.IndexOf("Direct2D", StringComparison.OrdinalIgnoreCase) >= 0))
        .Select(name => MakeAbsolute(File("./tests/" + name + "/bin/" + parameters.DirSuffix + "/" + name + ".dll")))
        .ToList();

    if (parameters.IsRunningOnWindows)
    {
        var leakTests = GetFiles("./tests/Avalonia.LeakTests/bin/" + parameters.DirSuffix + "/*.LeakTests.dll");

        unitTests.AddRange(leakTests);
    }

    var toolPath = (parameters.IsPlatformAnyCPU || parameters.IsPlatformX86) ? 
        "./tools/xunit.runner.console/tools/xunit.console.x86.exe" :
        "./tools/xunit.runner.console/tools/xunit.console.exe";

    var xUnitSettings = new XUnit2Settings 
    { 
        ToolPath = toolPath,<commit_msg>Enable all Net-Core unit tests<commit_after>///////////////////////////////////////////////////////////////////////////////
// ADDINS
///////////////////////////////////////////////////////////////////////////////

#addin "nuget:?package=Polly&version=4.2.0"
#addin "nuget:?package=NuGet.Core&version=2.12.0"
#tool "nuget:https://dotnet.myget.org/F/nuget-build/?package=NuGet.CommandLine&version=4.3.0-preview1-3980&prerelease"
#tool "nuget:?package=JetBrains.dotMemoryUnit&version=2.3.20160517.113140"
#tool "JetBrains.ReSharper.CommandLineTools"
///////////////////////////////////////////////////////////////////////////////
// TOOLS
///////////////////////////////////////////////////////////////////////////////

#tool "nuget:?package=xunit.runner.console&version=2.2.0"
#tool "nuget:?package=OpenCover"

///////////////////////////////////////////////////////////////////////////////
// USINGS
///////////////////////////////////////////////////////////////////////////////

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Polly;
using NuGet;

///////////////////////////////////////////////////////////////////////////////
// SCRIPTS
///////////////////////////////////////////////////////////////////////////////

#load "./parameters.cake"
#load "./packages.cake"

//////////////////////////////////////////////////////////////////////
// PARAMETERS
//////////////////////////////////////////////////////////////////////

Parameters parameters = new Parameters(Context);
Packages packages = new Packages(Context, parameters);

///////////////////////////////////////////////////////////////////////////////
// SETUP
///////////////////////////////////////////////////////////////////////////////

Setup(context =>
{
    Information("Building version {0} of Avalonia ({1}, {2}, {3}) using version {4} of Cake.", 
        parameters.Version,
        parameters.Platform,
        parameters.Configuration,
        parameters.Target,
        typeof(ICakeContext).Assembly.GetName().Version.ToString());

    if (parameters.IsRunningOnAppVeyor)
    {
        Information("Repository Name: " + BuildSystem.AppVeyor.Environment.Repository.Name);
        Information("Repository Branch: " + BuildSystem.AppVeyor.Environment.Repository.Branch);
    }

    Information("Target: " + parameters.Target);
    Information("Platform: " + parameters.Platform);
    Information("Configuration: " + parameters.Configuration);
    Information("IsLocalBuild: " + parameters.IsLocalBuild);
    Information("IsRunningOnUnix: " + parameters.IsRunningOnUnix);
    Information("IsRunningOnWindows: " + parameters.IsRunningOnWindows);
    Information("IsRunningOnAppVeyor: " + parameters.IsRunningOnAppVeyor);
    Information("IsPullRequest: " + parameters.IsPullRequest);
    Information("IsMainRepo: " + parameters.IsMainRepo);
    Information("IsMasterBranch: " + parameters.IsMasterBranch);
    Information("IsTagged: " + parameters.IsTagged);
    Information("IsReleasable: " + parameters.IsReleasable);
    Information("IsMyGetRelease: " + parameters.IsMyGetRelease);
    Information("IsNuGetRelease: " + parameters.IsNuGetRelease);
});

///////////////////////////////////////////////////////////////////////////////
// TEARDOWN
///////////////////////////////////////////////////////////////////////////////

Teardown(context =>
{
    Information("Finished running tasks.");
});

///////////////////////////////////////////////////////////////////////////////
// TASKS
///////////////////////////////////////////////////////////////////////////////

Task("Clean")
    .Does(() =>
{
    CleanDirectories(parameters.BuildDirs);
    CleanDirectory(parameters.ArtifactsDir);
    CleanDirectory(parameters.NugetRoot);
    CleanDirectory(parameters.ZipRoot);
    CleanDirectory(parameters.BinRoot);
    CleanDirectory(parameters.TestsRoot);
});

Task("Restore-NuGet-Packages")
    .IsDependentOn("Clean")
    .WithCriteria(parameters.IsRunningOnWindows)
    .Does(() =>
{
    var maxRetryCount = 5;
    var toolTimeout = 2d;
    Policy
        .Handle<Exception>()
        .Retry(maxRetryCount, (exception, retryCount, context) => {
            if (retryCount == maxRetryCount)
            {
                throw exception;
            }
            else
            {
                Verbose("{0}", exception);
                toolTimeout+=0.5;
            }})
        .Execute(()=> {
                NuGetRestore(parameters.MSBuildSolution, new NuGetRestoreSettings {
                    ToolPath = "./tools/NuGet.CommandLine/tools/NuGet.exe",
                    ToolTimeout = TimeSpan.FromMinutes(toolTimeout)
                });
        });
});

void DotNetCoreBuild()
{
    DotNetCoreRestore("samples\\ControlCatalog.NetCore");
    DotNetBuild("samples\\ControlCatalog.NetCore");
}

Task("DotNetCoreBuild")
    .IsDependentOn("Clean")
    .Does(() => DotNetCoreBuild());

Task("Build")
    .IsDependentOn("Restore-NuGet-Packages")
    .Does(() =>
{
    if(parameters.IsRunningOnWindows)
    {
        MSBuild(parameters.MSBuildSolution, settings => {
            settings.SetConfiguration(parameters.Configuration);
            settings.WithProperty("Platform", "\"" + parameters.Platform + "\"");
            settings.WithProperty("UseRoslynPathHack", "true");
            settings.SetVerbosity(Verbosity.Minimal);
            settings.WithProperty("Windows", "True");
            settings.UseToolVersion(MSBuildToolVersion.VS2017);
            settings.SetNodeReuse(false);
        });
    }
    else
    {
        DotNetCoreBuild();
    }
});

void RunCoreTest(string dir, Parameters parameters, bool net461Only)
{
    Information("Running tests from " + dir);
    DotNetCoreRestore(dir);
    var frameworks = new List<string>(){"netcoreapp1.1"};
    if(parameters.IsRunningOnWindows)
        frameworks.Add("net461");
    foreach(var fw in frameworks)
    {
        if(fw != "net461" && net461Only)
            continue;
        Information("Running for " + fw);
        DotNetCoreTest(System.IO.Path.Combine(dir, System.IO.Path.GetFileName(dir)+".csproj"),
            new DotNetCoreTestSettings{Framework = fw});
    }
}

Task("Run-Net-Core-Unit-Tests")
    .IsDependentOn("Clean")
    .Does(() => {
        RunCoreTest("./tests/Avalonia.Base.UnitTests", parameters, false);
        RunCoreTest("./tests/Avalonia.Controls.UnitTests", parameters, false);
        RunCoreTest("./tests/Avalonia.Input.UnitTests", parameters, false);
        RunCoreTest("./tests/Avalonia.Interactivity.UnitTests", parameters, false);
        RunCoreTest("./tests/Avalonia.Layout.UnitTests", parameters, false);
        RunCoreTest("./tests/Avalonia.Markup.UnitTests", parameters, false);
        RunCoreTest("./tests/Avalonia.Markup.Xaml.UnitTests", parameters, false);
        RunCoreTest("./tests/Avalonia.Styling.UnitTests", parameters, false);
        RunCoreTest("./tests/Avalonia.Visuals.UnitTests", parameters, false);
    });

Task("Run-Unit-Tests")
    .IsDependentOn("Run-Net-Core-Unit-Tests")
    .IsDependentOn("Build")
    .WithCriteria(() => !parameters.SkipTests)
    .Does(() =>
{
    if(!parameters.IsRunningOnWindows)
       return;

    var unitTests = GetDirectories("./tests/Avalonia.*.UnitTests")
        .Select(dir => System.IO.Path.GetFileName(dir.FullPath))
        .Where(name => parameters.IsRunningOnWindows ? true : !(name.IndexOf("Direct2D", StringComparison.OrdinalIgnoreCase) >= 0))
        .Select(name => MakeAbsolute(File("./tests/" + name + "/bin/" + parameters.DirSuffix + "/" + name + ".dll")))
        .ToList();

    if (parameters.IsRunningOnWindows)
    {
        var leakTests = GetFiles("./tests/Avalonia.LeakTests/bin/" + parameters.DirSuffix + "/*.LeakTests.dll");

        unitTests.AddRange(leakTests);
    }

    var toolPath = (parameters.IsPlatformAnyCPU || parameters.IsPlatformX86) ? 
        "./tools/xunit.runner.console/tools/xunit.console.x86.exe" :
        "./tools/xunit.runner.console/tools/xunit.console.exe";

    var xUnitSettings = new XUnit2Settings 
    { 
        ToolPath = toolPath,
{'fraction_non_alphanumeric': 0.277492100861161, 'fraction_numerical': 0.008549656155132892, 'mean_word_length': 1.8369068541300526, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 39, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1482678', 'n_tokens_mistral': 4307, 'n_tokens_neox': 4162, 'n_words': 573}