Skip to content

Commit 46683e6

Browse files
authored
Support for Swift Package Manager (#88)
1 parent 98905e5 commit 46683e6

File tree

8 files changed

+113
-28
lines changed

8 files changed

+113
-28
lines changed

opds/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
Carthage
22
readium-opds.xcodeproj/xcuserdata
3+
.build/

opds/CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ All notable changes to this project will be documented in this file.
44

55
**Warning:** Features marked as *experimental* may change or be removed in a future release without notice. Use with caution.
66

7-
<!--## [Unreleased]-->
7+
## [Unreleased]
8+
9+
### Added
10+
11+
* Support for Swift Package Manager (contributed by [@stevenzeck](https://github.com/readium/r2-opds-swift/pull/88)).
812

913
## [2.0.0]
1014

opds/Package.resolved

Lines changed: 43 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

opds/Package.swift

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// swift-tools-version:5.3
2+
//
3+
// Copyright 2021 Readium Foundation. All rights reserved.
4+
// Use of this source code is governed by the BSD-style license
5+
// available in the top-level LICENSE file of the project.
6+
//
7+
8+
import PackageDescription
9+
10+
let package = Package(
11+
name: "r2-opds-swift",
12+
defaultLocalization: "en",
13+
platforms: [.iOS(.v10)],
14+
products: [
15+
.library(
16+
name: "ReadiumOPDS",
17+
targets: ["ReadiumOPDS"]
18+
),
19+
],
20+
dependencies: [
21+
.package(url: "https://github.com/cezheng/Fuzi.git", from: "3.1.3"),
22+
.package(url: "https://github.com/readium/r2-shared-swift.git", .branch("develop")),
23+
],
24+
targets: [
25+
.target(
26+
name: "ReadiumOPDS",
27+
dependencies: [
28+
"Fuzi",
29+
.product(name: "R2Shared", package: "r2-shared-swift"),
30+
],
31+
path: "./readium-opds/",
32+
exclude: ["Info.plist"]
33+
),
34+
.testTarget(
35+
name: "ReadiumOPDSTests",
36+
dependencies: ["ReadiumOPDS"],
37+
path: "./readium-opdsTests/",
38+
exclude: ["Info.plist"],
39+
resources: [
40+
.copy("Samples"),
41+
]
42+
),
43+
]
44+
)

opds/readium-opds.xcodeproj/project.pbxproj

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,15 @@
1919
/* End PBXBuildFile section */
2020

2121
/* Begin PBXFileReference section */
22-
111E54CC201BBD9700A7FE9A /* wiki_1_1.opds */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; name = wiki_1_1.opds; path = "readium-opdsTests/Samples/wiki_1_1.opds"; sourceTree = SOURCE_ROOT; };
23-
111E54D9201FC91600A7FE9A /* feedbooks_catalog.atom */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; name = feedbooks_catalog.atom; path = "readium-opdsTests/Samples/feedbooks_catalog.atom"; sourceTree = SOURCE_ROOT; };
2422
111E54DB2021022700A7FE9A /* OPDS2Parser.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OPDS2Parser.swift; sourceTree = "<group>"; };
25-
111E54DE2022812B00A7FE9A /* opds_2_0.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = opds_2_0.json; path = "readium-opdsTests/Samples/opds_2_0.json"; sourceTree = SOURCE_ROOT; };
2623
111E54E02022816000A7FE9A /* readium_opds2_0_test.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = readium_opds2_0_test.swift; sourceTree = "<group>"; };
2724
AE49834620D902710013B912 /* ParseData.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ParseData.swift; sourceTree = "<group>"; };
2825
AE6B98DF20CAB93200117197 /* OPDSParser.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OPDSParser.swift; sourceTree = "<group>"; };
2926
AED681EF20A316160090DBCD /* URLHelper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = URLHelper.swift; sourceTree = "<group>"; };
3027
CA415EC9221D5182003A0F7F /* Deprecated.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Deprecated.swift; sourceTree = "<group>"; };
3128
CA7B77CB263AB97E00260838 /* R2Shared.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = R2Shared.framework; sourceTree = BUILT_PRODUCTS_DIR; };
3229
CA7B77CF263AB98800260838 /* Fuzi.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Fuzi.framework; sourceTree = BUILT_PRODUCTS_DIR; };
30+
CAF6487D266F5CC70067D2C3 /* Samples */ = {isa = PBXFileReference; lastKnownFileType = folder; path = Samples; sourceTree = "<group>"; };
3331
F34B7E4D1FA35B7900534FD3 /* ReadiumOPDS.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = ReadiumOPDS.framework; sourceTree = BUILT_PRODUCTS_DIR; };
3432
F34B7E501FA35B7900534FD3 /* readium_opds.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = readium_opds.h; sourceTree = "<group>"; };
3533
F34B7E511FA35B7900534FD3 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
@@ -51,16 +49,6 @@
5149
/* End PBXFrameworksBuildPhase section */
5250

5351
/* Begin PBXGroup section */
54-
111E54CB201BBD7A00A7FE9A /* Samples */ = {
55-
isa = PBXGroup;
56-
children = (
57-
111E54DE2022812B00A7FE9A /* opds_2_0.json */,
58-
111E54D9201FC91600A7FE9A /* feedbooks_catalog.atom */,
59-
111E54CC201BBD9700A7FE9A /* wiki_1_1.opds */,
60-
);
61-
path = Samples;
62-
sourceTree = "<group>";
63-
};
6452
F34B7E431FA35B7900534FD3 = {
6553
isa = PBXGroup;
6654
children = (
@@ -99,7 +87,7 @@
9987
children = (
10088
111E54E02022816000A7FE9A /* readium_opds2_0_test.swift */,
10189
F34B7E5B1FA35B7900534FD3 /* readium_opds1_1_test.swift */,
102-
111E54CB201BBD7A00A7FE9A /* Samples */,
90+
CAF6487D266F5CC70067D2C3 /* Samples */,
10391
F34B7E5D1FA35B7900534FD3 /* Info.plist */,
10492
);
10593
path = "readium-opdsTests";

opds/readium-opds/OPDS1Parser.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import Fuzi
1313
import R2Shared
14+
import Foundation
1415

1516
public enum OPDS1ParserError: Error {
1617
// The title is missing from the feed.

opds/readium-opdsTests/readium_opds1_1_test.swift

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,28 @@ import R2Shared
1212

1313
@testable import ReadiumOPDS
1414

15+
#if !SWIFT_PACKAGE
16+
extension Bundle {
17+
static let module = Bundle(for: readium_opds1_1_test.self)
18+
}
19+
#endif
20+
1521
class readium_opds1_1_test: XCTestCase {
16-
var feed: Feed?
22+
var feed: Feed!
1723

1824
override func setUp() {
1925
super.setUp()
2026

2127
continueAfterFailure = false
2228

23-
let testBundle = Bundle(for: type(of: self))
24-
guard let fileURL = testBundle.url(forResource: "wiki_1_1", withExtension: "opds") else {
29+
guard let fileURL = Bundle.module.url(forResource: "Samples/wiki_1_1", withExtension: "opds") else {
2530
XCTFail("Unable to locate test file")
2631
return
2732
}
2833

2934
do {
3035
let opdsData = try Data(contentsOf: fileURL)
31-
feed = try OPDS1Parser.parse(xmlData: opdsData)
36+
feed = try OPDS1Parser.parse(xmlData: opdsData, url: URL(string: "http://test.com")!, response: HTTPURLResponse()).feed
3237
XCTAssert(feed != nil)
3338
} catch {
3439
XCTFail(error.localizedDescription)
@@ -48,16 +53,16 @@ class readium_opds1_1_test: XCTestCase {
4853
}
4954

5055
func testLinks() {
51-
XCTAssert(feed!.links.count == 4)
52-
XCTAssert(feed!.links[0].rel.count == 1 && feed!.links[0].rel[0] == "related")
53-
XCTAssert(feed!.links[1].typeLink == "application/atom+xml;profile=opds-catalog;kind=acquisition")
54-
XCTAssert(feed!.links[2].href == "/opds-catalogs/root.xml")
56+
XCTAssertEqual(feed.links.count, 4)
57+
XCTAssertEqual(feed.links[0].rels, ["related"])
58+
XCTAssertEqual(feed.links[1].type, "application/atom+xml;profile=opds-catalog;kind=acquisition")
59+
XCTAssertEqual(feed.links[2].href, "http://test.com/opds-catalogs/root.xml")
5560
// TODO: add more tests...
5661
}
5762

5863
func testPublications() {
59-
XCTAssert(feed!.publications.count == 2)
60-
XCTAssert(feed!.publications[0].metadata.multilangTitle?.singleString == "Bob, Son of Bob")
64+
XCTAssertEqual(feed.publications.count, 2)
65+
XCTAssertEqual(feed.publications[0].metadata.title, "Bob, Son of Bob")
6166
// TODO: add more tests...
6267
}
6368
}

opds/readium-opdsTests/readium_opds2_0_test.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,14 @@ class readium_opds2_0_test: XCTestCase {
1919
super.setUp()
2020
continueAfterFailure = false
2121

22-
let testBundle = Bundle(for: type(of: self))
23-
guard let fileURL = testBundle.url(forResource: "opds_2_0", withExtension: "json") else {
22+
guard let fileURL = Bundle.module.url(forResource: "Samples/opds_2_0", withExtension: "json") else {
2423
XCTFail("Unable to locate test file")
2524
return
2625
}
2726

2827
do {
2928
let opdsData = try Data(contentsOf: fileURL)
30-
feed = try OPDS2Parser.parse(jsonData: opdsData)
29+
feed = try OPDS2Parser.parse(jsonData: opdsData, url: URL(string: "http://test.com")!, response: HTTPURLResponse()).feed
3130
XCTAssert(feed != nil)
3231
} catch {
3332
XCTFail(error.localizedDescription)

0 commit comments

Comments
 (0)