From 5ee2c8b9e37a8041de7c54d2c6a4d2d269667c47 Mon Sep 17 00:00:00 2001 From: X-0x01 <19320096+X-0x01@users.noreply.github.com> Date: Thu, 5 May 2022 13:37:29 +0800 Subject: [PATCH 1/8] Optimize the code --- LICENSE | 2 +- README.md | 10 +-- Sources/XcodeManager/XcodeManager.swift | 76 ++++++------------- Sources/XcodeManager/XcodeManagerFile.swift | 2 +- Sources/XcodeManager/XcodeManagerJSON.swift | 2 +- Sources/XcodeManager/XcodeManagerLogger.swift | 2 +- .../XcodeManagerTests/XcodeManagerTests.swift | 8 +- 7 files changed, 36 insertions(+), 66 deletions(-) diff --git a/LICENSE b/LICENSE index d98c8e1..1794b35 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ BSD 3-Clause License -Copyright (c) 2018, ShouDong Zheng +Copyright (c) 2018, Shoudong Zheng All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/README.md b/README.md index cbde659..19e7c2c 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # XcodeManager -[![Travis CI](https://travis-ci.org/ZhengShouDong/XcodeManager.svg?branch=master)](https://travis-ci.org/ZhengShouDong/XcodeManager) [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-00D835.svg?style=flat)](https://github.com/Carthage/Carthage) [![Platform](https://img.shields.io/badge/Platform-OSX-green.svg)](https://github.com/ZhengShouDong/XcodeManager) +[![Build Status](https://app.travis-ci.com/X-0x01/XcodeManager.svg?branch=master)](https://app.travis-ci.com/X-0x01/XcodeManager) [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-00D835.svg?style=flat)](https://github.com/Carthage/Carthage) [![Platform](https://img.shields.io/badge/Platform-OSX-green.svg)](https://github.com/X-0x01/XcodeManager) The better way to manage the Xcode project file (project.pbxproj) in swift. This swift module lets you automate the modification process. @@ -14,13 +14,13 @@ This swift module lets you automate the modification process. #### Swift Package Manager ```swift -.package(url: "https://github.com/ZhengShouDong/XcodeManager.git", from: "0.2.0") +.package(url: "https://github.com/X-0x01/XcodeManager.git", from: "0.2.0") ``` #### Carthage You can use [Carthage](https://github.com/Carthage/Carthage) to install `XcodeManager` by adding it to your Cartfile: ``` -github "ZhengShouDong/XcodeManager" ~> 0.2.0 +github "X-0x01/XcodeManager" ~> 0.2.0 ``` ## Usage @@ -69,7 +69,7 @@ project.setProductName("TestProduct") 7. How to modify the Bundle Identifier? ```swift -project.setBundleId("cn.zhengshoudong.TestProduct") +project.setBundleId("cn.x0x01.TestProduct") ``` 8. How to add new value? @@ -98,4 +98,4 @@ let isSaveSuccess = try? project.save() if (isSaveSuccess) { print("Done!") } -``` \ No newline at end of file +``` diff --git a/Sources/XcodeManager/XcodeManager.swift b/Sources/XcodeManager/XcodeManager.swift index 78ddf26..797273d 100644 --- a/Sources/XcodeManager/XcodeManager.swift +++ b/Sources/XcodeManager/XcodeManager.swift @@ -1,6 +1,6 @@ // XcodeManager.swift // -// Copyright (c) 2018, ShouDong Zheng +// Copyright (c) 2018, Shoudong Zheng // All rights reserved. // Redistribution and use in source and binary forms, with or without @@ -379,7 +379,6 @@ public struct XcodeManager { for (key, value) in objects { if var obj = value.dictionaryObject { if let isa = obj["isa"] as? String { - if (isa == "PBXBuildFile") { if let fileRef = obj["fileRef"] as? String { if (fileRef == uuid) { @@ -389,9 +388,7 @@ public struct XcodeManager { } } } - } - - if (isa == "PBXFrameworksBuildPhase") { + } else if (isa == "PBXFrameworksBuildPhase") { if let fileUuids = obj["files"] as? Array { obj["files"] = fileUuids.filter{ $0 != uuid } // 移除完毕, 开始回写缓存 @@ -457,14 +454,11 @@ public struct XcodeManager { if (isa == "PBXBuildFile") { let fileRef = obj["fileRef"] as? String ?? String() if (fileRef == uuid) { - // 找到指针树,移除并回写 if let _ = objects.removeValue(forKey: key) { self._cacheProjet["objects"] = XcodeManagerJSON(objects) } } - } - - if (isa == "PBXFrameworksBuildPhase") { + } else if (isa == "PBXFrameworksBuildPhase") { let fileUuids = obj["files"] as? Array ?? Array() if (fileUuids.isEmpty) { _logger.xcodeManagerPrintLog("`files` parse error!", type: .error) @@ -472,7 +466,6 @@ public struct XcodeManager { } obj["files"] = fileUuids.filter{ $0 != uuid } - // 移除完毕, 开始回写缓存 objects[key] = XcodeManagerJSON(obj) self._cacheProjet["objects"] = XcodeManagerJSON(objects) } @@ -601,16 +594,12 @@ public struct XcodeManager { let varType = frameworkSearchPaths?.type ?? Type.unknown switch varType { case .string: - let string = frameworkSearchPaths?.string ?? String() - if (newPath == string) { + let frameworkSearchPath = frameworkSearchPaths?.string ?? String() + if (newPath == frameworkSearchPath) { _logger.xcodeManagerPrintLog("Current object already exists.") return } - var newArray = Array() - newArray.append(string) - newArray.append(newPath) - - buildSettings["FRAMEWORK_SEARCH_PATHS"] = XcodeManagerJSON(newArray) + buildSettings["FRAMEWORK_SEARCH_PATHS"] = XcodeManagerJSON([frameworkSearchPath, newPath]) dict["buildSettings"] = XcodeManagerJSON(buildSettings) self._cacheProjet["objects"][element.key] = dict break @@ -625,17 +614,12 @@ public struct XcodeManager { } newArray.append(XcodeManagerJSON(newPath)) - buildSettings["FRAMEWORK_SEARCH_PATHS"] = XcodeManagerJSON(newArray) dict["buildSettings"] = XcodeManagerJSON(buildSettings) self._cacheProjet["objects"][element.key] = dict break default: - var newArray = Array() - newArray.append("$(inherited)") - newArray.append(newPath) - - buildSettings["FRAMEWORK_SEARCH_PATHS"] = XcodeManagerJSON(newArray) + buildSettings["FRAMEWORK_SEARCH_PATHS"] = XcodeManagerJSON(["$(inherited)", newPath]) dict["buildSettings"] = XcodeManagerJSON(buildSettings) self._cacheProjet["objects"][element.key] = dict break @@ -672,22 +656,17 @@ public struct XcodeManager { let varType = librarySearchPaths?.type ?? Type.unknown switch varType { case .string: - let string = librarySearchPaths?.string ?? String() - if (newPath == string) { + let librarySearchPath = librarySearchPaths?.string ?? String() + if (newPath == librarySearchPath) { _logger.xcodeManagerPrintLog("Current object already exists.") return } - var newArray = Array() - newArray.append(string) - newArray.append(newPath) - - buildSettings["LIBRARY_SEARCH_PATHS"] = XcodeManagerJSON(newArray) + buildSettings["LIBRARY_SEARCH_PATHS"] = XcodeManagerJSON([librarySearchPath, newPath]) dict["buildSettings"] = XcodeManagerJSON(buildSettings) self._cacheProjet["objects"][element.key] = dict break case .array: var newArray = librarySearchPaths?.array ?? Array() - for ele in newArray { let str = ele.string ?? String() if (str == newPath) { @@ -696,17 +675,12 @@ public struct XcodeManager { } newArray.append(XcodeManagerJSON(newPath)) - buildSettings["LIBRARY_SEARCH_PATHS"] = XcodeManagerJSON(newArray) dict["buildSettings"] = XcodeManagerJSON(buildSettings) self._cacheProjet["objects"][element.key] = dict break default: - var newArray = Array() - newArray.append("$(inherited)") - newArray.append(newPath) - - buildSettings["LIBRARY_SEARCH_PATHS"] = XcodeManagerJSON(newArray) + buildSettings["LIBRARY_SEARCH_PATHS"] = XcodeManagerJSON(["$(inherited)", newPath]) dict["buildSettings"] = XcodeManagerJSON(buildSettings) self._cacheProjet["objects"][element.key] = dict break @@ -737,29 +711,26 @@ public struct XcodeManager { continue } - let framework_search_paths = buildSettings["FRAMEWORK_SEARCH_PATHS"] - let varType = framework_search_paths?.type ?? Type.unknown + let frameworkSearchPaths = buildSettings["FRAMEWORK_SEARCH_PATHS"] + let varType = frameworkSearchPaths?.type ?? Type.unknown switch varType { case .string: - let string = framework_search_paths?.string ?? String() - if (removePath == string) { - var newArray = Array() - newArray.append("$(inherited)") - buildSettings["FRAMEWORK_SEARCH_PATHS"] = XcodeManagerJSON(newArray) + let frameworkSearchPath = frameworkSearchPaths?.string ?? String() + if (removePath == frameworkSearchPath) { + buildSettings["FRAMEWORK_SEARCH_PATHS"] = XcodeManagerJSON(["$(inherited)"]) dict["buildSettings"] = XcodeManagerJSON(buildSettings) self._cacheProjet["objects"][element.key] = dict } break case .array: - let newArray = framework_search_paths?.array ?? Array() + let newArray = frameworkSearchPaths?.array ?? Array() let array = newArray.filter { $0.stringValue != removePath } buildSettings["FRAMEWORK_SEARCH_PATHS"] = XcodeManagerJSON(array) dict["buildSettings"] = XcodeManagerJSON(buildSettings) self._cacheProjet["objects"][element.key] = dict break default: - let newArray = ["$(inherited)"] - buildSettings["FRAMEWORK_SEARCH_PATHS"] = XcodeManagerJSON(newArray) + buildSettings["FRAMEWORK_SEARCH_PATHS"] = XcodeManagerJSON(["$(inherited)"]) dict["buildSettings"] = XcodeManagerJSON(buildSettings) self._cacheProjet["objects"][element.key] = dict break @@ -794,8 +765,8 @@ public struct XcodeManager { let varType = librarySearchPaths?.type ?? Type.unknown switch varType { case .string: - let string = librarySearchPaths?.string ?? String() - if (removePath == string) { + let librarySearchPath = librarySearchPaths?.string ?? String() + if (removePath == librarySearchPath) { buildSettings["LIBRARY_SEARCH_PATHS"] = XcodeManagerJSON(["$(inherited)"]) dict["buildSettings"] = XcodeManagerJSON(buildSettings) self._cacheProjet["objects"][element.key] = dict @@ -809,8 +780,7 @@ public struct XcodeManager { self._cacheProjet["objects"][element.key] = dict break default: - let newArray = ["$(inherited)"] - buildSettings["LIBRARY_SEARCH_PATHS"] = XcodeManagerJSON(newArray) + buildSettings["LIBRARY_SEARCH_PATHS"] = XcodeManagerJSON(["$(inherited)"]) dict["buildSettings"] = XcodeManagerJSON(buildSettings) self._cacheProjet["objects"][element.key] = dict break @@ -894,8 +864,8 @@ public struct XcodeManager { } let rootObj = objects[self._rootObjectUUID]?.dictionary ?? Dictionary() - var attributes = rootObj["attributes"]?.dictionary ?? Dictionary() - var targetAttributes = attributes["TargetAttributes"]?.dictionary ?? Dictionary() + let attributes = rootObj["attributes"]?.dictionary ?? Dictionary() + let targetAttributes = attributes["TargetAttributes"]?.dictionary ?? Dictionary() var newTargetAttributes = Dictionary() for attribute in targetAttributes { diff --git a/Sources/XcodeManager/XcodeManagerFile.swift b/Sources/XcodeManager/XcodeManagerFile.swift index 19dd6df..18045fc 100644 --- a/Sources/XcodeManager/XcodeManagerFile.swift +++ b/Sources/XcodeManager/XcodeManagerFile.swift @@ -1,6 +1,6 @@ // XcodeManagerFile.swift // -// Copyright (c) 2018, ShouDong Zheng +// Copyright (c) 2018, Shoudong Zheng // All rights reserved. // Redistribution and use in source and binary forms, with or without diff --git a/Sources/XcodeManager/XcodeManagerJSON.swift b/Sources/XcodeManager/XcodeManagerJSON.swift index d422700..2287906 100644 --- a/Sources/XcodeManager/XcodeManagerJSON.swift +++ b/Sources/XcodeManager/XcodeManagerJSON.swift @@ -1,6 +1,6 @@ // XcodeManagerJSON.swift // -// Copyright (c) 2019, ShouDong Zheng +// Copyright (c) 2019, Shoudong Zheng // All rights reserved. // Redistribution and use in source and binary forms, with or without diff --git a/Sources/XcodeManager/XcodeManagerLogger.swift b/Sources/XcodeManager/XcodeManagerLogger.swift index b8f63f8..31a25f3 100644 --- a/Sources/XcodeManager/XcodeManagerLogger.swift +++ b/Sources/XcodeManager/XcodeManagerLogger.swift @@ -1,6 +1,6 @@ // XcodeManagerLogger.swift // -// Copyright (c) 2018, ShouDong Zheng +// Copyright (c) 2018, Shoudong Zheng // All rights reserved. // Redistribution and use in source and binary forms, with or without diff --git a/Sources/XcodeManagerTests/XcodeManagerTests.swift b/Sources/XcodeManagerTests/XcodeManagerTests.swift index 4f092d6..b1b40f3 100644 --- a/Sources/XcodeManagerTests/XcodeManagerTests.swift +++ b/Sources/XcodeManagerTests/XcodeManagerTests.swift @@ -1,6 +1,6 @@ // XcodeManagerTests.swift // -// Copyright (c) 2018, ShouDong Zheng +// Copyright (c) 2018, Shoudong Zheng // All rights reserved. // Redistribution and use in source and binary forms, with or without @@ -66,10 +66,10 @@ class XcodeManagerTests: XCTestCase { // test BundleId get and set. finally, will reset func testBundleId() { let bundleId = _project!.getBundleId() - XCTAssertEqual(bundleId, "cn.zhengshoudong.iOSTestProject") + XCTAssertEqual(bundleId, "cn.x0x01.iOSTestProject") - _project!.setBundleId("cn.zhengshoudong.xxxx") - XCTAssertEqual(_project!.getBundleId(), "cn.zhengshoudong.xxxx") + _project!.setBundleId("cn.x0x01.xxxx") + XCTAssertEqual(_project!.getBundleId(), "cn.x0x01.xxxx") _project!.setBundleId(bundleId) } From 97d059602f84f0cdf25b515330ca117f1f2441e8 Mon Sep 17 00:00:00 2001 From: X-0x01 <19320096+X-0x01@users.noreply.github.com> Date: Thu, 5 May 2022 13:47:26 +0800 Subject: [PATCH 2/8] Create swift.yml --- .github/workflows/swift.yml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 .github/workflows/swift.yml diff --git a/.github/workflows/swift.yml b/.github/workflows/swift.yml new file mode 100644 index 0000000..238915d --- /dev/null +++ b/.github/workflows/swift.yml @@ -0,0 +1,19 @@ +name: Swift + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + build: + + runs-on: macos-latest + + steps: + - uses: actions/checkout@v3 + - name: Build + run: swift build -v + - name: Run tests + run: swift test -v From fd96314be314e031797c3fb303cc33a02c4afe58 Mon Sep 17 00:00:00 2001 From: X-0x01 <19320096+X-0x01@users.noreply.github.com> Date: Thu, 5 May 2022 13:53:07 +0800 Subject: [PATCH 3/8] Update swift.yml --- .github/workflows/swift.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/swift.yml b/.github/workflows/swift.yml index 238915d..461759b 100644 --- a/.github/workflows/swift.yml +++ b/.github/workflows/swift.yml @@ -15,5 +15,4 @@ jobs: - uses: actions/checkout@v3 - name: Build run: swift build -v - - name: Run tests - run: swift test -v + From 1441a668ea8744dfae84b591293492f7f4c4fa5f Mon Sep 17 00:00:00 2001 From: X-0x01 <19320096+X-0x01@users.noreply.github.com> Date: Thu, 5 May 2022 13:53:20 +0800 Subject: [PATCH 4/8] Delete .travis.yml --- .travis.yml | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 1b8f628..0000000 --- a/.travis.yml +++ /dev/null @@ -1,8 +0,0 @@ -{ - "os": "osx", - "script": [ - "swift build -c release" - ], - "language": "swift", - "osx_image": "xcode9.3" -} \ No newline at end of file From f8d1179496d256c182d1edd6af0f0b0004357032 Mon Sep 17 00:00:00 2001 From: X-0x01 <19320096+X-0x01@users.noreply.github.com> Date: Thu, 5 May 2022 13:54:00 +0800 Subject: [PATCH 5/8] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 19e7c2c..2c558e2 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # XcodeManager -[![Build Status](https://app.travis-ci.com/X-0x01/XcodeManager.svg?branch=master)](https://app.travis-ci.com/X-0x01/XcodeManager) [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-00D835.svg?style=flat)](https://github.com/Carthage/Carthage) [![Platform](https://img.shields.io/badge/Platform-OSX-green.svg)](https://github.com/X-0x01/XcodeManager) +[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-00D835.svg?style=flat)](https://github.com/Carthage/Carthage) [![Platform](https://img.shields.io/badge/Platform-OSX-green.svg)](https://github.com/X-0x01/XcodeManager) The better way to manage the Xcode project file (project.pbxproj) in swift. This swift module lets you automate the modification process. From ed58d9db6ba73a73b8ad8a9a5ef2ec234bc16df5 Mon Sep 17 00:00:00 2001 From: X-0x01 <19320096+X-0x01@users.noreply.github.com> Date: Fri, 6 May 2022 11:07:31 +0800 Subject: [PATCH 6/8] Update README.md --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2c558e2..16057d7 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ # XcodeManager -[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-00D835.svg?style=flat)](https://github.com/Carthage/Carthage) [![Platform](https://img.shields.io/badge/Platform-OSX-green.svg)](https://github.com/X-0x01/XcodeManager) +![Build Status](https://github.com/X-0x01/XcodeManager/actions/workflows/swift.yml/badge.svg?branch=master) +[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-00D835.svg?style=flat)](https://github.com/Carthage/Carthage) +[![Platform](https://img.shields.io/badge/Platform-OSX-green.svg)](https://github.com/X-0x01/XcodeManager) The better way to manage the Xcode project file (project.pbxproj) in swift. This swift module lets you automate the modification process. From c0f66d145585bd7e2f72c3756ea4ca98a7991267 Mon Sep 17 00:00:00 2001 From: X-0x01 <19320096+X-0x01@users.noreply.github.com> Date: Wed, 11 May 2022 10:52:25 +0800 Subject: [PATCH 7/8] Update XcodeManagerFile.swift --- Sources/XcodeManager/XcodeManagerFile.swift | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Sources/XcodeManager/XcodeManagerFile.swift b/Sources/XcodeManager/XcodeManagerFile.swift index 18045fc..c551d11 100644 --- a/Sources/XcodeManager/XcodeManagerFile.swift +++ b/Sources/XcodeManager/XcodeManagerFile.swift @@ -53,17 +53,16 @@ internal struct XcodeManagerFile { } let fileURL = URL(fileURLWithPath: path) - let filePathExtension = fileURL.pathExtension if (!fileURL.isFileURL || filePathExtension.isEmpty) { return defaultFileType } let type = XcodeManagerFile.fileTypeDict[filePathExtension] ?? String() - if !type.isEmpty { - return type + if type.isEmpty { + return defaultFileType } - return "unknown" + return type } } From 02f809ed755d5c79caa86304b359a71bc04b9b1a Mon Sep 17 00:00:00 2001 From: 0x973 <19320096+0x973@users.noreply.github.com> Date: Wed, 22 Jun 2022 12:01:31 +0800 Subject: [PATCH 8/8] Update README.md --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 16057d7..b8d6d02 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # XcodeManager -![Build Status](https://github.com/X-0x01/XcodeManager/actions/workflows/swift.yml/badge.svg?branch=master) +![Build Status](https://github.com/0x973/XcodeManager/actions/workflows/swift.yml/badge.svg?branch=master) [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-00D835.svg?style=flat)](https://github.com/Carthage/Carthage) -[![Platform](https://img.shields.io/badge/Platform-OSX-green.svg)](https://github.com/X-0x01/XcodeManager) +[![Platform](https://img.shields.io/badge/Platform-OSX-green.svg)](https://github.com/0x973/XcodeManager) The better way to manage the Xcode project file (project.pbxproj) in swift. This swift module lets you automate the modification process. @@ -16,13 +16,13 @@ This swift module lets you automate the modification process. #### Swift Package Manager ```swift -.package(url: "https://github.com/X-0x01/XcodeManager.git", from: "0.2.0") +.package(url: "https://github.com/0x973/XcodeManager.git", from: "0.2.0") ``` #### Carthage You can use [Carthage](https://github.com/Carthage/Carthage) to install `XcodeManager` by adding it to your Cartfile: ``` -github "X-0x01/XcodeManager" ~> 0.2.0 +github "0x973/XcodeManager" ~> 0.2.0 ``` ## Usage