This repository has been archived by the owner on Nov 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 284
Pod Deintegrate #296
Merged
Merged
Pod Deintegrate #296
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a2dc530
[Podfile init] Slight task refactor
nwest 5db4dde
[Deintegrate] CocoaPods removal from a project.
nwest 032fcc5
[CHANGELOG] pod deintegrate
nwest 8b979e9
[Feedback]
nwest 19e77c4
Merge branch 'master' into pod-deintegrate
nwest File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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?) -> ()) { | ||
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) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 👍There was a problem hiding this comment.
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
.