Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add IDEActivityLogActionMessage support #189

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions Sources/XCLogParser/activityparser/ActivityParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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] {
Expand Down Expand Up @@ -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)")
}

Expand Down
45 changes: 45 additions & 0 deletions Sources/XCLogParser/activityparser/IDEActivityModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
41 changes: 41 additions & 0 deletions Tests/XCLogParserTests/ActivityParserTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import XCTest
@testable import XCLogParser

// swiftlint:disable type_body_length
// swiftlint:disable file_length
class ActivityParserTests: XCTestCase {

let parser = ActivityParser()
Expand Down Expand Up @@ -226,6 +227,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()
Expand Down Expand Up @@ -318,6 +335,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)
Expand Down