@@ -14,83 +14,83 @@ import SourceControl
14
14
import TSCBasic
15
15
import TSCUtility
16
16
17
- /// A downloaded artifact managed by the workspace.
18
- public struct ManagedArtifact {
19
- /// The package reference.
20
- public let packageRef : PackageReference
21
-
22
- /// The name of the binary target the artifact corresponds to.
23
- public let targetName : String
24
-
25
- /// The source of the artifact (local or remote).
26
- public let source : Source
27
-
28
- /// The path of the artifact on disk
29
- public let path : AbsolutePath
30
-
31
- public init (
32
- packageRef: PackageReference ,
33
- targetName: String ,
34
- source: Source ,
35
- path: AbsolutePath
36
- ) {
37
- self . packageRef = packageRef
38
- self . targetName = targetName
39
- self . source = source
40
- self . path = path
41
- }
17
+ extension Workspace {
18
+ /// A downloaded artifact managed by the workspace.
19
+ public struct ManagedArtifact {
20
+ /// The package reference.
21
+ public let packageRef : PackageReference
22
+
23
+ /// The name of the binary target the artifact corresponds to.
24
+ public let targetName : String
25
+
26
+ /// The source of the artifact (local or remote).
27
+ public let source : Source
28
+
29
+ /// The path of the artifact on disk
30
+ public let path : AbsolutePath
31
+
32
+ public init (
33
+ packageRef: PackageReference ,
34
+ targetName: String ,
35
+ source: Source ,
36
+ path: AbsolutePath
37
+ ) {
38
+ self . packageRef = packageRef
39
+ self . targetName = targetName
40
+ self . source = source
41
+ self . path = path
42
+ }
42
43
43
- /// Create an artifact downloaded from a remote url.
44
- public static func remote(
45
- packageRef: PackageReference ,
46
- targetName: String ,
47
- url: String ,
48
- checksum: String ,
49
- path: AbsolutePath
50
- ) -> ManagedArtifact {
51
- return ManagedArtifact (
52
- packageRef: packageRef,
53
- targetName: targetName,
54
- source: . remote( url: url, checksum: checksum) ,
55
- path: path
56
- )
57
- }
44
+ /// Create an artifact downloaded from a remote url.
45
+ public static func remote(
46
+ packageRef: PackageReference ,
47
+ targetName: String ,
48
+ url: String ,
49
+ checksum: String ,
50
+ path: AbsolutePath
51
+ ) -> ManagedArtifact {
52
+ return ManagedArtifact (
53
+ packageRef: packageRef,
54
+ targetName: targetName,
55
+ source: . remote( url: url, checksum: checksum) ,
56
+ path: path
57
+ )
58
+ }
58
59
59
- /// Create an artifact present locally on the filesystem.
60
- public static func local(
61
- packageRef: PackageReference ,
62
- targetName: String ,
63
- path: AbsolutePath
64
- ) -> ManagedArtifact {
65
- return ManagedArtifact (
66
- packageRef: packageRef,
67
- targetName: targetName,
68
- source: . local,
69
- path: path
70
- )
71
- }
60
+ /// Create an artifact present locally on the filesystem.
61
+ public static func local(
62
+ packageRef: PackageReference ,
63
+ targetName: String ,
64
+ path: AbsolutePath
65
+ ) -> ManagedArtifact {
66
+ return ManagedArtifact (
67
+ packageRef: packageRef,
68
+ targetName: targetName,
69
+ source: . local,
70
+ path: path
71
+ )
72
+ }
72
73
73
- /// Represents the source of the artifact.
74
- public enum Source : Equatable {
74
+ /// Represents the source of the artifact.
75
+ public enum Source : Equatable {
75
76
76
- /// Represents a remote artifact, with the url it was downloaded from, its checksum, and its path relative to
77
- /// the workspace artifacts path.
78
- case remote( url: String , checksum: String )
77
+ /// Represents a remote artifact, with the url it was downloaded from, its checksum, and its path relative to
78
+ /// the workspace artifacts path.
79
+ case remote( url: String , checksum: String )
79
80
80
- /// Represents a locally available artifact, with its path relative to its package.
81
- case local
81
+ /// Represents a locally available artifact, with its path relative to its package.
82
+ case local
83
+ }
82
84
}
83
85
}
84
86
85
- // MARK: - CustomStringConvertible
86
-
87
- extension ManagedArtifact : CustomStringConvertible {
87
+ extension Workspace . ManagedArtifact : CustomStringConvertible {
88
88
public var description : String {
89
89
return " <ManagedArtifact: \( self . packageRef. name) . \( self . targetName) \( self . source) \( self . path) > "
90
90
}
91
91
}
92
92
93
- extension ManagedArtifact . Source : CustomStringConvertible {
93
+ extension Workspace . ManagedArtifact . Source : CustomStringConvertible {
94
94
public var description : String {
95
95
switch self {
96
96
case . local:
@@ -101,42 +101,42 @@ extension ManagedArtifact.Source: CustomStringConvertible {
101
101
}
102
102
}
103
103
104
- // MARK: -
104
+ // MARK: - ManagedArtifacts
105
105
106
- /// A collection of managed artifacts which have been downloaded.
107
- public final class ManagedArtifacts {
106
+ extension Workspace {
107
+ /// A collection of managed artifacts which have been downloaded.
108
+ public final class ManagedArtifacts {
108
109
109
- /// A mapping from package url, to target name, to ManagedArtifact.
110
- private var artifactMap : [ String : [ String : ManagedArtifact ] ]
110
+ /// A mapping from package url, to target name, to ManagedArtifact.
111
+ private var artifactMap : [ String : [ String : ManagedArtifact ] ]
111
112
112
- internal var artifacts : AnyCollection < ManagedArtifact > {
113
- AnyCollection ( artifactMap. values. lazy. flatMap ( { $0. values } ) )
114
- }
113
+ internal var artifacts : AnyCollection < ManagedArtifact > {
114
+ AnyCollection ( artifactMap. values. lazy. flatMap ( { $0. values } ) )
115
+ }
115
116
116
- init ( artifactMap: [ String : [ String : ManagedArtifact ] ] = [ : ] ) {
117
- self . artifactMap = artifactMap
118
- }
117
+ init ( artifactMap: [ String : [ String : ManagedArtifact ] ] = [ : ] ) {
118
+ self . artifactMap = artifactMap
119
+ }
119
120
120
- public subscript( packageURL packageURL: String , targetName targetName: String ) -> ManagedArtifact ? {
121
- artifactMap [ packageURL] ? [ targetName]
122
- }
121
+ public subscript( packageURL packageURL: String , targetName targetName: String ) -> ManagedArtifact ? {
122
+ artifactMap [ packageURL] ? [ targetName]
123
+ }
123
124
124
- public subscript( packageName packageName: String , targetName targetName: String ) -> ManagedArtifact ? {
125
- artifacts. first ( where: { $0. packageRef. name == packageName && $0. targetName == targetName } )
126
- }
125
+ public subscript( packageName packageName: String , targetName targetName: String ) -> ManagedArtifact ? {
126
+ artifacts. first ( where: { $0. packageRef. name == packageName && $0. targetName == targetName } )
127
+ }
127
128
128
- public func add( _ artifact: ManagedArtifact ) {
129
- artifactMap [ artifact. packageRef. location, default: [ : ] ] [ artifact. targetName] = artifact
130
- }
129
+ public func add( _ artifact: ManagedArtifact ) {
130
+ artifactMap [ artifact. packageRef. location, default: [ : ] ] [ artifact. targetName] = artifact
131
+ }
131
132
132
- public func remove( packageURL: String , targetName: String ) {
133
- artifactMap [ packageURL] ? [ targetName] = nil
133
+ public func remove( packageURL: String , targetName: String ) {
134
+ artifactMap [ packageURL] ? [ targetName] = nil
135
+ }
134
136
}
135
137
}
136
138
137
- // MARK: - Collection
138
-
139
- extension ManagedArtifacts : Collection {
139
+ extension Workspace . ManagedArtifacts : Collection {
140
140
public var startIndex : AnyIndex {
141
141
artifacts. startIndex
142
142
}
@@ -145,7 +145,7 @@ extension ManagedArtifacts: Collection {
145
145
artifacts. endIndex
146
146
}
147
147
148
- public subscript( index: AnyIndex ) -> ManagedArtifact {
148
+ public subscript( index: AnyIndex ) -> Workspace . ManagedArtifact {
149
149
artifacts [ index]
150
150
}
151
151
@@ -154,9 +154,7 @@ extension ManagedArtifacts: Collection {
154
154
}
155
155
}
156
156
157
- // MARK: - CustomStringConvertible
158
-
159
- extension ManagedArtifacts : CustomStringConvertible {
157
+ extension Workspace . ManagedArtifacts : CustomStringConvertible {
160
158
public var description : String {
161
159
" <ManagedArtifacts: \( Array ( artifacts) ) > "
162
160
}
0 commit comments