示例#1
0
        public static NAntProject LoadProject(FileInfo nantProjectBuildFile)
        {
            NAntProject nantProject = new NAntProject(nantProjectBuildFile);
            XmlDocument buildDoc = new XmlDocument();
            buildDoc.Load(nantProjectBuildFile.FullName);

            XmlNamespaceManager namespaceManager = new XmlNamespaceManager(buildDoc.NameTable);
            namespaceManager.AddNamespace("nant", NANT_NAMESPACE);

            LoadProjectProperties(nantProject, buildDoc, namespaceManager);
            LoadTargets(nantProject, buildDoc, namespaceManager);
            return nantProject;
        }
示例#2
0
        public static int ExecuteNant(NAntProject nantProject, string targetName, OnNAntExecutionProgress output)
        {
            Assembly currentAssembly = Assembly.GetExecutingAssembly();
            string nantExePath = Path.Combine(Path.GetDirectoryName(currentAssembly.Location), NANT_EXE);
            ProcessStartInfo processStartInfo = new ProcessStartInfo(nantExePath);
            processStartInfo.UseShellExecute = false;
            processStartInfo.RedirectStandardOutput = true;
            processStartInfo.WorkingDirectory = Path.GetDirectoryName(currentAssembly.Location);

            processStartInfo.Arguments = GetNAntArgs(nantProject, targetName);
            processStartInfo.CreateNoWindow = true;

            int exitCode = Int32.MinValue;
            using (Process proc = new Process())
            {
                proc.StartInfo = processStartInfo;

                proc.OutputDataReceived += delegate(object sender, DataReceivedEventArgs e)
                                               {
                                                   if (!string.IsNullOrEmpty(e.Data))
                                                   {
                                                       output(new NAntExecutionProgressEventArgs(e.Data));
                                                   }
                                                   else
                                                   {
                                                       output(new NAntExecutionProgressEventArgs(Environment.NewLine));
                                                   }
                                               };

                proc.ErrorDataReceived += delegate(object sender, DataReceivedEventArgs e)
                                              {
                                                  if (!string.IsNullOrEmpty(e.Data))
                                                  {
                                                      output(new NAntExecutionProgressEventArgs(e.Data));
                                                  }
                                                  else
                                                  {
                                                      output(new NAntExecutionProgressEventArgs(Environment.NewLine));
                                                  }
                                              };

                proc.Start();
                proc.BeginOutputReadLine();
                proc.WaitForExit();
                exitCode = proc.ExitCode;
            }

            return exitCode;
        }
示例#3
0
 private static void LoadProjectProperties(NAntProject project, XmlDocument buildDoc, XmlNamespaceManager namespaceManager)
 {
     XmlNode projectNode = buildDoc.SelectSingleNode(@"/nant:project", namespaceManager);
     if (projectNode != null)
     {
         project.ProjectName = GetAttributeValue(projectNode, @"name");
         project.DefaultTargetName = GetAttributeValue(projectNode, @"default");
     }
 }
示例#4
0
 private static void LoadTargets(NAntProject project, XmlDocument buildDoc, XmlNamespaceManager namespaceManager)
 {
     XmlNodeList targetNodes = buildDoc.SelectNodes(@"//nant:target", namespaceManager);
     if (targetNodes != null)
     {
         foreach (XmlNode targetNode in targetNodes)
         {
             NAntTarget target = new NAntTarget(project, GetAttributeValue(targetNode, @"name"));
             target.Description = GetAttributeValue(targetNode, @"description");
             string dependeciesList = GetAttributeValue(targetNode, @"depends");
             if (!string.IsNullOrEmpty(dependeciesList))
             {
                 string[] splittedDependencies = dependeciesList.Split(',');
                 foreach (string dependency in splittedDependencies)
                 {
                     target.Dependencies.Add(dependency.Trim());
                 }
             }
             project.Targets.Add(target);
         }
     }
 }
示例#5
0
        private static string GetNAntArgs(NAntProject nantProject, string targetName)
        {
            StringBuilder sbArgs = new StringBuilder();
            sbArgs.AppendFormat("-nologo -buildfile:\"{0}\" \"{1}\"", nantProject.BuildFile.FullName, targetName);
            NAntConsoleConfigurationSection config = NAntConsoleConfigurationSection.GetConfigurationSection();
            foreach (NAntPropertyElement nAntProperty in config.NAntProperties)
            {
                sbArgs.AppendFormat(" -D:\"{0}\"=\"{1}\"", nAntProperty.Name, nAntProperty.Value);
            }
            sbArgs.AppendFormat(" -D:\"{0}\"=\"{1}\"", NANTCONSOLE_VERSION_PROPERTY_NAME, Assembly.GetAssembly(typeof(NAntHelper)).GetName().Version);

            return sbArgs.ToString();
        }
示例#6
0
        private void LoadProject()
        {
            nantProject = null;
            flowLayoutPanelTargets.Controls.Clear();
            if (projectFile == null) return;

            try
            {
                nantProject = NAntHelper.LoadProject(ProjectFile);

                if (nantProject != null)
                {
                    foreach (NAntTarget target in nantProject.Targets)
                    {
                        if (targetFilter.Display(target))
                        {
                            Button targetButton = new Button();
                            targetButton.AutoSize = true;
                            targetButton.Anchor = AnchorStyles.None;
                            targetButton.Text = target.Name;
                            targetButton.Click += OnTargetButtonClick;

                            toolTip.SetToolTip(targetButton, CreateToolTipFromTarget(target));

                            if (target.Name.Equals(nantProject.DefaultTargetName,
                                                   StringComparison.InvariantCultureIgnoreCase))
                            {
                                targetButton.Font = new Font(targetButton.Font, FontStyle.Bold);
                            }

                            flowLayoutPanelTargets.Controls.Add(targetButton);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, string.Format(Resources.ErrorLoadingProjectFile, ProjectFile.FullName, ex),
                                Resources.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
 public LinksAnalysisCommand(Form mainForm, NAntProject nantProject)
     : base(@"Links analysis")
 {
     this.mainForm = mainForm;
     this.nantProject = nantProject;
 }
 public NewEnvironmentConfigFileCommand(NAntProject project)
     : base(@"New environment config")
 {
     this.project = project;
 }
 public ShowLinksCommand(Form mainForm, NAntProject nantProject)
     : base(@"Show links")
 {
     this.mainForm = mainForm;
     this.nantProject = nantProject;
 }