PageRenderTime 17ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/core/externals/google-toolbox-for-mac/SpotlightPlugins/XcodeProject/GetMetadataForFile.m

http://macfuse.googlecode.com/
Objective C | 85 lines | 63 code | 2 blank | 20 comment | 16 complexity | 5d8af3fae5eb59a2ede590c4be38069d MD5 | raw file
Possible License(s): Apache-2.0, BSD-3-Clause, GPL-2.0
  1. //
  2. // GetMetadataForFile.m
  3. //
  4. // Copyright 2008 Google Inc.
  5. //
  6. // Licensed under the Apache License, Version 2.0 (the "License"); you may not
  7. // use this file except in compliance with the License. You may obtain a copy
  8. // of the License at
  9. //
  10. // http://www.apache.org/licenses/LICENSE-2.0
  11. //
  12. // Unless required by applicable law or agreed to in writing, software
  13. // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  14. // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  15. // License for the specific language governing permissions and limitations under
  16. // the License.
  17. //
  18. #import <Foundation/Foundation.h>
  19. static BOOL ImportProjectFile(NSMutableDictionary *attributes,
  20. NSString *pathToFile) {
  21. pathToFile = [pathToFile stringByAppendingPathComponent:@"project.pbxproj"];
  22. NSMutableSet *filenames = [[[NSMutableSet alloc] init] autorelease];
  23. NSMutableSet *comments = [[[NSMutableSet alloc] init] autorelease];
  24. BOOL wasGood = NO;
  25. NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:pathToFile];
  26. if (dict) {
  27. NSDictionary *objects = [dict objectForKey:@"objects"];
  28. if (objects) {
  29. NSEnumerator *objEnumerator = [objects objectEnumerator];
  30. NSDictionary *object;
  31. while ((object = [objEnumerator nextObject])) {
  32. NSString *isaType = [object objectForKey:@"isa"];
  33. if ([isaType caseInsensitiveCompare:@"PBXFileReference"] == NSOrderedSame) {
  34. NSString *path = [object objectForKey:@"path"];
  35. if (path) {
  36. [filenames addObject:[path lastPathComponent]];
  37. }
  38. } else if ([isaType caseInsensitiveCompare:@"PBXNativeTarget"] == NSOrderedSame) {
  39. NSString *name = [object objectForKey:@"name"];
  40. if (name) {
  41. [filenames addObject:name];
  42. }
  43. name = [object objectForKey:@"productName"];
  44. if (name) {
  45. [filenames addObject:name];
  46. }
  47. }
  48. NSString *comment = [object objectForKey:@"comments"];
  49. if (comment) {
  50. [comments addObject:comment];
  51. }
  52. }
  53. }
  54. }
  55. if ([filenames count]) {
  56. NSString *description = [[filenames allObjects] componentsJoinedByString:@"\n"];
  57. [attributes setObject:description forKey:(NSString*)kMDItemDescription];
  58. wasGood = YES;
  59. }
  60. if ([comments count]) {
  61. NSString *comment = [[comments allObjects] componentsJoinedByString:@"\n"];
  62. [attributes setObject:comment forKey:(NSString*)kMDItemComment];
  63. wasGood = YES;
  64. }
  65. return wasGood;
  66. }
  67. // Currently grabs all the filenames, target names, and product names
  68. // and sticks them into kMDItemDescription.
  69. // It also grabs all of the comments and sticks them into kMDItemComment.
  70. Boolean GetMetadataForFile(void* interface,
  71. CFMutableDictionaryRef cfAttributes,
  72. CFStringRef contentTypeUTI,
  73. CFStringRef cfPathToFile) {
  74. NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  75. NSMutableDictionary *attributes = (NSMutableDictionary*)cfAttributes;
  76. NSString *pathToFile = (NSString*)cfPathToFile;
  77. BOOL wasGood = NO;
  78. if (UTTypeConformsTo(contentTypeUTI, CFSTR("com.apple.xcode.project"))) {
  79. wasGood = ImportProjectFile(attributes, pathToFile);
  80. }
  81. [pool release];
  82. return wasGood == NO ? FALSE : TRUE;
  83. }