Skip to content

Commit

Permalink
Merge branch 'release/0.7.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
kolesnick committed Jul 2, 2019
2 parents 311bb55 + d5cb3a5 commit 56aa9cd
Show file tree
Hide file tree
Showing 8 changed files with 432 additions and 22 deletions.
2 changes: 2 additions & 0 deletions src/Cake.Unity.FSharp.Tests/Cake.Unity.FSharp.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Cake.Core" Version="0.33.0" />
<PackageReference Include="FSharp.Interop.Dynamic" Version="4.0.3.130" />
<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="InfoPlistParserTests.fs" />
<Compile Include="UnityEditorArgumentsTests.fs" />
<Compile Include="UnityVersionTests.fs" />
</ItemGroup>
Expand Down
91 changes: 91 additions & 0 deletions src/Cake.Unity.FSharp.Tests/InfoPlistParserTests.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
module Cake.Unity.Tests.InfoPlistParserTests

open FsUnit.TopLevelOperators
open NUnit.Framework
open Cake.Unity.SeekersOfEditors
open System.IO
open System.Text

[<Test>]
let ``Parse Info.plist`` () =

// arrange
let xml = @"<?xml version=""1.0"" encoding=""UTF-8""?>
<!DOCTYPE plist PUBLIC ""-//Apple//DTD PLIST 1.0//EN"" ""http://www.apple.com/DTDs/PropertyList-1.0.dtd"">
<plist version=""1.0"">
<dict>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>Unity Asset Store</string>
<key>CFBundleURLSchemes</key>
<array>
<string>com.unity3d.kharma</string>
</array>
</dict>
</array>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>unity</string>
<string>unityPackage</string>
</array>
<key>CFBundleTypeIconFile</key>
<string>UnityDocumentIcon</string>
<key>CFBundleTypeOSTypes</key>
<array>
<string>????</string>
</array>
<key>CFBundleTypeRole</key>
<string>Editor</string>
</dict>
</array>
<key>CFBundleExecutable</key>
<string>Unity</string>
<key>CFBundleGetInfoString</key>
<string>Unity version 2017.4.25f1 (9cba1c3a94f1). (c) 2019 Unity Technologies ApS. All rights reserved.</string>
<key>CFBundleIconFile</key>
<string>UnityAppIcon</string>
<key>CFBundleIdentifier</key>
<string>com.unity3d.UnityEditor5.x</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>Unity</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>Unity version 2017.4.25f1</string>
<key>CFBundleSignature</key>
<string>UNED</string>
<key>CFBundleVersion</key>
<string>2017.4.25f1</string>
<key>NSMainNibFile</key>
<string>MainMenuNew</string>
<key>NSPrincipalClass</key>
<string>EditorApplicationPrincipalClass</string>
<key>UnityBuildNumber</key>
<string>9cba1c3a94f1</string>
<key>LSMinimumSystemVersion</key>
<string>10.9.0</string>
</dict>
</plist>
"
let xmlStream = new MemoryStream(Encoding.UTF8.GetBytes(xml))
let parser = new InfoPlistParser()

// act
let version = parser.UnityVersionFromInfoPlist(xmlStream)

// assert
version |> should equal "2017.4.25f1"
17 changes: 17 additions & 0 deletions src/Cake.Unity.FSharp.Tests/UnityVersionTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,20 @@ let ``Unity version without suffix should be in Unknown stage`` () =
[<Test>]
let ``Unity version with unknown suffix should be in Unknown stage`` () =
(2022, 2, 2, 'x', 2) |> UnityVersion |> stage |> should equal UnityReleaseStage.Unknown


[<Test>]
let ``Parse UnityVersion from string`` () =

//arrange
let stringVersion = "2017.4.25f1"

//act
let unityVersion = UnityVersion.Parse(stringVersion)

//assert
unityVersion.Year |> should equal 2017
unityVersion.Stream |> should equal 4
unityVersion.Update |> should equal 25
unityVersion.SuffixCharacter |> should equal 'f'
unityVersion.SuffixNumber |> should equal 1
4 changes: 2 additions & 2 deletions src/Cake.Unity.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.28803.202
# Visual Studio 15
VisualStudioVersion = 15.0.28307.271
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cake.Unity", "Cake.Unity\Cake.Unity.csproj", "{0222DDD2-3716-4E19-854F-EB36D04268D0}"
EndProject
Expand Down
32 changes: 22 additions & 10 deletions src/Cake.Unity/SeekersOfEditors/OSXSeekerOfEditors.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,34 @@
using System.Linq;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Xml.Linq;
using Cake.Core;
using Cake.Core.Diagnostics;
using Cake.Core.IO;
using Cake.Unity.Version;

[assembly: InternalsVisibleTo("Cake.Unity.FSharp.Tests")]
namespace Cake.Unity.SeekersOfEditors
{
internal class OSXSeekerOfEditors : SeekerOfEditors
{
public OSXSeekerOfEditors(ICakeEnvironment environment, IGlobber globber, ICakeLog log)
private readonly IFileSystem fileSystem;

public OSXSeekerOfEditors(ICakeEnvironment environment, IGlobber globber, ICakeLog log, IFileSystem fileSystem)
: base(environment, globber, log)
{ }
{
this.fileSystem = fileSystem;
}

protected override string SearchPattern => "/Applications/**/Unity*.app/Contents/MacOS/Unity";

protected override UnityVersion DetermineVersion(FilePath editorPath)
{
log.Debug($"Determining version of Unity Editor at path {editorPath}...");

var version = UnityVersionFromInfoPlist(editorPath);
string version;
using (var stream = fileSystem.GetFile(PlistPath(editorPath)).OpenRead())
version = new InfoPlistParser().UnityVersionFromInfoPlist(stream);

if (version == null)
{
Expand All @@ -33,16 +42,19 @@ protected override UnityVersion DetermineVersion(FilePath editorPath)
return unityVersion;
}

private static string UnityVersionFromInfoPlist(FilePath editorPath) =>
XElement
.Load(PlistPath(editorPath))
private static string PlistPath(FilePath editorPath) =>
editorPath.FullPath.Replace("/MacOS/Unity", "/Info.plist");
}

internal class InfoPlistParser
{
public string UnityVersionFromInfoPlist(Stream infoPlistStream) =>
XDocument
.Load(infoPlistStream)
.Descendants()
.SkipWhile((element) => element.Value != "CFBundleVersion")
.Skip(1)
.FirstOrDefault()
?.Value;

private static string PlistPath(FilePath editorPath) =>
editorPath.FullPath.Replace("/MacOS/Unity", "/Info.plist");
}
}
4 changes: 2 additions & 2 deletions src/Cake.Unity/SeekersOfEditors/SeekerOfEditors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ internal abstract class SeekerOfEditors
private readonly IGlobber globber;
protected readonly ICakeLog log;

public static SeekerOfEditors GetSeeker(ICakeEnvironment environment, IGlobber globber, ICakeLog log)
public static SeekerOfEditors GetSeeker(ICakeEnvironment environment, IGlobber globber, ICakeLog log, IFileSystem fileSystem)
{
if (environment.Platform.Family == PlatformFamily.Windows)
return new WindowsSeekerOfEditors(environment, globber, log);

if (environment.Platform.Family == PlatformFamily.OSX)
return new OSXSeekerOfEditors(environment, globber, log);
return new OSXSeekerOfEditors(environment, globber, log, fileSystem);

throw new NotSupportedException("Cannot locate Unity Editors. Only Windows and OSX platform is supported.");
}
Expand Down
Loading

0 comments on commit 56aa9cd

Please sign in to comment.