|
| 1 | +/* |
| 2 | + This source file is part of the Swift.org open source project |
| 3 | + |
| 4 | + Copyright (c) 2020 Apple Inc. and the Swift project authors |
| 5 | + Licensed under Apache License v2.0 with Runtime Library Exception |
| 6 | + |
| 7 | + See http://swift.org/LICENSE.txt for license information |
| 8 | + See http://swift.org/CONTRIBUTORS.txt for Swift project authors |
| 9 | + */ |
| 10 | + |
| 11 | +import struct Foundation.Date |
| 12 | +import struct Foundation.URL |
| 13 | + |
| 14 | +import PackageModel |
| 15 | + |
| 16 | +extension JSONPackageCollectionModel { |
| 17 | + public enum V1 {} |
| 18 | +} |
| 19 | + |
| 20 | +extension JSONPackageCollectionModel.V1 { |
| 21 | + public struct Collection: Equatable, Codable { |
| 22 | + /// The name of the package collection, for display purposes only. |
| 23 | + public let name: String |
| 24 | + |
| 25 | + /// A description of the package collection. |
| 26 | + public let overview: String? |
| 27 | + |
| 28 | + /// An array of keywords that the collection is associated with. |
| 29 | + public let keywords: [String]? |
| 30 | + |
| 31 | + /// An array of package metadata objects |
| 32 | + public let packages: [JSONPackageCollectionModel.V1.Collection.Package] |
| 33 | + |
| 34 | + /// The version of the format to which the collection conforms. |
| 35 | + public let formatVersion: JSONPackageCollectionModel.FormatVersion |
| 36 | + |
| 37 | + /// The revision number of this package collection. |
| 38 | + public let revision: Int? |
| 39 | + |
| 40 | + /// The ISO 8601-formatted datetime string when the package collection was generated. |
| 41 | + public let generatedAt: Date |
| 42 | + |
| 43 | + /// The author of this package collection. |
| 44 | + public let generatedBy: Author? |
| 45 | + |
| 46 | + /// Creates a `Collection` |
| 47 | + public init( |
| 48 | + name: String, |
| 49 | + overview: String? = nil, |
| 50 | + keywords: [String]? = nil, |
| 51 | + packages: [JSONPackageCollectionModel.V1.Collection.Package], |
| 52 | + formatVersion: JSONPackageCollectionModel.FormatVersion, |
| 53 | + revision: Int? = nil, |
| 54 | + generatedAt: Date = Date(), |
| 55 | + generatedBy: Author? = nil |
| 56 | + ) { |
| 57 | + precondition(formatVersion == .v1_0, "Unsupported format version: \(formatVersion)") |
| 58 | + |
| 59 | + self.name = name |
| 60 | + self.overview = overview |
| 61 | + self.keywords = keywords |
| 62 | + self.packages = packages |
| 63 | + self.formatVersion = formatVersion |
| 64 | + self.revision = revision |
| 65 | + self.generatedAt = generatedAt |
| 66 | + self.generatedBy = generatedBy |
| 67 | + } |
| 68 | + |
| 69 | + public struct Author: Equatable, Codable { |
| 70 | + /// The author name. |
| 71 | + public let name: String |
| 72 | + |
| 73 | + /// Creates an `Author` |
| 74 | + public init(name: String) { |
| 75 | + self.name = name |
| 76 | + } |
| 77 | + } |
| 78 | + } |
| 79 | +} |
| 80 | + |
| 81 | +extension JSONPackageCollectionModel.V1.Collection { |
| 82 | + public struct Package: Equatable, Codable { |
| 83 | + /// The URL of the package. Currently only Git repository URLs are supported. |
| 84 | + public let url: Foundation.URL |
| 85 | + |
| 86 | + /// A description of the package. |
| 87 | + public let summary: String? |
| 88 | + |
| 89 | + /// An array of keywords that the package is associated with. |
| 90 | + public let keywords: [String]? |
| 91 | + |
| 92 | + /// An array of version objects representing the most recent and/or relevant releases of the package. |
| 93 | + public let versions: [JSONPackageCollectionModel.V1.Collection.Package.Version] |
| 94 | + |
| 95 | + /// The URL of the package's README. |
| 96 | + public let readmeURL: Foundation.URL? |
| 97 | + |
| 98 | + /// Creates a `Package` |
| 99 | + public init( |
| 100 | + url: URL, |
| 101 | + summary: String? = nil, |
| 102 | + keywords: [String]? = nil, |
| 103 | + versions: [JSONPackageCollectionModel.V1.Collection.Package.Version], |
| 104 | + readmeURL: URL? = nil |
| 105 | + ) { |
| 106 | + self.url = url |
| 107 | + self.summary = summary |
| 108 | + self.keywords = keywords |
| 109 | + self.versions = versions |
| 110 | + self.readmeURL = readmeURL |
| 111 | + } |
| 112 | + } |
| 113 | +} |
| 114 | + |
| 115 | +extension JSONPackageCollectionModel.V1.Collection.Package { |
| 116 | + public struct Version: Equatable, Codable { |
| 117 | + /// The semantic version string. |
| 118 | + public let version: String |
| 119 | + |
| 120 | + /// The name of the package. |
| 121 | + public let packageName: String |
| 122 | + |
| 123 | + /// An array of the package version's targets. |
| 124 | + public let targets: [JSONPackageCollectionModel.V1.Target] |
| 125 | + |
| 126 | + /// An array of the package version's products. |
| 127 | + public let products: [JSONPackageCollectionModel.V1.Product] |
| 128 | + |
| 129 | + /// The tools (semantic) version specified in `Package.swift`. |
| 130 | + public let toolsVersion: String |
| 131 | + |
| 132 | + /// An array of the package version’s supported platforms specified in `Package.swift`. |
| 133 | + public let minimumPlatformVersions: [JSONPackageCollectionModel.V1.PlatformVersion]? |
| 134 | + |
| 135 | + /// An array of platforms in which the package version has been tested and verified. |
| 136 | + public let verifiedPlatforms: [JSONPackageCollectionModel.V1.Platform]? |
| 137 | + |
| 138 | + /// An array of Swift versions that the package version has been tested and verified for. |
| 139 | + public let verifiedSwiftVersions: [String]? |
| 140 | + |
| 141 | + /// The package version's license. |
| 142 | + public let license: JSONPackageCollectionModel.V1.License? |
| 143 | + |
| 144 | + /// Creates a `Version` |
| 145 | + public init( |
| 146 | + version: String, |
| 147 | + packageName: String, |
| 148 | + targets: [JSONPackageCollectionModel.V1.Target], |
| 149 | + products: [JSONPackageCollectionModel.V1.Product], |
| 150 | + toolsVersion: String, |
| 151 | + minimumPlatformVersions: [JSONPackageCollectionModel.V1.PlatformVersion]? = nil, |
| 152 | + verifiedPlatforms: [JSONPackageCollectionModel.V1.Platform]? = nil, |
| 153 | + verifiedSwiftVersions: [String]? = nil, |
| 154 | + license: JSONPackageCollectionModel.V1.License? = nil |
| 155 | + ) { |
| 156 | + self.version = version |
| 157 | + self.packageName = packageName |
| 158 | + self.targets = targets |
| 159 | + self.products = products |
| 160 | + self.toolsVersion = toolsVersion |
| 161 | + self.minimumPlatformVersions = minimumPlatformVersions |
| 162 | + self.verifiedPlatforms = verifiedPlatforms |
| 163 | + self.verifiedSwiftVersions = verifiedSwiftVersions |
| 164 | + self.license = license |
| 165 | + } |
| 166 | + } |
| 167 | +} |
| 168 | + |
| 169 | +extension JSONPackageCollectionModel.V1 { |
| 170 | + public struct Target: Equatable, Codable { |
| 171 | + /// The target name. |
| 172 | + public let name: String |
| 173 | + |
| 174 | + /// The module name if this target can be imported as a module. |
| 175 | + public let moduleName: String? |
| 176 | + |
| 177 | + /// Creates a `Target` |
| 178 | + public init(name: String, moduleName: String? = nil) { |
| 179 | + self.name = name |
| 180 | + self.moduleName = moduleName |
| 181 | + } |
| 182 | + } |
| 183 | + |
| 184 | + public struct Product: Equatable, Codable { |
| 185 | + /// The product name. |
| 186 | + public let name: String |
| 187 | + |
| 188 | + /// The product type. |
| 189 | + public let type: ProductType |
| 190 | + |
| 191 | + /// An array of the product’s targets. |
| 192 | + public let targets: [String] |
| 193 | + |
| 194 | + /// Creates a `Product` |
| 195 | + public init( |
| 196 | + name: String, |
| 197 | + type: ProductType, |
| 198 | + targets: [String] |
| 199 | + ) { |
| 200 | + self.name = name |
| 201 | + self.type = type |
| 202 | + self.targets = targets |
| 203 | + } |
| 204 | + } |
| 205 | + |
| 206 | + public struct PlatformVersion: Equatable, Codable { |
| 207 | + /// The name of the platform (e.g., macOS, Linux, etc.). |
| 208 | + public let name: String |
| 209 | + |
| 210 | + /// The semantic version of the platform. |
| 211 | + public let version: String |
| 212 | + |
| 213 | + /// Creates a `PlatformVersion` |
| 214 | + public init(name: String, version: String) { |
| 215 | + self.name = name |
| 216 | + self.version = version |
| 217 | + } |
| 218 | + } |
| 219 | + |
| 220 | + public struct Platform: Equatable, Codable { |
| 221 | + /// The name of the platform (e.g., macOS, Linux, etc.). |
| 222 | + public let name: String |
| 223 | + |
| 224 | + /// Creates a `Platform` |
| 225 | + public init(name: String) { |
| 226 | + self.name = name |
| 227 | + } |
| 228 | + } |
| 229 | + |
| 230 | + public struct License: Equatable, Codable { |
| 231 | + /// License name (e.g., Apache-2.0, MIT, etc.) |
| 232 | + public let name: String |
| 233 | + |
| 234 | + /// The URL of the license file. |
| 235 | + public let url: URL |
| 236 | + |
| 237 | + /// Creates a `License` |
| 238 | + public init(name: String, url: URL) { |
| 239 | + self.name = name |
| 240 | + self.url = url |
| 241 | + } |
| 242 | + } |
| 243 | +} |
0 commit comments