Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated to use Xcode 16's new provisioning profiles directory #124

Merged
merged 4 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions UnitTests/TestHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
//
// TestHelper.cs
//
// Author: Jeffrey Stedfast <[email protected]>
//
// Copyright (c) 2017 Microsoft Corp.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

using System;
using System.IO;

using NUnit.Framework;

namespace UnitTests {
[SetUpFixture]
static class TestHelper {
public static readonly string ProjectDir;

static TestHelper ()
{
#if NET5_0_OR_GREATER
var codeBase = typeof (TestHelper).Assembly.Location;
#else
var codeBase = typeof (TestHelper).Assembly.CodeBase;
if (codeBase.StartsWith ("file://", StringComparison.OrdinalIgnoreCase))
codeBase = codeBase.Substring ("file://".Length);

if (Path.DirectorySeparatorChar == '\\') {
if (codeBase [0] == '/')
codeBase = codeBase.Substring (1);

codeBase = codeBase.Replace ('/', '\\');
}
#endif

var dir = Path.GetDirectoryName (codeBase);

while (Path.GetFileName (dir) != "UnitTests")
dir = Path.GetFullPath (Path.Combine (dir, ".."));

ProjectDir = Path.GetFullPath (dir);
}
}
}
13 changes: 11 additions & 2 deletions UnitTests/TestMobileProvisionIndex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,19 @@
namespace UnitTests {
[TestFixture]
public class TestMobileProvisionIndex {
static readonly string [] ProfileDirectories;

static TestMobileProvisionIndex ()
{
ProfileDirectories = new string [] {
Path.Combine (TestHelper.ProjectDir, "TestData", "Provisioning Profiles")
};
}

[Test]
public void TestCreateIndex ()
{
var index = MobileProvisionIndex.CreateIndex ("../../TestData/Provisioning Profiles", "profiles.index");
var index = MobileProvisionIndex.CreateIndex (ProfileDirectories, "profiles.index");

Assert.AreEqual (2, index.ProvisioningProfiles.Count);

Expand Down Expand Up @@ -77,7 +86,7 @@ public void TestCreateIndex ()
[Test]
public void TestOpenIndex ()
{
var index = MobileProvisionIndex.OpenIndex ("../../TestData/Provisioning Profiles", "profiles.index");
var index = MobileProvisionIndex.OpenIndex (ProfileDirectories, "profiles.index");

Assert.AreEqual (2, index.ProvisioningProfiles.Count);

Expand Down
72 changes: 40 additions & 32 deletions Xamarin.MacDev/MobileProvision.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,27 @@ public class MobileProvision {
public const string AutomaticAppStore = "Automatic:AppStore";
public const string AutomaticInHouse = "Automatic:InHouse";
public const string AutomaticAdHoc = "Automatic:AdHoc";
public static readonly string ProfileDirectory;
public static readonly string [] ProfileDirectories;

static MobileProvision ()
{
if (Environment.OSVersion.Platform == PlatformID.MacOSX
|| Environment.OSVersion.Platform == PlatformID.Unix) {
string personal = Environment.GetFolderPath (Environment.SpecialFolder.UserProfile);
ProfileDirectory = Path.Combine (personal, "Library", "MobileDevice", "Provisioning Profiles");

ProfileDirectories = new string [] {
// Xcode >= 16.x uses ~/Library/Developer/Xcode/UserData/Provisioning Profiles
Path.Combine (personal, "Library", "Developer", "Xcode", "UserData", "Provisioning Profiles"),

// Xcode < 16.x uses ~/Library/MobileDevice/Provisioning Profiles
Path.Combine (personal, "Library", "MobileDevice", "Provisioning Profiles"),
};
} else {
ProfileDirectory = Path.Combine (
Environment.GetFolderPath (Environment.SpecialFolder.LocalApplicationData),
"Xamarin",
"iOS",
"Provisioning",
"Profiles");
var appDataLocal = Environment.GetFolderPath (Environment.SpecialFolder.LocalApplicationData);

ProfileDirectories = new string [] {
Path.Combine (appDataLocal, "Xamarin", "iOS", "Provisioning", "Profiles")
};
}
}

Expand Down Expand Up @@ -145,9 +151,6 @@ public static IList<MobileProvision> GetAllInstalledProvisions (MobileProvisionP
/// </summary>
public static IList<MobileProvision> GetAllInstalledProvisions (MobileProvisionPlatform platform, bool includeExpired)
{
if (!Directory.Exists (ProfileDirectory))
return new MobileProvision [0];

var uuids = new Dictionary<string, MobileProvision> ();
var list = new List<MobileProvision> ();
var now = DateTime.Now;
Expand All @@ -165,33 +168,38 @@ public static IList<MobileProvision> GetAllInstalledProvisions (MobileProvisionP
throw new ArgumentOutOfRangeException (nameof (platform));
}

foreach (var file in Directory.EnumerateFiles (ProfileDirectory, pattern)) {
try {
var data = File.ReadAllBytes (file);

var m = new MobileProvision ();
m.Load (PDictionary.FromBinaryXml (data));
m.Data = data;

if (includeExpired || m.ExpirationDate > now) {
if (uuids.ContainsKey (m.Uuid)) {
// we always want the most recently created/updated provision
if (m.CreationDate > uuids [m.Uuid].CreationDate) {
int index = list.IndexOf (uuids [m.Uuid]);
uuids [m.Uuid] = m;
list [index] = m;
foreach (var profileDir in ProfileDirectories) {
if (!Directory.Exists (profileDir))
continue;

foreach (var file in Directory.EnumerateFiles (profileDir, pattern)) {
try {
var data = File.ReadAllBytes (file);

var m = new MobileProvision ();
m.Load (PDictionary.FromBinaryXml (data));
m.Data = data;

if (includeExpired || m.ExpirationDate > now) {
if (uuids.ContainsKey (m.Uuid)) {
// we always want the most recently created/updated provision
if (m.CreationDate > uuids [m.Uuid].CreationDate) {
int index = list.IndexOf (uuids [m.Uuid]);
uuids [m.Uuid] = m;
list [index] = m;
}
} else {
uuids.Add (m.Uuid, m);
list.Add (m);
}
} else {
uuids.Add (m.Uuid, m);
list.Add (m);
}
} catch (Exception ex) {
LoggingService.LogWarning ("Error reading " + platform + " provision file '" + file + "'", ex);
}
} catch (Exception ex) {
LoggingService.LogWarning ("Error reading " + platform + " provision file '" + file + "'", ex);
}
}

//newest first
// newest first
list.Sort ((x, y) => y.CreationDate.CompareTo (x.CreationDate));

return list;
Expand Down
Loading