forked from Carthage/Carthage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DuplicateDependency.swift
57 lines (48 loc) · 1.47 KB
/
DuplicateDependency.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/// A duplicate dependency, used in CarthageError.duplicateDependencies.
public struct DuplicateDependency: Equatable {
/// The duplicate dependency
public let dependency: Dependency
/// The locations where the dependency was found as duplicate.
public let locations: [String]
// The generated memberwise initialiser has internal access control and
// cannot be used in test cases, so we reimplement it as public. We are also
// sorting locations, which makes sure that we can match them in a
// test case.
public init(dependency: Dependency, locations: [String]) {
self.dependency = dependency
self.locations = locations.sorted(by: <)
}
}
extension DuplicateDependency: CustomStringConvertible {
public var description: String {
return "\(dependency) \(printableLocations)"
}
private var printableLocations: String {
if locations.isEmpty {
return ""
}
return "(found in "
+ locations.joined(separator: " and ")
+ ")"
}
}
extension DuplicateDependency: Comparable {
public static func < (_ lhs: DuplicateDependency, _ rhs: DuplicateDependency) -> Bool {
if lhs.description < rhs.description {
return true
}
if lhs.locations.count < rhs.locations.count {
return true
} else if lhs.locations.count > rhs.locations.count {
return false
}
for (lhsLocation, rhsLocation) in zip(lhs.locations, rhs.locations) {
if lhsLocation < rhsLocation {
return true
} else if lhsLocation > rhsLocation {
return false
}
}
return false
}
}