-
-
Notifications
You must be signed in to change notification settings - Fork 301
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Pedro Piñera
committed
Jan 6, 2019
1 parent
f363129
commit 8d1e856
Showing
4 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "https://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>BuildSystemType</key> | ||
<string>Original</string> | ||
</dict> | ||
</plist> |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import Foundation | ||
import PathKit | ||
|
||
public enum WorkspaceSettingsError: Error { | ||
/// thrown when the settings file was not found. | ||
case notFound(path: Path) | ||
} | ||
|
||
/// It represents the WorkspaceSettings.xcsettings file under a workspace data directory. | ||
public class WorkspaceSettings: Decodable { | ||
/// Workspace build system. | ||
public let buildSystem: String? | ||
|
||
/// Decodable coding keys. | ||
/// | ||
/// - buildSystem: Build system. | ||
enum CodingKeys: String, CodingKey { | ||
case buildSystem = "BuildSystemType" | ||
} | ||
|
||
/// Initializes the settings reading the values from the WorkspaceSettings.xcsettings file. | ||
/// | ||
/// - Parameter path: Path to the WorkspaceSettings.xcsettings | ||
/// - Returns: The initialized workspace settings. | ||
/// - Throws: An error if the file doesn't exist or has an invalid format. | ||
public static func at(path: Path) throws -> WorkspaceSettings { | ||
if !path.exists { | ||
throw WorkspaceSettingsError.notFound(path: path) | ||
} | ||
let data = try Data(contentsOf: path.url) | ||
let plistDecoder = PropertyListDecoder() | ||
return try plistDecoder.decode(WorkspaceSettings.self, from: data) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import Foundation | ||
import PathKit | ||
import XCTest | ||
|
||
@testable import xcodeproj | ||
|
||
final class WorkspaceSettingsTests: XCTestCase { | ||
func test_init() throws { | ||
let path = fixturesPath() + "WorkspaceSettings.xcsettings" | ||
let got = try WorkspaceSettings.at(path: path) | ||
XCTAssertEqual(got.buildSystem, "Original") | ||
} | ||
} |