From 415c58c5ef0b7179bce8323ccaa26a8ebf04c725 Mon Sep 17 00:00:00 2001 From: Daniel Jankowski Date: Mon, 16 Oct 2023 14:20:22 +0200 Subject: [PATCH 1/3] Add IDEActivityLogActionMessage support Signed-off-by: Daniel Jankowski --- .../activityparser/ActivityParser.swift | 21 +++++++++ .../activityparser/IDEActivityModel.swift | 45 +++++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/Sources/XCLogParser/activityparser/ActivityParser.swift b/Sources/XCLogParser/activityparser/ActivityParser.swift index 58fd3c7..b3927bc 100644 --- a/Sources/XCLogParser/activityparser/ActivityParser.swift +++ b/Sources/XCLogParser/activityparser/ActivityParser.swift @@ -234,6 +234,24 @@ public class ActivityParser { endLocation: try parseDocumentLocation(iterator: &iterator)) } + public func parseIDEActivityLogActionMessage(iterator: inout IndexingIterator<[Token]>) throws + -> IDEActivityLogActionMessage { + return IDEActivityLogActionMessage( + title: try parseAsString(token: iterator.next()), + shortTitle: try parseAsString(token: iterator.next()), + timeEmitted: try Double(parseAsInt(token: iterator.next())), + rangeEndInSectionText: try parseAsInt(token: iterator.next()), + rangeStartInSectionText: try parseAsInt(token: iterator.next()), + subMessages: try parseMessages(iterator: &iterator), + severity: Int(try parseAsInt(token: iterator.next())), + type: try parseAsString(token: iterator.next()), + location: try parseDocumentLocation(iterator: &iterator), + categoryIdent: try parseAsString(token: iterator.next()), + secondaryLocations: try parseDocumentLocations(iterator: &iterator), + additionalDescription: try parseAsString(token: iterator.next()), + action: try parseAsString(token: iterator.next())) + } + private func getTokens(_ logURL: URL, redacted: Bool, withoutBuildSpecificInformation: Bool) throws -> [Token] { @@ -337,6 +355,9 @@ public class ActivityParser { if className == String(describing: IDEActivityLogAnalyzerEventStepMessage.self) { return try parseIDEActivityLogAnalyzerEventStepMessage(iterator: &iterator) } + if className == String(describing: IDEActivityLogActionMessage.self) { + return try parseIDEActivityLogActionMessage(iterator: &iterator) + } throw XCLogParserError.parseError("Unexpected className found parsing IDEActivityLogMessage \(className)") } diff --git a/Sources/XCLogParser/activityparser/IDEActivityModel.swift b/Sources/XCLogParser/activityparser/IDEActivityModel.swift index 2a092d1..bbd1069 100644 --- a/Sources/XCLogParser/activityparser/IDEActivityModel.swift +++ b/Sources/XCLogParser/activityparser/IDEActivityModel.swift @@ -521,6 +521,51 @@ public class IDEActivityLogAnalyzerEventStepMessage: IDEActivityLogMessage { } } +public class IDEActivityLogActionMessage: IDEActivityLogMessage { + + public let action: String + + public init(title: String, + shortTitle: String, + timeEmitted: Double, + rangeEndInSectionText: UInt64, + rangeStartInSectionText: UInt64, + subMessages: [IDEActivityLogMessage], + severity: Int, + type: String, + location: DVTDocumentLocation, + categoryIdent: String, + secondaryLocations: [DVTDocumentLocation], + additionalDescription: String, + action: String) { + + self.action = action + + super.init(title: title, + shortTitle: shortTitle, + timeEmitted: timeEmitted, + rangeEndInSectionText: rangeEndInSectionText, + rangeStartInSectionText: rangeStartInSectionText, + subMessages: subMessages, + severity: severity, + type: type, + location: location, + categoryIdent: categoryIdent, + secondaryLocations: secondaryLocations, + additionalDescription: additionalDescription) + } + + private enum CodingKeys: String, CodingKey { + case action + } + + override public func encode(to encoder: Encoder) throws { + try super.encode(to: encoder) + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(action, forKey: .action) + } +} + // MARK: IDEInterfaceBuilderKit public class IBMemberID: Encodable { From d87f70a4f29311887189be39c572066d9745352f Mon Sep 17 00:00:00 2001 From: Daniel Jankowski Date: Mon, 13 Nov 2023 12:01:23 +0100 Subject: [PATCH 2/3] Add unit tests Signed-off-by: Daniel Jankowski --- .../ActivityParserTests.swift | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/Tests/XCLogParserTests/ActivityParserTests.swift b/Tests/XCLogParserTests/ActivityParserTests.swift index 8b4b9f8..30365ba 100644 --- a/Tests/XCLogParserTests/ActivityParserTests.swift +++ b/Tests/XCLogParserTests/ActivityParserTests.swift @@ -226,6 +226,22 @@ class ActivityParserTests: XCTestCase { Token.double(2.2)] }() + lazy var IDEActivityLogActionMessageTokens: [Token] = { + let startTokens = [Token.string("The identity of “XYZ.xcframework” is not recorded in your project."), + Token.null, + Token.int(9), + Token.int(18446744073709551615), + Token.int(575479851), + Token.null, + Token.int(0), + Token.null, + Token.classNameRef("DVTTextDocumentLocation")] + let endTokens = [Token.string("categoryIdent"), + Token.null, + Token.string("additionalDescription")] + return startTokens + textDocumentLocationTokens + endTokens + [Token.string("action")] + }() + func testParseDVTTextDocumentLocation() throws { let tokens = textDocumentLocationTokens var iterator = tokens.makeIterator() @@ -318,6 +334,30 @@ class ActivityParserTests: XCTestCase { } } + func testParseIDEActivityLogActionMessage() throws { + var iterator = IDEActivityLogActionMessageTokens.makeIterator() + let logActionMessage = try parser.parseIDEActivityLogActionMessage(iterator: &iterator) + XCTAssertEqual("The identity of “XYZ.xcframework” is not recorded in your project.", logActionMessage.title) + XCTAssertEqual("", logActionMessage.shortTitle) + XCTAssertEqual(9.0, logActionMessage.timeEmitted) + XCTAssertEqual(575479851, logActionMessage.rangeStartInSectionText) + XCTAssertEqual(18446744073709551615, logActionMessage.rangeEndInSectionText) + XCTAssertEqual(0, logActionMessage.subMessages.count) + XCTAssertEqual(0, logActionMessage.severity) + XCTAssertEqual("", logActionMessage.type) + XCTAssertNotNil(logActionMessage.location) + guard let documentLocation = logActionMessage.location as? DVTTextDocumentLocation else { + XCTFail("documentLocation is nil") + return + } + XCTAssertEqual(expectedDVTTextDocumentLocation.documentURLString, documentLocation.documentURLString) + XCTAssertEqual(expectedDVTTextDocumentLocation.timestamp, documentLocation.timestamp) + XCTAssertEqual("categoryIdent", logActionMessage.categoryIdent) + XCTAssertEqual(0, logActionMessage.secondaryLocations.count) + XCTAssertEqual("additionalDescription", logActionMessage.additionalDescription) + XCTAssertEqual(logActionMessage.action, "action") + } + func testParseIBDocumentMemberLocation() throws { var iterator = IBDocumentMemberLocationTokens.makeIterator() let documentLocation = try parser.parseDocumentLocation(iterator: &iterator) From 2bccaf52d591eb07e7675717068abbeba9c0ee05 Mon Sep 17 00:00:00 2001 From: Daniel Jankowski Date: Mon, 13 Nov 2023 15:46:54 +0100 Subject: [PATCH 3/3] Fix linting issue Signed-off-by: Daniel Jankowski --- Tests/XCLogParserTests/ActivityParserTests.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/Tests/XCLogParserTests/ActivityParserTests.swift b/Tests/XCLogParserTests/ActivityParserTests.swift index 30365ba..1076d13 100644 --- a/Tests/XCLogParserTests/ActivityParserTests.swift +++ b/Tests/XCLogParserTests/ActivityParserTests.swift @@ -21,6 +21,7 @@ import XCTest @testable import XCLogParser // swiftlint:disable type_body_length +// swiftlint:disable file_length class ActivityParserTests: XCTestCase { let parser = ActivityParser()