Skip to content

Commit

Permalink
Merge branch 'release/0.3.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
kolesnick committed Dec 14, 2018
2 parents fa68435 + ef8c837 commit f0c0c66
Show file tree
Hide file tree
Showing 10 changed files with 173 additions and 18 deletions.
4 changes: 2 additions & 2 deletions nuspec/nuget/Cake.Unity.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<metadata xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<id>Cake.Unity</id>
<version>0.0.0</version>
<authors>patriksvensson</authors>
<owners>patriksvensson, cake-contrib</owners>
<authors>Patrik Svensson, Anatoliy Kolesnick</authors>
<owners>patriksvensson, cake-contrib, kolesnick</owners>
<description>Cake Unity AddIn.</description>
<summary>Cake AddIn that extends Cake with ability to execute the Unity Editor as a command line utility.</summary>
<licenseUrl>https://github.com/cake-contrib/Cake.Unity/blob/master/LICENSE</licenseUrl>
Expand Down
5 changes: 2 additions & 3 deletions setup.cake
Original file line number Diff line number Diff line change
@@ -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();

Expand All @@ -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);

Expand Down
27 changes: 27 additions & 0 deletions src/Cake.Unity.FSharp.Tests/Cake.Unity.FSharp.Tests.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net46</TargetFramework>
<IsPackable>false</IsPackable>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FsUnit" Version="3.4.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.10.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.8.0" />
</ItemGroup>

<ItemGroup>
<Compile Include="UnityVersionTests.fs" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Cake.Unity\Cake.Unity.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Update="System.ValueTuple" Version="4.5.0" />
</ItemGroup>

</Project>
31 changes: 31 additions & 0 deletions src/Cake.Unity.FSharp.Tests/UnityVersionTests.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module UnityVersionTests

open FsUnit.TopLevelOperators
open NUnit.Framework
open Cake.Unity.Version

let stage (version : UnityVersion) = version.Stage

[<Test>]
let ``Unity version with 'a' suffix should be in Alpha stage`` () =
(2019, 1, 0, 'a', 9) |> UnityVersion |> stage |> should equal UnityReleaseStage.Alpha

[<Test>]
let ``Unity version with 'b' suffix should be in Beta stage`` () =
(2018, 3, 0, 'b', 2) |> UnityVersion |> stage |> should equal UnityReleaseStage.Beta

[<Test>]
let ``Unity version with 'p' suffix should be in Patch stage`` () =
(2017, 2, 2, 'p', 1) |> UnityVersion |> stage |> should equal UnityReleaseStage.Patch

[<Test>]
let ``Unity version with 'f' suffix should be in Final stage`` () =
(2018, 2, 20, 'f', 1) |> UnityVersion |> stage |> should equal UnityReleaseStage.Final

[<Test>]
let ``Unity version without suffix should be in Unknown stage`` () =
(2018, 4, 13) |> UnityVersion |> stage |> should equal UnityReleaseStage.Unknown

[<Test>]
let ``Unity version with unknown suffix should be in Unknown stage`` () =
(2022, 2, 2, 'x', 2) |> UnityVersion |> stage |> should equal UnityReleaseStage.Unknown
15 changes: 12 additions & 3 deletions src/Cake.Unity.sln
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
11 changes: 6 additions & 5 deletions src/Cake.Unity/SeekerOfEditors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Cake.Core;
using Cake.Core.Diagnostics;
using Cake.Core.IO;
using Cake.Unity.Version;

namespace Cake.Unity
{
Expand Down Expand Up @@ -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);
Expand All @@ -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;
}

Expand All @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/Cake.Unity/UnityEditorDescriptor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Cake.Core.IO;
using Cake.Unity.Version;

namespace Cake.Unity
{
Expand Down
68 changes: 64 additions & 4 deletions src/Cake.Unity/UnityExtensions.cs
Original file line number Diff line number Diff line change
@@ -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<UnityEditorDescriptor> unityEditorsCache;

[CakeMethodAlias]
[CakeAliasCategory("Build")]
[CakeNamespaceImport("Cake.Unity.Platforms")]
Expand All @@ -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
(
Expand All @@ -30,13 +54,15 @@ from editor in context.FindUnityEditors()
where
version.Year == year
orderby
ReleaseStagePriority(version.Stage),
version.Stream descending,
version.Update descending
select editor
);

[CakeMethodAlias]
[CakeAliasCategory("Build")]
[CakeNamespaceImport("Cake.Unity.Version")]
public static UnityEditorDescriptor FindUnityEditor(this ICakeContext context, int year, int stream) =>
Enumerable.FirstOrDefault
(
Expand All @@ -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<UnityEditorDescriptor> FindUnityEditors(this ICakeContext context) =>
new SeekerOfEditors(context.Environment, context.Globber, context.Log)
.Seek();
[CakeNamespaceImport("Cake.Unity.Version")]
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();
}

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;
}
}
}
}
11 changes: 11 additions & 0 deletions src/Cake.Unity/Version/UnityReleaseStage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace Cake.Unity.Version
{
public enum UnityReleaseStage
{
Alpha = -100,
Beta = -10,
Unknown = 0,
Patch = 10,
Final = 100,
}
}
Original file line number Diff line number Diff line change
@@ -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<char, UnityReleaseStage> SuffixToStage = new Dictionary<char, UnityReleaseStage>
{
{ 'a', Alpha },
{ 'b', Beta },
{ 'p', Patch },
{ 'f', Final },
};

public UnityVersion(int year, int stream, int update)
{
this.Year = year;
Expand All @@ -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}"
Expand Down

0 comments on commit f0c0c66

Please sign in to comment.