/core/externals/google-toolbox-for-mac/Xcode4Plugin/GTMXcodePluginManager.m

http://macfuse.googlecode.com/ · Objective C · 100 lines · 66 code · 17 blank · 17 comment · 7 complexity · 8778abbaecae2ad80b1926f23bc1ca5a MD5 · raw file

  1. //
  2. // GTMXcodePluginManager.m
  3. //
  4. // Copyright 2007-2011 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 "GTMXcodePluginManager.h"
  19. #import <Cocoa/Cocoa.h>
  20. static NSMutableArray *gRegisteredClasses = nil;
  21. static NSMutableArray *gPlugins = nil;
  22. @implementation GTMXcodePluginManager
  23. + (void)registerPluginClass:(Class)cls {
  24. @synchronized([self class]) {
  25. if (!gRegisteredClasses) {
  26. gRegisteredClasses = [[NSMutableArray alloc] init];
  27. }
  28. if (cls) {
  29. [gRegisteredClasses addObject:cls];
  30. }
  31. }
  32. }
  33. + (void)pluginDidLoad:(NSBundle *)bundle {
  34. gPlugins
  35. = [[NSMutableArray alloc] initWithCapacity:[gRegisteredClasses count]];
  36. for (Class cls in gRegisteredClasses) {
  37. GTMXcodePlugin *plugin = [[cls alloc] initWithBundle:bundle];
  38. if (plugin) {
  39. [gPlugins addObject:plugin];
  40. }
  41. }
  42. [gRegisteredClasses release];
  43. gRegisteredClasses = nil;
  44. NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
  45. [nc addObserver:self
  46. selector:@selector(applicationDidFinishLaunching:)
  47. name:NSApplicationDidFinishLaunchingNotification
  48. object:NSApp];
  49. }
  50. + (void)applicationDidFinishLaunching:(NSNotification *)notification {
  51. NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
  52. [nc removeObserver:self
  53. name:NSApplicationDidFinishLaunchingNotification
  54. object:NSApp];
  55. for (GTMXcodePlugin *plugin in gPlugins) {
  56. [plugin applicationDidFinishLaunching:notification];
  57. }
  58. }
  59. + (float)xCodeVersion {
  60. NSBundle *bundle = [NSBundle mainBundle];
  61. id object = [bundle objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
  62. float value = [object floatValue];
  63. if (!(value > 0.0)) {
  64. NSLog(@"Unable to get Xcode Version");
  65. }
  66. return value;
  67. }
  68. @end
  69. @implementation GTMXcodePlugin
  70. @synthesize bundle = bundle_;
  71. - (id)initWithBundle:(NSBundle *)bundle {
  72. if ((self = [super init])) {
  73. bundle_ = [bundle retain];
  74. }
  75. return self;
  76. }
  77. - (void)dealloc {
  78. [bundle_ release];
  79. [super dealloc];
  80. }
  81. - (void)applicationDidFinishLaunching:(NSNotification *)notification {
  82. }
  83. @end