private void ProcessPlatform(XmlNode platformNode) { if (platformNode == null) { throw new ArgumentNullException("platformNode"); } // process platform task assemblies if (!ScannedTasks) { FileSet platformTaskAssemblies = new FileSet(); platformTaskAssemblies.BaseDirectory = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory); platformTaskAssemblies.Project = Project; platformTaskAssemblies.NamespaceManager = NamespaceManager; platformTaskAssemblies.Parent = Project; // avoid warnings by setting the parent of the fileset platformTaskAssemblies.ID = "platform-task-assemblies"; // avoid warnings by assigning an id XmlNode taskAssembliesNode = platformNode.SelectSingleNode( "nant:task-assemblies", NamespaceManager); if (taskAssembliesNode != null) { platformTaskAssemblies.Initialize(taskAssembliesNode, Project.Properties, null); } // scan platform extensions assemblies LoadTasksTask loadTasks = new LoadTasksTask(); loadTasks.Project = Project; loadTasks.NamespaceManager = NamespaceManager; loadTasks.Parent = Project; loadTasks.TaskFileSet = platformTaskAssemblies; loadTasks.FailOnError = false; loadTasks.Threshold = (Project.Threshold == Level.Debug) ? Level.Debug : Level.Warning; loadTasks.Execute(); // scan NAnt.Core TypeFactory.ScanAssembly(Assembly.GetExecutingAssembly(), loadTasks); } // process the framework nodes of the current platform ProcessFrameworks(platformNode); // process runtime framework task assemblies if (!ScannedTasks) { LoadTasksTask loadTasks = new LoadTasksTask(); loadTasks.Project = Project; loadTasks.NamespaceManager = NamespaceManager; loadTasks.Parent = Project; loadTasks.TaskFileSet = Project.RuntimeFramework.TaskAssemblies; loadTasks.FailOnError = false; loadTasks.Threshold = (Project.Threshold == Level.Debug) ? Level.Debug : Level.Warning; loadTasks.Execute(); // ensure we don't scan task assemblies for the current // runtime framework and platform again ScannedTasks = true; } }
/// <summary> /// Executes the tdc task. /// </summary> protected override void ExecuteTask() { if (!IsOutputUpToDate()) { string source = "using System.Xml;\n" + "using NAnt.Core;\n" + "using NAnt.Core.Attributes;\n" + "using NAnt.Core.Types;\n"; foreach (string fileName in Sources.FileNames) { XmlDocument tasksXml = new XmlDocument(); tasksXml.Load(fileName); UseDefaultNamespace(tasksXml, Project); foreach (XmlNode taskXml in tasksXml.SelectNodes("/*/*[local-name()='taskdef']")) { Log(Level.Verbose, "generating task from: " + taskXml.OuterXml); TaskDefTask taskDef = (TaskDefTask)Project.CreateTask(taskXml); source += taskDef.GenerateCSharpCode() + "\n"; } } Log(Level.Verbose, source); CompileSource(source); } LoadTasksTask loadTasksTask = new LoadTasksTask(); loadTasksTask.Project = Project; loadTasksTask.AssemblyPath = new FileInfo(Output); loadTasksTask.Execute(); }
/// <summary> /// Loads the extension assemblies in the current <see cref="AppDomain" /> /// and scans them for extensions. /// </summary> /// <param name="extensionAssemblies">The extension assemblies to load.</param> /// <param name="project">The <see cref="Project" /> which will be used to output messages to the build log.</param> private static void LoadExtensionAssemblies(StringCollection extensionAssemblies, Project project) { LoadTasksTask loadTasks = new LoadTasksTask(); loadTasks.Project = project; loadTasks.NamespaceManager = project.NamespaceManager; loadTasks.Parent = project; loadTasks.Threshold = (project.Threshold == Level.Debug) ? Level.Debug : Level.Warning; foreach (string extensionAssembly in extensionAssemblies) { loadTasks.TaskFileSet.Includes.Add(extensionAssembly); } loadTasks.Execute(); }
/// <summary> /// Executes the tdc task. /// </summary> protected override void ExecuteTask() { if (!IsOutputUpToDate()) { string source = "using System;\n" + "using System.Xml;\n" + "using NAnt.Core;\n" + "using NAnt.Core.Attributes;\n" + "using NAnt.Core.Types;\n"; foreach (string fileName in Sources.FileNames) { XmlDocument tasksXml = new XmlDocument(); tasksXml.Load(fileName); UseDefaultNamespace(tasksXml, Project); foreach (XmlNode taskXml in tasksXml.SelectNodes("/*/*[local-name()='taskdef']")) { Log(Level.Verbose, "generating task from: " + taskXml.OuterXml); TaskDefTask taskDef = (TaskDefTask)Project.CreateTask(taskXml); source += taskDef.GenerateCSharpCode() + "\n"; } } Dictionary <string, List <FuncDefTask> > funcs = new Dictionary <string, List <FuncDefTask> >(); foreach (string fileName in Sources.FileNames) { XmlDocument tasksXml = new XmlDocument(); tasksXml.Load(fileName); UseDefaultNamespace(tasksXml, Project); foreach (XmlNode taskXml in tasksXml.SelectNodes("/*/*[local-name()='funcdef']")) { Log(Level.Verbose, "generating task from: " + taskXml.OuterXml); FuncDefTask funcDef = (FuncDefTask)Project.CreateTask(taskXml); if (!funcs.ContainsKey(funcDef.Namespace)) { funcs[funcDef.Namespace] = new List <FuncDefTask>(); } funcs[funcDef.Namespace].Add(funcDef); } } foreach (string ns in funcs.Keys) { source += string.Format("[FunctionSet(\"{0}\", \"{0}\")]", ns); source += string.Format("public class {0}: FunctionSetBase {{\n", ns); source += string.Format("public {0}(Project project, PropertyDictionary properties) : base(project, properties) {{}}\n", ns); foreach (FuncDefTask fd in funcs[ns]) { source += fd.GenerateCSharpCode() + "\n"; } source += "}\n"; } Log(Level.Verbose, source); CompileSource(source); } LoadTasksTask loadTasksTask = new LoadTasksTask(); loadTasksTask.Project = Project; loadTasksTask.AssemblyPath = new FileInfo(Output); loadTasksTask.Execute(); }