<commit_before>﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Cake.Core;
using Cake.Core.Annotations;
using Cake.Core.IO;
using Cake.Unity.Platforms;
using static Cake.Core.PlatformFamily;

namespace Cake.Unity
{
    [CakeAliasCategory("Unity")]
    public static class UnityExtensions
    {
        [CakeMethodAlias]
        [CakeAliasCategory("Build")]
        [CakeNamespaceImport("Cake.Unity.Platforms")]
        public static void UnityBuild(this ICakeContext context, DirectoryPath projectPath, UnityPlatform platform)
        {
            var tool = new UnityRunner(context.FileSystem, context.Environment, context.ProcessRunner, context.Tools);
            tool.Run(context, projectPath, platform);
        }

        [CakeMethodAlias]
        [CakeAliasCategory("Build")]
        public static UnityEditorDescriptor FindUnityEditor(this ICakeContext context) =>
            Enumerable.FirstOrDefault
            (
                from editor in context.FindUnityEditors()
                let version = editor.Version
                orderby
                    version.Year descending,
                    version.Stream descending,
                    version.Update descending
                select editor
            );

        [CakeMethodAlias]
        [CakeAliasCategory("Build")]
        public static UnityEditorDescriptor FindUnityEditor(this ICakeContext context, int year) =>
            Enumerable.FirstOrDefault
            (
                from editor in context.FindUnityEditors()
                let version = editor.Version
                where
                    version.Year == year
                orderby
                    version.Stream descending,
                    version.Update descending
                select editor
            );

        [CakeMethodAlias]
        [CakeAliasCategory("Build")]
        public static UnityEditorDescriptor FindUnityEditor(this ICakeContext context, int year, int stream) =>
            Enumerable.FirstOrDefault
            (
                from editor in context.FindUnityEditors()
                let version = editor.Version
                where
                    version.Year == year &&
                    version.Stream == stream
                orderby
                    version.Update descending
                select editor
            );

        [CakeMethodAlias]
        [CakeAliasCategory("Build")]
        public static IReadOnlyCollection<UnityEditorDescriptor> FindUnityEditors(this ICakeContext context) =>
            context.Environment.Platform.Family != Windows
                ? throw new NotSupportedException("Cannot locate Unity Editors. Only Windows platform is supported.")
                : new SeekerOfEditors(context.Environment, context.Globber, context.Log)
                    .Seek();
    }
}<commit_msg>Cache of already found Unity Editors.<commit_after>﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Cake.Core;
using Cake.Core.Annotations;
using Cake.Core.Diagnostics;
using Cake.Core.IO;
using Cake.Unity.Platforms;
using static Cake.Core.PlatformFamily;

namespace Cake.Unity
{
    [CakeAliasCategory("Unity")]
    public static class UnityExtensions
    {
        private static IReadOnlyCollection<UnityEditorDescriptor> unityEditorsCache;

        [CakeMethodAlias]
        [CakeAliasCategory("Build")]
        [CakeNamespaceImport("Cake.Unity.Platforms")]
        public static void UnityBuild(this ICakeContext context, DirectoryPath projectPath, UnityPlatform platform)
        {
            var tool = new UnityRunner(context.FileSystem, context.Environment, context.ProcessRunner, context.Tools);
            tool.Run(context, projectPath, platform);
        }

        [CakeMethodAlias]
        [CakeAliasCategory("Build")]
        public static UnityEditorDescriptor FindUnityEditor(this ICakeContext context) =>
            Enumerable.FirstOrDefault
            (
                from editor in context.FindUnityEditors()
                let version = editor.Version
                orderby
                    version.Year descending,
                    version.Stream descending,
                    version.Update descending
                select editor
            );

        [CakeMethodAlias]
        [CakeAliasCategory("Build")]
        public static UnityEditorDescriptor FindUnityEditor(this ICakeContext context, int year) =>
            Enumerable.FirstOrDefault
            (
                from editor in context.FindUnityEditors()
                let version = editor.Version
                where
                    version.Year == year
                orderby
                    version.Stream descending,
                    version.Update descending
                select editor
            );

        [CakeMethodAlias]
        [CakeAliasCategory("Build")]
        public static UnityEditorDescriptor FindUnityEditor(this ICakeContext context, int year, int stream) =>
            Enumerable.FirstOrDefault
            (
                from editor in context.FindUnityEditors()
                let version = editor.Version
                where
                    version.Year == year &&
                    version.Stream == stream
                orderby
                    version.Update descending
                select editor
            );

        [CakeMethodAlias]
        [CakeAliasCategory("Build")]
        public static IReadOnlyCollection<UnityEditorDescriptor> FindUnityEditors(this ICakeContext context)
        {
            if (context.Environment.Platform.Family != Windows)
                throw new NotSupportedException("Cannot locate Unity Editors. Only Windows platform is supported.");

            if (unityEditorsCache != null)
            {
                context.Log.Debug("Already searched for Unity Editors. Using cached results.");
                return unityEditorsCache;
            }

            return
                unityEditorsCache =
                    new SeekerOfEditors(context.Environment, context.Globber, context.Log)
                        .Seek();
        }
    }
}
{'fraction_non_alphanumeric': 0.06868131868131869, 'fraction_numerical': 0.0, 'mean_word_length': 1.8613037447988905, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 13, 'https://': 0, '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': '799518', 'n_tokens_mistral': 1485, 'n_tokens_neox': 1338, 'n_words': 343}