@@ -3,6 +3,7 @@ package xcode
3
3
import (
4
4
"bufio"
5
5
"fmt"
6
+ "io"
6
7
"regexp"
7
8
"strings"
8
9
"time"
@@ -41,68 +42,94 @@ func parseSchemesFromXcodeOutput(xcodeOutput string) []string {
41
42
return foundSchemes
42
43
}
43
44
44
- func parseCodeSigningSettingsFromXcodeOutput (xcodeOutput string ) common.CodeSigningSettings {
45
- scanner := bufio .NewScanner (strings .NewReader (xcodeOutput ))
45
+ // ReadLongLine ...
46
+ func ReadLongLine (r * bufio.Reader ) (string , error ) {
47
+ isPrefix := true
48
+ var err error
49
+ var line , ln []byte
50
+
51
+ for isPrefix && err == nil {
52
+ line , isPrefix , err = r .ReadLine ()
53
+ ln = append (ln , line ... )
54
+ }
55
+
56
+ return string (ln ), err
57
+ }
58
+
59
+ func parseCodeSigningSettingsFromXcodeOutput (xcodeOutput string ) (common.CodeSigningSettings , error ) {
60
+ logReader := bufio .NewReader (strings .NewReader (xcodeOutput ))
46
61
47
62
identitiesMap := map [string ]common.CodeSigningIdentityInfo {}
48
63
provProfilesMap := map [string ]provprofile.ProvisioningProfileInfo {}
49
64
teamIDsMap := map [string ]interface {}{}
50
65
appBundleIDsMap := map [string ]interface {}{}
51
- for scanner .Scan () {
52
- line := scanner .Text ()
53
66
54
- // Team ID
55
- if rexp := regexp .MustCompile (`^[[:space:]]*"com.apple.developer.team-identifier" = (?P<teamid>[a-zA-Z0-9]+);$` ); rexp .MatchString (line ) {
56
- results , err := regexputil .NamedFindStringSubmatch (rexp , line )
57
- if err != nil {
58
- log .Errorf ("Failed to scan TeamID: %s" , err )
59
- continue
67
+ // scan log line by line
68
+ {
69
+ line , readErr := ReadLongLine (logReader )
70
+ for ; readErr == nil ; line , readErr = ReadLongLine (logReader ) {
71
+ // Team ID
72
+ if rexp := regexp .MustCompile (`^[[:space:]]*"com.apple.developer.team-identifier" = (?P<teamid>[a-zA-Z0-9]+);$` ); rexp .MatchString (line ) {
73
+ results , err := regexputil .NamedFindStringSubmatch (rexp , line )
74
+ if err != nil {
75
+ log .Errorf ("Failed to scan TeamID: %s" , err )
76
+ continue
77
+ }
78
+ teamIDsMap [results ["teamid" ]] = 1
60
79
}
61
- teamIDsMap [results ["teamid" ]] = 1
62
- }
63
80
64
- // App Bundle ID
65
- if rexp := regexp .MustCompile (`^[[:space:]]*"application-identifier" = "(?P<appbundleid>.+)";$` ); rexp .MatchString (line ) {
66
- results , err := regexputil .NamedFindStringSubmatch (rexp , line )
67
- if err != nil {
68
- log .Errorf ("Failed to scan App Bundle ID: %s" , err )
69
- continue
81
+ // App Bundle ID
82
+ if rexp := regexp .MustCompile (`^[[:space:]]*"application-identifier" = "(?P<appbundleid>.+)";$` ); rexp .MatchString (line ) {
83
+ results , err := regexputil .NamedFindStringSubmatch (rexp , line )
84
+ if err != nil {
85
+ log .Errorf ("Failed to scan App Bundle ID: %s" , err )
86
+ continue
87
+ }
88
+ appBundleIDsMap [results ["appbundleid" ]] = 1
70
89
}
71
- appBundleIDsMap [results ["appbundleid" ]] = 1
72
- }
73
90
74
- // Signing Identity
75
- if rexp := regexp .MustCompile (`^[[:space:]]*Signing Identity:[[:space:]]*"(?P<title>.+)"$` ); rexp .MatchString (line ) {
76
- results , err := regexputil .NamedFindStringSubmatch (rexp , line )
77
- if err != nil {
78
- log .Errorf ("Failed to scan Signing Identity title: %s" , err )
79
- continue
91
+ // Signing Identity
92
+ if rexp := regexp .MustCompile (`^[[:space:]]*Signing Identity:[[:space:]]*"(?P<title>.+)"$` ); rexp .MatchString (line ) {
93
+ results , err := regexputil .NamedFindStringSubmatch (rexp , line )
94
+ if err != nil {
95
+ log .Errorf ("Failed to scan Signing Identity title: %s" , err )
96
+ continue
97
+ }
98
+ codeSigningID := common.CodeSigningIdentityInfo {Title : results ["title" ]}
99
+ identitiesMap [codeSigningID .Title ] = codeSigningID
80
100
}
81
- codeSigningID := common.CodeSigningIdentityInfo {Title : results ["title" ]}
82
- identitiesMap [codeSigningID .Title ] = codeSigningID
83
- }
84
- // Prov. Profile - title line
85
- if rexp := regexp .MustCompile (`^[[:space:]]*Provisioning Profile:[[:space:]]*"(?P<title>.+)"$` ); rexp .MatchString (line ) {
86
- results , err := regexputil .NamedFindStringSubmatch (rexp , line )
87
- if err != nil {
88
- log .Errorf ("Failed to scan Provisioning Profile title: %s" , err )
89
- continue
90
- }
91
- tmpProvProfile := provprofile.ProvisioningProfileInfo {Title : results ["title" ]}
92
- if ! scanner .Scan () {
93
- log .Error ("Failed to scan Provisioning Profile UUID: no more lines to scan" )
94
- continue
101
+ // Prov. Profile - title line
102
+ if rexp := regexp .MustCompile (`^[[:space:]]*Provisioning Profile:[[:space:]]*"(?P<title>.+)"$` ); rexp .MatchString (line ) {
103
+ results , err := regexputil .NamedFindStringSubmatch (rexp , line )
104
+ if err != nil {
105
+ log .Errorf ("Failed to scan Provisioning Profile title: %s" , err )
106
+ continue
107
+ }
108
+ tmpProvProfile := provprofile.ProvisioningProfileInfo {Title : results ["title" ]}
109
+
110
+ // read next line
111
+ line , readErr = ReadLongLine (logReader )
112
+ if readErr != nil {
113
+ continue
114
+ }
115
+ if line == "" {
116
+ log .Error ("Failed to scan Provisioning Profile UUID: no more lines to scan" )
117
+ continue
118
+ }
119
+ provProfileUUIDLine := line
120
+
121
+ rexp = regexp .MustCompile (`^[[:space:]]*\((?P<uuid>[a-zA-Z0-9-]{36})\)` )
122
+ results , err = regexputil .NamedFindStringSubmatch (rexp , provProfileUUIDLine )
123
+ if err != nil {
124
+ log .Errorf ("Failed to scan Provisioning Profile UUID: %s | line was: %s" , err , provProfileUUIDLine )
125
+ continue
126
+ }
127
+ tmpProvProfile .UUID = results ["uuid" ]
128
+ provProfilesMap [tmpProvProfile .Title ] = tmpProvProfile
95
129
}
96
- provProfileUUIDLine := scanner .Text ()
97
-
98
- rexp = regexp .MustCompile (`^[[:space:]]*\((?P<uuid>[a-zA-Z0-9-]{36})\)` )
99
- results , err = regexputil .NamedFindStringSubmatch (rexp , provProfileUUIDLine )
100
- if err != nil {
101
- log .Errorf ("Failed to scan Provisioning Profile UUID: %s | line was: %s" , err , provProfileUUIDLine )
102
- continue
103
- }
104
- tmpProvProfile .UUID = results ["uuid" ]
105
- provProfilesMap [tmpProvProfile .Title ] = tmpProvProfile
130
+ }
131
+ if readErr != nil && readErr != io .EOF {
132
+ return common.CodeSigningSettings {}, fmt .Errorf ("Failed to scan log output, error: %s" , readErr )
106
133
}
107
134
}
108
135
@@ -122,11 +149,11 @@ func parseCodeSigningSettingsFromXcodeOutput(xcodeOutput string) common.CodeSign
122
149
ProvProfiles : provProfiles ,
123
150
TeamIDs : teamIDs ,
124
151
AppBundleIDs : appBundleIDs ,
125
- }
152
+ }, nil
126
153
}
127
154
128
- // ScanCodeSigningSettings ...
129
- func (xccmd CommandModel ) ScanCodeSigningSettings () (common. CodeSigningSettings , string , error ) {
155
+ // GenerateLog : generates the log for subsequent "Scan" call
156
+ func (xccmd CommandModel ) GenerateLog () (string , error ) {
130
157
xcoutput := ""
131
158
var err error
132
159
@@ -136,11 +163,14 @@ func (xccmd CommandModel) ScanCodeSigningSettings() (common.CodeSigningSettings,
136
163
fmt .Println ()
137
164
138
165
if err != nil {
139
- return common.CodeSigningSettings {}, xcoutput ,
140
- fmt .Errorf ("Failed to Archive, error: %s" , err )
166
+ return xcoutput , fmt .Errorf ("Failed to Archive, error: %s" , err )
141
167
}
168
+ return xcoutput , nil
169
+ }
142
170
143
- return parseCodeSigningSettingsFromXcodeOutput (xcoutput ), xcoutput , nil
171
+ // ScanCodeSigningSettings ...
172
+ func (xccmd CommandModel ) ScanCodeSigningSettings (logToScan string ) (common.CodeSigningSettings , error ) {
173
+ return parseCodeSigningSettingsFromXcodeOutput (logToScan )
144
174
}
145
175
146
176
func (xccmd CommandModel ) xcodeProjectOrWorkspaceParam () (string , error ) {
0 commit comments