Esempio n. 1
0
        /// <summary>
        /// Renames the item.
        /// Equivalent to setting the <see cref="UnevaluatedInclude"/> value.
        /// Generally, no expansion occurs. This is because it would potentially result in several items,
        /// which is not meaningful semantics when renaming a single item.
        /// However if the item does not need to be split (which would invalidate its ProjectItemElement),
        /// and the new value expands to exactly one item, then its evaluated include is updated
        /// with the expanded value, rather than the unexpanded value.
        /// </summary>
        /// <remarks>
        /// Even if the new value expands to zero items, we do not expand it.
        /// The common case we are interested in for expansion here is setting something
        /// like "$(sourcesroot)\foo.cs" and expanding that to a single item.
        /// If say "@(foo)" is set as the new name, and it expands to blank, that might
        /// be surprising to the host and maybe even unhandled, if on full reevaluation
        /// it wouldn’t expand to blank. That’s why we're being cautious and supporting
        /// the most common scenario only.
        /// Many hosts will do a ReevaluateIfNecessary before reading anyway.
        /// </remarks>
        public void Rename(string name)
        {
            Project.VerifyThrowInvalidOperationNotImported(_xml.ContainingProject);
            ErrorUtilities.VerifyThrowInvalidOperation(_xml.Parent != null && _xml.Parent.Parent != null, "OM_ObjectIsNoLongerActive");

            if (String.Equals(UnevaluatedInclude, name, StringComparison.Ordinal))
            {
                return;
            }

            _fullPath = null; // Clear cached value

            if (_xml.Count == 0 /* no metadata */ && _project.IsSuitableExistingItemXml(_xml, name, null /* no metadata */) && !FileMatcher.HasWildcardsSemicolonItemOrPropertyReferences(name))
            {
                _evaluatedIncludeEscaped = name;

                // Fast item lookup tables are invalid now.
                // Make sure that when the caller invokes ReevaluateIfNecessary() that they'll be refreshed.
                Project.MarkDirty();
                return;
            }

            bool splitOccurred = _project.SplitItemElementIfNecessary(_xml);

            _xml.Include = name;

            if (splitOccurred)
            {
                _evaluatedIncludeEscaped = name;
            }
            else
            {
                _evaluatedIncludeEscaped = _project.ExpandItemIncludeBestEffortLeaveEscaped(_xml);
            }
        }
Esempio n. 2
0
		public void DirtyMarking2 ()
		{
			string project_xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003' />";
			var xml = XmlReader.Create (new StringReader (project_xml));
			var root = ProjectRootElement.Create (xml);
			var proj = new Project (root);
			proj.DisableMarkDirty = true;
			proj.MarkDirty ();
			Assert.IsFalse (proj.IsDirty, "#1"); // not rejected, just ignored.
			proj.DisableMarkDirty = false;
			Assert.IsFalse (proj.IsDirty, "#2"); // not like status pending
			proj.MarkDirty ();
			Assert.IsTrue (proj.IsDirty, "#3");
		}
Esempio n. 3
0
		public void DirtyMarking ()
		{
			string project_xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003' />";
			var xml = XmlReader.Create (new StringReader (project_xml));
			var root = ProjectRootElement.Create (xml);
			var proj = new Project (root);
			Assert.IsFalse (proj.IsDirty, "#1");
			proj.MarkDirty ();
			Assert.IsTrue (proj.IsDirty, "#2");
		}
