incubator-nmaven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sisb...@apache.org
Subject svn commit: r532051 - /incubator/nmaven/branches/SI_XPT/assemblies/NMaven.Plugin.Loader/src/main/csharp/NMaven/Plugin/Loader/PluginLoader.cs
Date Tue, 24 Apr 2007 19:39:10 GMT
Author: sisbell
Date: Tue Apr 24 12:39:10 2007
New Revision: 532051

URL: http://svn.apache.org/viewvc?view=rev&rev=532051
Log:
Cleaned up the code for plugin loader.

Modified:
    incubator/nmaven/branches/SI_XPT/assemblies/NMaven.Plugin.Loader/src/main/csharp/NMaven/Plugin/Loader/PluginLoader.cs

Modified: incubator/nmaven/branches/SI_XPT/assemblies/NMaven.Plugin.Loader/src/main/csharp/NMaven/Plugin/Loader/PluginLoader.cs
URL: http://svn.apache.org/viewvc/incubator/nmaven/branches/SI_XPT/assemblies/NMaven.Plugin.Loader/src/main/csharp/NMaven/Plugin/Loader/PluginLoader.cs?view=diff&rev=532051&r1=532050&r2=532051
==============================================================================
--- incubator/nmaven/branches/SI_XPT/assemblies/NMaven.Plugin.Loader/src/main/csharp/NMaven/Plugin/Loader/PluginLoader.cs
(original)
+++ incubator/nmaven/branches/SI_XPT/assemblies/NMaven.Plugin.Loader/src/main/csharp/NMaven/Plugin/Loader/PluginLoader.cs
Tue Apr 24 12:39:10 2007
@@ -1,3 +1,23 @@
+#region Apache License, Version 2.0 
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
+#endregion
 using System;
 using System.IO;
 using System.Reflection;
@@ -15,74 +35,41 @@
 		{
 		}
 
