Skip to content

Commit

Permalink
Merge pull request #2106 from Dogild/CappLintxCode
Browse files Browse the repository at this point in the history
New: Integration of capp_lint in xCodeCapp
  • Loading branch information
primalmotion committed Apr 21, 2014
2 parents 4284b97 + d161556 commit 120ac31
Show file tree
Hide file tree
Showing 7 changed files with 977 additions and 738 deletions.
3 changes: 2 additions & 1 deletion Tools/XcodeCapp/XcodeCapp/AppController.m
Expand Up @@ -151,7 +151,8 @@ - (void)registerDefaultPreferences
kDefaultLogLevel: [NSNumber numberWithInt:LOG_LEVEL_WARN],
kDefaultAutoOpenXcodeProject: @YES,
kDefaultShowProcessingNotices: @YES,
kDefaultUseSymlinkWhenCreatingProject: @YES
kDefaultUseSymlinkWhenCreatingProject: @YES,
KDefaultUsesCappLintForEveryNotifications: @NO
};

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
Expand Down
1 change: 1 addition & 0 deletions Tools/XcodeCapp/XcodeCapp/UserDefaults.h
Expand Up @@ -27,5 +27,6 @@ extern NSString * const kDefaultLogLevel;
extern NSString * const kDefaultAutoOpenXcodeProject;
extern NSString * const kDefaultShowProcessingNotices;
extern NSString * const kDefaultUseSymlinkWhenCreatingProject;
extern NSString * const KDefaultUsesCappLintForEveryNotifications;

#endif
1 change: 1 addition & 0 deletions Tools/XcodeCapp/XcodeCapp/UserDefaults.m
Expand Up @@ -25,3 +25,4 @@
NSString * const kDefaultAutoOpenXcodeProject = @"autoOpenXcodeProject";
NSString * const kDefaultShowProcessingNotices = @"showProcessingNotices";
NSString * const kDefaultUseSymlinkWhenCreatingProject = @"useSymlinkWhenCreatingProject";
NSString * const KDefaultUsesCappLintForEveryNotifications = @"usesCappLintForEveryNotifications";
1 change: 1 addition & 0 deletions Tools/XcodeCapp/XcodeCapp/XcodeCapp.h
Expand Up @@ -119,6 +119,7 @@ extern NSString * const XCCProjectDidFinishLoadingNotification;
- (IBAction)openErrorInEditor:(id)sender;
- (IBAction)openXcodeProject:(id)aSender;
- (IBAction)synchronizeProject:(id)aSender;
- (IBAction)checkProjectWithCappLint:(id)aSender;

- (BOOL)executablesAreAccessible;
- (void)stop;
Expand Down
75 changes: 73 additions & 2 deletions Tools/XcodeCapp/XcodeCapp/XcodeCapp.m
Expand Up @@ -241,7 +241,7 @@ - (void)initTaskEnvironment
// Make sure we are using jsc as the narwhal engine!
self.environment[@"NARWHAL_ENGINE"] = @"jsc";

self.executables = @[@"python", @"narwhal-jsc", @"objj", @"nib2cib", @"capp"];
self.executables = @[@"python", @"narwhal-jsc", @"objj", @"nib2cib", @"capp", @"capp_lint"];

// This is used to get the env var of $CAPP_BUILD
NSDictionary *processEnvironment = [[NSProcessInfo processInfo] environment];
Expand Down Expand Up @@ -729,7 +729,12 @@ - (void)sourceConversionDidEnd:(NSNotification *)note
self.pbxOperations[@"add"] = addPaths;
}
}


NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

if ([defaults boolForKey:KDefaultUsesCappLintForEveryNotifications])
[self checkCappLintForPath:path];

DDLogVerbose(@"%@ %@", NSStringFromSelector(_cmd), path);
}

Expand Down Expand Up @@ -1723,6 +1728,72 @@ - (BOOL)userNotificationCenter:(NSUserNotificationCenter *)center shouldPresentN
return YES;
}

- (IBAction)checkProjectWithCappLint:(id)aSender
{
[self clearErrors:self];
[self performSelectorInBackground:@selector(checkCappLintForPath:) withObject:self.projectPath];
}

- (void)checkCappLintForPath:(NSString*)aPath
{
DDLogVerbose(@"Checking path %@ with capp_lint", aPath);

self.isProcessing = YES;
[[NSNotificationCenter defaultCenter] postNotificationName:XCCBatchDidStartNotification object:self];

NSArray *arguments = [NSArray arrayWithObject:aPath];

NSDictionary *taskResult = [self runTaskWithLaunchPath:self.executablePaths[@"capp_lint"]
arguments:arguments
returnType:kTaskReturnTypeStdOut];

NSInteger status = [taskResult[@"status"] intValue];
NSString *response = taskResult[@"response"];

if (status == 0)
return;

NSMutableArray *errors = [NSMutableArray arrayWithArray:[response componentsSeparatedByString:@"\n\n"]];

// We need to remove the first object who is the number of errors and the last object who is an empty line
[errors removeLastObject];
[errors removeObjectAtIndex:0];

NSInteger i = 0;
NSInteger numberOfErrors = [errors count];

for (i = 0; i < numberOfErrors; i++)
{
NSMutableString *error = (NSMutableString*)[errors objectAtIndex:i];
NSString *firstCaract = [NSString stringWithFormat:@"%c" ,[error characterAtIndex:0]];
NSString *path;
NSString *line;

if ([[NSScanner scannerWithString:firstCaract] scanInt:nil])
error = (NSMutableString*)[NSString stringWithFormat:@"%@:%@",aPath,error];

NSInteger positionOfFirstColon = [error rangeOfString:@":"].location;
path = [error substringToIndex:positionOfFirstColon];

NSString *errorWithoutPath = [error substringFromIndex:(positionOfFirstColon + 1)];
NSInteger positionOfSecondColon = [errorWithoutPath rangeOfString:@":"].location;
line = [errorWithoutPath substringToIndex:positionOfSecondColon];

NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:[line intValue]], @"line",
[NSString stringWithFormat:@"capp_lint error in %@ \n%@", path, errorWithoutPath], @"message",
path, @"path",
nil];

[self.errorListController addObject:dict];
}

[self showErrors];

self.isProcessing = NO;
[[NSNotificationCenter defaultCenter] postNotificationName:XCCBatchDidEndNotification object:self];
}

@end


Expand Down

0 comments on commit 120ac31

Please sign in to comment.