Skip to content

Commit 0615500

Browse files
Merge pull request #189 from mollyIV/add-IDEActivityLogActionMessage-support
Add IDEActivityLogActionMessage support
2 parents ab34d14 + 2bccaf5 commit 0615500

File tree

3 files changed

+107
-0
lines changed

3 files changed

+107
-0
lines changed

Sources/XCLogParser/activityparser/ActivityParser.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,24 @@ public class ActivityParser {
234234
endLocation: try parseDocumentLocation(iterator: &iterator))
235235
}
236236

237+
public func parseIDEActivityLogActionMessage(iterator: inout IndexingIterator<[Token]>) throws
238+
-> IDEActivityLogActionMessage {
239+
return IDEActivityLogActionMessage(
240+
title: try parseAsString(token: iterator.next()),
241+
shortTitle: try parseAsString(token: iterator.next()),
242+
timeEmitted: try Double(parseAsInt(token: iterator.next())),
243+
rangeEndInSectionText: try parseAsInt(token: iterator.next()),
244+
rangeStartInSectionText: try parseAsInt(token: iterator.next()),
245+
subMessages: try parseMessages(iterator: &iterator),
246+
severity: Int(try parseAsInt(token: iterator.next())),
247+
type: try parseAsString(token: iterator.next()),
248+
location: try parseDocumentLocation(iterator: &iterator),
249+
categoryIdent: try parseAsString(token: iterator.next()),
250+
secondaryLocations: try parseDocumentLocations(iterator: &iterator),
251+
additionalDescription: try parseAsString(token: iterator.next()),
252+
action: try parseAsString(token: iterator.next()))
253+
}
254+
237255
private func getTokens(_ logURL: URL,
238256
redacted: Bool,
239257
withoutBuildSpecificInformation: Bool) throws -> [Token] {
@@ -337,6 +355,9 @@ public class ActivityParser {
337355
if className == String(describing: IDEActivityLogAnalyzerEventStepMessage.self) {
338356
return try parseIDEActivityLogAnalyzerEventStepMessage(iterator: &iterator)
339357
}
358+
if className == String(describing: IDEActivityLogActionMessage.self) {
359+
return try parseIDEActivityLogActionMessage(iterator: &iterator)
360+
}
340361
throw XCLogParserError.parseError("Unexpected className found parsing IDEActivityLogMessage \(className)")
341362
}
342363

Sources/XCLogParser/activityparser/IDEActivityModel.swift

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,51 @@ public class IDEActivityLogAnalyzerEventStepMessage: IDEActivityLogMessage {
521521
}
522522
}
523523

524+
public class IDEActivityLogActionMessage: IDEActivityLogMessage {
525+
526+
public let action: String
527+
528+
public init(title: String,
529+
shortTitle: String,
530+
timeEmitted: Double,
531+
rangeEndInSectionText: UInt64,
532+
rangeStartInSectionText: UInt64,
533+
subMessages: [IDEActivityLogMessage],
534+
severity: Int,
535+
type: String,
536+
location: DVTDocumentLocation,
537+
categoryIdent: String,
538+
secondaryLocations: [DVTDocumentLocation],
539+
additionalDescription: String,
540+
action: String) {
541+
542+
self.action = action
543+
544+
super.init(title: title,
545+
shortTitle: shortTitle,
546+
timeEmitted: timeEmitted,
547+
rangeEndInSectionText: rangeEndInSectionText,
548+
rangeStartInSectionText: rangeStartInSectionText,
549+
subMessages: subMessages,
550+
severity: severity,
551+
type: type,
552+
location: location,
553+
categoryIdent: categoryIdent,
554+
secondaryLocations: secondaryLocations,
555+
additionalDescription: additionalDescription)
556+
}
557+
558+
private enum CodingKeys: String, CodingKey {
559+
case action
560+
}
561+
562+
override public func encode(to encoder: Encoder) throws {
563+
try super.encode(to: encoder)
564+
var container = encoder.container(keyedBy: CodingKeys.self)
565+
try container.encode(action, forKey: .action)
566+
}
567+
}
568+
524569
// MARK: IDEInterfaceBuilderKit
525570

526571
public class IBMemberID: Encodable {

Tests/XCLogParserTests/ActivityParserTests.swift

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import XCTest
2121
@testable import XCLogParser
2222

2323
// swiftlint:disable type_body_length
24+
// swiftlint:disable file_length
2425
class ActivityParserTests: XCTestCase {
2526

2627
let parser = ActivityParser()
@@ -226,6 +227,22 @@ class ActivityParserTests: XCTestCase {
226227
Token.double(2.2)]
227228
}()
228229

230+
lazy var IDEActivityLogActionMessageTokens: [Token] = {
231+
let startTokens = [Token.string("The identity of “XYZ.xcframework” is not recorded in your project."),
232+
Token.null,
233+
Token.int(9),
234+
Token.int(18446744073709551615),
235+
Token.int(575479851),
236+
Token.null,
237+
Token.int(0),
238+
Token.null,
239+
Token.classNameRef("DVTTextDocumentLocation")]
240+
let endTokens = [Token.string("categoryIdent"),
241+
Token.null,
242+
Token.string("additionalDescription")]
243+
return startTokens + textDocumentLocationTokens + endTokens + [Token.string("action")]
244+
}()
245+
229246
func testParseDVTTextDocumentLocation() throws {
230247
let tokens = textDocumentLocationTokens
231248
var iterator = tokens.makeIterator()
@@ -318,6 +335,30 @@ class ActivityParserTests: XCTestCase {
318335
}
319336
}
320337

338+
func testParseIDEActivityLogActionMessage() throws {
339+
var iterator = IDEActivityLogActionMessageTokens.makeIterator()
340+
let logActionMessage = try parser.parseIDEActivityLogActionMessage(iterator: &iterator)
341+
XCTAssertEqual("The identity of “XYZ.xcframework” is not recorded in your project.", logActionMessage.title)
342+
XCTAssertEqual("", logActionMessage.shortTitle)
343+
XCTAssertEqual(9.0, logActionMessage.timeEmitted)
344+
XCTAssertEqual(575479851, logActionMessage.rangeStartInSectionText)
345+
XCTAssertEqual(18446744073709551615, logActionMessage.rangeEndInSectionText)
346+
XCTAssertEqual(0, logActionMessage.subMessages.count)
347+
XCTAssertEqual(0, logActionMessage.severity)
348+
XCTAssertEqual("", logActionMessage.type)
349+
XCTAssertNotNil(logActionMessage.location)
350+
guard let documentLocation = logActionMessage.location as? DVTTextDocumentLocation else {
351+
XCTFail("documentLocation is nil")
352+
return
353+
}
354+
XCTAssertEqual(expectedDVTTextDocumentLocation.documentURLString, documentLocation.documentURLString)
355+
XCTAssertEqual(expectedDVTTextDocumentLocation.timestamp, documentLocation.timestamp)
356+
XCTAssertEqual("categoryIdent", logActionMessage.categoryIdent)
357+
XCTAssertEqual(0, logActionMessage.secondaryLocations.count)
358+
XCTAssertEqual("additionalDescription", logActionMessage.additionalDescription)
359+
XCTAssertEqual(logActionMessage.action, "action")
360+
}
361+
321362
func testParseIBDocumentMemberLocation() throws {
322363
var iterator = IBDocumentMemberLocationTokens.makeIterator()
323364
let documentLocation = try parser.parseDocumentLocation(iterator: &iterator)

0 commit comments

Comments
 (0)