예제 #1
0
        /// <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();
        }
예제 #2
0
        /// <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();
        }