Skip to content

Commit

Permalink
Cleans up a few dumb mistakes in ObjCPluginManager.
Browse files Browse the repository at this point in the history
  • Loading branch information
Grayson Hansard committed Feb 5, 2009
1 parent da78bc0 commit 8f27ece
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
4 changes: 1 addition & 3 deletions src/ObjCPluginManager.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
enum { enum {
ObjCPMBundleLoadError = 1, ObjCPMBundleLoadError = 1,
ObjCPMClassLoadError = 2 ObjCPMClassLoadError = 2
} };


@interface ObjCPluginManager : NSObject <PluginManagerProtocol> { @interface ObjCPluginManager : NSObject <PluginManagerProtocol> {
NSMutableDictionary *_plugins; NSMutableDictionary *_plugins;
Expand All @@ -33,11 +33,9 @@ enum {
@end @end


@protocol ObjCPlugin @protocol ObjCPlugin

-(NSString *)actionProperty; -(NSString *)actionProperty;
-(BOOL)actionEnableForValue:(id)forValue withValue:(id)withValue; -(BOOL)actionEnableForValue:(id)forValue withValue:(id)withValue;
-(NSString *)actionTitleForValue:(id)forValue withValue:(id)withValue; -(NSString *)actionTitleForValue:(id)forValue withValue:(id)withValue;
-(void)actionPerformForValue:(id)forValue withValue:(id)withValue; -(void)actionPerformForValue:(id)forValue withValue:(id)withValue;
-(id)run; -(id)run;

@end @end
13 changes: 7 additions & 6 deletions src/ObjCPluginManager.m
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ - (id)init
- (void)dealloc - (void)dealloc
{ {
[self setPlugins:nil]; [self setPlugins:nil];
[super dealloc];
} }


- (void)build - (void)build
Expand All @@ -47,17 +48,17 @@ - (void)build
if (![fm fileExistsAtPath:pluginsPath isDirectory:&isFolder] || !isFolder) return; if (![fm fileExistsAtPath:pluginsPath isDirectory:&isFolder] || !isFolder) return;


// Add all of the plugins available in either the plugins folder in Application Support or in the bundle resources // Add all of the plugins available in either the plugins folder in Application Support or in the bundle resources
NSArray *plugins = [fm directoryContentsAtPath:pluginsPath]; NSArray *foundPlugins = [fm directoryContentsAtPath:pluginsPath];
plugins = [plugins arrayByAddingObjectsFromArray:[fm directoryContentsAtPath:[[NSBundle mainBundle] pathForResource:@"Plug-Ins" ofType:nil]]]; foundPlugins = [foundPlugins arrayByAddingObjectsFromArray:[fm directoryContentsAtPath:[[NSBundle mainBundle] pathForResource:@"Plug-Ins" ofType:nil]]];
NSEnumerator *pluginEnumerator = [plugins objectEnumerator]; NSEnumerator *pluginEnumerator = [foundPlugins objectEnumerator];
NSString *path; NSString *path;
NSArray *extensions = [self extensions]; NSArray *extensions = [self extensions];
while (path = [pluginEnumerator nextObject]) while (path = [pluginEnumerator nextObject])
{ {
if (![extensions containsObject:[path pathExtension]]) continue; if (![extensions containsObject:[path pathExtension]]) continue;


NSBundle *b = [NSBundle bundleWithPath:path]; NSBundle *b = [NSBundle bundleWithPath:path];
if (!b) goto next; if (!b) continue;


Class c = [b principalClass]; Class c = [b principalClass];
if (![c conformsToProtocol:@protocol(ObjCPlugin)]) continue; if (![c conformsToProtocol:@protocol(ObjCPlugin)]) continue;
Expand Down Expand Up @@ -105,7 +106,7 @@ -(id)runScriptAtPath:(NSString *)path
if (!path) return nil; if (!path) return nil;
NSMutableDictionary *plugins = [self plugins]; NSMutableDictionary *plugins = [self plugins];
if (!plugins) plugins = [NSMutableDictionary dictionary]; if (!plugins) plugins = [NSMutableDictionary dictionary];
id plugin = [plugins objectForKey:path]; id<ObjCPlugin> plugin = [plugins objectForKey:path];
unsigned int errorCode = 0; unsigned int errorCode = 0;
NSString *errorString = nil; NSString *errorString = nil;
if (!plugin) { if (!plugin) {
Expand All @@ -121,7 +122,7 @@ -(id)runScriptAtPath:(NSString *)path
errorCode = ObjCPMClassLoadError; errorCode = ObjCPMClassLoadError;
goto error; goto error;
} }
if (![plugin respondsToSelector:@selector(run)]) { if (![(id)plugin respondsToSelector:@selector(run)]) {
errorString = [NSString stringWithFormat:NSLocalizedString(@"Loaded bundle at path '%@' does not respond to -(id)run.", @"error message"), path]; errorString = [NSString stringWithFormat:NSLocalizedString(@"Loaded bundle at path '%@' does not respond to -(id)run.", @"error message"), path];
errorCode = 3; errorCode = 3;
goto error; goto error;
Expand Down

0 comments on commit 8f27ece

Please sign in to comment.