Пример #1
0
        public virtual int Add(Target t)
        {
            // throw an exception if an attempt is made to add a null target
            if (t == null) {
                throw new BuildException("Null Target!");
            }

            logger.Debug(string.Format(
                CultureInfo.InvariantCulture,
                ResourceUtils.GetString("String_AddingTarget"),
                t.Name));

            // check for existing target with same name.
            if (Find(t.Name) == null) {
                return base.Add(t);
            } else {
                throw new BuildException(string.Format(CultureInfo.InvariantCulture,
                    ResourceUtils.GetString("NA1073"), t.Name));
            }
        }
Пример #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BuildEventArgs" />
 /// class for a <see cref="Target" /> level event.
 /// </summary>
 /// <param name="target">The <see cref="Target" /> that emitted the event.</param>
 public BuildEventArgs(Target target)
 {
     _project = target.Project;
     _target = target;
     _task = null;
 }
Пример #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BuildEventArgs" />
 /// class for a <see cref="Task" /> level event.
 /// </summary>
 /// <param name="task">The <see cref="Task" /> that emitted the event.</param>
 public BuildEventArgs(Task task)
 {
     _project = task.Project;
     _target = task.Parent as Target;
     _task = task;
 }
Пример #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BuildEventArgs" /> 
 /// class.
 /// </summary>
 public BuildEventArgs()
 {
     _project = null;
     _target = null;
     _task = null;
 }
Пример #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BuildEventArgs" />
 /// class for a <see cref="Project" /> level event.
 /// </summary>
 /// <param name="project">The <see cref="Project" /> that emitted the event.</param>
 public BuildEventArgs(Project project)
 {
     _project = project;
     _target = null;
     _task = null;
 }
Пример #6
0
 /// <summary>
 /// Creates a shallow copy of the <see cref="Target" />.
 /// </summary>
 /// <returns>
 /// A shallow copy of the <see cref="Target" />.
 /// </returns>
 public Target Clone()
 {
     Target clone = new Target();
     base.CopyTo(clone);
     clone._dependencies = _dependencies;
     clone._description = _description;
     clone._executed = _executed;
     clone._ifCondition = _ifCondition;
     clone._name = _name;
     clone._unlessCondition = _unlessCondition;
     return clone;
 }
Пример #7
0
        /// <summary>
        /// Writes a <see cref="Target" /> level message to the build log with 
        /// the given <see cref="Level" />.
        /// </summary>
        /// <param name="target">The <see cref="Target" /> from which the message orignated.</param>
        /// <param name="messageLevel">The level to log at.</param>
        /// <param name="message">The message to log.</param>
        public void Log(Target target, Level messageLevel, string message)
        {
            BuildEventArgs eventArgs = new BuildEventArgs(target);

            eventArgs.Message = message;
            eventArgs.MessageLevel = messageLevel;
            OnMessageLogged(eventArgs);
        }
Пример #8
0
        /// <summary>
        /// Executes a specific target.
        /// </summary>
        /// <param name="targetName">The name of the target to execute.</param>
        /// <param name="forceDependencies">Whether dependencies should be forced to execute</param>
        /// <remarks>
        /// Global tasks are not executed.
        /// </remarks>
        public void Execute(string targetName, bool forceDependencies)
        {
            // sort the dependency tree, and run everything from the
            // beginning until we hit our targetName.
            //
            // sorting checks if all the targets (and dependencies)
            // exist, and if there is any cycle in the dependency
            // graph.
            TargetCollection sortedTargets = TopologicalTargetSort(targetName, Targets);
            int currentIndex = 0;
            Target currentTarget;

            // store calling target
            Target callingTarget = _currentTarget;

            do {
                // determine target that should be executed
                currentTarget = (Target) sortedTargets[currentIndex++];

                // store target that will be executed
                _currentTarget = currentTarget;

                // only execute targets that have not been executed already, if
                // we are not forcing.
                if (forceDependencies || !currentTarget.Executed) {
                    currentTarget.Execute();
                }
            } while (!currentTarget.Name.Equals(targetName));

            // restore calling target, as a <call> task might have caused the
            // current target to be executed and when finished executing this
            // target, the target that contained the <call> task should be
            // considered the current target again
            _currentTarget = callingTarget;
        }
Пример #9
0
        /// <summary>
        /// Creates a new <see cref="Task" /> from the given <see cref="XmlNode" /> 
        /// within a <see cref="Target" />.
        /// </summary>
        /// <param name="taskNode">The <see cref="Task" /> definition.</param>
        /// <param name="target">The owner <see cref="Target" />.</param>
        /// <returns>The new <see cref="Task" /> instance.</returns>
        public Task CreateTask(XmlNode taskNode, Target target)
        {
            Task task = TypeFactory.CreateTask(taskNode, this);

            task.Project = this;
            task.Parent = target;
            task.NamespaceManager = NamespaceManager;
            task.Initialize(taskNode);
            return task;
        }
Пример #10
0
        /// <summary>
        /// This method is only meant to be used by the <see cref="Project"/> 
        /// class and <see cref="CIScript.Core.Tasks.IncludeTask"/>.
        /// </summary>
        internal void InitializeProjectDocument(XmlDocument doc)
        {
            // load line and column number information into position map
            LocationMap.Add(doc);

            // initialize targets first
            foreach (XmlNode childNode in doc.DocumentElement.ChildNodes) {
                // skip non-ciscript namespace elements and special elements like
                // comments, pis, text, etc.
                if (childNode.LocalName.Equals(TargetXml) && childNode.NamespaceURI.Equals(NamespaceManager.LookupNamespace("ciscript"))) {
                    Target target = new Target();

                    target.Project = this;
                    target.Parent = this;
                    target.NamespaceManager = NamespaceManager;
                    target.Initialize(childNode);
                    Targets.Add(target);
                }
            }

            // initialize datatypes and execute global tasks
            foreach (XmlNode childNode in doc.DocumentElement.ChildNodes) {
                // skip targets that were handled above, skip non-ciscript namespace
                // elements and special elements like comments, pis, text, etc.
                if (!(childNode.NodeType == XmlNodeType.Element) || !childNode.NamespaceURI.Equals(NamespaceManager.LookupNamespace("ciscript")) || childNode.LocalName.Equals(TargetXml)) {
                    continue;
                }

                if (TypeFactory.TaskBuilders.Contains(childNode.Name)) {
                    // create task instance
                    Task task = CreateTask(childNode);
                    task.Parent = this;
                    // execute task
                    task.Execute();
                } else if (TypeFactory.DataTypeBuilders.Contains(childNode.Name)) {
                    // we are an datatype declaration
                    DataTypeBase dataType = CreateDataTypeBase(childNode);

                    Log(Level.Debug, "Adding a {0} reference with id '{1}'.", childNode.Name, dataType.ID);
                    if (! DataTypeReferences.Contains(dataType.ID)) {
                        DataTypeReferences.Add(dataType.ID, dataType);
                    } else {
                        DataTypeReferences[dataType.ID] = dataType; // overwrite with the new reference.
                    }
                } else {
                    throw new BuildException(string.Format(CultureInfo.InvariantCulture,
                        ResourceUtils.GetString("NA1071"), childNode.Name),
                        LocationMap.GetLocation(childNode));
                }
            }
        }