/// <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(); }
/// <summary> /// Registers the project with <see cref="TypeFactory" />, and optionally /// scan the <see cref="Project.BaseDirectory" /> for extension assemblies. /// </summary> /// <param name="project">The project to work from.</param> /// <param name="scan">Specified whether to scan the <see cref="Project.BaseDirectory" /> for extension assemblies.</param> internal static void AddProject(Project project, bool scan) { if (!scan || String.IsNullOrEmpty(project.BaseDirectory)) return; LoadTasksTask loadTasks = new LoadTasksTask(); loadTasks.Project = project; loadTasks.NamespaceManager = project.NamespaceManager; loadTasks.Parent = project; loadTasks.FailOnError = false; loadTasks.Threshold = (project.Threshold == Level.Debug) ? Level.Debug : Level.Warning; string tasksDir = Path.Combine(project.BaseDirectory, "extensions"); string commonTasksDir = Path.Combine(tasksDir, "common"); // scan framework-neutral and version-neutral assemblies ScanDir(Path.Combine(commonTasksDir, "neutral"), loadTasks, false); // skip further processing if runtime framework has not yet // been set if (project.RuntimeFramework == null) { return; } // scan framework-neutral but version-specific assemblies ScanDir(Path.Combine(commonTasksDir, project.RuntimeFramework. ClrVersion.ToString (2)), loadTasks, false); string frameworkTasksDir = Path.Combine(tasksDir, project.RuntimeFramework.Family); // scan framework-specific but version-neutral assemblies ScanDir(Path.Combine(frameworkTasksDir, "neutral"), loadTasks, false); // scan framework-specific and version-specific assemblies ScanDir(Path.Combine(frameworkTasksDir, project.RuntimeFramework .Version.ToString()), loadTasks, false); }
/// <summary> /// Adds any task assemblies in the project base directory /// and its <c>tasks</c> subdirectory. /// </summary> /// <param name="project">The project to work from.</param> public static void AddProject(Project project) { if (!StringUtils.IsNullOrEmpty(project.BaseDirectory)) { LoadTasksTask loadTasks = new LoadTasksTask(); loadTasks.Project = project; loadTasks.NamespaceManager = project.NamespaceManager; loadTasks.Parent = project; loadTasks.FailOnError = false; loadTasks.Threshold = (project.Threshold == Level.Debug) ? Level.Debug : Level.Warning; // scan project base directory ScanDir(project.BaseDirectory, loadTasks, false); // scan framework-neutral assemblies ScanDir(Path.Combine(project.BaseDirectory, "tasks"), loadTasks, false); // skip further processing if runtime framework has not yet // been set if (project.RuntimeFramework == null) { return; } // scan framework-specific assemblies ScanDir(Path.Combine(Path.Combine(project.BaseDirectory, "tasks"), project.RuntimeFramework.Family), loadTasks, false); // scan framework version specific assemblies ScanDir(Path.Combine(Path.Combine(Path.Combine(project.BaseDirectory, "tasks"), project.RuntimeFramework.Family), project.RuntimeFramework.Version.ToString()), loadTasks, false); } // create weakref to project. It is possible that project may go // away, we don't want to hold it _projects.Add(new WeakReference(project)); foreach (TaskBuilder tb in TaskBuilders) { UpdateProjectWithBuilder(project, tb); } }
private void ProcessPlatform(XmlNode 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(); }