internal void Add (UsingTask usingTask)
		{
			if (usingTask == null)
				throw new ArgumentNullException ("usingTask");
			
			if (usingTasks.Contains (usingTask))
				throw new InvalidOperationException ("Task already registered.");
			
			usingTasks.Add (usingTask);
		}
예제 #2
0
        internal void Add(UsingTask usingTask)
        {
            if (usingTask == null)
            {
                throw new ArgumentNullException("usingTask");
            }

            if (usingTasks.Contains(usingTask))
            {
                throw new InvalidOperationException("Task already registered.");
            }

            usingTasks.Add(usingTask);
        }
예제 #3
0
        public void TestICollectionMethods()
        {
            Project project = ObjectModelHelpers.CreateInMemoryProject(string.Format(@"

                    <Project xmlns=`msbuildnamespace`>

                        <UsingTask TaskName=`Microsoft.Build.UnitTests.Project_Tests.WashCar` AssemblyFile=`{0}` Condition=` true == true `/>
                        <UsingTask TaskName=`Microsoft.Build.UnitTests.Project_Tests.Message` AssemblyName=`{1}` Condition=` false == true `/>

                        <Target Name=`Build`>
                            <WashCar/>
                        </Target>

                    </Project>

                ", new Uri(Assembly.GetExecutingAssembly().EscapedCodeBase).LocalPath, Assembly.GetExecutingAssembly().FullName));

            UsingTaskCollection usingTasks = project.UsingTasks;

            Assertion.AssertEquals(2, usingTasks.Count);

            UsingTask[] array = new UsingTask[2];
            usingTasks.CopyTo(array, 0);

            Assertion.AssertEquals(usingTasks[0], array[0]);
            Assertion.AssertEquals(usingTasks[1], array[1]);

            object[] arrayObjects = new object[2];
            usingTasks.CopyTo(arrayObjects, 0);

            Assertion.AssertEquals(usingTasks[0], arrayObjects[0]);
            Assertion.AssertEquals(usingTasks[1], arrayObjects[1]);

            Assertion.AssertEquals("Microsoft.Build.UnitTests.Project_Tests.WashCar", usingTasks[0].TaskName);
            Assertion.AssertEquals("Microsoft.Build.UnitTests.Project_Tests.Message", usingTasks[1].TaskName);

            Assert.IsFalse(usingTasks.IsSynchronized, "Expected IsSynchronized to be false");
            Assert.IsNotNull(usingTasks.SyncRoot, "Expected SynchRoot to not be null");
        }
예제 #4
0
		public void TestUsingTaskOrder1 ()
		{
			Engine engine = new Engine (Consts.BinPath);
			Project proj = engine.CreateNewProject ();

			string documentString = @"
				<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
					<PropertyGroup>
						<Property>Test\resources\TestTasks.dll</Property>
					</PropertyGroup>

					<UsingTask AssemblyFile='$(Property)' TaskName='TrueTestTask' />
				</Project>
			";

			proj.LoadXml (documentString);

			UsingTask [] ut = new UsingTask [1];
			proj.UsingTasks.CopyTo (ut, 0);

			Assert.AreEqual ("$(Property)", ut [0].AssemblyFile, "A1");
		}
예제 #5
0
		public void TestCopyTo7 ()
		{
			string documentString = @"
				<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
					<UsingTask
						AssemblyFile='Test/resources/TestTasks.dll'
						TaskName='TrueTestTask'
					/>
				</Project>
			";

			engine = new Engine (Consts.BinPath);

			project = engine.CreateNewProject ();
			project.LoadXml (documentString);

			UsingTask [] array = new UsingTask [1];
			project.UsingTasks.CopyTo ((Array) array, 0);
		}
예제 #6
0
 public void RegisterUsingTask(UsingTask ut)
 {
     usingTasksByFullName [ut.TaskName] = new UsingTaskInfo(GetShortName(ut.TaskName), ut);
 }
예제 #7
0
 public UsingTaskInfo(string shortname, UsingTask task)
 {
     ShortName = shortname;
     Task      = task;
 }
예제 #8
0
 /// <summary>
 /// Adds a new UsingTask to this collection. Does not alter the parent project's XML.
 /// </summary>
 /// <param name="usingTask"></param>
 /// <owner>LukaszG</owner>
 internal void Add(UsingTask usingTask)
 {
     ErrorUtilities.VerifyThrow(this.usingTasks != null, "UsingTaskCollection's ArrayList not initialized!");
     this.usingTasks.Add(usingTask);
 }
예제 #9
0
 /// <summary>
 /// Adds a new UsingTask to this collection. Does not alter the parent project's XML.
 /// </summary>
 /// <param name="usingTask"></param>
 /// <owner>LukaszG</owner>
 internal void Add(UsingTask usingTask)
 {
     ErrorUtilities.VerifyThrow(this.usingTasks != null, "UsingTaskCollection's ArrayList not initialized!");
     this.usingTasks.Add(usingTask);
 }
예제 #10
0
 public void CopyTo_ZeroIndex()
 {
     Project p = new Project(new Engine());
     p.AddNewUsingTaskFromAssemblyFile("TaskName1", "AssemblyFile1.dll");
     p.AddNewUsingTaskFromAssemblyFile("TaskName2", "AssemblyFile2.dll");
     UsingTask[] usingTasks = new UsingTask[p.UsingTasks.Count];
     p.UsingTasks.CopyTo(usingTasks, 0);
     int i = 0;
     foreach (UsingTask usingTask in p.UsingTasks)
     {
         Assertion.AssertEquals(usingTasks[i].AssemblyFile, usingTask.AssemblyFile);
         i++;
     }
 }
예제 #11
0
		public void RegisterUsingTask (UsingTask ut)
		{
			usingTasksByFullName [ut.TaskName] = new UsingTaskInfo (GetShortName (ut.TaskName), ut);
		}
예제 #12
0
		public UsingTaskInfo (string shortname, UsingTask task)
		{
			ShortName = shortname;
			Task = task;
		}
예제 #13
0
파일: Project.cs 프로젝트: nikson/msbuild
        /// <summary>
        /// Process each of the direct children beneath the &gt;Project&lt; element.
        /// These include things like &lt;PropertyGroup&gt;, &lt;ItemGroup&gt;, &lt;Target&gt;, etc.
        /// This method is simply capturing the data in the form of our own
        /// internal objects.  It is not actually evaluating any of the properties
        /// or other data.
        /// </summary>
        /// <param name="projectElement"></param>
        /// <param name="projectDirectoryLocation"></param>
        /// <param name="importedProject"></param>
        /// <owner>RGoel</owner>
        private void ProcessProjectChildren
        (
            XmlElement projectElement,
            string projectDirectoryLocation,
            bool importedProject
        )
        {
            // Make sure the <Project> node has been given to us.
            error.VerifyThrow(projectElement != null,
                "Need an XML node representing the <project> element.");

            // Make sure this really is the <Project> node.
            ProjectXmlUtilities.VerifyThrowElementName(projectElement, XMakeElements.project);

            // Loop through all the direct children of the <project> element.
            // This verifies all the XML is legitimate, and creates ordered lists of objects
            // representing the top-level nodes (itemgroup, choose, etc.)
            // As this progresses, the Chooses and PropertyGroups are evaluated, so that conditions
            // on Imports involving properties can be evaluated too, because we need to know whether to
            // follow the imports.
            // All this comprises "Pass 1".
            List<XmlElement> childElements = ProjectXmlUtilities.GetValidChildElements(projectElement);

            string currentPerThreadProjectDirectory = Project.PerThreadProjectDirectory;

            try
            {
                // Make the correct project directory available. This is needed because it is 
                // used for evaluating "exists" in conditional expressions, for example on <Import> elements.
                Project.PerThreadProjectDirectory = ProjectDirectory;

                foreach (XmlElement childElement in childElements)
                {
                    switch (childElement.Name)
                    {
                        // Process the <ItemDefinitionGroup> element.
                        case XMakeElements.itemDefinitionGroup:
                            itemDefinitionLibrary.Add(childElement);
                            break;

                        // Process the <ItemGroup> element.
                        case XMakeElements.itemGroup:
                            BuildItemGroup newItemGroup = new BuildItemGroup(childElement, importedProject, /*parent project*/ this);
                            this.rawItemGroups.InsertAtEnd(newItemGroup);
                            break;

                    // Process the <PropertyGroup> element.
                    case XMakeElements.propertyGroup:
                        BuildPropertyGroup newPropertyGroup = new BuildPropertyGroup(this, childElement, importedProject);
                        newPropertyGroup.EnsureNoReservedProperties();
                        this.rawPropertyGroups.InsertAtEnd(newPropertyGroup);
                        // PropertyGroups/Chooses are evaluated immediately during this scan, as they're needed to figure out whether
                        // we include Imports.
                        newPropertyGroup.Evaluate(this.evaluatedProperties, this.conditionedPropertiesTable, ProcessingPass.Pass1);
                        break;

                        // Process the <Choose> element.
                        case XMakeElements.choose:
                            Choose newChoose = new Choose(this, this.rawGroups, childElement, importedProject, 0 /* not nested in another <Choose> */);

                            this.rawGroups.InsertAtEnd(newChoose);
                            // PropertyGroups/Chooses are evaluated immediately during this scan, as they're needed to figure out whether
                            // we include Imports.
                            newChoose.Evaluate(this.evaluatedProperties, false, true, this.conditionedPropertiesTable, ProcessingPass.Pass1);
                            break;

                        // Process the <Target> element.
                        case XMakeElements.target:
                            XmlElement targetElement = childElement;
                            Target newTarget = new Target(targetElement, this, importedProject);

                            // If a target with this name already exists, log a low priority message.
                            if (!ParentEngine.LoggingServices.OnlyLogCriticalEvents)
                            {
                                if (targets.Exists(newTarget.Name))
                                {
                                    ParentEngine.LoggingServices.LogComment(projectBuildEventContext, "OverridingTarget",
                                         targets[newTarget.Name].Name, targets[newTarget.Name].ProjectFileOfTargetElement,
                                         newTarget.Name, newTarget.ProjectFileOfTargetElement);
                                }
                            }

                            this.targets.AddOverrideTarget(newTarget);

                            if (this.nameOfFirstTarget == null)
                            {
                                this.nameOfFirstTarget = targetElement.GetAttribute(XMakeAttributes.name);
                            }
                            break;

                        // Process the <UsingTask> element.
                        case XMakeElements.usingTask:
                            UsingTask usingTask = new UsingTask(childElement, importedProject);
                            this.usingTasks.Add(usingTask);
                            break;

                        // Process the <ProjectExtensions> element.
                        case XMakeElements.projectExtensions:
                            if (!importedProject)
                            {
                                ProjectErrorUtilities.VerifyThrowInvalidProject(null == this.projectExtensionsNode, childElement,
                                    "DuplicateProjectExtensions");
                                this.projectExtensionsNode = childElement;

                                // No attributes are legal on this element
                                ProjectXmlUtilities.VerifyThrowProjectNoAttributes(childElement);
                            }
                            break;

                        // Process the <Error>, <Warning>, and <Message> elements
                        case XMakeElements.error:
                        case XMakeElements.warning:
                        case XMakeElements.message:
                            ProjectErrorUtilities.VerifyThrowInvalidProject(false, childElement, "ErrorWarningMessageNotSupported", childElement.Name);
                            break;

                        case XMakeElements.importGroup:
                            foreach (XmlElement importGroupChild in childElement.ChildNodes)
                            {
                                switch(importGroupChild.Name)
                                {
                                    case XMakeElements.import:
                                        ProcessImportElement(importGroupChild, projectDirectoryLocation, importedProject);
                                        break;
                                    default:
                                        ProjectXmlUtilities.ThrowProjectInvalidChildElement(importGroupChild);
                                        break;
                                }
                            }
                            break;

                        // Process the <Import> element.
                        case XMakeElements.import:
                            ProcessImportElement(childElement, projectDirectoryLocation, importedProject);
                            break;

                        default:
                            // We've encounted an unknown child element beneath <project>.
                            ProjectXmlUtilities.ThrowProjectInvalidChildElement(childElement);
                            break;
                    }
                }
            }
            finally
            {
                // Reset back to the original value
                Project.PerThreadProjectDirectory = currentPerThreadProjectDirectory;
            }
        }
예제 #14
0
 /// <summary>
 /// Copy the contents of this collection into a strongly typed array
 /// </summary>
 /// <param name="array"></param>
 /// <param name="index"></param>
 /// <owner>LukaszG</owner>
 public void CopyTo(UsingTask[] array, int index)
 {
     ErrorUtilities.VerifyThrow(this.usingTasks != null, "UsingTaskCollection's ArrayList not initialized!");
     this.usingTasks.CopyTo(array, index);
 }
예제 #15
0
 public void CopyTo_OffsetIndex()
 {
     int offSet = 3;
     Project p = new Project(new Engine());
     p.AddNewUsingTaskFromAssemblyFile("TaskName1", "AssemblyFile1.dll");
     p.AddNewUsingTaskFromAssemblyFile("TaskName2", "AssemblyFile2.dll");
     UsingTask[] taskArray = new UsingTask[p.UsingTasks.Count + offSet];
     p.UsingTasks.CopyTo(taskArray, offSet);
     int i = offSet - 1;
     Assertion.AssertNull(taskArray[offSet - 1]);
     foreach (UsingTask usingTask in p.UsingTasks)
     {
         Assertion.AssertEquals(taskArray[i].AssemblyFile, usingTask.AssemblyFile);
         i++;
     }
 }
		public void CopyTo (UsingTask[] array, int index)
		{
			usingTasks.CopyTo (array, index);
		}
예제 #17
0
 public void CopyTo_OffsetIndexArrayTooSmall()
 {
     int offSet = 3;
     Project p = new Project(new Engine());
     p.AddNewUsingTaskFromAssemblyFile("TaskName1", "AssemblyFile1.dll");
     p.AddNewUsingTaskFromAssemblyFile("TaskName2", "AssemblyFile2.dll");
     UsingTask[] usingTasks = new UsingTask[p.UsingTasks.Count];
     p.UsingTasks.CopyTo(usingTasks, offSet);
 }
예제 #18
0
        /// <summary>
        /// Reads the given &lt;UsingTask&gt; tag and saves the task information specified in it.
        /// </summary>
        /// <param name="usingTask"></param>
        /// <param name="expander"></param>
        /// <param name="loggingServices"></param>
        /// <param name="buildEventContext"></param>
        public void RegisterTask(UsingTask usingTask, Expander expander, EngineLoggingServices loggingServices, BuildEventContext buildEventContext)
        {
            if (
                // if the <UsingTask> tag doesn't have a condition on it
                (usingTask.Condition == null)
                ||
                // or if the condition holds
                Utilities.EvaluateCondition(usingTask.Condition, usingTask.ConditionAttribute, expander,
                                            null, ParserOptions.AllowProperties | ParserOptions.AllowItemLists, loggingServices, buildEventContext)
                )
            {
                // Lazily allocate the hashtables if they are needed
                if (registeredTasks == null)
                {
                    cachedTaskClassesWithExactMatch = new Hashtable(StringComparer.OrdinalIgnoreCase);
                    cachedTaskClassesWithFuzzyMatch = new Hashtable(StringComparer.OrdinalIgnoreCase);
                    registeredTasks = new Hashtable(StringComparer.OrdinalIgnoreCase);
                }

                string assemblyName = null;
                string assemblyFile = null;

                if (usingTask.AssemblyName != null)
                {
                    // expand out all embedded properties and items in the assembly name
                    assemblyName = expander.ExpandAllIntoString(usingTask.AssemblyName, usingTask.AssemblyNameAttribute);

                    ProjectErrorUtilities.VerifyThrowInvalidProject(assemblyName.Length > 0,
                                                                    usingTask.AssemblyNameAttribute, "InvalidEvaluatedAttributeValue", assemblyName, usingTask.AssemblyName, XMakeAttributes.assemblyName, XMakeElements.usingTask);
                }
                else
                {
                    // expand out all embedded properties and items in the assembly file/path
                    assemblyFile = expander.ExpandAllIntoString(usingTask.AssemblyFile, usingTask.AssemblyFileAttribute);

                    ProjectErrorUtilities.VerifyThrowInvalidProject(assemblyFile.Length > 0,
                                                                    usingTask.AssemblyFileAttribute, "InvalidEvaluatedAttributeValue", assemblyFile, usingTask.AssemblyFile, XMakeAttributes.assemblyFile, XMakeElements.usingTask);

                    // figure out the directory of the project in which this <UsingTask> node was defined
                    string projectFile = XmlUtilities.GetXmlNodeFile(usingTask.TaskNameAttribute.OwnerElement, String.Empty);
                    string projectDir  = (projectFile.Length > 0)
                        ? Path.GetDirectoryName(projectFile)
                        : String.Empty;

                    // ensure the assembly file/path is relative to the project in which this <UsingTask> node was defined -- we
                    // don't want paths from imported projects being interpreted relative to the main project file
                    try
                    {
                        assemblyFile = Path.Combine(projectDir, assemblyFile);
                    }
                    catch (ArgumentException ex)
                    {
                        // Invalid chars in AssemblyFile path
                        ProjectErrorUtilities.VerifyThrowInvalidProject(false, usingTask.AssemblyFileAttribute,
                                                                        "InvalidAttributeValueWithException", assemblyFile,
                                                                        XMakeAttributes.assemblyFile, XMakeElements.usingTask, ex.Message);
                    }
                }

                AssemblyLoadInfo taskAssembly = new AssemblyLoadInfo(assemblyName, assemblyFile);

                // expand out all embedded properties and items
                string taskName = expander.ExpandAllIntoString(usingTask.TaskName, usingTask.TaskNameAttribute);

                ProjectErrorUtilities.VerifyThrowInvalidProject(taskName.Length > 0,
                                                                usingTask.TaskNameAttribute, "InvalidEvaluatedAttributeValue", taskName, usingTask.TaskName, XMakeAttributes.taskName, XMakeElements.usingTask);

                // since more than one task can have the same name, we want to keep track of all assemblies that are declared to
                // contain tasks with a given name...
                ArrayList taskAssemblies = (ArrayList)registeredTasks[taskName];

                if (taskAssemblies == null)
                {
                    taskAssemblies            = new ArrayList();
                    registeredTasks[taskName] = taskAssemblies;
                }

                taskAssemblies.Add(taskAssembly);
            }
        }
예제 #19
0
        /// <summary>
        /// Reads the given &lt;UsingTask&gt; tag and saves the task information specified in it.
        /// </summary>
        /// <param name="usingTask"></param>
        /// <param name="expander"></param>
        /// <param name="loggingServices"></param>
        /// <param name="buildEventContext"></param>
        public void RegisterTask(UsingTask usingTask, Expander expander, EngineLoggingServices loggingServices, BuildEventContext buildEventContext)
        {
            if (
                // if the <UsingTask> tag doesn't have a condition on it
                    (usingTask.Condition == null)
                    ||
                // or if the condition holds
                    Utilities.EvaluateCondition(usingTask.Condition, usingTask.ConditionAttribute, expander,
                        null, ParserOptions.AllowProperties | ParserOptions.AllowItemLists, loggingServices, buildEventContext)
                )
            {
                // Lazily allocate the hashtables if they are needed
                if (registeredTasks == null)
                {
                    cachedTaskClassesWithExactMatch = new Hashtable(StringComparer.OrdinalIgnoreCase);
                    cachedTaskClassesWithFuzzyMatch = new Hashtable(StringComparer.OrdinalIgnoreCase);
                    registeredTasks = new Hashtable(StringComparer.OrdinalIgnoreCase);
                }

                string assemblyName = null;
                string assemblyFile = null;

                if (usingTask.AssemblyName != null)
                {
                    // expand out all embedded properties and items in the assembly name
                    assemblyName = expander.ExpandAllIntoString(usingTask.AssemblyName, usingTask.AssemblyNameAttribute);

                    ProjectErrorUtilities.VerifyThrowInvalidProject(assemblyName.Length > 0,
                        usingTask.AssemblyNameAttribute, "InvalidEvaluatedAttributeValue", assemblyName, usingTask.AssemblyName, XMakeAttributes.assemblyName, XMakeElements.usingTask);
                }
                else
                {
                    // expand out all embedded properties and items in the assembly file/path
                    assemblyFile = expander.ExpandAllIntoString(usingTask.AssemblyFile, usingTask.AssemblyFileAttribute);

                    ProjectErrorUtilities.VerifyThrowInvalidProject(assemblyFile.Length > 0,
                        usingTask.AssemblyFileAttribute, "InvalidEvaluatedAttributeValue", assemblyFile, usingTask.AssemblyFile, XMakeAttributes.assemblyFile, XMakeElements.usingTask);

                    // figure out the directory of the project in which this <UsingTask> node was defined
                    string projectFile = XmlUtilities.GetXmlNodeFile(usingTask.TaskNameAttribute.OwnerElement, String.Empty);
                    string projectDir = (projectFile.Length > 0)
                        ? Path.GetDirectoryName(projectFile)
                        : String.Empty;

                    // ensure the assembly file/path is relative to the project in which this <UsingTask> node was defined -- we
                    // don't want paths from imported projects being interpreted relative to the main project file
                    try
                    {
                        assemblyFile = Path.Combine(projectDir, assemblyFile);
                    }
                    catch (ArgumentException ex)
                    {
                        // Invalid chars in AssemblyFile path
                        ProjectErrorUtilities.VerifyThrowInvalidProject(false, usingTask.AssemblyFileAttribute,
                            "InvalidAttributeValueWithException", assemblyFile,
                            XMakeAttributes.assemblyFile, XMakeElements.usingTask, ex.Message);
                    }

                }

                AssemblyLoadInfo taskAssembly = new AssemblyLoadInfo(assemblyName, assemblyFile);

                // expand out all embedded properties and items
                string taskName = expander.ExpandAllIntoString(usingTask.TaskName, usingTask.TaskNameAttribute);

                ProjectErrorUtilities.VerifyThrowInvalidProject(taskName.Length > 0,
                    usingTask.TaskNameAttribute, "InvalidEvaluatedAttributeValue", taskName, usingTask.TaskName, XMakeAttributes.taskName, XMakeElements.usingTask);

                // since more than one task can have the same name, we want to keep track of all assemblies that are declared to
                // contain tasks with a given name...
                ArrayList taskAssemblies = (ArrayList)registeredTasks[taskName];

                if (taskAssemblies == null)
                {
                    taskAssemblies = new ArrayList();
                    registeredTasks[taskName] = taskAssemblies;
                }

                taskAssemblies.Add(taskAssembly);
            }
        }