diff --git a/msbuild/Xamarin.MacDev.Tasks/Tasks/CompileEntitlementsTaskBase.cs b/msbuild/Xamarin.MacDev.Tasks/Tasks/CompileEntitlementsTaskBase.cs index 24ffd52b3ffa..d2fd1648c61f 100644 --- a/msbuild/Xamarin.MacDev.Tasks/Tasks/CompileEntitlementsTaskBase.cs +++ b/msbuild/Xamarin.MacDev.Tasks/Tasks/CompileEntitlementsTaskBase.cs @@ -7,6 +7,8 @@ using Xamarin.Localization.MSBuild; using Xamarin.Utils; +#nullable enable + namespace Xamarin.MacDev.Tasks { public abstract class CompileEntitlementsTaskBase : XamarinTask @@ -46,42 +48,42 @@ public abstract class CompileEntitlementsTaskBase : XamarinTask #region Inputs [Required] - public string AppBundleDir { get; set; } + public string AppBundleDir { get; set; } = string.Empty; [Required] - public string AppIdentifier { get; set; } + public string AppIdentifier { get; set; } = string.Empty; [Required] - public string BundleIdentifier { get; set; } + public string BundleIdentifier { get; set; } = string.Empty; [Required] - public ITaskItem CompiledEntitlements { get; set; } + public ITaskItem? CompiledEntitlements { get; set; } public bool Debug { get; set; } - public string Entitlements { get; set; } + public string Entitlements { get; set; } = string.Empty; [Required] public bool IsAppExtension { get; set; } - public string ProvisioningProfile { get; set; } + public string ProvisioningProfile { get; set; } = string.Empty; [Required] - public string SdkDevPath { get; set; } + public string SdkDevPath { get; set; } = string.Empty; public bool SdkIsSimulator { get; set; } [Required] - public string SdkPlatform { get; set; } + public string SdkPlatform { get; set; } = string.Empty; [Required] - public string SdkVersion { get; set; } + public string SdkVersion { get; set; } = string.Empty; [Output] - public ITaskItem EntitlementsInExecutable { get; set; } + public ITaskItem? EntitlementsInExecutable { get; set; } [Output] - public ITaskItem EntitlementsInSignature { get; set; } + public ITaskItem? EntitlementsInSignature { get; set; } #endregion @@ -139,11 +141,7 @@ protected string EntitlementBundlePath { } } - protected virtual bool MergeProfileEntitlements { - get { return true; } - } - - PString MergeEntitlementString (PString pstr, MobileProvision profile, bool expandWildcards) + PString MergeEntitlementString (PString pstr, MobileProvision? profile, bool expandWildcards) { string TeamIdentifierPrefix; string AppIdentifierPrefix; @@ -151,7 +149,7 @@ PString MergeEntitlementString (PString pstr, MobileProvision profile, bool expa if (string.IsNullOrEmpty (pstr.Value)) return (PString) pstr.Clone (); - if (profile == null) { + if (profile is null) { if (!warnedTeamIdentifierPrefix && pstr.Value.Contains ("$(TeamIdentifierPrefix)")) { Log.LogWarning (null, null, null, Entitlements, 0, 0, 0, 0, MSBStrings.W0108); warnedTeamIdentifierPrefix = true; @@ -163,12 +161,12 @@ PString MergeEntitlementString (PString pstr, MobileProvision profile, bool expa } } - if (profile != null && profile.ApplicationIdentifierPrefix.Count > 0) + if (profile is not null && profile.ApplicationIdentifierPrefix.Count > 0) AppIdentifierPrefix = profile.ApplicationIdentifierPrefix[0] + "."; else AppIdentifierPrefix = string.Empty; - if (profile != null && profile.TeamIdentifierPrefix.Count > 0) + if (profile is not null && profile.TeamIdentifierPrefix.Count > 0) TeamIdentifierPrefix = profile.TeamIdentifierPrefix[0] + "."; else TeamIdentifierPrefix = AppIdentifierPrefix; @@ -203,12 +201,12 @@ PString MergeEntitlementString (PString pstr, MobileProvision profile, bool expa return new PString (expanded); } - PArray MergeEntitlementArray (PArray array, MobileProvision profile) + PArray? MergeEntitlementArray (PArray array, MobileProvision? profile) { var result = new PArray (); foreach (var item in array) { - PObject value; + PObject? value; if (item is PDictionary) value = MergeEntitlementDictionary ((PDictionary) item, profile); @@ -219,7 +217,7 @@ PArray MergeEntitlementArray (PArray array, MobileProvision profile) else value = item.Clone (); - if (value != null) + if (value is not null) result.Add (value); } @@ -229,12 +227,12 @@ PArray MergeEntitlementArray (PArray array, MobileProvision profile) return null; } - PDictionary MergeEntitlementDictionary (PDictionary dict, MobileProvision profile) + PDictionary MergeEntitlementDictionary (PDictionary dict, MobileProvision? profile) { var result = new PDictionary (); foreach (var item in dict) { - PObject value = item.Value; + PObject? value = item.Value; if (value is PDictionary) value = MergeEntitlementDictionary ((PDictionary) value, profile); @@ -245,7 +243,7 @@ PDictionary MergeEntitlementDictionary (PDictionary dict, MobileProvision profil else value = value.Clone (); - if (value != null) + if (value is not null) result.Add (item.Key, value); } @@ -289,11 +287,11 @@ static void WriteXcent (PObject doc, string path) } } - protected virtual PDictionary GetCompiledEntitlements (MobileProvision profile, PDictionary template) + protected virtual PDictionary GetCompiledEntitlements (MobileProvision? profile, PDictionary template) { var entitlements = new PDictionary (); - if (profile != null && MergeProfileEntitlements) { + if (profile is not null) { // start off with the settings from the provisioning profile foreach (var item in profile.Entitlements) { if (!AllowedProvisioningKeys.Contains (item.Key)) @@ -312,7 +310,7 @@ protected virtual PDictionary GetCompiledEntitlements (MobileProvision profile, else value = value.Clone (); - if (value != null) + if (value is not null) entitlements.Add (item.Key, value); } } @@ -325,7 +323,7 @@ protected virtual PDictionary GetCompiledEntitlements (MobileProvision profile, item.Key == "com.apple.developer.icloud-container-identifiers" || item.Key == "com.apple.developer.icloud-container-environment" || item.Key == "com.apple.developer.icloud-services") { - if (profile == null) + if (profile is null) Log.LogWarning (null, null, null, Entitlements, 0, 0, 0, 0, MSBStrings.W0110, item.Key); else if (!profile.Entitlements.ContainsKey (item.Key)) Log.LogWarning (null, null, null, Entitlements, 0, 0, 0, 0, MSBStrings.W0111, item.Key); @@ -333,7 +331,7 @@ protected virtual PDictionary GetCompiledEntitlements (MobileProvision profile, var str = value as PString; // Ignore ONLY if it is empty, otherwise take the user's value - if (str == null || string.IsNullOrEmpty (str.Value)) + if (str is null || string.IsNullOrEmpty (str.Value)) continue; } @@ -346,7 +344,7 @@ protected virtual PDictionary GetCompiledEntitlements (MobileProvision profile, else value = value.Clone (); - if (value != null) + if (value is not null) entitlements[item.Key] = value; } @@ -389,7 +387,7 @@ protected virtual MobileProvision GetMobileProvision (MobileProvisionPlatform pl public override bool Execute () { MobileProvisionPlatform platform; - MobileProvision profile; + MobileProvision? profile; PDictionary template; PDictionary compiled; PDictionary archived; @@ -418,7 +416,7 @@ public override bool Execute () } if (!string.IsNullOrEmpty (ProvisioningProfile)) { - if ((profile = GetMobileProvision (platform, ProvisioningProfile)) == null) { + if ((profile = GetMobileProvision (platform, ProvisioningProfile)) is null) { Log.LogError (MSBStrings.E0049, ProvisioningProfile); return false; } @@ -448,7 +446,7 @@ public override bool Execute () archived = GetArchivedExpandedEntitlements (template, compiled); try { - Directory.CreateDirectory (Path.GetDirectoryName (CompiledEntitlements.ItemSpec)); + Directory.CreateDirectory (Path.GetDirectoryName (CompiledEntitlements!.ItemSpec)); WriteXcent (compiled, CompiledEntitlements.ItemSpec); } catch (Exception ex) { Log.LogError (MSBStrings.E0114, CompiledEntitlements, ex.Message);