New: xcc --reset resets the Xcode support before opening the project.

This will help in cases where the project is way out of sync and crashes XCC.
This commit is contained in:
Aparajita Fishman
2013-05-12 16:18:41 -04:00
parent 574672f15f
commit e047212f5f
12 changed files with 261 additions and 276 deletions
+20 -35
View File
@@ -26,6 +26,7 @@
#import "Notifications.h"
#import "ProcessSourceOperation.h"
#import "UserDefaults.h"
#import "XcodeProjectCloser.h"
#if MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_6
@@ -50,23 +51,6 @@ enum XCCLineSpecifier {
};
typedef enum XCCLineSpecifier XCCLineSpecifier;
// Used to close the Xcode project if it is open.
static const char *XCCCloseProjectScript =
"tell application \"Xcode\"\n"
"set docs to (document of every window)\n"
"repeat with doc in docs\n"
"if class of doc is workspace document then\n"
"set docURL to file of doc\n"
"set docPath to docURL as text\n"
"set docPath to POSIX path of docPath\n"
"if docPath begins with \"%@\" then\n"
"close doc\n"
"return\n"
"end if\n"
"end if\n"
"end repeat\n"
"end tell";
// Where we put the generated Cocoa class files
static NSString * const XCCSupportFolderName = @".XcodeSupport";
@@ -109,10 +93,7 @@ static NSArray *XCCDefaultIgnoredPathPredicates = nil;
@property NSFileManager *fm;
// Full path to the <project>.xcodeproj
@property NSString *xcodeProjectPath;
// An NSString version of XCCCloseProjectScript
// An NSString version of XCCCloseXcodeProjectScript
@property NSString *closeXcodeProjectScriptSource;
// Full path to .xcodecapp-ignore
@@ -199,7 +180,6 @@ void fsevents_callback(ConstFSEventStreamRef streamRef,
self.fm = [NSFileManager defaultManager];
self.ignoredPathPredicates = [NSMutableArray new];
self.parserPath = [[NSBundle mainBundle].sharedSupportPath stringByAppendingPathComponent:@"parser.j"];
self.closeXcodeProjectScriptSource = [NSString stringWithUTF8String:XCCCloseProjectScript];
self.appStartedTimestamp = [NSDate date];
self.projectPathsForSourcePaths = [NSMutableDictionary new];
self.xcodecappIgnorePath = @"";
@@ -287,6 +267,13 @@ void fsevents_callback(ConstFSEventStreamRef streamRef,
return _pathModificationDates;
}
- (BOOL)xcodeProjectCanBeOpened
{
return (self.xcodeProjectPath &&
!self.isProcessing &&
[self.fm fileExistsAtPath:self.xcodeProjectPath]);
}
#pragma mark - Project Management
- (void)loadProjectAtPath:(NSString *)path
@@ -445,14 +432,21 @@ void fsevents_callback(ConstFSEventStreamRef streamRef,
}
}
- (IBAction)synchronizeProject:(id)aSender
- (void)resetProject
{
NSString *projectPath = self.projectPath;
[self stop];
[self removeSupportFilesAtPath:projectPath];
[self removeAllCibsAtPath:[projectPath stringByAppendingPathComponent:@"Resources"]];
[self loadProjectAtPath:projectPath];
self.projectPath = projectPath;
}
- (IBAction)synchronizeProject:(id)aSender
{
[self resetProject];
[self loadProjectAtPath:self.projectPath];
}
- (void)removeAllCibsAtPath:(NSString *)path
@@ -468,21 +462,12 @@ void fsevents_callback(ConstFSEventStreamRef streamRef,
- (void)removeSupportFilesAtPath:(NSString *)projectPath
{
[self closeXcodeProjectForProject:projectPath];
[XcodeProjectCloser closeXcodeProjectForProject:projectPath];
[self.fm removeItemAtPath:self.xcodeProjectPath error:nil];
[self.fm removeItemAtPath:self.supportPath error:nil];
}
- (void)closeXcodeProjectForProject:(NSString *)projectPath
{
NSString *source = [NSString stringWithFormat:self.closeXcodeProjectScriptSource, projectPath];
NSAppleScript *script = [[NSAppleScript alloc] initWithSource:source];
NSAppleEventDescriptor *descriptor;
descriptor = [script executeAndReturnError:nil];
}
- (void)stop
{
// Increment the projectId to ensure remaining notifications in the queue for the current project are ignored