diff --git a/nuspec/nuget/Cake.Unity.nuspec b/nuspec/nuget/Cake.Unity.nuspec index 75954cd..9c1d225 100644 --- a/nuspec/nuget/Cake.Unity.nuspec +++ b/nuspec/nuget/Cake.Unity.nuspec @@ -3,8 +3,8 @@ Cake.Unity 0.0.0 - patriksvensson - patriksvensson, cake-contrib + Patrik Svensson, Anatoliy Kolesnick + patriksvensson, cake-contrib, kolesnick Cake Unity AddIn. Cake AddIn that extends Cake with ability to execute the Unity Editor as a command line utility. https://github.com/cake-contrib/Cake.Unity/blob/master/LICENSE diff --git a/setup.cake b/setup.cake index e6be7f2..656f01b 100644 --- a/setup.cake +++ b/setup.cake @@ -1,4 +1,4 @@ -#load "nuget:https://www.myget.org/F/cake-contrib/api/v2?package=Cake.Recipe&prerelease" +#load nuget:https://www.myget.org/F/cake-contrib/api/v2?package=Cake.Recipe&prerelease Environment.SetVariableNames(); @@ -8,8 +8,7 @@ BuildParameters.SetParameters(context: Context, title: "Cake.Unity", repositoryOwner: "cake-contrib", repositoryName: "Cake.Unity", - appVeyorAccountName: "cakecontrib", - shouldPublishMyGet: false); + appVeyorAccountName: "cakecontrib"); BuildParameters.PrintParameters(Context); diff --git a/src/Cake.Unity.FSharp.Tests/Cake.Unity.FSharp.Tests.fsproj b/src/Cake.Unity.FSharp.Tests/Cake.Unity.FSharp.Tests.fsproj new file mode 100644 index 0000000..0973ebe --- /dev/null +++ b/src/Cake.Unity.FSharp.Tests/Cake.Unity.FSharp.Tests.fsproj @@ -0,0 +1,27 @@ + + + + net46 + false + true + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Cake.Unity.FSharp.Tests/UnityVersionTests.fs b/src/Cake.Unity.FSharp.Tests/UnityVersionTests.fs new file mode 100644 index 0000000..ca02e07 --- /dev/null +++ b/src/Cake.Unity.FSharp.Tests/UnityVersionTests.fs @@ -0,0 +1,31 @@ +module UnityVersionTests + +open FsUnit.TopLevelOperators +open NUnit.Framework +open Cake.Unity.Version + +let stage (version : UnityVersion) = version.Stage + +[] +let ``Unity version with 'a' suffix should be in Alpha stage`` () = + (2019, 1, 0, 'a', 9) |> UnityVersion |> stage |> should equal UnityReleaseStage.Alpha + +[] +let ``Unity version with 'b' suffix should be in Beta stage`` () = + (2018, 3, 0, 'b', 2) |> UnityVersion |> stage |> should equal UnityReleaseStage.Beta + +[] +let ``Unity version with 'p' suffix should be in Patch stage`` () = + (2017, 2, 2, 'p', 1) |> UnityVersion |> stage |> should equal UnityReleaseStage.Patch + +[] +let ``Unity version with 'f' suffix should be in Final stage`` () = + (2018, 2, 20, 'f', 1) |> UnityVersion |> stage |> should equal UnityReleaseStage.Final + +[] +let ``Unity version without suffix should be in Unknown stage`` () = + (2018, 4, 13) |> UnityVersion |> stage |> should equal UnityReleaseStage.Unknown + +[] +let ``Unity version with unknown suffix should be in Unknown stage`` () = + (2022, 2, 2, 'x', 2) |> UnityVersion |> stage |> should equal UnityReleaseStage.Unknown diff --git a/src/Cake.Unity.sln b/src/Cake.Unity.sln index da83a8a..0b7414f 100644 --- a/src/Cake.Unity.sln +++ b/src/Cake.Unity.sln @@ -1,12 +1,14 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 14 -VisualStudioVersion = 14.0.22013.1 +# Visual Studio 15 +VisualStudioVersion = 15.0.28307.168 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cake.Unity", "Cake.Unity\Cake.Unity.csproj", "{0222DDD2-3716-4E19-854F-EB36D04268D0}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cake.Unity", "Cake.Unity\Cake.Unity.csproj", "{0222DDD2-3716-4E19-854F-EB36D04268D0}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cake.Unity.Tests", "Cake.Unity.Tests\Cake.Unity.Tests.csproj", "{9AA57ADE-FA83-4162-9CAA-ED7C1219EED4}" EndProject +Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Cake.Unity.FSharp.Tests", "Cake.Unity.FSharp.Tests\Cake.Unity.FSharp.Tests.fsproj", "{240E476F-324F-4489-B7A9-98A8EBD28C2A}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -21,8 +23,15 @@ Global {9AA57ADE-FA83-4162-9CAA-ED7C1219EED4}.Debug|Any CPU.Build.0 = Debug|Any CPU {9AA57ADE-FA83-4162-9CAA-ED7C1219EED4}.Release|Any CPU.ActiveCfg = Release|Any CPU {9AA57ADE-FA83-4162-9CAA-ED7C1219EED4}.Release|Any CPU.Build.0 = Release|Any CPU + {240E476F-324F-4489-B7A9-98A8EBD28C2A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {240E476F-324F-4489-B7A9-98A8EBD28C2A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {240E476F-324F-4489-B7A9-98A8EBD28C2A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {240E476F-324F-4489-B7A9-98A8EBD28C2A}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {A9E59E56-A55F-4B76-9773-D5C1CC6171E1} + EndGlobalSection EndGlobal diff --git a/src/Cake.Unity/SeekerOfEditors.cs b/src/Cake.Unity/SeekerOfEditors.cs index 19b35c9..676bd58 100644 --- a/src/Cake.Unity/SeekerOfEditors.cs +++ b/src/Cake.Unity/SeekerOfEditors.cs @@ -5,6 +5,7 @@ using Cake.Core; using Cake.Core.Diagnostics; using Cake.Core.IO; +using Cake.Unity.Version; namespace Cake.Unity { @@ -44,6 +45,7 @@ from candidatePath in candidates private UnityVersion DetermineVersion(FilePath editorPath) { + log.Debug(string.Empty); log.Debug("Determining version of Unity Editor at path {0}...", editorPath); var fileVersion = FileVersionInfo.GetVersionInfo(editorPath.FullPath); @@ -52,9 +54,10 @@ private UnityVersion DetermineVersion(FilePath editorPath) if (year <= 0 || stream <= 0 || update < 0) { - log.Debug( - "Failed: file version {0}.{1}.{2} is incorrect. Expected first two parts to be positive numbers and third one to be non negative.", - year, stream, update); + log.Warning( + "Unity Editor file version {0} at path {1} is incorrect. Expected first two parts to be positive numbers and third one to be non negative.", + $"{year}.{stream}.{update}.{fileVersion.FilePrivatePart}", + editorPath.FullPath); return null; } @@ -64,14 +67,12 @@ private UnityVersion DetermineVersion(FilePath editorPath) if (suffix.HasValue) { - log.Debug("Unity version suffix determined."); var version = new UnityVersion(year, stream, update, suffix.Value.character, suffix.Value.number); log.Debug("Result Unity Editor version (full): {0}", version); return version; } else { - log.Debug("Unity version suffix not determined."); var version = new UnityVersion(year, stream, update); log.Debug("Result Unity Editor version (short): {0}", version); return version; diff --git a/src/Cake.Unity/UnityEditorDescriptor.cs b/src/Cake.Unity/UnityEditorDescriptor.cs index a577e13..8f48e12 100644 --- a/src/Cake.Unity/UnityEditorDescriptor.cs +++ b/src/Cake.Unity/UnityEditorDescriptor.cs @@ -1,4 +1,5 @@ using Cake.Core.IO; +using Cake.Unity.Version; namespace Cake.Unity { diff --git a/src/Cake.Unity/UnityExtensions.cs b/src/Cake.Unity/UnityExtensions.cs index 0a7776c..245a6b0 100644 --- a/src/Cake.Unity/UnityExtensions.cs +++ b/src/Cake.Unity/UnityExtensions.cs @@ -1,16 +1,23 @@ -using System.Collections; +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 Cake.Unity.Version; +using static Cake.Core.PlatformFamily; +using static Cake.Unity.Version.UnityReleaseStage; namespace Cake.Unity { [CakeAliasCategory("Unity")] public static class UnityExtensions { + private static IReadOnlyCollection unityEditorsCache; + [CakeMethodAlias] [CakeAliasCategory("Build")] [CakeNamespaceImport("Cake.Unity.Platforms")] @@ -22,6 +29,23 @@ public static void UnityBuild(this ICakeContext context, DirectoryPath projectPa [CakeMethodAlias] [CakeAliasCategory("Build")] + [CakeNamespaceImport("Cake.Unity.Version")] + public static UnityEditorDescriptor FindUnityEditor(this ICakeContext context) => + Enumerable.FirstOrDefault + ( + from editor in context.FindUnityEditors() + let version = editor.Version + orderby + ReleaseStagePriority(version.Stage), + version.Year descending, + version.Stream descending, + version.Update descending + select editor + ); + + [CakeMethodAlias] + [CakeAliasCategory("Build")] + [CakeNamespaceImport("Cake.Unity.Version")] public static UnityEditorDescriptor FindUnityEditor(this ICakeContext context, int year) => Enumerable.FirstOrDefault ( @@ -30,6 +54,7 @@ from editor in context.FindUnityEditors() where version.Year == year orderby + ReleaseStagePriority(version.Stage), version.Stream descending, version.Update descending select editor @@ -37,6 +62,7 @@ select editor [CakeMethodAlias] [CakeAliasCategory("Build")] + [CakeNamespaceImport("Cake.Unity.Version")] public static UnityEditorDescriptor FindUnityEditor(this ICakeContext context, int year, int stream) => Enumerable.FirstOrDefault ( @@ -46,14 +72,48 @@ from editor in context.FindUnityEditors() version.Year == year && version.Stream == stream orderby + ReleaseStagePriority(version.Stage), version.Update descending select editor ); [CakeMethodAlias] [CakeAliasCategory("Build")] - public static IReadOnlyCollection FindUnityEditors(this ICakeContext context) => - new SeekerOfEditors(context.Environment, context.Globber, context.Log) - .Seek(); + [CakeNamespaceImport("Cake.Unity.Version")] + public static IReadOnlyCollection 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(); + } + + private static int ReleaseStagePriority(UnityReleaseStage stage) + { + switch (stage) + { + case Final: + case Patch: + return 1; + + case Beta: + return 3; + + case Alpha: + return 4; + + default: + return 2; + } + } } } diff --git a/src/Cake.Unity/Version/UnityReleaseStage.cs b/src/Cake.Unity/Version/UnityReleaseStage.cs new file mode 100644 index 0000000..d81f9c4 --- /dev/null +++ b/src/Cake.Unity/Version/UnityReleaseStage.cs @@ -0,0 +1,11 @@ +namespace Cake.Unity.Version +{ + public enum UnityReleaseStage + { + Alpha = -100, + Beta = -10, + Unknown = 0, + Patch = 10, + Final = 100, + } +} diff --git a/src/Cake.Unity/UnityVersion.cs b/src/Cake.Unity/Version/UnityVersion.cs similarity index 60% rename from src/Cake.Unity/UnityVersion.cs rename to src/Cake.Unity/Version/UnityVersion.cs index d03a4ee..c937983 100644 --- a/src/Cake.Unity/UnityVersion.cs +++ b/src/Cake.Unity/Version/UnityVersion.cs @@ -1,7 +1,18 @@ -namespace Cake.Unity +using System.Collections.Generic; +using static Cake.Unity.Version.UnityReleaseStage; + +namespace Cake.Unity.Version { public class UnityVersion { + private static readonly Dictionary SuffixToStage = new Dictionary + { + { 'a', Alpha }, + { 'b', Beta }, + { 'p', Patch }, + { 'f', Final }, + }; + public UnityVersion(int year, int stream, int update) { this.Year = year; @@ -22,6 +33,11 @@ public UnityVersion(int year, int stream, int update, char suffixCharacter, int public char? SuffixCharacter { get; } public int? SuffixNumber { get; } + public UnityReleaseStage Stage => + SuffixCharacter.HasValue && SuffixToStage.ContainsKey(SuffixCharacter.Value) + ? SuffixToStage[SuffixCharacter.Value] + : Unknown; + public override string ToString() => SuffixCharacter.HasValue && SuffixNumber.HasValue ? $"{Year}.{Stream}.{Update}{SuffixCharacter}{SuffixNumber}"