Skip to content

Commit

Permalink
Implement the new models
Browse files Browse the repository at this point in the history
  • Loading branch information
pepicrft committed Jul 20, 2024
1 parent 6b6ee0d commit ac5ab67
Show file tree
Hide file tree
Showing 5 changed files with 183 additions and 4 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,7 @@ tmp/
XcodeProj.framework.zip

!Fixtures/**/xcuserdata/

Derived/
*.xcworkspace/
*.xcodeproj/
2 changes: 2 additions & 0 deletions .mise.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[tools]
tuist = "4.21.2"
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import Foundation


/// Class representing an element that may contain other elements.
public class PBXFileSystemSynchronizedBuildFileExceptionSet: PBXObject {

Check warning on line 5 in Sources/XcodeProj/Objects/Files/PBXFileSystemSynchronizedBuildFileExceptionSet.swift

View workflow job for this annotation

GitHub Actions / Swiftlint

Type Name Violation: Type name 'PBXFileSystemSynchronizedBuildFileExceptionSet' should be between 3 and 40 characters long (type_name)

Check warning on line 5 in Sources/XcodeProj/Objects/Files/PBXFileSystemSynchronizedBuildFileExceptionSet.swift

View workflow job for this annotation

GitHub Actions / Swiftlint

Type Name Violation: Type name 'PBXFileSystemSynchronizedBuildFileExceptionSet' should be between 3 and 40 characters long (type_name)

// MARK: - Attributes

/// A list of relative paths to children subfolders for which exceptions are applied.
public var membershipExceptions: [String]?

var targetReference: PBXObjectReference

public var target: PBXTarget! {
get {
targetReference.getObject() as? PBXTarget
}
set {
targetReference = newValue.reference
}
}

// MARK: - Init

public init(target: PBXTarget, membershipExceptions: [String]) {
self.targetReference = target.reference
self.membershipExceptions = membershipExceptions
super.init()
}

// MARK: - Decodable

fileprivate enum CodingKeys: String, CodingKey {
case target
case membershipExceptions
}

public required init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
let referenceRepository = decoder.context.objectReferenceRepository
let objects = decoder.context.objects
let targetReference: String = try container.decode(.target)
self.targetReference = referenceRepository.getOrCreate(reference: targetReference, objects: objects)
self.membershipExceptions = try container.decodeIfPresent(.membershipExceptions)
try super.init(from: decoder)
}

// MARK: - Equatable

override func isEqual(to object: Any?) -> Bool {
guard let rhs = object as? PBXFrameworksBuildPhase else { return false }
return isEqual(to: rhs)
}

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,106 @@
import Foundation
import PathKit

