Skip to content
This repository has been archived by the owner on Nov 3, 2020. It is now read-only.

Pod Deintegrate #296

Merged
merged 5 commits into from
Apr 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
## master

* Deintegrate CocoaPods from a project
[Nate West](https://github.com/nwest)
[#296](https://github.com/CocoaPods/CocoaPods-app/pull/296)

* Pod Repo Source Management, both in the Podfile Editor, and in the Main Menu
[orta](https://github.com/orta)
[#294](https://github.com/CocoaPods/CocoaPods-app/pull/294)


## [1.0.0.beta.8 2016.05.19](https://github.com/CocoaPods/CocoaPods-app/releases/tag/1.0.0.beta.8)

* Re-designed Home Window
Expand Down
4 changes: 4 additions & 0 deletions app/CocoaPods.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
E72E9FDC1C6E38B400A8705B /* CocoaPodsTests-Bridging-Header.h in Sources */ = {isa = PBXBuildFile; fileRef = E72E9FDB1C6E379200A8705B /* CocoaPodsTests-Bridging-Header.h */; };
E72E9FDE1C6E459800A8705B /* CPTestHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = E72E9FDD1C6E459800A8705B /* CPTestHelper.swift */; };
E72E9FDF1C6E4DC900A8705B /* CPTestHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = E72E9FDD1C6E459800A8705B /* CPTestHelper.swift */; };
E7ACFDBE1CCAA26C00475976 /* CPDeintegrateController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E7ACFDBD1CCAA26C00475976 /* CPDeintegrateController.swift */; };
FA16FAD21C144BF300DC3791 /* URLHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA16FAD11C144BF300DC3791 /* URLHandler.swift */; };
FCDCC48F0E8CE099C20D1DEB /* Pods_CocoaPodsTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 62FB6E124C8280A7EBFD41C6 /* Pods_CocoaPodsTests.framework */; };
/* End PBXBuildFile section */
Expand Down Expand Up @@ -297,6 +298,7 @@
E72E9FD91C6E328C00A8705B /* CPStringArrayToSentenceValueTransformerSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CPStringArrayToSentenceValueTransformerSpec.swift; sourceTree = "<group>"; };
E72E9FDB1C6E379200A8705B /* CocoaPodsTests-Bridging-Header.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "CocoaPodsTests-Bridging-Header.h"; sourceTree = "<group>"; };
E72E9FDD1C6E459800A8705B /* CPTestHelper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CPTestHelper.swift; sourceTree = "<group>"; };
E7ACFDBD1CCAA26C00475976 /* CPDeintegrateController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CPDeintegrateController.swift; sourceTree = "<group>"; };
EBD9373107B77CCDFCD43B67 /* Pods-CocoaPods.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-CocoaPods.release.xcconfig"; path = "Pods/Target Support Files/Pods-CocoaPods/Pods-CocoaPods.release.xcconfig"; sourceTree = "<group>"; };
EEB7DFACCFDF9B3B443AF311 /* Pods_CocoaPods.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_CocoaPods.framework; sourceTree = BUILT_PRODUCTS_DIR; };
FA16FAD11C144BF300DC3791 /* URLHandler.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = URLHandler.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -618,6 +620,7 @@
934FF1881C4F1E2A000B4302 /* CPDocumentController.swift */,
657841C81C6BE0EC00B6671E /* CPPodfileInitController.swift */,
60C2CBF31CC25D5A009B30CA /* CPSparkleDelegate.swift */,
E7ACFDBD1CCAA26C00475976 /* CPDeintegrateController.swift */,
);
name = "Home Window";
sourceTree = "<group>";
Expand Down Expand Up @@ -1009,6 +1012,7 @@
60227EC21C351A6300A29515 /* CPPodfilePluginCoordinator.swift in Sources */,
602D84551CC58B5100EE3076 /* CPSourceRepoCoordinator.swift in Sources */,
601ACAA61C392BDD0058FA86 /* NSArray+Helpers.m in Sources */,
E7ACFDBE1CCAA26C00475976 /* CPDeintegrateController.swift in Sources */,
60E693B01C4A3AF80058DF5F /* NSAttributedString+Helpers.m in Sources */,
6035BFF01C07C916003250A8 /* CPHiddenTabViewController.swift in Sources */,
60227EC41C351A7700A29515 /* CPInstallPluginsViewController.swift in Sources */,
Expand Down
7 changes: 7 additions & 0 deletions app/CocoaPods/Base.lproj/MainMenu.xib
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,13 @@
</items>
</menu>
</menuItem>
<menuItem isSeparatorItem="YES" id="wV5-hB-goc"/>
<menuItem title="Remove CocoaPods from a Project…" id="fXB-fZ-GrP">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="removeCocoaPodsFromProject:" target="Qtz-kf-riq" id="Bd7-DP-sNv"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="m54-Is-iLE"/>
<menuItem title="Close" keyEquivalent="w" id="DVo-aG-piG">
<connections>
Expand Down
54 changes: 54 additions & 0 deletions app/CocoaPods/CPDeintegrateController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import Foundation

public enum CPDeintegrateErrors: ErrorType {
case CommandError(String)

var message: String {
switch self {
case .CommandError(let s): return s
}
}
}