Esempio n. 4
0
        public void BuildEvaluationUsesCustomLoggers()
        {
            string importProjectContent =
                ObjectModelHelpers.CleanupFileContents(@"<Project xmlns='msbuildnamespace'>
                </Project>");

            string importFileName = Microsoft.Build.Shared.FileUtilities.GetTemporaryFile() + ".proj";
            File.WriteAllText(importFileName, importProjectContent);

            string projectContent =
                ObjectModelHelpers.CleanupFileContents(@"<Project xmlns='msbuildnamespace'>
                    <Import Project=""" + importFileName + @"""/>
                    <Import Project=""" + importFileName + @"""/>
                    <ItemGroup>
                        <Compile Include='a.cs' />
                    </ItemGroup>
                    <Target Name=""Build"" />
                </Project>");

            Project project = new Project(XmlReader.Create(new StringReader(projectContent)));
            project.MarkDirty();

            MockLogger collectionLogger = new MockLogger();
            project.ProjectCollection.RegisterLogger(collectionLogger);

            MockLogger mockLogger = new MockLogger();

            bool result;

            try
            {
                result = project.Build(new ILogger[] { mockLogger });
            }
            catch
            {
                throw;
            }
            finally
            {
                project.ProjectCollection.UnregisterAllLoggers();
            }

            Assert.Equal(true, result);

            Assert.Equal(0, mockLogger.WarningCount); //                 "Log should not contain MSB4011 because the build logger will not receive evaluation messages."

            Assert.Equal(collectionLogger.Warnings[0].Code, "MSB4011"); //                 "Log should contain MSB4011 because the project collection logger should have been used for evaluation."
        }
Esempio n. 5
0
        public void ExternallyMarkDirty()
        {
            Project project = new Project();
            project.SetProperty("p", "v");
            project.ReevaluateIfNecessary();

            Assert.Equal(false, project.IsDirty);

            ProjectProperty property1 = project.GetProperty("p");

            project.MarkDirty();

            Assert.Equal(true, project.IsDirty);

            project.ReevaluateIfNecessary();

            Assert.Equal(false, project.IsDirty);

            ProjectProperty property2 = project.GetProperty("p");

            Assert.Equal(false, Object.ReferenceEquals(property1, property2)); // different object indicates reevaluation occurred
        }
Esempio n. 6
0
        /// <summary>
        /// Removes an interpreter factory from the project. This function will
        /// modify the project, but does not handle source control.
        /// </summary>
        /// <param name="factory">
        /// The id of the factory to remove. The function returns silently if
        /// the factory is not known by this provider.
        /// </param>
        public void RemoveInterpreterFactory(IPythonInterpreterFactory factory)
        {
            if (factory == null)
            {
                throw new ArgumentNullException("factory");
            }

            if (!_factories.ContainsKey(factory))
            {
                return;
            }

            string rootPath;

            if (_rootPaths.TryGetValue(factory.Id, out rootPath))
            {
                _rootPaths.Remove(factory.Id);
                foreach (var item in _project.GetItems(InterpreterItem))
                {
                    Guid itemId;
                    if (Guid.TryParse(item.GetMetadataValue(IdKey), out itemId) && factory.Id == itemId)
                    {
                        _project.RemoveItem(item);
                        _project.MarkDirty();
                        break;
                    }
                }
            }
            else
            {
                foreach (var item in _project.GetItems(InterpreterReferenceItem))
                {
                    Guid    itemId;
                    Version itemVer;
                    var     match = InterpreterReferencePath.Match(item.EvaluatedInclude);
                    if (match != null && match.Success && match.Groups.Cast <Group>().All(g => g.Success) &&
                        Guid.TryParse(match.Groups["id"].Value, out itemId) &&
                        Version.TryParse(match.Groups["version"].Value, out itemVer) &&
                        factory.Id == itemId &&
                        factory.Configuration.Version == itemVer)
                    {
                        _project.RemoveItem(item);
                        _project.MarkDirty();
                        break;
                    }
                }
            }

            bool        raiseEvent;
            FactoryInfo factInfo;

            lock (_factoriesLock) {
                raiseEvent = _factories.TryGetValue(factory, out factInfo) && _factories.Remove(factory);
            }
            if (factInfo != null &&
                factInfo.Owned &&
                factory is IDisposable)
            {
                ((IDisposable)factory).Dispose();
            }
            UpdateActiveInterpreter();
            if (raiseEvent)
            {
                OnInterpreterFactoriesChanged();
            }
        }