-		public void load(FileInfo paramFile, FileInfo assemblyFile, string mojoName)
+		/// <summary>
+		/// Loads the specified plugin assembly file into the returned plugin application domain.
+		/// </summary>
+		/// <param name="pluginAssemblyFile">the.NET maven plugin</param>
+		/// <returns>application domain for .NET maven plugin</returns>
+		/// 
+		public AppDomain LoadPlugin(FileInfo pluginAssemblyFile)
 		{
-			Console.WriteLine("Loading Loader: " + assemblyFile.DirectoryName);
+			Console.WriteLine("Loading Plugin: " + pluginAssemblyFile.DirectoryName);
 			AppDomainSetup setup = new AppDomainSetup();
-			setup.ApplicationBase = assemblyFile.DirectoryName;
+			setup.ApplicationBase = pluginAssemblyFile.DirectoryName;
 
-			AppDomain domain = AppDomain.CreateDomain("Loader", null, setup);
-			PluginDomainManager domainManager = (PluginDomainManager) domain.DomainManager;
-            domainManager.LoadPlugin(assemblyFile);
-			ObjectHandle oh = domain.CreateInstanceFrom(assemblyFile.FullName, mojoName);
-			AbstractMojo o = (AbstractMojo) oh.Unwrap();
-			o.injectFields(paramFile.FullName);
-			o.Execute();
-			//Console.WriteLine("Type = " + o.getT());
-			/*
-			foreach(MethodInfo methodInfo in o.GetType().GetMethods())
-			{
-				Console.WriteLine(methodInfo.Name);
-			}
-			MethodInfo executeMethod = o.GetType().GetMethod("Execute");
-			executeMethod.Invoke(o, null);
-*/
-			//PluginDomainManager domainManager = new PluginDomainManager();
-			//AppDomain domain = domainManager.CreateDomain("Loader", null, setup);
-			//domain.CreateInstance();
-			/*
-			PluginDomainManager domainManager = (PluginDomainManager) domain.DomainManager;
-			
-			if(domainManager == null)
-			{
-				Console.WriteLine("DM is null");
-				return;
-			}
-						
-			domainManager.Load(paramFile, assemblyFile);
-			*/
-	/*		
-			Assembly assembly = null;
-			try 
-			{
-				assembly = domain.Load(@"NMaven.Plugin.Solution");				
-			}
-			catch(FileNotFoundException e)
-			{
-				Console.WriteLine(e.Message);
-				return;
-			}
-			
-			Type plugin = assembly.GetType("NMaven.Plugin.Solution.SolutionPlugin");
-			
-			object o = Activator.CreateInstance(plugin);
-			MethodInfo executeMethod = plugin.GetMethod("Execute");
-			executeMethod.Invoke(o, null);
-			*/
-			//Read in XML file, Executable Assembly Info (Directory, ArtifactId);
-/*			
-			string[] args = new string[2];
-			args[0] = @"C:\Documents and Settings\shane\nmaven-apache\SI_XPT\integration-tests\tests\it0020\target\assembly-resources\resgen";
-			args[1] = @"C:\tmp\test.resx";
-			FileInfo fileInfo = new FileInfo(@"C:\Documents and Settings\shane\.m2\repository\NMaven\Plugin\NMaven.Plugin.Resx\0.14\NMaven.Plugin.Resx.exe");
-			
-			AppDomainSetup setup = new AppDomainSetup();
-			setup.ApplicationBase = fileInfo.DirectoryName;		
-			setup.ConfigurationFile = @"NMaven.Plugin.Resx.exe.config";
-			AppDomain domain = AppDomain.CreateDomain("Loader", null, setup);
-		    int i = domain.ExecuteAssembly(@"NMaven.Plugin.Resx.exe", null, args);
-			Console.WriteLine("INT = " + i);	
-	*/
+			AppDomain applicationDomain = AppDomain.CreateDomain("Loader", null, setup);
+			PluginDomainManager pluginDomainManager = (PluginDomainManager) applicationDomain.DomainManager;
+            pluginDomainManager.LoadPlugin(pluginAssemblyFile);
+			return applicationDomain;
+		}
+		
+		/// <summary>
+		/// Creates an instance of the specified mojo name within the specified application domain.
+		/// </summary>
+		/// <param name="mojoName">the name of the mojo to create</param>
+		/// <param name="pluginAssemblyFile">the.NET maven plugin</param>
+		/// <param name="paramFile">the file containing the parameters to inject into an
instance 
+		/// of the specified mojo</param>
+		/// <param name="applicationDomain"></param>
+		/// <returns>an instance of the specified mojo name within the specified application
domain</returns>
+		public AbstractMojo CreateAbstractMojoFor(String mojoName, FileInfo pluginAssemblyFile,

+		                                          FileInfo paramFile, AppDomain applicationDomain)
+		{
+            ObjectHandle objectHandle = 
+            	applicationDomain.CreateInstanceFrom(pluginAssemblyFile.FullName, mojoName);
+			AbstractMojo abstractMojo = (AbstractMojo) objectHandle.Unwrap();
+			abstractMojo.injectFields(paramFile.FullName);
+			return abstractMojo;		
 		}
 		
 		public static void Main(string[] args)
@@ -94,7 +81,13 @@
 			                  paramFile, assemblyFile, mojoName);
 			
 			PluginLoader pluginLoader = new PluginLoader();
-			pluginLoader.load(new FileInfo(paramFile), new FileInfo(assemblyFile), mojoName);
+			AppDomain applicationDomain = pluginLoader.LoadPlugin(new FileInfo(assemblyFile));
+			AbstractMojo abstractMojo = pluginLoader.CreateAbstractMojoFor(mojoName, 
+			                                                               new FileInfo(assemblyFile),

+			                                                               new FileInfo(paramFile),
+			                                                               applicationDomain);
+			abstractMojo.Execute();
+			
 		}
 		
 		private static string GetArgFor(string name, string[] args)



Mime
View raw message