@@ -21,6 +21,13 @@ import (
2121 "github.com/pkg/errors"
2222)
2323
24+ const collectCodesigningFilesInfo = `To collect available code sign files, we search for installed Provisioning Profiles:"
25+ - which has installed Codesign Identity in your Keychain"
26+ - which can provision your application target's bundle ids"
27+ - which has the project defined Capabilities set"
28+ - which matches to the selected ipa export method"
29+ `
30+
2431func initExportOutputDir () (string , error ) {
2532 confExportOutputDirPath := "./codesigndoc_exports"
2633 absExportOutputDirPath , err := pathutil .AbsPath (confExportOutputDirPath )
@@ -59,7 +66,7 @@ func analyzeArchive(archive xcarchive.IosArchive, installedCertificates []certif
5966 }, nil
6067}
6168
62- func collectIpaExportSelectableCodeSignGroups (archive xcarchive.IosArchive , installedCertificates []certificateutil.CertificateInfoModel , installedProfiles []profileutil.ProvisioningProfileInfoModel ) ( []export.SelectableCodeSignGroup , error ) {
69+ func collectIpaExportSelectableCodeSignGroups (archive xcarchive.IosArchive , installedCertificates []certificateutil.CertificateInfoModel , installedProfiles []profileutil.ProvisioningProfileInfoModel ) []export.SelectableCodeSignGroup {
6370 bundleIDEntitlemenstMap := archive .BundleIDEntitlementsMap ()
6471
6572 fmt .Println ()
@@ -83,8 +90,7 @@ func collectIpaExportSelectableCodeSignGroups(archive xcarchive.IosArchive, inst
8390 }
8491
8592 if len (codeSignGroups ) == 0 {
86- log .Errorf ("Failed to create codesigning groups for the project" )
87- return []export.SelectableCodeSignGroup {}, nil
93+ return []export.SelectableCodeSignGroup {}
8894 }
8995
9096 codeSignGroups = export .FilterSelectableCodeSignGroups (codeSignGroups ,
@@ -108,11 +114,7 @@ func collectIpaExportSelectableCodeSignGroups(archive xcarchive.IosArchive, inst
108114 log .Debugf (group .String ())
109115 }
110116
111- if len (codeSignGroups ) == 0 {
112- log .Errorf ("Failed to create codesigning groups for the project" )
113- }
114-
115- return codeSignGroups , nil
117+ return codeSignGroups
116118}
117119
118120func filterLatestProfiles (profiles []profileutil.ProvisioningProfileInfoModel ) []profileutil.ProvisioningProfileInfoModel {
@@ -145,19 +147,9 @@ func filterLatestProfiles(profiles []profileutil.ProvisioningProfileInfoModel) [
145147func collectIpaExportCodeSignGroups (tool Tool , archive xcarchive.IosArchive , installedCertificates []certificateutil.CertificateInfoModel , installedProfiles []profileutil.ProvisioningProfileInfoModel ) ([]export.IosCodeSignGroup , error ) {
146148 iosCodeSignGroups := []export.IosCodeSignGroup {}
147149
148- codeSignGroups , err := collectIpaExportSelectableCodeSignGroups (archive , installedCertificates , installedProfiles )
149- if err != nil {
150- return nil , ArchiveError {tool , "failed to collect valid code sign settings: " + err .Error ()}
151- }
152-
150+ codeSignGroups := collectIpaExportSelectableCodeSignGroups (archive , installedCertificates , installedProfiles )
153151 if len (codeSignGroups ) == 0 {
154- fmt .Println ()
155- log .Errorf ("No code sign files (Codesign Identities and Provisioning Profiles) are installed to export an ipa" )
156- log .Errorf ("To collect available code sign files, we search for installed Provisioning Profiles:" )
157- log .Errorf ("- which has installed Codesign Identity in your Keychain" )
158- log .Errorf ("- which can provision your application target's bundle ids" )
159- log .Errorf ("- which has the project defined Capabilities set" )
160- return nil , ArchiveError {tool , "failed to find code sign files" }
152+ return nil , errors .New ("no code sign files (Codesign Identities and Provisioning Profiles) are installed to export an ipa\n " + collectCodesigningFilesInfo )
161153 }
162154
163155 exportMethods := []string {"development" , "app-store" , "ad-hoc" , "enterprise" }
@@ -166,7 +158,7 @@ func collectIpaExportCodeSignGroups(tool Tool, archive xcarchive.IosArchive, ins
166158 fmt .Println ()
167159 selectedExportMethod , err := goinp .SelectFromStringsWithDefault ("Select the ipa export method" , 1 , exportMethods )
168160 if err != nil {
169- return nil , ArchiveError { tool , "failed to select ipa export method: " + err . Error ()}
161+ return nil , fmt . Errorf ( "failed to read input: %s" , err )
170162 }
171163 log .Debugf ("selected export method: %v" , selectedExportMethod )
172164
@@ -183,20 +175,14 @@ func collectIpaExportCodeSignGroups(tool Tool, archive xcarchive.IosArchive, ins
183175
184176 if len (filteredCodeSignGroups ) == 0 {
185177 fmt .Println ()
186- log .Errorf ("No code sign files (Codesign Identities and Provisioning Profiles) are installed for %s ipa export" , selectedExportMethod )
187- log .Errorf ("To collect available code sign files, we search for installed Provisioning Profiles:" )
188- log .Errorf ("- which has installed Codesign Identity in your Keychain" )
189- log .Errorf ("- which can provision your application target's bundle ids" )
190- log .Errorf ("- which has the project defined Capabilities set" )
191- log .Errorf ("- which matches to the selected ipa export method" )
192-
178+ log .Errorf (collectCodesigningFilesInfo )
193179 fmt .Println ()
194180 fmt .Println ()
195181 question := "Do you want to collect another ipa export code sign files"
196182 question += "\n (select NO to finish collecting codesign files and continue)"
197183 anotherExport , err := goinp .AskForBoolWithDefault (question , false )
198184 if err != nil {
199- return nil , fmt .Errorf ("failed to ask : %s" , err )
185+ return nil , fmt .Errorf ("failed to read input : %s" , err )
200186 }
201187 if ! anotherExport {
202188 break
@@ -226,7 +212,7 @@ func collectIpaExportCodeSignGroups(tool Tool, archive xcarchive.IosArchive, ins
226212 question := fmt .Sprintf ("Select the Codesign Indentity for %s ipa export" , selectedExportMethod )
227213 selectedCertificateOption , err = goinp .SelectFromStringsWithDefault (question , 1 , certificateOptions )
228214 if err != nil {
229- return nil , ArchiveError { tool , fmt .Sprintf ("failed to select Codesign Indentity : %s" , err )}
215+ return nil , fmt .Errorf ("failed to read input : %s" , err )
230216 }
231217 }
232218
@@ -239,7 +225,7 @@ func collectIpaExportCodeSignGroups(tool Tool, archive xcarchive.IosArchive, ins
239225 }
240226 }
241227 if selectedCertificate == nil {
242- return nil , ArchiveError { tool , "failed to find selected Codesign Indentity" }
228+ return nil , errors . New ( "failed to find selected Codesign Indentity" )
243229 }
244230
245231 // Select Profiles
@@ -252,7 +238,7 @@ func collectIpaExportCodeSignGroups(tool Tool, archive xcarchive.IosArchive, ins
252238 }
253239 }
254240 if len (bundleIDProfilesMap ) == 0 {
255- return nil , ArchiveError { tool , "failed to find Provisioning Profiles for Code Sign Identity" }
241+ return nil , errors . New ( "failed to find Provisioning Profiles for Code Sign Identity" )
256242 }
257243
258244 selectedBundleIDProfileMap := map [string ]profileutil.ProvisioningProfileInfoModel {}
@@ -276,7 +262,7 @@ func collectIpaExportCodeSignGroups(tool Tool, archive xcarchive.IosArchive, ins
276262 question := fmt .Sprintf ("Select the Provisioning Profile to sign target with bundle ID: %s" , bundleID )
277263 selectedProfileOption , err = goinp .SelectFromStringsWithDefault (question , 1 , profileOptions )
278264 if err != nil {
279- return nil , ArchiveError { tool , fmt .Sprintf ("failed to select Provisioning Profile : %s" , err )}
265+ return nil , fmt .Errorf ("failed to read input : %s" , err )
280266 }
281267 }
282268
@@ -288,7 +274,7 @@ func collectIpaExportCodeSignGroups(tool Tool, archive xcarchive.IosArchive, ins
288274 }
289275 }
290276 if len (selectedBundleIDProfileMap ) != len (bundleIDProfilesMap ) {
291- return nil , ArchiveError { tool , fmt .Sprintf ("failed to find Provisioning Profiles for ipa export" )}
277+ return nil , fmt .Errorf ("failed to find Provisioning Profiles for ipa export" )
292278 }
293279
294280 iosCodeSignGroup := export.IosCodeSignGroup {
@@ -310,7 +296,7 @@ func collectIpaExportCodeSignGroups(tool Tool, archive xcarchive.IosArchive, ins
310296 question += "\n (select NO to finish collecting codesign files and continue)"
311297 anotherExport , err := goinp .AskForBoolWithDefault (question , false )
312298 if err != nil {
313- return nil , fmt .Errorf ("failed to ask : %s" , err )
299+ return nil , fmt .Errorf ("failed to read input : %s" , err )
314300 }
315301 if ! anotherExport {
316302 break
@@ -323,11 +309,11 @@ func collectIpaExportCodeSignGroups(tool Tool, archive xcarchive.IosArchive, ins
323309func collectIpaExportCertificate (tool Tool , archiveCertificate certificateutil.CertificateInfoModel , installedCertificates []certificateutil.CertificateInfoModel ) (certificateutil.CertificateInfoModel , error ) {
324310 fmt .Println ()
325311 fmt .Println ()
326- question := fmt .Sprintf (`The Xcode archive used codesigning files of team: %s - %s
312+ question := fmt .Sprintf (`The archive used codesigning files of team: %s - %s
327313Would you like to use this team to sign your project?` , archiveCertificate .TeamID , archiveCertificate .TeamName )
328314 useArchiveTeam , err := goinp .AskForBoolWithDefault (question , true )
329315 if err != nil {
330- return certificateutil.CertificateInfoModel {}, fmt .Errorf ("failed to ask : %s" , err )
316+ return certificateutil.CertificateInfoModel {}, fmt .Errorf ("failed to read input : %s" , err )
331317 }
332318
333319 selectedTeam := ""
@@ -342,7 +328,7 @@ Would you like to use this team to sign your project?`, archiveCertificate.TeamI
342328 fmt .Println ()
343329 selectedTeam , err = goinp .SelectFromStringsWithDefault ("Select the Development team to sign your project" , 1 , teams )
344330 if err != nil {
345- return certificateutil.CertificateInfoModel {}, ArchiveError { tool , fmt .Sprintf ("failed to select Codesign Indentity : %s" , err )}
331+ return certificateutil.CertificateInfoModel {}, fmt .Errorf ("failed to read input : %s" , err )
346332 }
347333 } else {
348334 selectedTeam = fmt .Sprintf ("%s - %s" , archiveCertificate .TeamID , archiveCertificate .TeamName )
@@ -367,7 +353,7 @@ Would you like to use this team to sign your project?`, archiveCertificate.TeamI
367353Please select a development certificate:` , archiveCertificate .CommonName , archiveCertificate .Serial )
368354 selectedCertificateOption , err := goinp .SelectFromStringsWithDefault (question , 1 , certificateOptions )
369355 if err != nil {
370- return certificateutil.CertificateInfoModel {}, ArchiveError { tool , fmt .Sprintf ("failed to select Codesign Indentity : %s" , err )}
356+ return certificateutil.CertificateInfoModel {}, fmt .Errorf ("failed to read input : %s" , err )
371357 }
372358
373359 for _ , certInfo := range developmentCertificates {
@@ -393,7 +379,7 @@ Please select a development certificate:`, archiveCertificate.CommonName, archiv
393379Please select a distribution certificate:` , archiveCertificate .CommonName , archiveCertificate .Serial )
394380 selectedCertificateOption , err := goinp .SelectFromStringsWithDefault (question , 1 , certificateOptions )
395381 if err != nil {
396- return certificateutil.CertificateInfoModel {}, ArchiveError { tool , fmt .Sprintf ("failed to select Codesign Indentity : %s" , err )}
382+ return certificateutil.CertificateInfoModel {}, fmt .Errorf ("failed to read input : %s" , err )
397383 }
398384
399385 for _ , certInfo := range distributionCertificates {
@@ -429,14 +415,14 @@ func collectAndExportProvisioningProfiles(profiles []profileutil.ProvisioningPro
429415 log .Printf ("searching for required Provisioning Profile: %s (UUID: %s)" , profile .Name , profile .UUID )
430416 _ , pth , err := profileutil .FindProvisioningProfileInfo (profile .UUID )
431417 if err != nil {
432- return errors .Wrap (err , "Failed to find Provisioning Profile" )
418+ return errors .Wrap (err , "failed to find Provisioning Profile" )
433419 }
434420 profilePathInfoMap [pth ] = profile
435421 log .Printf ("file found at: %s" , pth )
436422 }
437423
438424 if err := exportProvisioningProfiles (profilePathInfoMap , absExportOutputDirPath ); err != nil {
439- return fmt .Errorf ("Failed to export the Provisioning Profile into the export directory: %s" , err )
425+ return fmt .Errorf ("failed to export the Provisioning Profile into the export directory: %s" , err )
440426 }
441427
442428 return nil
@@ -466,11 +452,11 @@ func collectAndExportIdentities(certificates []certificateutil.CertificateInfoMo
466452 log .Printf ("searching for Identity: %s" , certificate .CommonName )
467453 identityRef , err := osxkeychain .FindAndValidateIdentity (certificate .CommonName )
468454 if err != nil {
469- return fmt .Errorf ("Failed to export, error: %s" , err )
455+ return fmt .Errorf ("failed to export, error: %s" , err )
470456 }
471457
472458 if identityRef == nil {
473- return errors .New ("Identity not found in the keychain, or it was invalid (expired)" )
459+ return errors .New ("identity not found in the keychain, or it was invalid (expired)" )
474460 }
475461
476462 identitiesWithKeychainRefs = append (identitiesWithKeychainRefs , * identityRef )
@@ -497,7 +483,7 @@ func collectAndExportIdentities(certificates []certificateutil.CertificateInfoMo
497483 fmt .Println ()
498484
499485 if err := osxkeychain .ExportFromKeychain (identityKechainRefs , filepath .Join (absExportOutputDirPath , "Identities.p12" ), isAskForPassword ); err != nil {
500- return fmt .Errorf ("Failed to export from Keychain: %s" , err )
486+ return fmt .Errorf ("failed to export from Keychain: %s" , err )
501487 }
502488
503489 return nil
@@ -542,7 +528,7 @@ func exportCodesignFiles(tool Tool, archivePath, outputDirPath string) error {
542528 // archive code sign settings
543529 installedCertificates , err := certificateutil .InstalledCodesigningCertificateInfos ()
544530 if err != nil {
545- return ArchiveError { tool , fmt .Sprintf ("failed to list installed code signing identities, error: %s" , err )}
531+ return fmt .Errorf ("failed to list installed code signing identities, error: %s" , err )
546532 }
547533 installedCertificates = certificateutil .FilterValidCertificateInfos (installedCertificates )
548534
@@ -553,7 +539,7 @@ func exportCodesignFiles(tool Tool, archivePath, outputDirPath string) error {
553539
554540 installedProfiles , err := profileutil .InstalledProvisioningProfileInfos (profileutil .ProfileTypeIos )
555541 if err != nil {
556- return err
542+ return fmt . Errorf ( "failed to list installed provisioning profiles, error: %s" , err )
557543 }
558544
559545 log .Debugf ("Installed profiles:" )
@@ -563,16 +549,16 @@ func exportCodesignFiles(tool Tool, archivePath, outputDirPath string) error {
563549
564550 archive , err := xcarchive .NewIosArchive (archivePath )
565551 if err != nil {
566- return ArchiveError { tool , fmt .Sprintf ("failed to analyze archive, error: %s" , err )}
552+ return fmt .Errorf ("failed to analyze archive, error: %s" , err )
567553 }
568554
569555 archiveCodeSignGroup , err := analyzeArchive (archive , installedCertificates )
570556 if err != nil {
571- return ArchiveError { tool , fmt .Sprintf ("failed to analyze the archive, error: %s" , err )}
557+ return fmt .Errorf ("failed to analyze the archive, error: %s" , err )
572558 }
573559
574560 fmt .Println ()
575- log .Infof ("Codesign settings used for Xamarin archive:" )
561+ log .Infof ("Codesign settings used for archive:" )
576562 fmt .Println ()
577563 printCodesignGroup (archiveCodeSignGroup )
578564
@@ -594,7 +580,11 @@ func exportCodesignFiles(tool Tool, archivePath, outputDirPath string) error {
594580 } else {
595581 ipaExportCodeSignGroups , err := collectIpaExportCodeSignGroups (tool , archive , installedCertificates , installedProfiles )
596582 if err != nil {
597- return ArchiveError {tool , fmt .Sprintf ("failed to collect ipa export code sign groups, error: %s" , err )}
583+ return err
584+ }
585+
586+ if len (ipaExportCodeSignGroups ) == 0 {
587+ return errors .New ("no ipa export code sign groups collected" )
598588 }
599589
600590 codeSignGroups := append (ipaExportCodeSignGroups , archiveCodeSignGroup )
@@ -605,19 +595,20 @@ func exportCodesignFiles(tool Tool, archivePath, outputDirPath string) error {
605595 }
606596
607597 if err := collectAndExportIdentities (certificatesToExport , outputDirPath ); err != nil {
608- return ArchiveError { tool , fmt . Sprintf ( "failed to export codesign identities, error: %s" , err )}
598+ return err
609599 }
610600
611601 if err := collectAndExportProvisioningProfiles (profilesToExport , outputDirPath ); err != nil {
612- return ArchiveError { tool , fmt . Sprintf ( "failed to export provisioning profiles, error: %s" , err )}
602+ return err
613603 }
614604
615605 fmt .Println ()
616606 log .Successf ("Exports finished you can find the exported files at: %s" , outputDirPath )
617607 if err := command .RunCommand ("open" , outputDirPath ); err != nil {
618608 log .Errorf ("Failed to open the export directory in Finder: %s" , outputDirPath )
609+ } else {
610+ fmt .Println ("Opened the directory in Finder." )
619611 }
620- fmt .Println ("Opened the directory in Finder." )
621612
622613 printFinished (certificatesOnly )
623614
0 commit comments