1 // NAnt - A .NET build tool
\r
2 // Copyright (C) 2001 Gerry Shaw
\r
4 // This program is free software; you can redistribute it and/or modify
\r
5 // it under the terms of the GNU General Public License as published by
\r
6 // the Free Software Foundation; either version 2 of the License, or
\r
7 // (at your option) any later version.
\r
9 // This program is distributed in the hope that it will be useful,
\r
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
12 // GNU General Public License for more details.
\r
14 // You should have received a copy of the GNU General Public License
\r
15 // along with this program; if not, write to the Free Software
\r
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\r
18 // Gerry Shaw (gerry_shaw@yahoo.com)
\r
19 // Ian MacLean (ian_maclean@another.com)
\r
21 namespace SourceForge.NAnt {
\r
24 using System.Collections.Specialized;
\r
27 public class Target {
\r
31 bool _hasExecuted = false;
\r
32 TaskCollection _tasks = new TaskCollection();
\r
33 StringCollection _dependencies = new StringCollection();
\r
35 public Target(Project project) {
\r
39 public string Name {
\r
40 get { return _name; }
\r
41 set { _name = value; }
\r
44 public Project Project {
\r
45 get { return _project; }
\r
46 set { _project = value; }
\r
49 public bool HasExecuted {
\r
50 get { return _hasExecuted; }
\r
53 public TaskCollection Tasks {
\r
54 get { return _tasks; }
\r
57 public StringCollection Dependencies {
\r
58 get { return _dependencies; }
\r
61 public void Initialize(XmlNode targetNode) {
\r
63 XmlNode nameNode = targetNode.SelectSingleNode("@name");
\r
64 if (nameNode == null) {
\r
65 // TODO: add Location to exception
\r
66 throw new BuildException("target must have a name attribute");
\r
68 Name = nameNode.Value;
\r
71 XmlNode dependsNode = targetNode.SelectSingleNode("@depends");
\r
72 if (dependsNode != null) {
\r
73 string depends = dependsNode.Value;
\r
74 foreach (string str in depends.Split(new char[]{','})) {
\r
75 string dependency = str.Trim();
\r
76 if (dependency.Length > 0) {
\r
77 Dependencies.Add(dependency);
\r
82 // select all the non-target nodes (these are global tasks for the project)
\r
83 XmlNodeList taskList = targetNode.SelectNodes("*");
\r
84 foreach (XmlNode taskNode in taskList) {
\r
85 Task task = Project.CreateTask(taskNode, this);
\r
92 public void Execute() {
\r
95 foreach (string targetName in Dependencies) {
\r
96 Target target = Project.Targets.Find(targetName);
\r
97 if (target == null) {
\r
98 // TODO: add Location to exception
\r
99 throw new BuildException(String.Format("unknown dependent target '{0}' of target '{1}'", targetName, Name));
\r
105 Log.WriteLine("{0}:", Name);
\r
106 foreach (Task task in Tasks) {
\r
110 _hasExecuted = true;
\r