From nmaven-commits-return-243-apmail-incubator-nmaven-commits-archive=incubator.apache.org@incubator.apache.org Tue Apr 24 19:39:46 2007 Return-Path: Delivered-To: apmail-incubator-nmaven-commits-archive@locus.apache.org Received: (qmail 87211 invoked from network); 24 Apr 2007 19:39:41 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 24 Apr 2007 19:39:41 -0000 Received: (qmail 9456 invoked by uid 500); 24 Apr 2007 19:39:42 -0000 Delivered-To: apmail-incubator-nmaven-commits-archive@incubator.apache.org Received: (qmail 9407 invoked by uid 500); 24 Apr 2007 19:39:42 -0000 Mailing-List: contact nmaven-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: nmaven-dev@incubator.apache.org Delivered-To: mailing list nmaven-commits@incubator.apache.org Received: (qmail 9082 invoked by uid 99); 24 Apr 2007 19:39:41 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 24 Apr 2007 12:39:40 -0700 X-ASF-Spam-Status: No, hits=-99.5 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 24 Apr 2007 12:39:31 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id 04F231A9838; Tue, 24 Apr 2007 12:39:11 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: nmaven-commits@incubator.apache.org From: sisbell@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070424193911.04F231A9838@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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) + /// + /// Loads the specified plugin assembly file into the returned plugin application domain. + /// + /// the.NET maven plugin + /// application domain for .NET maven plugin + /// + 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; + } + + /// + /// Creates an instance of the specified mojo name within the specified application domain. + /// + /// the name of the mojo to create + /// the.NET maven plugin + /// the file containing the parameters to inject into an instance + /// of the specified mojo + /// + /// an instance of the specified mojo name within the specified application domain + 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)