public class PBXFileSystemSynchronizedRootGroup: PBXFileElement {}
public class PBXFileSystemSynchronizedRootGroup: PBXFileElement {

/// It maps relative paths inside the synchronized root group to a particular file type.
/// If a path doesn't have a particular file type specified, Xcode defaults to the default file type
/// based on the extension of the file.
public var explicitFileTypes: [String: String]

/// Returns the references of the exceptions.
var exceptionsReferences: [PBXObjectReference]

/** 6CEC6EEA2C4BAE2D005DD0F8 /* Test */ = {isa =
PBXFileSystemSynchronizedRootGroup;
explicitFileTypes = {}; explicitFolders = (); path = Test; sourceTree = "<group>"; }; */
/// It returns a list of exception objects that override the configuration for some children
/// in the synchronized root group.
public var exceptions: [PBXFileSystemSynchronizedBuildFileExceptionSet] {
set {
exceptionsReferences = newValue.references()
}
get {
exceptionsReferences.objects()
}
}

/// A list of relative paths to children folder whose configuration is overriden.
public var explicitFolders: [String]

/// Initializes the file element with its properties.
///
/// - Parameters:
/// - sourceTree: file source tree.
/// - path: object relative path from `sourceTree`, if different than `name`.
/// - name: object name.
/// - includeInIndex: should the IDE index the object?
/// - usesTabs: object uses tabs.
/// - indentWidth: the number of positions to indent blocks of code
/// - tabWidth: the visual width of tab characters
/// - wrapsLines: should the IDE wrap lines when editing the object?
/// - explicitFileTypes: It maps relative paths inside the synchronized root group to a particular file type.
/// - exceptions: It returns a list of exception objects that override the configuration for some children in the synchronized root group.
/// - explicitFolders: A list of relative paths to children folder whose configuration is overriden.
public init(sourceTree: PBXSourceTree? = nil,
path: String? = nil,
name: String? = nil,
includeInIndex: Bool? = nil,
usesTabs: Bool? = nil,
indentWidth: UInt? = nil,
tabWidth: UInt? = nil,
wrapsLines: Bool? = nil,
explicitFileTypes: [String: String] = [:],
exceptions: [PBXFileSystemSynchronizedBuildFileExceptionSet] = [],
explicitFolders: [String] = []) {
self.explicitFileTypes = explicitFileTypes
self.exceptionsReferences = exceptions.references()
self.explicitFolders = explicitFolders
super.init(sourceTree: sourceTree,
path: path,
name: name,
includeInIndex: includeInIndex,
usesTabs: usesTabs,
indentWidth: indentWidth,
tabWidth: tabWidth,
wrapsLines: wrapsLines)
}

// MARK: - Decodable

fileprivate enum CodingKeys: String, CodingKey {
case explicitFileTypes
case exceptions
case explicitFolders
}

public required init(from decoder: Decoder) throws {
let objects = decoder.context.objects
let objectReferenceRepository = decoder.context.objectReferenceRepository
let container = try decoder.container(keyedBy: CodingKeys.self)
self.explicitFileTypes = (try container.decodeIfPresent(.explicitFileTypes)) ?? [:]
let exceptionsReferences: [String] = (try container.decodeIfPresent(.exceptions)) ?? []
self.exceptionsReferences = exceptionsReferences.map { objectReferenceRepository.getOrCreate(reference: $0, objects: objects) }
self.explicitFolders = (try container.decodeIfPresent(.explicitFolders)) ?? []
try super.init(from: decoder)
}

// MARK: - PlistSerializable

override func plistKeyAndValue(proj: PBXProj, reference: String) throws -> (key: CommentedString, value: PlistValue) {
var dictionary: [CommentedString: PlistValue] = try super.plistKeyAndValue(proj: proj, reference: reference).value.dictionary ?? [:]
dictionary["isa"] = .string(CommentedString(type(of: self).isa))
dictionary["exceptions"] = .array(self.exceptionsReferences.map({ exceptionReference in
return .string(CommentedString(exceptionReference.value, comment: "PBXFileSystemSynchronizedBuildFileExceptionSet"))
}))
dictionary["explicitFileTypes"] = .dictionary(Dictionary(uniqueKeysWithValues: self.explicitFileTypes.map({ (relativePath, fileType) in
return (CommentedString(relativePath), .string(CommentedString(fileType)))
})))
dictionary["explicitFolders"] = .array(explicitFolders.map({ .string(CommentedString($0)) }))
return (key: CommentedString(reference,
comment: name ?? path),
value: .dictionary(dictionary))
}

override func isEqual(to object: Any?) -> Bool {
guard let rhs = object as? PBXFrameworksBuildPhase else { return false }
return isEqual(to: rhs)
}
}
20 changes: 20 additions & 0 deletions Sources/XcodeProj/Objects/Sourcery/Equality.generated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -301,3 +301,23 @@ extension XCVersionGroup {
return super.isEqual(to: rhs)
}
}


extension PBXFileSystemSynchronizedRootGroup {
/// :nodoc:
func isEqual(to rhs: PBXFileSystemSynchronizedRootGroup) -> Bool {
if explicitFileTypes != rhs.explicitFileTypes { return false }
if exceptionsReferences != rhs.exceptionsReferences { return false }
if explicitFolders != rhs.explicitFolders { return false }
return super.isEqual(to: rhs)
}
}

extension PBXFileSystemSynchronizedBuildFileExceptionSet {
/// :nodoc:
func isEqual(to rhs: PBXFileSystemSynchronizedBuildFileExceptionSet) -> Bool {
if membershipExceptions != rhs.membershipExceptions { return false }
if targetReference != rhs.targetReference { return false }
return super.isEqual(to: rhs)
}
}

0 comments on commit ac5ab67

Please sign in to comment.