diff --git a/Sources/ProjectSpec/AggregateTarget.swift b/Sources/ProjectSpec/AggregateTarget.swift index e8159640..3d91ba39 100644 --- a/Sources/ProjectSpec/AggregateTarget.swift +++ b/Sources/ProjectSpec/AggregateTarget.swift @@ -62,11 +62,11 @@ extension AggregateTarget: NamedJSONDictionaryConvertible { } } -extension AggregateTarget: JSONDictionaryEncodable { - public func toJSONDictionary() -> JSONDictionary { +extension AggregateTarget: JSONEncodable { + public func toJSONValue() -> Any { var dict: JSONDictionary = [:] - let settingsDict = settings.toJSONDictionary() + let settingsDict = settings.toJSONValue() if settingsDict.count > 0 { dict["settings"] = settingsDict } @@ -81,10 +81,10 @@ extension AggregateTarget: JSONDictionaryEncodable { dict["attributes"] = attributes } if buildScripts.count > 0 { - dict["buildScripts"] = buildScripts.map { $0.toJSONDictionary() } + dict["buildScripts"] = buildScripts.map { $0.toJSONValue() } } if let scheme = scheme { - dict["scheme"] = scheme.toJSONDictionary() + dict["scheme"] = scheme.toJSONValue() } return dict diff --git a/Sources/ProjectSpec/BuildRule.swift b/Sources/ProjectSpec/BuildRule.swift index a4e4ae36..9c4e3cea 100644 --- a/Sources/ProjectSpec/BuildRule.swift +++ b/Sources/ProjectSpec/BuildRule.swift @@ -81,8 +81,8 @@ extension BuildRule: JSONObjectConvertible { } } -extension BuildRule: JSONDictionaryEncodable { - public func toJSONDictionary() -> JSONDictionary { +extension BuildRule: JSONEncodable { + public func toJSONValue() -> Any { var dict: [String: Any] = [ "outputFiles": outputFiles, "outputFilesCompilerFlags": outputFilesCompilerFlags, diff --git a/Sources/ProjectSpec/BuildScript.swift b/Sources/ProjectSpec/BuildScript.swift index 2ed00778..ed9aada8 100644 --- a/Sources/ProjectSpec/BuildScript.swift +++ b/Sources/ProjectSpec/BuildScript.swift @@ -61,8 +61,8 @@ extension BuildScript: JSONObjectConvertible { showEnvVars = jsonDictionary.json(atKeyPath: "showEnvVars") ?? true } } -extension BuildScript: JSONDictionaryEncodable { - public func toJSONDictionary() -> JSONDictionary { +extension BuildScript: JSONEncodable { + public func toJSONValue() -> Any { var dict: JSONDictionary = [:] if runOnlyWhenInstalling { diff --git a/Sources/ProjectSpec/Dependency.swift b/Sources/ProjectSpec/Dependency.swift index 8aea2f06..6ea575b6 100644 --- a/Sources/ProjectSpec/Dependency.swift +++ b/Sources/ProjectSpec/Dependency.swift @@ -81,8 +81,8 @@ extension Dependency: JSONObjectConvertible { } } -extension Dependency: JSONDictionaryEncodable { - public func toJSONDictionary() -> JSONDictionary { +extension Dependency: JSONEncodable { + public func toJSONValue() -> Any { var dict: JSONDictionary = [:] if !removeHeaders { diff --git a/Sources/ProjectSpec/DeploymentTarget.swift b/Sources/ProjectSpec/DeploymentTarget.swift index 2feff095..0968cfee 100644 --- a/Sources/ProjectSpec/DeploymentTarget.swift +++ b/Sources/ProjectSpec/DeploymentTarget.swift @@ -79,8 +79,8 @@ extension DeploymentTarget: JSONObjectConvertible { } } -extension DeploymentTarget: JSONDictionaryEncodable { - public func toJSONDictionary() -> JSONDictionary { +extension DeploymentTarget: JSONEncodable { + public func toJSONValue() -> Any { var dict: JSONDictionary = [:] if let iOS = iOS { diff --git a/Sources/ProjectSpec/Encoding.swift b/Sources/ProjectSpec/Encoding.swift index ee024177..46e1ad52 100644 --- a/Sources/ProjectSpec/Encoding.swift +++ b/Sources/ProjectSpec/Encoding.swift @@ -1,19 +1,7 @@ import Foundation import JSONUtilities -public protocol JSONDictionaryEncodable { - func toJSONDictionary() -> JSONDictionary -} - -public protocol JSONArrayEncodable { - func toJSONArray() -> JSONArray -} - -public protocol JSONPrimitiveEncodable { - func toJSONValue() -> JSONRawType -} - -public protocol JSONDynamicEncodable { +public protocol JSONEncodable { // returns JSONDictionary or JSONArray or JSONRawType func toJSONValue() -> Any } diff --git a/Sources/ProjectSpec/Plist.swift b/Sources/ProjectSpec/Plist.swift index 9140b080..e174a9ab 100644 --- a/Sources/ProjectSpec/Plist.swift +++ b/Sources/ProjectSpec/Plist.swift @@ -25,8 +25,8 @@ extension Plist: JSONObjectConvertible { } } -extension Plist: JSONDictionaryEncodable { - public func toJSONDictionary() -> JSONDictionary { +extension Plist: JSONEncodable { + public func toJSONValue() -> Any { return [ "path": path, "properties": properties diff --git a/Sources/ProjectSpec/Project.swift b/Sources/ProjectSpec/Project.swift index 63660edc..869ad3e9 100644 --- a/Sources/ProjectSpec/Project.swift +++ b/Sources/ProjectSpec/Project.swift @@ -231,14 +231,18 @@ extension BuildSettingsContainer { } } -extension Project: JSONDictionaryEncodable { +extension Project: JSONEncodable { + public func toJSONValue() -> Any { + return toJSONDictionary() + } + public func toJSONDictionary() -> JSONDictionary { var dict: JSONDictionary = [ "name": name, - "options": options.toJSONDictionary(), + "options": options.toJSONValue(), ] - let settingsDict = settings.toJSONDictionary() + let settingsDict = settings.toJSONValue() if settingsDict.count > 0 { dict["settings"] = settingsDict } @@ -256,7 +260,7 @@ extension Project: JSONDictionaryEncodable { dict["attributes"] = attributes } - let targetPairs = targets.map { ($0.name, $0.toJSONDictionary()) } + let targetPairs = targets.map { ($0.name, $0.toJSONValue()) } if targetPairs.count > 0 { dict["targets"] = Dictionary(uniqueKeysWithValues: targetPairs) } @@ -266,18 +270,18 @@ extension Project: JSONDictionaryEncodable { dict["configs"] = Dictionary(uniqueKeysWithValues: configsPairs) } - let aggregateTargetsPairs = aggregateTargets.map { ($0.name, $0.toJSONDictionary()) } + let aggregateTargetsPairs = aggregateTargets.map { ($0.name, $0.toJSONValue()) } if aggregateTargetsPairs.count > 0 { dict["aggregateTargets"] = Dictionary(uniqueKeysWithValues: aggregateTargetsPairs) } - let schemesPairs = schemes.map { ($0.name, $0.toJSONDictionary()) } + let schemesPairs = schemes.map { ($0.name, $0.toJSONValue()) } if schemesPairs.count > 0 { dict["schemes"] = Dictionary(uniqueKeysWithValues: schemesPairs) } if settingGroups.count > 0 { - dict["settingGroups"] = settingGroups.mapValues { $0.toJSONDictionary() } + dict["settingGroups"] = settingGroups.mapValues { $0.toJSONValue() } } return dict diff --git a/Sources/ProjectSpec/Scheme.swift b/Sources/ProjectSpec/Scheme.swift index 86a6acd0..25eb51da 100644 --- a/Sources/ProjectSpec/Scheme.swift +++ b/Sources/ProjectSpec/Scheme.swift @@ -218,8 +218,8 @@ extension Scheme.ExecutionAction: JSONObjectConvertible { } } -extension Scheme.ExecutionAction: JSONDictionaryEncodable { - public func toJSONDictionary() -> JSONDictionary { +extension Scheme.ExecutionAction: JSONEncodable { + public func toJSONValue() -> Any { var dict = [ "script": script, "name": name, @@ -244,20 +244,20 @@ extension Scheme.Run: JSONObjectConvertible { } } -extension Scheme.Run: JSONDictionaryEncodable { - public func toJSONDictionary() -> JSONDictionary { +extension Scheme.Run: JSONEncodable { + public func toJSONValue() -> Any { var dict: JSONDictionary = [ "commandLineArguments": commandLineArguments, ] if preActions.count > 0 { - dict["preActions"] = preActions.map { $0.toJSONDictionary() } + dict["preActions"] = preActions.map { $0.toJSONValue() } } if postActions.count > 0 { - dict["postActions"] = postActions.map { $0.toJSONDictionary() } + dict["postActions"] = postActions.map { $0.toJSONValue() } } if environmentVariables.count > 0 { - dict["environmentVariables"] = environmentVariables.map { $0.toJSONDictionary() } + dict["environmentVariables"] = environmentVariables.map { $0.toJSONValue() } } if let config = config { dict["config"] = config @@ -292,8 +292,8 @@ extension Scheme.Test: JSONObjectConvertible { } } -extension Scheme.Test: JSONDictionaryEncodable { - public func toJSONDictionary() -> JSONDictionary { +extension Scheme.Test: JSONEncodable { + public func toJSONValue() -> Any { var dict: JSONDictionary = [ "gatherCoverageData": gatherCoverageData, ] @@ -305,13 +305,13 @@ extension Scheme.Test: JSONDictionaryEncodable { dict["targets"] = targets.map { $0.toJSONValue() } } if preActions.count > 0 { - dict["preActions"] = preActions.map { $0.toJSONDictionary() } + dict["preActions"] = preActions.map { $0.toJSONValue() } } if postActions.count > 0 { - dict["postActions"] = postActions.map { $0.toJSONDictionary() } + dict["postActions"] = postActions.map { $0.toJSONValue() } } if environmentVariables.count > 0 { - dict["environmentVariables"] = environmentVariables.map { $0.toJSONDictionary() } + dict["environmentVariables"] = environmentVariables.map { $0.toJSONValue() } } if let config = config { dict["config"] = config @@ -330,7 +330,7 @@ extension Scheme.Test.TestTarget: JSONObjectConvertible { } } -extension Scheme.Test.TestTarget: JSONDynamicEncodable { +extension Scheme.Test.TestTarget: JSONEncodable { public func toJSONValue() -> Any { if !randomExecutionOrder && !parallelizable { return name @@ -362,20 +362,20 @@ extension Scheme.Profile: JSONObjectConvertible { } } -extension Scheme.Profile: JSONDictionaryEncodable { - public func toJSONDictionary() -> JSONDictionary { +extension Scheme.Profile: JSONEncodable { + public func toJSONValue() -> Any { var dict: JSONDictionary = [ "commandLineArguments": commandLineArguments, ] if preActions.count > 0 { - dict["preActions"] = preActions.map { $0.toJSONDictionary() } + dict["preActions"] = preActions.map { $0.toJSONValue() } } if postActions.count > 0 { - dict["postActions"] = postActions.map { $0.toJSONDictionary() } + dict["postActions"] = postActions.map { $0.toJSONValue() } } if environmentVariables.count > 0 { - dict["environmentVariables"] = environmentVariables.map { $0.toJSONDictionary() } + dict["environmentVariables"] = environmentVariables.map { $0.toJSONValue() } } if let config = config { dict["config"] = config @@ -392,8 +392,8 @@ extension Scheme.Analyze: JSONObjectConvertible { } } -extension Scheme.Analyze: JSONDictionaryEncodable { - public func toJSONDictionary() -> JSONDictionary { +extension Scheme.Analyze: JSONEncodable { + public func toJSONValue() -> Any { var dict: JSONDictionary = [:] if let config = config { @@ -415,18 +415,18 @@ extension Scheme.Archive: JSONObjectConvertible { } } -extension Scheme.Archive: JSONDictionaryEncodable { - public func toJSONDictionary() -> JSONDictionary { +extension Scheme.Archive: JSONEncodable { + public func toJSONValue() -> Any { var dict: JSONDictionary = [:] if !revealArchiveInOrganizer { dict["revealArchiveInOrganizer"] = revealArchiveInOrganizer } if preActions.count > 0 { - dict["preActions"] = preActions.map { $0.toJSONDictionary() } + dict["preActions"] = preActions.map { $0.toJSONValue() } } if postActions.count > 0 { - dict["postActions"] = postActions.map { $0.toJSONDictionary() } + dict["postActions"] = postActions.map { $0.toJSONValue() } } if let config = config { dict["config"] = config @@ -452,26 +452,26 @@ extension Scheme: NamedJSONDictionaryConvertible { } } -extension Scheme: JSONDictionaryEncodable { - public func toJSONDictionary() -> JSONDictionary { +extension Scheme: JSONEncodable { + public func toJSONValue() -> Any { var dict = [ - "build": build.toJSONDictionary() + "build": build.toJSONValue() ] if let run = run { - dict["run"] = run.toJSONDictionary() + dict["run"] = run.toJSONValue() } if let test = test { - dict["test"] = test.toJSONDictionary() + dict["test"] = test.toJSONValue() } if let analyze = analyze { - dict["analyze"] = analyze.toJSONDictionary() + dict["analyze"] = analyze.toJSONValue() } if let profile = profile { - dict["profile"] = profile.toJSONDictionary() + dict["profile"] = profile.toJSONValue() } if let archive = archive { - dict["archive"] = archive.toJSONDictionary() + dict["archive"] = archive.toJSONValue() } return dict @@ -510,8 +510,8 @@ extension Scheme.Build: JSONObjectConvertible { } } -extension Scheme.Build: JSONDictionaryEncodable { - public func toJSONDictionary() -> JSONDictionary { +extension Scheme.Build: JSONEncodable { + public func toJSONValue() -> Any { let targetPairs = targets.map { ($0.target, $0.buildTypes.map { $0.toJSONValue() }) } var dict: JSONDictionary = [ @@ -525,10 +525,10 @@ extension Scheme.Build: JSONDictionaryEncodable { dict["buildImplicitDependencies"] = buildImplicitDependencies } if preActions.count > 0 { - dict["preActions"] = preActions.map { $0.toJSONDictionary() } + dict["preActions"] = preActions.map { $0.toJSONValue() } } if postActions.count > 0 { - dict["postActions"] = postActions.map { $0.toJSONDictionary() } + dict["postActions"] = postActions.map { $0.toJSONValue() } } return dict @@ -555,8 +555,8 @@ extension BuildType: JSONPrimitiveConvertible { } } -extension BuildType: JSONPrimitiveEncodable { - public func toJSONValue() -> JSONRawType { +extension BuildType: JSONEncodable { + public func toJSONValue() -> Any { switch self { case .testing: return "testing" case .profiling: return "profiling" @@ -604,8 +604,8 @@ extension XCScheme.EnvironmentVariable: JSONObjectConvertible { } } -extension XCScheme.EnvironmentVariable: JSONDictionaryEncodable { - public func toJSONDictionary() -> JSONDictionary { +extension XCScheme.EnvironmentVariable: JSONEncodable { + public func toJSONValue() -> Any { return [ "variable": variable, "value": value, diff --git a/Sources/ProjectSpec/Settings.swift b/Sources/ProjectSpec/Settings.swift index d06122c7..b60268e8 100644 --- a/Sources/ProjectSpec/Settings.swift +++ b/Sources/ProjectSpec/Settings.swift @@ -106,8 +106,8 @@ public func += (lhs: inout BuildSettings, rhs: BuildSettings?) { lhs.merge(rhs) } -extension Settings: JSONDictionaryEncodable { - public func toJSONDictionary() -> JSONDictionary { +extension Settings: JSONEncodable { + public func toJSONValue() -> Any { if groups.count > 0 || configSettings.count > 0 { var dict: JSONDictionary = [:] @@ -118,7 +118,7 @@ extension Settings: JSONDictionaryEncodable { dict["groups"] = groups } if configSettings.count > 0 { - dict["configs"] = configSettings.mapValues { $0.toJSONDictionary() } + dict["configs"] = configSettings.mapValues { $0.toJSONValue() } } return dict diff --git a/Sources/ProjectSpec/SpecOptions.swift b/Sources/ProjectSpec/SpecOptions.swift index afb4a246..ce2f2e99 100644 --- a/Sources/ProjectSpec/SpecOptions.swift +++ b/Sources/ProjectSpec/SpecOptions.swift @@ -126,10 +126,10 @@ extension SpecOptions: JSONObjectConvertible { } } -extension SpecOptions: JSONDictionaryEncodable { - public func toJSONDictionary() -> JSONDictionary { +extension SpecOptions: JSONEncodable { + public func toJSONValue() -> Any { var dict: JSONDictionary = [ - "deploymentTarget": deploymentTarget.toJSONDictionary(), + "deploymentTarget": deploymentTarget.toJSONValue(), "transitivelyLinkDependencies": transitivelyLinkDependencies, "groupSortPosition": groupSortPosition.rawValue, ] diff --git a/Sources/ProjectSpec/Target.swift b/Sources/ProjectSpec/Target.swift index 820eefc7..20c272bc 100644 --- a/Sources/ProjectSpec/Target.swift +++ b/Sources/ProjectSpec/Target.swift @@ -272,8 +272,8 @@ extension LegacyTarget: JSONObjectConvertible { } } -extension LegacyTarget: JSONDictionaryEncodable { - public func toJSONDictionary() -> JSONDictionary { +extension LegacyTarget: JSONEncodable { + public func toJSONValue() -> Any { var dict: JSONDictionary = [ "toolPath": toolPath, "passSettings": passSettings, @@ -362,14 +362,14 @@ extension Target: NamedJSONDictionaryConvertible { } -extension Target: JSONDictionaryEncodable { - public func toJSONDictionary() -> JSONDictionary { +extension Target: JSONEncodable { + public func toJSONValue() -> Any { var dict: JSONDictionary = [ "type": type.name, "platform": platform.rawValue, ] - let settingsDict = settings.toJSONDictionary() + let settingsDict = settings.toJSONValue() if settingsDict.count > 0 { dict["settings"] = settingsDict } @@ -387,28 +387,28 @@ extension Target: JSONDictionaryEncodable { dict["sources"] = sources.map { $0.toJSONValue() } } if dependencies.count > 0 { - dict["dependencies"] = dependencies.map { $0.toJSONDictionary() } + dict["dependencies"] = dependencies.map { $0.toJSONValue() } } if postCompileScripts.count > 0 { - dict["postCompileScripts"] = postCompileScripts.map{ $0.toJSONDictionary() } + dict["postCompileScripts"] = postCompileScripts.map{ $0.toJSONValue() } } if preBuildScripts.count > 0 { - dict["prebuildScripts"] = preBuildScripts.map{ $0.toJSONDictionary() } + dict["prebuildScripts"] = preBuildScripts.map{ $0.toJSONValue() } } if postBuildScripts.count > 0 { - dict["postbuildScripts"] = postBuildScripts.map{ $0.toJSONDictionary() } + dict["postbuildScripts"] = postBuildScripts.map{ $0.toJSONValue() } } if buildRules.count > 0 { - dict["buildRules"] = buildRules.map{ $0.toJSONDictionary() } + dict["buildRules"] = buildRules.map{ $0.toJSONValue() } } if let deploymentTarget = deploymentTarget { dict["deploymentTarget"] = deploymentTarget.deploymentTarget } if let info = info { - dict["info"] = info.toJSONDictionary() + dict["info"] = info.toJSONValue() } if let entitlements = entitlements { - dict["entitlements"] = entitlements.toJSONDictionary() + dict["entitlements"] = entitlements.toJSONValue() } if let transitivelyLinkDependencies = transitivelyLinkDependencies { dict["transitivelyLinkDependencies"] = transitivelyLinkDependencies @@ -420,10 +420,10 @@ extension Target: JSONDictionaryEncodable { dict["requiresObjCLinking"] = requiresObjCLinking } if let scheme = scheme { - dict["scheme"] = scheme.toJSONDictionary() + dict["scheme"] = scheme.toJSONValue() } if let legacy = legacy { - dict["legacy"] = legacy.toJSONDictionary() + dict["legacy"] = legacy.toJSONValue() } return dict diff --git a/Sources/ProjectSpec/TargetScheme.swift b/Sources/ProjectSpec/TargetScheme.swift index 3dde710e..6878bf58 100644 --- a/Sources/ProjectSpec/TargetScheme.swift +++ b/Sources/ProjectSpec/TargetScheme.swift @@ -55,8 +55,8 @@ extension TargetScheme: JSONObjectConvertible { } } -extension TargetScheme: JSONDictionaryEncodable { - public func toJSONDictionary() -> JSONDictionary { +extension TargetScheme: JSONEncodable { + public func toJSONValue() -> Any { var dict: JSONDictionary = [ "gatherCoverageData": gatherCoverageData, ] @@ -71,13 +71,13 @@ extension TargetScheme: JSONDictionaryEncodable { dict["testTargets"] = testTargets.map { $0.toJSONValue() } } if environmentVariables.count > 0 { - dict["environmentVariables"] = environmentVariables.map { $0.toJSONDictionary() } + dict["environmentVariables"] = environmentVariables.map { $0.toJSONValue() } } if preActions.count > 0 { - dict["preActions"] = preActions.map { $0.toJSONDictionary() } + dict["preActions"] = preActions.map { $0.toJSONValue() } } if postActions.count > 0 { - dict["postActions"] = postActions.map { $0.toJSONDictionary() } + dict["postActions"] = postActions.map { $0.toJSONValue() } } return dict diff --git a/Sources/ProjectSpec/TargetSource.swift b/Sources/ProjectSpec/TargetSource.swift index 9b341020..a68ed31b 100644 --- a/Sources/ProjectSpec/TargetSource.swift +++ b/Sources/ProjectSpec/TargetSource.swift @@ -181,7 +181,7 @@ extension TargetSource: JSONObjectConvertible { } } -extension TargetSource: JSONDynamicEncodable { +extension TargetSource: JSONEncodable { public func toJSONValue() -> Any { var dict: JSONDictionary = [:] @@ -243,13 +243,13 @@ extension TargetSource.BuildPhase: JSONObjectConvertible { } } -extension TargetSource.BuildPhase: JSONDynamicEncodable { +extension TargetSource.BuildPhase: JSONEncodable { public func toJSONValue() -> Any { switch self { case .sources: return "sources" case .headers: return "headers" case .resources: return "resources" - case .copyFiles(let files): return ["copyFiles": files.toJSONDictionary()] + case .copyFiles(let files): return ["copyFiles": files.toJSONValue()] case .none: return "none" case .frameworks: fatalError("invalid build phase") case .runScript: fatalError("invalid build phase") @@ -267,8 +267,8 @@ extension TargetSource.BuildPhase.CopyFilesSettings: JSONObjectConvertible { } } -extension TargetSource.BuildPhase.CopyFilesSettings: JSONDictionaryEncodable { - public func toJSONDictionary() -> JSONDictionary { +extension TargetSource.BuildPhase.CopyFilesSettings: JSONEncodable { + public func toJSONValue() -> Any { return [ "destination": destination.rawValue, "subpath": subpath