-
-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #166 from orj/main
Adds --xcworkspace-path option and "file parser"
- Loading branch information
Showing
8 changed files
with
197 additions
and
82 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
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
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
40 changes: 40 additions & 0 deletions
40
Sources/LicensePlistCore/Entity/FileReader/XcodeWorkspaceFileReader.swift
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,40 @@ | ||
import Foundation | ||
|
||
/// An object that reads a xcodeproj file. | ||
struct XcodeWorkspaceFileReader: FileReader { | ||
|
||
typealias ResultType = String? | ||
|
||
let path: URL | ||
|
||
/// The path which specifies `"*.xcworkspace"` file wrapper. | ||
var workspacePath: URL? { | ||
if path.lastPathComponent.contains("*") { | ||
// find first "xcworkspace" in directory | ||
return path.deletingLastPathComponent().lp.listDir().first { $0.pathExtension == Consts.xcworkspaceExtension } | ||
} else { | ||
// use the specified path | ||
return path | ||
} | ||
} | ||
|
||
func read() throws -> String? { | ||
guard let validatedPath = workspacePath else { return nil } | ||
|
||
if validatedPath.pathExtension != Consts.xcworkspaceExtension { | ||
return nil | ||
} | ||
|
||
let packageResolvedPath = validatedPath | ||
.appendingPathComponent("xcshareddata") | ||
.appendingPathComponent("swiftpm") | ||
.appendingPathComponent("Package.resolved") | ||
|
||
guard packageResolvedPath.lp.isExists else { | ||
return nil | ||
} | ||
|
||
return try SwiftPackageFileReader(path: packageResolvedPath).read() | ||
} | ||
|
||
} |
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
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
37 changes: 37 additions & 0 deletions
37
Tests/LicensePlistTests/Entity/FileReader/XcodeWorkspaceFileReaderTests.swift
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,37 @@ | ||
import XCTest | ||
@testable import LicensePlistCore | ||
|
||
@available(OSX 10.11, *) | ||
class XcodeWorkspaceFileReaderTests: XCTestCase { | ||
|
||
var workspaceFileURL: URL! | ||
var wildcardFileURL: URL! | ||
|
||
override func setUpWithError() throws { | ||
workspaceFileURL = URL(fileURLWithPath: "\(TestUtil.testProjectsPath)/SwiftPackageManagerTestProject/SwiftPackageManagerTestProject.xcworkspace") | ||
wildcardFileURL = URL(fileURLWithPath: "\(TestUtil.testProjectsPath)/SwiftPackageManagerTestProject/*") | ||
|
||
print("fileURL: \(String(describing: workspaceFileURL))") | ||
print("wildcardURL: \(String(describing: wildcardFileURL))") | ||
} | ||
|
||
override func tearDownWithError() throws { | ||
workspaceFileURL = nil | ||
wildcardFileURL = nil | ||
} | ||
|
||
func testProjectPathWhenSpecifiesCorrectFilePath() throws { | ||
let fileReader = XcodeWorkspaceFileReader(path: workspaceFileURL) | ||
XCTAssertEqual(fileReader.workspacePath, workspaceFileURL) | ||
} | ||
|
||
func testProjectPathWhenSpecifiesWildcard() throws { | ||
let fileReader = XcodeWorkspaceFileReader(path: wildcardFileURL) | ||
XCTAssertEqual(fileReader.workspacePath, workspaceFileURL) | ||
} | ||
|
||
func testReadNotNil() throws { | ||
let fileReader = XcodeWorkspaceFileReader(path: workspaceFileURL) | ||
XCTAssertNotNil(try fileReader.read()) | ||
} | ||
} |
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