diff --git a/Sources/ProjectSpec/Plist.swift b/Sources/ProjectSpec/Plist.swift index 252d3f64..90904c4f 100644 --- a/Sources/ProjectSpec/Plist.swift +++ b/Sources/ProjectSpec/Plist.swift @@ -4,16 +4,16 @@ import JSONUtilities public struct Plist: Equatable { public let path: String - public let attributes: [String: Any] + public let properties: [String: Any] public init(path: String, attributes: [String: Any] = [:]) { self.path = path - self.attributes = attributes + self.properties = attributes } public static func == (lhs: Plist, rhs: Plist) -> Bool { return lhs.path == rhs.path && - NSDictionary(dictionary: lhs.attributes).isEqual(to: rhs.attributes) + NSDictionary(dictionary: lhs.properties).isEqual(to: rhs.properties) } } @@ -21,6 +21,6 @@ extension Plist: JSONObjectConvertible { public init(jsonDictionary: JSONDictionary) throws { path = try jsonDictionary.json(atKeyPath: "path") - attributes = jsonDictionary.json(atKeyPath: "attributes") ?? [:] + properties = jsonDictionary.json(atKeyPath: "properties") ?? [:] } } diff --git a/Sources/XcodeGenKit/InfoPlistGenerator.swift b/Sources/XcodeGenKit/InfoPlistGenerator.swift index b2725a31..0c4536cc 100644 --- a/Sources/XcodeGenKit/InfoPlistGenerator.swift +++ b/Sources/XcodeGenKit/InfoPlistGenerator.swift @@ -20,7 +20,7 @@ public class InfoPlistGenerator { return dictionary }() - public func generateAttributes(target: Target) -> [String: Any] { + public func generateProperties(target: Target) -> [String: Any] { var targetInfoPlist = defaultInfoPlist switch target.type { case .uiTestBundle, diff --git a/Sources/XcodeGenKit/ProjectWriter.swift b/Sources/XcodeGenKit/ProjectWriter.swift index fad938d7..84ef2a59 100644 --- a/Sources/XcodeGenKit/ProjectWriter.swift +++ b/Sources/XcodeGenKit/ProjectWriter.swift @@ -30,22 +30,22 @@ public class ProjectWriter { for target in project.targets { // write Info.plist if let plist = target.info { - let path = project.basePath + plist.path - let attributes = infoPlistGenerator.generateAttributes(target: target).merged(plist.attributes) - let data = try PropertyListSerialization.data(fromPropertyList: attributes, format: .xml, options: 0) - try? path.delete() - try path.parent().mkpath() - try path.write(data) + let properties = infoPlistGenerator.generateProperties(target: target).merged(plist.properties) + try writePlist(properties, path: plist.path) } // write entitlements if let plist = target.entitlements { - let path = project.basePath + plist.path - let data = try PropertyListSerialization.data(fromPropertyList: plist.attributes, format: .xml, options: 0) - try? path.delete() - try path.parent().mkpath() - try path.write(data) + try writePlist(plist.properties, path: plist.path) } } } + + private func writePlist(_ plist: [String: Any], path: String) throws { + let path = project.basePath + path + let data = try PropertyListSerialization.data(fromPropertyList: plist, format: .xml, options: 0) + try? path.delete() + try path.parent().mkpath() + try path.write(data) + } } diff --git a/Tests/Fixtures/TestProject/project.yml b/Tests/Fixtures/TestProject/project.yml index 5c561607..f01ae1ad 100644 --- a/Tests/Fixtures/TestProject/project.yml +++ b/Tests/Fixtures/TestProject/project.yml @@ -28,7 +28,7 @@ targets: platform: macOS info: path: App_macOS/Info.plist - attributes: + properties: LSMinimumSystemVersion: $(MACOSX_DEPLOYMENT_TARGET) NSMainStoryboardFile: Main NSPrincipalClass: NSApplication diff --git a/Tests/XcodeGenKitTests/SpecLoadingTests.swift b/Tests/XcodeGenKitTests/SpecLoadingTests.swift index b15b3339..e6c731f4 100644 --- a/Tests/XcodeGenKitTests/SpecLoadingTests.swift +++ b/Tests/XcodeGenKitTests/SpecLoadingTests.swift @@ -159,7 +159,7 @@ class SpecLoadingTests: XCTestCase { var targetDictionary = validTarget targetDictionary["info"] = [ "path": "Info.plist", - "attributes": [ + "properties": [ "CFBundleName": "MyAppName", "UIBackgroundModes": ["fetch"] ] @@ -176,7 +176,7 @@ class SpecLoadingTests: XCTestCase { var targetDictionary = validTarget targetDictionary["entitlements"] = [ "path": "app.entitlements", - "attributes": [ + "properties": [ "com.apple.security.application-groups": "com.group", ] ]