X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=sope-core%2FNGExtensions%2FNGBundleManager.m;h=001fc60dbcf4ac586272307cc0fce4b8b8054a8b;hb=61879b49f7cbc5be91e5c46018ed0fb2b37067f3;hp=2f7066dd5a76b12bfcbd048aa9e82f1c5efd9df8;hpb=770a77ee455ed03dbca084e56386d50e8bcffcc2;p=sope diff --git a/sope-core/NGExtensions/NGBundleManager.m b/sope-core/NGExtensions/NGBundleManager.m index 2f7066dd..001fc60d 100644 --- a/sope-core/NGExtensions/NGBundleManager.m +++ b/sope-core/NGExtensions/NGBundleManager.m @@ -595,12 +595,14 @@ static NSString *NGEnvVarPathSeparator = @":"; bn = [_name stringByAppendingPathExtension:_type]; bundle = NSMapGet(self->nameToBundle, bn); - if (bundle == nil) - bundle = [self bundleWithPath:[self pathForBundleWithName:_name type:_type]]; - - if (![[bundle bundleType] isEqualToString:_type]) + if (bundle == nil) { + bundle = [self bundleWithPath: + [self pathForBundleWithName:_name type:_type]]; + } + + if (bundle != nil && ![[bundle bundleType] isEqualToString:_type]) bundle = nil; - + return bundle; } - (NSBundle *)bundleWithName:(NSString *)_name { @@ -1159,83 +1161,100 @@ static BOOL _doesInfoMatch(NSArray *keys, NSDictionary *dict, NSDictionary *info NSFileManager *fm; NSEnumerator *e; NSString *path; + + if (debugOn) { + NSLog(@"BM LOOKUP pathes (%d bundles loaded): %@ / %@", + NSCountMapTable(self->loadedBundles), _resourceName, _type); + } fm = [NSFileManager defaultManager]; result = [NSMutableArray arrayWithCapacity:64]; + // TODO: look in loaded bundles + + /* check physical pathes */ + e = [self->bundleSearchPaths objectEnumerator]; - while ((path = [e nextObject])) { - BOOL isDir = NO; + while ((path = [e nextObject]) != nil) { + NSEnumerator *dir; + BOOL isDir = NO; + NSString *tmp, *bundleDirPath; + id info = nil; - if ([fm fileExistsAtPath:path isDirectory:&isDir]) { - NSString *tmp; - id info = nil; - if (!isDir) continue; - - /* check whether an appropriate bundle is contained in 'path' */ - { - NSEnumerator *dir; - - dir = [[fm directoryContentsAtPath:path] objectEnumerator]; - while ((tmp = [dir nextObject])) { - NSDictionary *bundleInfo = nil; - NSEnumerator *providedResources = nil; - NSString *infoPath; - id info; + if (![fm fileExistsAtPath:path isDirectory:&isDir]) + continue; + + if (!isDir) continue; + + /* check whether an appropriate bundle is contained in 'path' */ + + dir = [[fm directoryContentsAtPath:path] objectEnumerator]; + while ((bundleDirPath = [dir nextObject]) != nil) { + NSDictionary *bundleInfo = nil; + NSEnumerator *providedResources = nil; + NSString *infoPath; + id info; - tmp = [path stringByAppendingPathComponent:tmp]; - infoPath = [self makeBundleInfoPath:tmp]; - - if ((bundleInfo = NSMapGet(self->pathToBundleInfo, infoPath)) == nil) { - if (![fm fileExistsAtPath:infoPath]) - continue; - - bundleInfo = [self _loadBundleInfoAtExistingPath:infoPath]; - } - - providedResources = - [[(NSDictionary *)[bundleInfo objectForKey:@"provides"] - objectForKey:_type] - objectEnumerator]; - if (providedResources == nil) continue; + bundleDirPath = [path stringByAppendingPathComponent:bundleDirPath]; + infoPath = [self makeBundleInfoPath:bundleDirPath]; + + // TODO: can we use _doesBundleInfo:path:providedResource:... ? + if ((bundleInfo = NSMapGet(self->pathToBundleInfo, infoPath))==nil) { + if (![fm fileExistsAtPath:infoPath]) + continue; - // scan provide array - while ((info = [providedResources nextObject])) { - NSString *name; + bundleInfo = [self _loadBundleInfoAtExistingPath:infoPath]; + } + + providedResources = + [[(NSDictionary *)[bundleInfo objectForKey:@"provides"] + objectForKey:_type] + objectEnumerator]; + if (providedResources == nil) continue; + + /* scan 'provides' array */ + while ((info = [providedResources nextObject])) { + NSString *name; - name = [[(NSDictionary *)info objectForKey:@"name"] stringValue]; - if (name == nil) continue; - - if (_resourceName) { - if (![name isEqualToString:_resourceName]) - continue; - } - if (_selector) { - if (!_selector(name, _type, tmp, info, self, _context)) - continue; - } - - [result addObject:tmp]; - break; - } - } + name = [[(NSDictionary *)info objectForKey:@"name"] stringValue]; + if (name == nil) continue; + + if (_resourceName != nil) { + if (![name isEqualToString:_resourceName]) + continue; + } + if (_selector != NULL) { + if (!_selector(name, _type, bundleDirPath, info, self, _context)) + continue; + } + + [result addObject:bundleDirPath]; + break; } + } + + /* check for direct match (NGBundlePath element is a bundle) */ + + tmp = [self makeBundleInfoPath:path]; - /* check for direct match */ - - tmp = [self makeBundleInfoPath:path]; - - if ((info = NSMapGet(self->pathToBundleInfo, tmp)) == nil) { - if ([fm fileExistsAtPath:tmp]) - info = [self _loadBundleInfoAtExistingPath:tmp]; - } - - [self _processInfoForProvidedResources:info ofType:_type path:path - resourceName:_resourceName resourceSelector:_selector - context:_context - andAddToResultArray:result]; + if ((info = NSMapGet(self->pathToBundleInfo, tmp)) == nil) { + if ([fm fileExistsAtPath:tmp]) + info = [self _loadBundleInfoAtExistingPath:tmp]; } + + [self _processInfoForProvidedResources:info ofType:_type path:path + resourceName:_resourceName resourceSelector:_selector + context:_context + andAddToResultArray:result]; } + + if ([result count] == 0) { + [self logWithFormat: + @"Note(%s): method does not search in loaded bundles for " + @"resources of type '%@'", + __PRETTY_FUNCTION__, _type]; + } + return [[result copy] autorelease]; } @@ -1979,7 +1998,7 @@ static BOOL _doesInfoMatch(NSArray *keys, NSDictionary *dict, NSDictionary *info - (NSString *)description { char buffer[1024]; - + sprintf (buffer, "<%s %p fullPath: %s infoDictionary: %p loaded=%s>", (char*)object_get_class_name(self),