Revision: 2805
http://skim-app.svn.sourceforge.net/skim-app/?rev=2805&view=rev
Author: hofman
Date: 2007-09-01 14:27:50 -0700 (Sat, 01 Sep 2007)
Log Message:
-----------
Add category on NSTask with some convenience class methods.
Modified Paths:
--------------
trunk/SKApplicationController.m
trunk/SKDocument.h
trunk/SKDocument.m
trunk/SKPSProgressController.m
trunk/Skim.xcodeproj/project.pbxproj
Added Paths:
-----------
trunk/NSTask_SKExtensions.h
trunk/NSTask_SKExtensions.m
Added: trunk/NSTask_SKExtensions.h
===================================================================
--- trunk/NSTask_SKExtensions.h (rev 0)
+++ trunk/NSTask_SKExtensions.h 2007-09-01 21:27:50 UTC (rev 2805)
@@ -0,0 +1,45 @@
+//
+// NSTask_SKExtensions.h
+// Skim
+//
+// Created by Christiaan Hofman on 9/1/07.
+/*
+ This software is Copyright (c) 2007
+ Christiaan Hofman. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ - Neither the name of Christiaan Hofman nor the names of any
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import <Cocoa/Cocoa.h>
+
+
[EMAIL PROTECTED] NSTask (SKExtensions)
++ (NSTask *)launchedTaskWithLaunchPath:(NSString *)launchPath
arguments:(NSArray *)arguments currentDirectoryPath:(NSString *)directoryPath;
++ (BOOL)runTaskWithLaunchPath:(NSString *)launchPath arguments:(NSArray
*)arguments currentDirectoryPath:(NSString *)directoryPath;
[EMAIL PROTECTED]
Added: trunk/NSTask_SKExtensions.m
===================================================================
--- trunk/NSTask_SKExtensions.m (rev 0)
+++ trunk/NSTask_SKExtensions.m 2007-09-01 21:27:50 UTC (rev 2805)
@@ -0,0 +1,81 @@
+//
+// NSTask_SKExtensions.m
+// Skim
+//
+// Created by Christiaan Hofman on 9/1/07.
+/*
+ This software is Copyright (c) 2007
+ Christiaan Hofman. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ - Neither the name of Christiaan Hofman nor the names of any
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "NSTask_SKExtensions.h"
+
+
[EMAIL PROTECTED] NSTask (SKExtensions)
+
++ (NSTask *)launchedTaskWithLaunchPath:(NSString *)launchPath
arguments:(NSArray *)arguments currentDirectoryPath:(NSString *)directoryPath {
+ NSTask *task = [[[NSTask alloc] init] autorelease];
+
+ [task setLaunchPath:launchPath];
+ [task setCurrentDirectoryPath:directoryPath];
+ [task setArguments:arguments];
+ [task setStandardOutput:[NSFileHandle fileHandleWithNullDevice]];
+ [task setStandardError:[NSFileHandle fileHandleWithNullDevice]];
+ @try {
+ [task launch];
+ }
+ @catch(id exception) {
+ if ([task isRunning])
+ [task terminate];
+ NSLog(@"%@ %@ failed", [task description], [task launchPath]);
+ task = nil;
+ }
+ return task;
+}
+
++ (BOOL)runTaskWithLaunchPath:(NSString *)launchPath arguments:(NSArray
*)arguments currentDirectoryPath:(NSString *)directoryPath {
+ NSTask *task = [[self class] launchedTaskWithLaunchPath:launchPath
arguments:arguments currentDirectoryPath:directoryPath];
+ BOOL success = task != nil;
+
+ if (success) {
+ if ([task isRunning])
+ [task waitUntilExit];
+ if ([task isRunning]) {
+ [task terminate];
+ success = NO;
+ } else {
+ success = 0 == [task terminationStatus];
+ }
+ }
+ return success;
+}
+
[EMAIL PROTECTED]
Modified: trunk/SKApplicationController.m
===================================================================
--- trunk/SKApplicationController.m 2007-09-01 20:48:36 UTC (rev 2804)
+++ trunk/SKApplicationController.m 2007-09-01 21:27:50 UTC (rev 2805)
@@ -57,6 +57,7 @@
#import "SKDocumentController.h"
#import "Files_SKExtensions.h"
#import "NSGeometry_SKExtensions.h"
+#import "NSTask_SKExtensions.h"
#define WEBSITE_URL @"http://skim-app.sourceforge.net/"
#define WIKI_URL @"http://skim-app.sourceforge.net/wiki/"
@@ -347,10 +348,7 @@
if (runImporter) {
NSString *mdimportPath = @"/usr/bin/mdimport";
if ([[NSFileManager defaultManager]
isExecutableFileAtPath:mdimportPath]) {
- NSTask *importerTask = [[[NSTask alloc] init] autorelease];
- [importerTask setLaunchPath:mdimportPath];
- [importerTask setArguments:[NSArray arrayWithObjects:@"-r",
importerPath, nil]];
- [importerTask launch];
+ [NSTask launchedTaskWithLaunchPath:mdimportPath
arguments:[NSArray arrayWithObjects:@"-r", importerPath, nil]];
NSDictionary *info = [NSDictionary
dictionaryWithObjectsAndKeys:[NSNumber numberWithLong:sysVersion],
@"lastSysVersion", importerVersion, @"lastImporterVersion", nil];
[[NSUserDefaults standardUserDefaults] setObject:info
forKey:@"SKSpotlightVersionInfo"];
Modified: trunk/SKDocument.h
===================================================================
--- trunk/SKDocument.h 2007-09-01 20:48:36 UTC (rev 2804)
+++ trunk/SKDocument.h 2007-09-01 21:27:50 UTC (rev 2805)
@@ -144,8 +144,3 @@
@interface NSView (SKExtensions)
- (id)subviewOfClass:(Class)aClass;
@end
-
-
[EMAIL PROTECTED] NSTask (SKExtensions)
-+ (BOOL)runTaskWithLaunchPath:(NSString *)launchPath arguments:(NSArray
*)arguments currentDirectoryPath:(NSString *)directoryPath;
[EMAIL PROTECTED]
Modified: trunk/SKDocument.m
===================================================================
--- trunk/SKDocument.m 2007-09-01 20:48:36 UTC (rev 2804)
+++ trunk/SKDocument.m 2007-09-01 21:27:50 UTC (rev 2805)
@@ -60,6 +60,7 @@
#import "SKLine.h"
#import "SKApplicationController.h"
#import "Files_SKExtensions.h"
+#import "NSTask_SKExtensions.h"
// maximum length of xattr value recommended by Apple
#define MAX_XATTR_LENGTH 2048
@@ -1231,12 +1232,7 @@
[cmdString insertString:@"/usr/bin/osascript " atIndex:0];
}
- NSTask *task = [[[NSTask alloc] init] autorelease];
- [task setLaunchPath:@"/bin/sh"];
- [task setArguments:[NSArray arrayWithObjects:@"-c", cmdString, nil]];
- [task setCurrentDirectoryPath:[file
stringByDeletingLastPathComponent]];
- [task setEnvironment:environment];
- [task launch];
+ [NSTask launchedTaskWithLaunchPath:@"/bin/sh" arguments:[NSArray
arrayWithObjects:@"-c", cmdString, nil] currentDirectoryPath:[file
stringByDeletingLastPathComponent]];
}
}
@@ -1671,23 +1667,3 @@
}
@end
-
-
[EMAIL PROTECTED] NSTask (SKExtensions)
-
-+ (BOOL)runTaskWithLaunchPath:(NSString *)launchPath arguments:(NSArray
*)arguments currentDirectoryPath:(NSString *)directoryPath {
- NSTask *task = [[[NSTask alloc] init] autorelease];
-
- [task setLaunchPath:launchPath];
- [task setCurrentDirectoryPath:directoryPath];
- [task setArguments:arguments];
- [task setStandardOutput:[NSFileHandle fileHandleWithNullDevice]];
- [task setStandardError:[NSFileHandle fileHandleWithNullDevice]];
- [task launch];
- if ([task isRunning])
- [task waitUntilExit];
-
- return 0 == [task terminationStatus];
-}
-
[EMAIL PROTECTED]
Modified: trunk/SKPSProgressController.m
===================================================================
--- trunk/SKPSProgressController.m 2007-09-01 20:48:36 UTC (rev 2804)
+++ trunk/SKPSProgressController.m 2007-09-01 21:27:50 UTC (rev 2805)
@@ -38,6 +38,7 @@
#import "SKPSProgressController.h"
#import "NSString_SKExtensions.h"
+#import "NSTask_SKExtensions.h"
enum {
SKConversionSucceeded = 0,
@@ -337,22 +338,8 @@
[fm createDirectoryAtPath:tmpDir attributes:nil];
- task = [[NSTask alloc] init];
- [task setLaunchPath:commandPath];
- [task setArguments:arguments];
- [task setCurrentDirectoryPath:[dviFile
stringByDeletingLastPathComponent]];
- [task setStandardError:[NSFileHandle fileHandleWithNullDevice]];
+ task = [[NSTask launchedTaskWithLaunchPath:commandPath
arguments:arguments currentDirectoryPath:[dviFile
stringByDeletingLastPathComponent]] retain];
- @try {
- [task launch];
- }
- @catch(id exception) {
- if([task isRunning])
- [task terminate];
- NSLog(@"%@ %@ failed", [task description], [task launchPath]);
- success = NO;
- }
-
ms = [self methodSignatureForSelector:@selector(conversionStarted)];
invocation = [NSInvocation invocationWithMethodSignature:ms];
[invocation setTarget:self];
Modified: trunk/Skim.xcodeproj/project.pbxproj
===================================================================
--- trunk/Skim.xcodeproj/project.pbxproj 2007-09-01 20:48:36 UTC (rev
2804)
+++ trunk/Skim.xcodeproj/project.pbxproj 2007-09-01 21:27:50 UTC (rev
2805)
@@ -140,6 +140,7 @@
CE7469180B7F40B700CBF969 /* Skim.icns in Resources */ = {isa =
PBXBuildFile; fileRef = CE7469170B7F40B600CBF969 /* Skim.icns */; };
CE7C20500C259A5D0059E08C /* NSColor_SKExtensions.m in Sources
*/ = {isa = PBXBuildFile; fileRef = CE7C204E0C259A5D0059E08C /*
NSColor_SKExtensions.m */; };
CE7C5D190BD8086C0011315D /* ToolbarLineNote.tiff in Resources
*/ = {isa = PBXBuildFile; fileRef = CE7C5D180BD8086C0011315D /*
ToolbarLineNote.tiff */; };
+ CE820A220C8A0E310020E6B0 /* NSTask_SKExtensions.m in Sources */
= {isa = PBXBuildFile; fileRef = CE820A200C8A0E310020E6B0 /*
NSTask_SKExtensions.m */; };
CE898F060C843A8B008A0856 /* PDFDDocument.icns in Resources */ =
{isa = PBXBuildFile; fileRef = CE898F050C843A8B008A0856 /* PDFDDocument.icns
*/; };
CE8B46E90C29CA00005CE7F1 /* SKLineInspector.m in Sources */ =
{isa = PBXBuildFile; fileRef = CE8B46E70C29CA00005CE7F1 /* SKLineInspector.m
*/; };
CE8B46F00C29CA3D005CE7F1 /* LineInspector.nib in Resources */ =
{isa = PBXBuildFile; fileRef = CE8B46EA0C29CA3D005CE7F1 /* LineInspector.nib
*/; };
@@ -507,6 +508,8 @@
CE7C204D0C259A5D0059E08C /* NSColor_SKExtensions.h */ = {isa =
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path =
NSColor_SKExtensions.h; sourceTree = "<group>"; };
CE7C204E0C259A5D0059E08C /* NSColor_SKExtensions.m */ = {isa =
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path
= NSColor_SKExtensions.m; sourceTree = "<group>"; };
CE7C5D180BD8086C0011315D /* ToolbarLineNote.tiff */ = {isa =
PBXFileReference; lastKnownFileType = image.tiff; name = ToolbarLineNote.tiff;
path = Images/ToolbarLineNote.tiff; sourceTree = "<group>"; };
+ CE820A1F0C8A0E310020E6B0 /* NSTask_SKExtensions.h */ = {isa =
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path =
NSTask_SKExtensions.h; sourceTree = "<group>"; };
+ CE820A200C8A0E310020E6B0 /* NSTask_SKExtensions.m */ = {isa =
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path
= NSTask_SKExtensions.m; sourceTree = "<group>"; };
CE87EF690BA9FF5A0027BBDD /* skimhelp.css */ = {isa =
PBXFileReference; explicitFileType = text; fileEncoding = 30; name =
skimhelp.css; path = "English.lproj/Skim Help/sty/skimhelp.css"; sourceTree =
"<group>"; };
CE898F050C843A8B008A0856 /* PDFDDocument.icns */ = {isa =
PBXFileReference; lastKnownFileType = image.icns; name = PDFDDocument.icns;
path = Images/PDFDDocument.icns; sourceTree = "<group>"; };
CE8B46E60C29CA00005CE7F1 /* SKLineInspector.h */ = {isa =
PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path =
SKLineInspector.h; sourceTree = "<group>"; };
@@ -809,6 +812,8 @@
CE070EA10B89039700733CC8 /*
NSScrollView_SKExtensions.m */,
CE38ECD10B8093B200A1B779 /*
NSString_SKExtensions.h */,
CE38ECD20B8093B200A1B779 /*
NSString_SKExtensions.m */,
+ CE820A1F0C8A0E310020E6B0 /*
NSTask_SKExtensions.h */,
+ CE820A200C8A0E310020E6B0 /*
NSTask_SKExtensions.m */,
CEAA67230C70A882006BD633 /*
NSURL_SKExtensions.h */,
CEAA67240C70A882006BD633 /*
NSURL_SKExtensions.m */,
CEF7119F0B90B714003A2771 /*
NSUserDefaultsController_SKExtensions.h */,
@@ -1488,6 +1493,7 @@
CE5BEA190C7C635400EBDCF7 /*
NSGeometry_SKExtensions.m in Sources */,
CE5BF8010C7CBF6300EBDCF7 /* SKTableView.m in
Sources */,
CE5BF8430C7CC24A00EBDCF7 /* SKOutlineView.m in
Sources */,
+ CE820A220C8A0E310020E6B0 /*
NSTask_SKExtensions.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit