Commits

Ivan Vučica  committed 19aa21b

Added XCPluginManager.

  • Participants
  • Parent commits 5de93d8

Comments (0)

Files changed (3)

File Plugins/XCPluginManager.h

+/*
+ Project: Zcode
+ 
+ Copyright (C) 2011 Ivan Vučica
+ 
+ Author: Ivan Vučica
+ 
+ This application is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+ 
+ This application is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ Lesser General Public License for more details.
+ 
+ You should have received a copy of the GNU Lesser General Public
+ License along with this application; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+@interface XCPluginManager : NSObject
+{
+    NSMutableArray *searchPaths;
+    NSMutableArray *plugins;
+    NSSet *extensions;
+}
+
++(XCPluginManager*)sharedPluginManager;
+-(BOOL)loadPluginBundle:(NSString*)path;
+-(void)findAndLoadPlugins;
+// -(void)findAndLoadPluginsInDomain:(NSString*)domain;
+-(NSArray*)loadedPlugins;
+@end

File Plugins/XCPluginManager.m

+/*
+ Project: Zcode
+ 
+ Copyright (C) 2011 Ivan Vučica
+ 
+ Author: Ivan Vučica
+ 
+ This application is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+ 
+ This application is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ Lesser General Public License for more details.
+ 
+ You should have received a copy of the GNU Lesser General Public
+ License along with this application; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include "XCPluginManager.h"
+static XCPluginManager* pluginManager = nil;
+
+@implementation XCPluginManager
+
++(XCPluginManager*)sharedPluginManager;
+{
+    if(!pluginManager)
+        pluginManager = [XCPluginManager new];
+    return pluginManager;
+}
+-(id)init
+{
+    self = [super init];
+    if(!self)
+        return nil;
+    
+    searchPaths = [[NSMutableArray alloc] initWithObjects:
+                   [[NSBundle mainBundle] builtInPlugInsPath],
+                   [[[NSBundle mainBundle] bundlePath] stringByDeletingLastPathComponent],
+                   nil];
+    
+    extensions = [[NSSet alloc] initWithObjects:@"zcplugin", nil];
+    
+    plugins = [[NSMutableArray alloc] init];
+    return self;
+}
+-(void)dealloc
+{
+    [searchPaths release];
+    [plugins release];
+    [extensions release];
+    [super dealloc];
+}
+
+-(void)findAndLoadPlugins;
+{
+    for (NSString* s in searchPaths) 
+    {
+        NSArray *directory = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:s error:nil];
+        for (NSString *item in directory) 
+        {
+            if ([extensions containsObject:[item pathExtension]]) 
+            {
+                [self loadPluginBundle:item];
+            }
+        }
+    }
+}
+-(NSArray*)loadedPlugins
+{
+    return plugins;
+}
+-(BOOL)loadPluginBundle:(NSString *)path
+{
+    NSBundle *bundle = [NSBundle bundleWithPath:path];
+    
+    if([bundle load])
+    {
+        [plugins addObject:bundle];
+        return YES;
+    }
+    
+    [plugins release];
+    return NO;
+}
+@end

File Zcode.xcodeproj/project.pbxproj

 		7F11AFB31304541F00D2B67A /* run.png in Resources */ = {isa = PBXBuildFile; fileRef = 7F11AFB11304541F00D2B67A /* run.png */; };
 		7F11AFC0130454B900D2B67A /* app.png in Resources */ = {isa = PBXBuildFile; fileRef = 7F11AFBE130454B900D2B67A /* app.png */; };
 		7F11AFC1130454B900D2B67A /* target.png in Resources */ = {isa = PBXBuildFile; fileRef = 7F11AFBF130454B900D2B67A /* target.png */; };
+		7F24C24513CF86E0007B3928 /* XCPluginManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 7F24C24413CF86E0007B3928 /* XCPluginManager.m */; };
+		7F24C24613CF86E0007B3928 /* XCPluginManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 7F24C24413CF86E0007B3928 /* XCPluginManager.m */; };
 		7F427DA9136D859500679719 /* ZCPBXShellScriptBuildPhaseInspectorViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 7F427DA8136D859500679719 /* ZCPBXShellScriptBuildPhaseInspectorViewController.xib */; };
 		7F427DAD136D85AD00679719 /* ZCPBXShellScriptBuildPhaseInspectorViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 7F427DAC136D85AD00679719 /* ZCPBXShellScriptBuildPhaseInspectorViewController.m */; };
 		7F6ACAC312E99F5C00536F3D /* Zcode_main.m in Sources */ = {isa = PBXBuildFile; fileRef = 7F6ACAC212E99F5C00536F3D /* Zcode_main.m */; };
 		7F11AFB11304541F00D2B67A /* run.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = run.png; sourceTree = "<group>"; };
 		7F11AFBE130454B900D2B67A /* app.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = app.png; sourceTree = "<group>"; };
 		7F11AFBF130454B900D2B67A /* target.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = target.png; sourceTree = "<group>"; };
+		7F24C24313CF86E0007B3928 /* XCPluginManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XCPluginManager.h; sourceTree = "<group>"; };
+		7F24C24413CF86E0007B3928 /* XCPluginManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = XCPluginManager.m; sourceTree = "<group>"; };
 		7F427DA8136D859500679719 /* ZCPBXShellScriptBuildPhaseInspectorViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = ZCPBXShellScriptBuildPhaseInspectorViewController.xib; sourceTree = "<group>"; };
 		7F427DAB136D85AD00679719 /* ZCPBXShellScriptBuildPhaseInspectorViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ZCPBXShellScriptBuildPhaseInspectorViewController.h; sourceTree = "<group>"; };
 		7F427DAC136D85AD00679719 /* ZCPBXShellScriptBuildPhaseInspectorViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ZCPBXShellScriptBuildPhaseInspectorViewController.m; sourceTree = "<group>"; };
 		2A37F4ABFDCFA73011CA2CEA /* Classes */ = {
 			isa = PBXGroup;
 			children = (
+				7F24C24213CF86E0007B3928 /* Plugins */,
 				7F050B50136DAAB400754FDE /* Builder */,
 				7FD67AD2133CFFA500BEF030 /* IDE */,
 				96EABD0812EC9BBB006239A6 /* PBXProjLib */,
 			path = Builder;
 			sourceTree = "<group>";
 		};
+		7F24C24213CF86E0007B3928 /* Plugins */ = {
+			isa = PBXGroup;
+			children = (
+				7F24C24313CF86E0007B3928 /* XCPluginManager.h */,
+				7F24C24413CF86E0007B3928 /* XCPluginManager.m */,
+			);
+			path = Plugins;
+			sourceTree = "<group>";
+		};
 		7FD67AD2133CFFA500BEF030 /* IDE */ = {
 			isa = PBXGroup;
 			children = (
 				7F08B616136DF58E00577310 /* PBXCompilerSpecification.m in Sources */,
 				7F08B61A136DF67C00577310 /* XCSpecification.m in Sources */,
 				7F08B622136E061B00577310 /* XCCompilerSpecification.m in Sources */,
+				7F24C24613CF86E0007B3928 /* XCPluginManager.m in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
 				7F08B615136DF58E00577310 /* PBXCompilerSpecification.m in Sources */,
 				7F08B619136DF67C00577310 /* XCSpecification.m in Sources */,
 				7F08B621136E061B00577310 /* XCCompilerSpecification.m in Sources */,
+				7F24C24513CF86E0007B3928 /* XCPluginManager.m in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};