class CPDeintegrateController: NSObject, CPCLITaskDelegate {
let xcodeprojURL: NSURL
private let completionHandler: (CPDeintegrateErrors?) -> ()
private var task: CPCLITask!
private let output = NSMutableAttributedString()

init(xcodeprojURL: NSURL, completionHandler: (error: CPDeintegrateErrors?) -> ()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

init should be public if we're making the class and other methods public

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've not been bothering with public at all so far, don't have a strong opinion either way 👍

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took it out. This was mostly because I was looking at CPPodfileInitController.

self.xcodeprojURL = xcodeprojURL
self.completionHandler = completionHandler
super.init()
self.task = CPCLITask(workingDirectory: xcodeprojURL.URLByDeletingLastPathComponent!.path,
command: "deintegrate",
delegate: self,
qualityOfService: .UserInitiated)
self.task.run()
}

func task(task: CPCLITask!, didUpdateOutputContents updatedOutput: NSAttributedString!) {
output.appendAttributedString(updatedOutput)
}

func taskCompleted(task: CPCLITask!) {
guard task.finishedSuccessfully() else {
self.callbackWithError(CPDeintegrateErrors.CommandError(self.output.string))
return
}

callbackWithSuccess()
}

private func callbackWithError(error: CPDeintegrateErrors) {
dispatch_async(dispatch_get_main_queue()) {
self.completionHandler(error)
}
}

private func callbackWithSuccess() {
dispatch_async(dispatch_get_main_queue()) {
self.completionHandler(nil)
}
}
}
67 changes: 52 additions & 15 deletions app/CocoaPods/CPDocumentController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class CPDocumentController: NSDocumentController {
static let ClearRecentDocumentsNotification = "CPDocumentControllerClearRecentDocumentsNotification"

var podInitController: CPPodfileInitController?
var deintegrateController: CPDeintegrateController?

// All of the `openDocument...` calls end up calling this one method, so adding our notification here is simple

Expand All @@ -23,28 +24,64 @@ class CPDocumentController: NSDocumentController {
}
}

override func newDocument(sender: AnyObject?) {
func selectXcodeproj(completion: NSURL? -> Void) {
let openPanel = NSOpenPanel()
openPanel.allowsMultipleSelection = false
openPanel.allowedFileTypes = ["xcodeproj"]

openPanel.beginWithCompletionHandler { buttonIndex in
guard buttonIndex == NSFileHandlingPanelOKButton else { return }
guard let fileURL = openPanel.URL else { return }

self.podInitController = CPPodfileInitController(xcodeprojURL: fileURL, completionHandler: { podfileURL, error -> () in
guard let podfileURL = podfileURL else {
let alert = NSAlert(error: error! as NSError)
alert.informativeText = error!.message
alert.runModal()

return
}
self.openDocumentWithContentsOfURL(podfileURL, display: true) { _ in }
})
guard buttonIndex == NSFileHandlingPanelOKButton else { completion(.None); return }
guard let fileURL = openPanel.URL else { completion(.None); return }
completion(fileURL)
}
}

override func newDocument(sender: AnyObject?) {
selectXcodeproj { fileURL in
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice change 👍

if let URL = fileURL {
self.setupPodfile(URL)
}
}
}

func setupPodfile(xcodeprojURL: NSURL) {
self.podInitController = CPPodfileInitController(xcodeprojURL: xcodeprojURL, completionHandler: { (podfileURL, error) in
guard let podfileURL = podfileURL else {
let alert = NSAlert(error: error! as NSError)
alert.informativeText = error!.message
alert.runModal()

return
}
self.openDocumentWithContentsOfURL(podfileURL, display: true) { _ in }
})
}

@IBAction func removeCocoaPodsFromProject(sender: AnyObject?) {
selectXcodeproj { fileURL in
if let url = fileURL {
self.deintegrateProject(url)
}
}
}

func deintegrateProject(xcodeprojURL: NSURL) {
self.deintegrateController = CPDeintegrateController(xcodeprojURL: xcodeprojURL, completionHandler: { error in
if let error = error {
let alert = NSAlert(error: error as NSError)
alert.informativeText = error.message
alert.runModal()
}
else {
let projectName = xcodeprojURL.lastPathComponent!
let localized = NSLocalizedString("POD_DEINTEGRATE_CONFIRMATION", comment: "")
let alert = NSAlert()
alert.messageText = NSLocalizedString("POD_DEINTEGRATE_INFO", comment: "")
alert.informativeText = String.localizedStringWithFormat(localized, projectName)
alert.runModal()
}
})
}

// `noteNewRecentDocument` ends up calling to this method so we can just override this one method

override func noteNewRecentDocumentURL(url: NSURL) {
Expand Down
4 changes: 1 addition & 3 deletions app/CocoaPods/CPPodfileInitController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,10 @@ public class CPPodfileInitController: NSObject, CPCLITaskDelegate {

super.init()

let task = CPCLITask(workingDirectory: xcodeprojURL.URLByDeletingLastPathComponent!.path,
self.task = CPCLITask(workingDirectory: xcodeprojURL.URLByDeletingLastPathComponent!.path,
command: "init \(xcodeprojURL.lastPathComponent!)",
delegate: self,
qualityOfService: .UserInitiated)
self.task = task

self.task.run()
}

Expand Down
3 changes: 3 additions & 0 deletions app/CocoaPods/Supporting Files/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
"PODFILE_WINDOW_POD_INSTALL_BUTTON_TITLE" = "Pod Install";
"PODFILE_WINDOW_PODFILE_SYNTAX_ERROR_REPLACE" = "your Podfile";

"POD_DEINTEGRATE_INFO" = "Finished.";
"POD_DEINTEGRATE_CONFIRMATION" = "CocoaPods has been removed from %@.";

"POD_INSTALL_SHEET_COMPLETED_BUTTON_TITLE" = "Done";
"POD_INSTALL_SHEET_IN_PROGRESS_BUTTON_TITLE" = "Cancel";

Expand Down