diff -r 5a71993a1a70 -r d52f6b0d94be MYTask.m --- a/MYTask.m Sat Mar 28 09:36:46 2009 -0700 +++ b/MYTask.m Wed Jul 01 14:04:56 2009 -0700 @@ -30,7 +30,7 @@ - (id) initWithCommand: (NSString*)command arguments: (NSArray*)arguments { - NSParameterAssert(command); + Assert(command); self = [super init]; if (self != nil) { _command = command; @@ -107,6 +107,18 @@ } +- (NSString*) commandLine { + NSMutableString *desc = [NSMutableString stringWithString: _command]; + for (NSString *arg in _arguments) { + [desc appendString: @" "]; + if ([arg rangeOfString: @" "].length > 0) + arg = [NSString stringWithFormat: @"'%@'", arg]; + [desc appendString: arg]; + } + return desc; +} + + - (void) ignoreOutput { _ignoreOutput = YES; @@ -119,7 +131,7 @@ va_start(args,fmt); NSString *message = [[NSString alloc] initWithFormat: fmt arguments: args]; - Log(@"MYTask Error: %@",message); + LogTo(MYTask, @"Error: %@",message); NSMutableDictionary *info = [NSMutableDictionary dictionaryWithObject: message forKey: NSLocalizedDescriptionKey]; _error = [NSError errorWithDomain: MYTaskErrorDomain code: kMYTaskError userInfo: info]; @@ -155,7 +167,7 @@ /** Subclasses can override this. */ - (NSTask*) createTask { - NSAssert(!_task,@"createTask called twice"); + Assert(!_task,@"createTask called twice"); NSTask *task = [[NSTask alloc] init]; task.launchPath = _command; task.arguments = _arguments; @@ -167,14 +179,14 @@ - (BOOL) start { - NSAssert(!_task, @"Task has already been run"); + Assert(!_task, @"Task has already been run"); if( _error ) return NO; _task = [self createTask]; - NSAssert(_task,@"createTask returned nil"); + Assert(_task,@"createTask returned nil"); - Log(@"Task: %@ %@",_task.launchPath,[_task.arguments componentsJoinedByString: @" "]); + LogTo(MYTask,@"$ %@", self.commandLine); _task.standardOutput = [self _openPipeAndHandle: &_outHandle notifying: @selector(_gotOutput:)]; _outputData = [[NSMutableData alloc] init]; @@ -188,7 +200,7 @@ @try{ [_task launch]; }@catch( id x ) { - Log(@"Task failed to launch: %@",x); + Warn(@"Task failed to launch: %@",x); _resultCode = 666; [self _close]; return [self makeError: @"Exception launching %@: %@",_task.launchPath,x]; @@ -221,7 +233,7 @@ if( n.object == _outHandle ) { if( data.length > 0 ) { [_outHandle readInBackgroundAndNotifyForModes: _modes]; - LogTo(Task,@"Got %u bytes of output",data.length); + LogTo(HgTaskVerbose, @"Got %u bytes of output",data.length); if( _outputData ) { [self willChangeValueForKey: @"output"]; [self willChangeValueForKey: @"outputData"]; @@ -231,7 +243,7 @@ [self didChangeValueForKey: @"output"]; } } else { - LogTo(Task,@"Closed output"); + LogTo(HgTaskVerbose, @"Closed output"); _outHandle = nil; if( [self _shouldFinishUp] ) [self _finishUp]; @@ -245,12 +257,12 @@ NSData *data = [n.userInfo objectForKey: NSFileHandleNotificationDataItem]; if( data.length > 0 ) { [_errHandle readInBackgroundAndNotifyForModes: _modes]; - LogTo(Task,@"Got %u bytes of stderr",data.length); + LogTo(HgTaskVerbose, @"Got %u bytes of stderr",data.length); [self willChangeValueForKey: @"errorData"]; [_errorData appendData: data]; [self didChangeValueForKey: @"errorData"]; } else { - LogTo(Task,@"Closed stderr"); + LogTo(HgTaskVerbose, @"Closed stderr"); _errHandle = nil; if( [self _shouldFinishUp] ) [self _finishUp]; @@ -261,7 +273,7 @@ - (void) _exited: (NSNotification*)n { _resultCode = _task.terminationStatus; - LogTo(Task,@"Exited with result=%i",_resultCode); + LogTo(HgTaskVerbose, @"Exited with result=%i",_resultCode); _taskRunning = NO; if( [self _shouldFinishUp] ) [self _finishUp]; @@ -275,14 +287,14 @@ [NSObject cancelPreviousPerformRequestsWithTarget: self selector: @selector(_finishUp) object: nil]; [self _close]; - LogTo(Task,@"Finished!"); + LogTo(HgTaskVerbose, @"Finished!"); if( _resultCode != 0 ) { // Handle errors: NSString *errStr = nil; if( _errorData.length > 0 ) errStr = [[NSString alloc] initWithData: _errorData encoding: NSUTF8StringEncoding]; - Log(@" *** task returned %i: %@",_resultCode,errStr); + LogTo(MYTask, @" *** task returned %i: %@",_resultCode,errStr); if( errStr.length == 0 ) errStr = [NSString stringWithFormat: @"Command returned status %i",_resultCode]; NSString *desc = [NSString stringWithFormat: @"%@ command error", _task.launchPath.lastPathComponent]; @@ -351,7 +363,7 @@ // If output isn't valid UTF-8, fall back to CP1252, aka WinLatin1, a superset of ISO-Latin-1. if( ! _output ) { _output = [[NSString alloc] initWithData: _outputData encoding: NSWindowsCP1252StringEncoding]; - Log(@"Warning: Output of '%@' was not valid UTF-8; interpreting as CP1252",self); + Warn(@"MYTask: Output of '%@' was not valid UTF-8; interpreting as CP1252",self); } } return _output;