/// <summary> /// Constructor for IVSOutput2 implementation /// </summary> /// <param name="projectManager">Project that produce this output</param> /// <param name="outputAssembly">MSBuild generated item corresponding to the output assembly (by default, these would be of type MainAssembly</param> public Output(ProjectNode projectManager, ProjectItemInstance outputAssembly) { Utilities.ArgumentNotNull("projectManager", projectManager); project = projectManager; output = outputAssembly; }
protected override ProjectFileReference CreateProjectFileReference(ProjectItemInstance reference) { var filePath = reference.EvaluatedInclude; var aliases = GetAliases(reference); return new ProjectFileReference(filePath, aliases); }
/// <summary> /// Constructor for IVSOutput2 implementation /// </summary> /// <param name="projectManager">Project that produce this output</param> /// <param name="outputAssembly">MSBuild generated item corresponding to the output assembly (by default, these would be of type MainAssembly</param> public Output(ProjectNode projectManager, ProjectItemInstance outputAssembly) { if(projectManager == null) throw new ArgumentNullException("projectManager"); if(outputAssembly == null) throw new ArgumentNullException("outputAssembly"); project = projectManager; output = outputAssembly; }
/// <summary> /// Constructor for IVSOutput2 implementation /// </summary> /// <param name="projectManager">Project that produce this output</param> /// <param name="configuration">Configuration that produce this output</param> /// <param name="outputAssembly">MSBuild generated item corresponding to the output assembly (by default, these would be of type MainAssembly</param> public Output(ProjectNode projectManager, MSBuildExecution.ProjectItemInstance outputAssembly) { if (projectManager == null) { throw new ArgumentNullException("projectManager"); } if (outputAssembly == null) { throw new ArgumentNullException("outputAssembly"); } project = projectManager; output = outputAssembly; }
public static string GetEvaluatedItemIncludeEscaped(ProjectItemInstance item) { return(ProjectCollection.Escape(item.EvaluatedInclude)); }
public static string GetMetadataValueEscaped (ProjectItemInstance item, string name) { throw new NotImplementedException (); }
public bool RemoveItem (ProjectItemInstance item) { throw new NotImplementedException (); }
public static string GetEvaluatedInclude(MSBuildExecution.ProjectItemInstance item) { return(item.EvaluatedInclude); }
public static string GetMetadataValueEscaped(ProjectItemInstance item, string name) { throw new NotImplementedException(); }
public void KeepMetadataOnlySpecifiedPropagate4() { ProjectInstance project = ProjectHelpers.CreateEmptyProjectInstance(); ItemDictionary<ProjectItemInstance> table1 = new ItemDictionary<ProjectItemInstance>(); Lookup lookup = LookupHelpers.CreateLookup(table1); Lookup.Scope enteredScope = lookup.EnterScope("x"); // Add an item with m=m1 ProjectItemInstance item1 = new ProjectItemInstance(project, "i1", "a2", project.FullPath); item1.SetMetadata("m1", "m1"); item1.SetMetadata("m2", "m2"); lookup.AddNewItem(item1); Lookup.Scope enteredScope2 = lookup.EnterScope("x"); // Get rid of all of the metadata, then add m3 Lookup.MetadataModifications newMetadata = new Lookup.MetadataModifications(keepOnlySpecified: true); newMetadata.Add("m3", "m3"); ICollection<ProjectItemInstance> group = lookup.GetItems(item1.ItemType); lookup.ModifyItems(item1.ItemType, group, newMetadata); group = lookup.GetItems("i1"); Assert.Equal(1, group.Count); // m1 and m2 are gone. Assert.Equal(String.Empty, group.First().GetMetadataValue("m1")); Assert.Equal(String.Empty, group.First().GetMetadataValue("m2")); // m3 is still there. Assert.Equal("m3", group.First().GetMetadataValue("m3")); enteredScope2.LeaveScope(); // Keep m3. Lookup.MetadataModifications newMetadata2 = new Lookup.MetadataModifications(keepOnlySpecified: true); newMetadata2["m3"] = Lookup.MetadataModification.CreateFromNoChange(); group = lookup.GetItems(item1.ItemType); lookup.ModifyItems(item1.ItemType, group, newMetadata2); group = lookup.GetItems("i1"); Assert.Equal(1, group.Count); // m1 and m2 are gone Assert.Equal(String.Empty, group.First().GetMetadataValue("m1")); Assert.Equal(String.Empty, group.First().GetMetadataValue("m2")); // m3 is still there Assert.Equal("m3", group.First().GetMetadataValue("m3")); enteredScope.LeaveScope(); group = lookup.GetItems("i1"); Assert.Equal(1, group.Count); // m1 and m2 are gone Assert.Equal(String.Empty, group.First().GetMetadataValue("m1")); Assert.Equal(String.Empty, group.First().GetMetadataValue("m2")); // m3 is still there. Assert.Equal("m3", group.First().GetMetadataValue("m3")); }
public bool RemoveItem(ProjectItemInstance item) { throw new NotImplementedException(); }
/// <summary> /// Gets task item outputs /// </summary> private void GatherTaskItemOutputs(bool outputTargetIsItem, string outputTargetName, ITaskItem[] outputs, ElementLocation parameterLocation) { // if the task has generated outputs (if it didn't, don't do anything) if (outputs != null) { if (outputTargetIsItem) { foreach (ITaskItem output in outputs) { // if individual items in the array are null, ignore them if (output != null) { ProjectItemInstance newItem; ProjectItemInstance.TaskItem outputAsProjectItem = output as ProjectItemInstance.TaskItem; string parameterLocationEscaped = EscapingUtilities.EscapeWithCaching(parameterLocation.File); if (outputAsProjectItem != null) { // The common case -- all items involved are Microsoft.Build.Execution.ProjectItemInstance.TaskItems. // Furthermore, because that is true, we know by definition that they also implement ITaskItem2. newItem = new ProjectItemInstance(_projectInstance, outputTargetName, outputAsProjectItem.IncludeEscaped, parameterLocationEscaped); newItem.SetMetadata(outputAsProjectItem.MetadataCollection); // copy-on-write! } else { ITaskItem2 outputAsITaskItem2 = output as ITaskItem2; if (outputAsITaskItem2 != null) { // Probably a Microsoft.Build.Utilities.TaskItem. Not quite as good, but we can still preserve escaping. newItem = new ProjectItemInstance(_projectInstance, outputTargetName, outputAsITaskItem2.EvaluatedIncludeEscaped, parameterLocationEscaped); // It would be nice to be copy-on-write here, but Utilities.TaskItem doesn't know about CopyOnWritePropertyDictionary. foreach (DictionaryEntry entry in outputAsITaskItem2.CloneCustomMetadataEscaped()) { newItem.SetMetadataOnTaskOutput((string)entry.Key, (string)entry.Value); } } else { // Not a ProjectItemInstance.TaskItem or even a ITaskItem2, so we have to fake it. // Setting an item spec expects the escaped value, as does setting metadata. newItem = new ProjectItemInstance(_projectInstance, outputTargetName, EscapingUtilities.Escape(output.ItemSpec), parameterLocationEscaped); foreach (DictionaryEntry entry in output.CloneCustomMetadata()) { newItem.SetMetadataOnTaskOutput((string)entry.Key, EscapingUtilities.Escape((string)entry.Value)); } } } _batchBucket.Lookup.AddNewItem(newItem); } } if (_logTaskInputs && !_taskLoggingContext.LoggingService.OnlyLogCriticalEvents && outputs.Length > 0) { string parameterText = ItemGroupLoggingHelper.GetParameterText( ResourceUtilities.FormatResourceString("OutputItemParameterMessagePrefix"), outputTargetName, outputs); _taskLoggingContext.LogCommentFromText(MessageImportance.Low, parameterText); } } else { // to store an ITaskItem array in a property, join all the item-specs with semi-colons to make the // property value, and ignore/discard the attributes on the ITaskItems. // // An empty ITaskItem[] should create a blank value property, for compatibility. StringBuilder joinedOutputs = (outputs.Length == 0) ? new StringBuilder() : null; foreach (ITaskItem output in outputs) { // if individual items in the array are null, ignore them if (output != null) { joinedOutputs = joinedOutputs ?? new StringBuilder(); if (joinedOutputs.Length > 0) { joinedOutputs.Append(';'); } ITaskItem2 outputAsITaskItem2 = output as ITaskItem2; if (outputAsITaskItem2 != null) { joinedOutputs.Append(outputAsITaskItem2.EvaluatedIncludeEscaped); } else { joinedOutputs.Append(EscapingUtilities.Escape(output.ItemSpec)); } } } if (joinedOutputs != null) { var outputString = joinedOutputs.ToString(); if (_logTaskInputs && !_taskLoggingContext.LoggingService.OnlyLogCriticalEvents) { _taskLoggingContext.LogComment(MessageImportance.Low, "OutputPropertyLogMessage", outputTargetName, outputString); } _batchBucket.Lookup.SetProperty(ProjectPropertyInstance.Create(outputTargetName, outputString, parameterLocation, _projectInstance.IsImmutable)); } } } }
/// <summary> /// Initialize the host object /// </summary> /// <param name="throwOnExecute">Should the task throw when executed</param> private void InitializeHost(bool throwOnExecute) { _loggingService = LoggingService.CreateLoggingService(LoggerMode.Synchronous, 1) as ILoggingService; _logger = new MockLogger(); _loggingService.RegisterLogger(_logger); _host = new TaskExecutionHost(); TargetLoggingContext tlc = new TargetLoggingContext(_loggingService, new BuildEventContext(1, 1, BuildEventContext.InvalidProjectContextId, 1)); // Set up a temporary project and add some items to it. ProjectInstance project = CreateTestProject(); TypeLoader typeLoader = new TypeLoader(new TypeFilter(IsTaskFactoryClass)); AssemblyLoadInfo loadInfo = AssemblyLoadInfo.Create(Assembly.GetAssembly(typeof(TaskBuilderTestTask.TaskBuilderTestTaskFactory)).FullName, null); LoadedType loadedType = new LoadedType(typeof(TaskBuilderTestTask.TaskBuilderTestTaskFactory), loadInfo); TaskBuilderTestTask.TaskBuilderTestTaskFactory taskFactory = new TaskBuilderTestTask.TaskBuilderTestTaskFactory(); taskFactory.ThrowOnExecute = throwOnExecute; string taskName = "TaskBuilderTestTask"; (_host as TaskExecutionHost)._UNITTESTONLY_TaskFactoryWrapper = new TaskFactoryWrapper(taskFactory, loadedType, taskName, null); _host.InitializeForTask ( this, tlc, project, taskName, ElementLocation.Create("none", 1, 1), this, false, null, false, CancellationToken.None ); ProjectTaskInstance taskInstance = project.Targets["foo"].Tasks.First(); TaskLoggingContext talc = tlc.LogTaskBatchStarted(".", taskInstance); ItemDictionary<ProjectItemInstance> itemsByName = new ItemDictionary<ProjectItemInstance>(); ProjectItemInstance item = new ProjectItemInstance(project, "ItemListContainingOneItem", "a.cs", "."); item.SetMetadata("Culture", "fr-fr"); itemsByName.Add(item); _oneItem = new ITaskItem[] { new TaskItem(item) }; item = new ProjectItemInstance(project, "ItemListContainingTwoItems", "b.cs", "."); ProjectItemInstance item2 = new ProjectItemInstance(project, "ItemListContainingTwoItems", "c.cs", "."); item.SetMetadata("HintPath", "c:\\foo"); item2.SetMetadata("HintPath", "c:\\bar"); itemsByName.Add(item); itemsByName.Add(item2); _twoItems = new ITaskItem[] { new TaskItem(item), new TaskItem(item2) }; _bucket = new ItemBucket(new string[0], new Dictionary<string, string>(), new Lookup(itemsByName, new PropertyDictionary<ProjectPropertyInstance>(), null), 0); _host.FindTask(null); _host.InitializeForBatch(talc, _bucket, null); _parametersSetOnTask = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase); _outputsReadFromTask = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase); }
private static Lookup GenerateLookup(ProjectInstance project, PropertyDictionary<ProjectPropertyInstance> properties) { List<ProjectItemInstance> items = new List<ProjectItemInstance>(); ProjectItemInstance item1 = new ProjectItemInstance(project, "i0", "a1", project.FullPath); ProjectItemInstance item2 = new ProjectItemInstance(project, "i0", "a2", project.FullPath); ProjectItemInstance item3 = new ProjectItemInstance(project, "i0", "a3", project.FullPath); ProjectItemInstance item4 = new ProjectItemInstance(project, "i0", "a4", project.FullPath); item1.SetMetadata("m", "m1"); item1.SetMetadata("n", "n1"); item2.SetMetadata("m", "m2"); item2.SetMetadata("n", "n2"); item3.SetMetadata("m", "m2"); item3.SetMetadata("n", "n2"); item4.SetMetadata("m", "m3"); item4.SetMetadata("n", "n3"); items.Add(item1); items.Add(item2); items.Add(item3); items.Add(item4); ItemDictionary<ProjectItemInstance> itemsByName = new ItemDictionary<ProjectItemInstance>(); itemsByName.ImportItems(items); Lookup lookup = LookupHelpers.CreateLookup(properties, itemsByName); return lookup; }
public MSBuild12ProjectItemType(ProjectItemInstance projectItemInstance) : base(projectItemInstance) { this.projectItemInstance = projectItemInstance; }
/// <summary> /// Creates a set of complicated item metadata and properties, and items to exercise /// the Expander class. The data here contains escaped characters, metadata that /// references properties, properties that reference items, and other complex scenarios. /// </summary> /// <param name="pg"></param> /// <param name="primaryItemsByName"></param> /// <param name="secondaryItemsByName"></param> /// <param name="itemMetadata"></param> private void CreateComplexPropertiesItemsMetadata ( out ReadOnlyLookup readOnlyLookup, out StringMetadataTable itemMetadata ) { ProjectInstance project = ProjectHelpers.CreateEmptyProjectInstance(); Dictionary<string, string> itemMetadataTable = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase); itemMetadataTable["Culture"] = "abc%253bdef;$(Gee_Aych_Ayee)"; itemMetadataTable["Language"] = "english"; itemMetadata = new StringMetadataTable(itemMetadataTable); PropertyDictionary<ProjectPropertyInstance> pg = new PropertyDictionary<ProjectPropertyInstance>(); pg.Set(ProjectPropertyInstance.Create("Gee_Aych_Ayee", "ghi")); pg.Set(ProjectPropertyInstance.Create("OutputPath", @"\jk ; l\mno%253bpqr\stu")); pg.Set(ProjectPropertyInstance.Create("TargetPath", "@(IntermediateAssembly->'%(RelativeDir)')")); List<ProjectItemInstance> intermediateAssemblyItemGroup = new List<ProjectItemInstance>(); ProjectItemInstance i1 = new ProjectItemInstance(project, "IntermediateAssembly", @"subdir1\engine.dll", project.FullPath); intermediateAssemblyItemGroup.Add(i1); i1.SetMetadata("aaa", "111"); ProjectItemInstance i2 = new ProjectItemInstance(project, "IntermediateAssembly", @"subdir2\tasks.dll", project.FullPath); intermediateAssemblyItemGroup.Add(i2); i2.SetMetadata("bbb", "222"); List<ProjectItemInstance> contentItemGroup = new List<ProjectItemInstance>(); ProjectItemInstance i3 = new ProjectItemInstance(project, "Content", "splash.bmp", project.FullPath); contentItemGroup.Add(i3); i3.SetMetadata("ccc", "333"); List<ProjectItemInstance> resourceItemGroup = new List<ProjectItemInstance>(); ProjectItemInstance i4 = new ProjectItemInstance(project, "Resource", "string$(p).resx", project.FullPath); resourceItemGroup.Add(i4); i4.SetMetadata("ddd", "444"); ProjectItemInstance i5 = new ProjectItemInstance(project, "Resource", "dialogs%253b.resx", project.FullPath); resourceItemGroup.Add(i5); i5.SetMetadata("eee", "555"); List<ProjectItemInstance> contentItemGroup2 = new List<ProjectItemInstance>(); ProjectItemInstance i6 = new ProjectItemInstance(project, "Content", "about.bmp", project.FullPath); contentItemGroup2.Add(i6); i6.SetMetadata("fff", "666"); ItemDictionary<ProjectItemInstance> secondaryItemsByName = new ItemDictionary<ProjectItemInstance>(); secondaryItemsByName.ImportItems(resourceItemGroup); secondaryItemsByName.ImportItems(contentItemGroup2); Lookup lookup = new Lookup(secondaryItemsByName, pg, null); // Add primary items lookup.EnterScope("x"); lookup.PopulateWithItems("IntermediateAssembly", intermediateAssemblyItemGroup); lookup.PopulateWithItems("Content", contentItemGroup); readOnlyLookup = new ReadOnlyLookup(lookup); }
public void KeepMetadataOnlySpecifiedPropagate2() { ProjectInstance project = ProjectHelpers.CreateEmptyProjectInstance(); ItemDictionary<ProjectItemInstance> table1 = new ItemDictionary<ProjectItemInstance>(); Lookup lookup = LookupHelpers.CreateLookup(table1); Lookup.Scope enteredScope = lookup.EnterScope("x"); // Add an item with m=m1 ProjectItemInstance item1 = new ProjectItemInstance(project, "i1", "a2", project.FullPath); item1.SetMetadata("m1", "m1"); item1.SetMetadata("m2", "m2"); lookup.AddNewItem(item1); Lookup.Scope enteredScope2 = lookup.EnterScope("x"); // Add m3 metadata Lookup.MetadataModifications newMetadata = new Lookup.MetadataModifications(keepOnlySpecified: false); newMetadata.Add("m3", "m3"); ICollection<ProjectItemInstance> group = lookup.GetItems(item1.ItemType); lookup.ModifyItems(item1.ItemType, group, newMetadata); group = lookup.GetItems("i1"); Assert.AreEqual(1, group.Count); // All metadata are present Assert.AreEqual("m1", group.First().GetMetadataValue("m1")); Assert.AreEqual("m2", group.First().GetMetadataValue("m2")); Assert.AreEqual("m3", group.First().GetMetadataValue("m3")); enteredScope2.LeaveScope(); // Now clear metadata Lookup.MetadataModifications newMetadata2 = new Lookup.MetadataModifications(keepOnlySpecified: true); group = lookup.GetItems(item1.ItemType); lookup.ModifyItems(item1.ItemType, group, newMetadata2); group = lookup.GetItems("i1"); Assert.AreEqual(1, group.Count); // All metadata are gone Assert.AreEqual(String.Empty, group.First().GetMetadataValue("m1")); Assert.AreEqual(String.Empty, group.First().GetMetadataValue("m2")); Assert.AreEqual(String.Empty, group.First().GetMetadataValue("m3")); enteredScope.LeaveScope(); group = lookup.GetItems("i1"); Assert.AreEqual(1, group.Count); // All metadata are gone Assert.AreEqual(String.Empty, group.First().GetMetadataValue("m1")); Assert.AreEqual(String.Empty, group.First().GetMetadataValue("m2")); Assert.AreEqual(String.Empty, group.First().GetMetadataValue("m3")); }
/// <summary> /// Creates an expander populated with some ProjectPropertyInstances and ProjectPropertyItems. /// </summary> /// <returns></returns> private Expander<ProjectPropertyInstance, ProjectItemInstance> CreateExpander() { ProjectInstance project = ProjectHelpers.CreateEmptyProjectInstance(); PropertyDictionary<ProjectPropertyInstance> pg = new PropertyDictionary<ProjectPropertyInstance>(); pg.Set(ProjectPropertyInstance.Create("p", "v0")); pg.Set(ProjectPropertyInstance.Create("p", "v1")); ItemDictionary<ProjectItemInstance> ig = new ItemDictionary<ProjectItemInstance>(); ProjectItemInstance i0 = new ProjectItemInstance(project, "i", "i0", project.FullPath); ProjectItemInstance i1 = new ProjectItemInstance(project, "i", "i1", project.FullPath); ig.Add(i0); ig.Add(i1); Expander<ProjectPropertyInstance, ProjectItemInstance> expander = new Expander<ProjectPropertyInstance, ProjectItemInstance>(pg, ig); return expander; }
public void ModifyItemTwiceInSameScope1() { ProjectInstance project = ProjectHelpers.CreateEmptyProjectInstance(); ItemDictionary<ProjectItemInstance> table1 = new ItemDictionary<ProjectItemInstance>(); Lookup lookup = LookupHelpers.CreateLookup(table1); // Add an item with m=m1 and n=n1 ProjectItemInstance item1 = new ProjectItemInstance(project, "i1", "a2", project.FullPath); item1.SetMetadata("m", "m1"); lookup.PopulateWithItem(item1); Lookup.Scope enteredScope = lookup.EnterScope("x"); // Make a modification to the item to be m=m2 Lookup.MetadataModifications newMetadata = new Lookup.MetadataModifications(keepOnlySpecified: false); newMetadata.Add("m", "m2"); ICollection<ProjectItemInstance> group = new List<ProjectItemInstance>(); group.Add(item1); lookup.ModifyItems(item1.ItemType, group, newMetadata); // Make an unrelated modification to the item newMetadata = new Lookup.MetadataModifications(keepOnlySpecified: false); newMetadata.Add("n", "n1"); lookup.ModifyItems(item1.ItemType, group, newMetadata); // It's now m=m2 group = lookup.GetItems("i1"); Assert.Equal(1, group.Count); Assert.Equal("m2", group.First().GetMetadataValue("m")); }
public void RemoveItemAddedInLowerScope() { ProjectInstance project = ProjectHelpers.CreateEmptyProjectInstance(); ItemDictionary<ProjectItemInstance> table1 = new ItemDictionary<ProjectItemInstance>(); Lookup lookup = LookupHelpers.CreateLookup(table1); // Start a target Lookup.Scope enteredScope = lookup.EnterScope("x"); // Add an item ProjectItemInstance item1 = new ProjectItemInstance(project, "i1", "a2", project.FullPath); lookup.AddNewItem(item1); // Start a task (eg) Lookup.Scope enteredScope2 = lookup.EnterScope("x"); // We see the item below Assert.Equal(1, lookup.GetItems("i1").Count); // Remove that item lookup.RemoveItem(item1); // We see no items Assert.Equal(0, lookup.GetItems("i1").Count); // Finish the task enteredScope2.LeaveScope(); // We still see no items Assert.Equal(0, lookup.GetItems("i1").Count); // Finish the target enteredScope.LeaveScope(); // We still see no items Assert.Equal(0, lookup.GetItems("i1").Count); }
public void ModifyItemThatWasAddedInSameScope() { ProjectInstance project = ProjectHelpers.CreateEmptyProjectInstance(); ItemDictionary<ProjectItemInstance> table1 = new ItemDictionary<ProjectItemInstance>(); Lookup lookup = LookupHelpers.CreateLookup(table1); Lookup.Scope enteredScope = lookup.EnterScope("x"); // Add an item with m=m1 ProjectItemInstance item1 = new ProjectItemInstance(project, "i1", "a2", project.FullPath); item1.SetMetadata("m", "m1"); lookup.AddNewItem(item1); // Change the item to be m=m2 Lookup.MetadataModifications newMetadata = new Lookup.MetadataModifications(keepOnlySpecified: false); newMetadata.Add("m", "m2"); ICollection<ProjectItemInstance> group = new List<ProjectItemInstance>(); group.Add(item1); lookup.ModifyItems(item1.ItemType, group, newMetadata); // Now it has m=m2 group = lookup.GetItems("i1"); Assert.Equal(1, group.Count); Assert.Equal("m2", group.First().GetMetadataValue("m")); // But the original item hasn't changed yet Assert.Equal("m1", item1.GetMetadataValue("m")); enteredScope.LeaveScope(); // It still has m=m2 group = lookup.GetItems("i1"); Assert.Equal(1, group.Count); Assert.Equal("m2", group.First().GetMetadataValue("m")); // But now the original item has changed as well Assert.Equal("m2", item1.GetMetadataValue("m")); }
public void KeepMetadataOnlySpecifiedNoneSpecified() { ProjectInstance project = ProjectHelpers.CreateEmptyProjectInstance(); ItemDictionary<ProjectItemInstance> table1 = new ItemDictionary<ProjectItemInstance>(); Lookup lookup = LookupHelpers.CreateLookup(table1); Lookup.Scope enteredScope = lookup.EnterScope("x"); // Add an item with m=m1 ProjectItemInstance item1 = new ProjectItemInstance(project, "i1", "a2", project.FullPath); item1.SetMetadata("m1", "m1"); item1.SetMetadata("m2", "m2"); lookup.AddNewItem(item1); Lookup.Scope enteredScope2 = lookup.EnterScope("x"); // Test keeping only specified metadata Lookup.MetadataModifications newMetadata = new Lookup.MetadataModifications(keepOnlySpecified: true); ICollection<ProjectItemInstance> group = lookup.GetItems(item1.ItemType); lookup.ModifyItems(item1.ItemType, group, newMetadata); group = lookup.GetItems("i1"); Assert.Equal(1, group.Count); // m1 and m2 are gone. Assert.Equal(String.Empty, group.First().GetMetadataValue("m1")); Assert.Equal(String.Empty, group.First().GetMetadataValue("m2")); enteredScope2.LeaveScope(); group = lookup.GetItems("i1"); Assert.Equal(1, group.Count); // m1 and m2 are gone. Assert.Equal(String.Empty, group.First().GetMetadataValue("m1")); Assert.Equal(String.Empty, group.First().GetMetadataValue("m2")); enteredScope.LeaveScope(); group = lookup.GetItems("i1"); Assert.Equal(1, group.Count); // m1 and m2 are gone. Assert.Equal(String.Empty, group.First().GetMetadataValue("m1")); Assert.Equal(String.Empty, group.First().GetMetadataValue("m2")); }
public static string GetEvaluatedItemIncludeEscaped(ProjectItemInstance item) { throw new NotImplementedException(); }
public void ModifyItemTwiceInSameScope2() { ProjectInstance project = ProjectHelpers.CreateEmptyProjectInstance(); ItemDictionary<ProjectItemInstance> table1 = new ItemDictionary<ProjectItemInstance>(); Lookup lookup = LookupHelpers.CreateLookup(table1); // Add an item with m=m1 and n=n1 and o=o1 ProjectItemInstance item1 = new ProjectItemInstance(project, "i1", "a2", project.FullPath); item1.SetMetadata("m", "m1"); item1.SetMetadata("n", "n1"); item1.SetMetadata("o", "o1"); lookup.PopulateWithItem(item1); Lookup.Scope enteredScope = lookup.EnterScope("x"); // It's still m=m1, n=n1, o=o1 ICollection<ProjectItemInstance> group = lookup.GetItems("i1"); Assert.Equal(1, group.Count); Assert.Equal("m1", group.First().GetMetadataValue("m")); Assert.Equal("n1", group.First().GetMetadataValue("n")); Assert.Equal("o1", group.First().GetMetadataValue("o")); // Make a modification to the item to be m=m2 and n=n2 Lookup.MetadataModifications newMetadata = new Lookup.MetadataModifications(keepOnlySpecified: false); newMetadata.Add("m", "m2"); newMetadata.Add("n", "n2"); group = new List<ProjectItemInstance>(); group.Add(item1); lookup.ModifyItems("i1", group, newMetadata); // It's now m=m2, n=n2, o=o1 ICollection<ProjectItemInstance> foundGroup = lookup.GetItems("i1"); Assert.Equal(1, foundGroup.Count); Assert.Equal("m2", foundGroup.First().GetMetadataValue("m")); Assert.Equal("n2", foundGroup.First().GetMetadataValue("n")); Assert.Equal("o1", foundGroup.First().GetMetadataValue("o")); // Make a modification to the item to be n=n3 newMetadata = new Lookup.MetadataModifications(keepOnlySpecified: false); newMetadata.Add("n", "n3"); lookup.ModifyItems("i1", group, newMetadata); // It's now m=m2, n=n3, o=o1 foundGroup = lookup.GetItems("i1"); Assert.Equal(1, foundGroup.Count); Assert.Equal("m2", foundGroup.First().GetMetadataValue("m")); Assert.Equal("n3", foundGroup.First().GetMetadataValue("n")); Assert.Equal("o1", foundGroup.First().GetMetadataValue("o")); // But the original item hasn't changed yet Assert.Equal("m1", item1.GetMetadataValue("m")); Assert.Equal("n1", item1.GetMetadataValue("n")); Assert.Equal("o1", item1.GetMetadataValue("o")); enteredScope.LeaveScope(); // It's still m=m2, n=n3, o=o1 foundGroup = lookup.GetItems("i1"); Assert.Equal(1, foundGroup.Count); Assert.Equal("m2", foundGroup.First().GetMetadataValue("m")); Assert.Equal("n3", foundGroup.First().GetMetadataValue("n")); Assert.Equal("o1", foundGroup.First().GetMetadataValue("o")); // And the original item has changed Assert.Equal("m2", item1.GetMetadataValue("m")); Assert.Equal("n3", item1.GetMetadataValue("n")); Assert.Equal("o1", item1.GetMetadataValue("o")); }
public void ValidUnqualifiedMetadataReference() { ProjectInstance project = ProjectHelpers.CreateEmptyProjectInstance(); List<string> parameters = new List<string>(); parameters.Add("@(File)"); parameters.Add("%(Culture)"); ItemDictionary<ProjectItemInstance> itemsByType = new ItemDictionary<ProjectItemInstance>(); List<ProjectItemInstance> items = new List<ProjectItemInstance>(); ProjectItemInstance a = new ProjectItemInstance(project, "File", "a.foo", project.FullPath); ProjectItemInstance b = new ProjectItemInstance(project, "File", "b.foo", project.FullPath); a.SetMetadata("Culture", "fr-fr"); b.SetMetadata("Culture", "en-en"); items.Add(a); items.Add(b); itemsByType.ImportItems(items); PropertyDictionary<ProjectPropertyInstance> properties = new PropertyDictionary<ProjectPropertyInstance>(); List<ItemBucket> buckets = BatchingEngine.PrepareBatchingBuckets(parameters, CreateLookup(itemsByType, properties), null); Assert.AreEqual(2, buckets.Count); }
public static string GetMetadataValue(MSBuildExecution.ProjectItemInstance item, string name) { return(item.GetMetadataValue(name)); }
public void InvalidUnqualifiedMetadataReference() { ProjectInstance project = ProjectHelpers.CreateEmptyProjectInstance(); List<string> parameters = new List<string>(); parameters.Add("@(File)"); parameters.Add("%(Culture)"); ItemDictionary<ProjectItemInstance> itemsByType = new ItemDictionary<ProjectItemInstance>(); List<ProjectItemInstance> items = new List<ProjectItemInstance>(); ProjectItemInstance a = new ProjectItemInstance(project, "File", "a.foo", project.FullPath); items.Add(a); ProjectItemInstance b = new ProjectItemInstance(project, "File", "b.foo", project.FullPath); items.Add(b); a.SetMetadata("Culture", "fr-fr"); itemsByType.ImportItems(items); PropertyDictionary<ProjectPropertyInstance> properties = new PropertyDictionary<ProjectPropertyInstance>(); // This is expected to throw because not all items contain a value for metadata "Culture". // Only a.foo has a Culture metadata. b.foo does not. List<ItemBucket> buckets = BatchingEngine.PrepareBatchingBuckets(parameters, CreateLookup(itemsByType, properties), MockElementLocation.Instance); }
public void ModifyItemInProjectPreviouslyModifiedAndGottenThroughGetItem() { ProjectInstance project = ProjectHelpers.CreateEmptyProjectInstance(); // Create some project state with an item with m=m1 and n=n1 ItemDictionary<ProjectItemInstance> table1 = new ItemDictionary<ProjectItemInstance>(); ProjectItemInstance item1 = new ProjectItemInstance(project, "i1", "a2", project.FullPath); item1.SetMetadata("m", "m1"); table1.Add(item1); Lookup lookup = LookupHelpers.CreateLookup(table1); Lookup.Scope enteredScope = lookup.EnterScope("x"); // Make a modification to the item to be m=m2 Lookup.MetadataModifications newMetadata = new Lookup.MetadataModifications(keepOnlySpecified: false); newMetadata.Add("m", "m2"); List<ProjectItemInstance> group = new List<ProjectItemInstance>(); group.Add(item1); lookup.ModifyItems(item1.ItemType, group, newMetadata); // Get the item (under the covers, it cloned it in order to apply the modification) ICollection<ProjectItemInstance> group2 = lookup.GetItems(item1.ItemType); Assert.Equal(1, group2.Count); ProjectItemInstance item1b = group2.First(); // Modify to m=m3 Lookup.MetadataModifications newMetadata2 = new Lookup.MetadataModifications(keepOnlySpecified: false); newMetadata2.Add("m", "m3"); List<ProjectItemInstance> group3 = new List<ProjectItemInstance>(); group3.Add(item1b); lookup.ModifyItems(item1b.ItemType, group3, newMetadata2); // Modifications are visible ICollection<ProjectItemInstance> group4 = lookup.GetItems(item1b.ItemType); Assert.Equal(1, group4.Count); Assert.Equal("m3", group4.First().GetMetadataValue("m")); // Leave scope enteredScope.LeaveScope(); // Still visible ICollection<ProjectItemInstance> group5 = lookup.GetItems(item1b.ItemType); Assert.Equal(1, group5.Count); Assert.Equal("m3", group5.First().GetMetadataValue("m")); // And the one in the project is changed Assert.Equal("m3", item1.GetMetadataValue("m")); }
public void RemoveItemFromProjectPreviouslyModifiedAndGottenThroughGetItem() { ProjectInstance project = ProjectHelpers.CreateEmptyProjectInstance(); // Create some project state with an item with m=m1 and n=n1 ItemDictionary<ProjectItemInstance> table1 = new ItemDictionary<ProjectItemInstance>(); ProjectItemInstance item1 = new ProjectItemInstance(project, "i1", "a2", project.FullPath); item1.SetMetadata("m", "m1"); table1.Add(item1); Lookup lookup = LookupHelpers.CreateLookup(table1); Lookup.Scope enteredScope = lookup.EnterScope("x"); // Make a modification to the item to be m=m2 Lookup.MetadataModifications newMetadata = new Lookup.MetadataModifications(keepOnlySpecified: false); newMetadata.Add("m", "m2"); List<ProjectItemInstance> group = new List<ProjectItemInstance>(); group.Add(item1); lookup.ModifyItems(item1.ItemType, group, newMetadata); // Get the item (under the covers, it cloned it in order to apply the modification) ICollection<ProjectItemInstance> group2 = lookup.GetItems(item1.ItemType); Assert.Equal(1, group2.Count); ProjectItemInstance item1b = group2.First(); // Remove the item lookup.RemoveItem(item1b); // There's now no items at all ICollection<ProjectItemInstance> group3 = lookup.GetItems(item1.ItemType); Assert.Equal(0, group3.Count); // Leave scope enteredScope.LeaveScope(); // And now none left in the project either Assert.Equal(0, table1["i1"].Count); }
public static string GetEvaluatedItemIncludeEscaped (ProjectItemInstance item) { throw new NotImplementedException (); }
public void AddsWithDuplicateRemovalItemSpecsOnly() { ProjectInstance project = ProjectHelpers.CreateEmptyProjectInstance(); // One item in the project ItemDictionary<ProjectItemInstance> table1 = new ItemDictionary<ProjectItemInstance>(); table1.Add(new ProjectItemInstance(project, "i1", "a1", project.FullPath)); // Add an existing duplicate table1.Add(new ProjectItemInstance(project, "i1", "a1", project.FullPath)); Lookup lookup = LookupHelpers.CreateLookup(table1); var scope = lookup.EnterScope("test"); // This one should not get added ProjectItemInstance[] newItems = new ProjectItemInstance[] { new ProjectItemInstance(project, "i1", "a1", project.FullPath), // Should not get added new ProjectItemInstance(project, "i1", "a2", project.FullPath), // Should get added }; // Perform the addition lookup.AddNewItemsOfItemType("i1", newItems, doNotAddDuplicates: true); var group = lookup.GetItems("i1"); // We should have the original two duplicates plus one new addition. Assert.Equal(3, group.Count); // Only two of the items should have the 'a1' include. Assert.Equal(2, group.Where(item => item.EvaluatedInclude == "a1").Count()); // And ensure the other item got added. Assert.Equal(1, group.Where(item => item.EvaluatedInclude == "a2").Count()); scope.LeaveScope(); group = lookup.GetItems("i1"); // We should have the original two duplicates plus one new addition. Assert.Equal(3, group.Count); // Only two of the items should have the 'a1' include. Assert.Equal(2, group.Where(item => item.EvaluatedInclude == "a1").Count()); // And ensure the other item got added. Assert.Equal(1, group.Where(item => item.EvaluatedInclude == "a2").Count()); }
public bool RemoveItem(ProjectItemInstance item) { // yeah, this raw_items should vanish... raw_items.Remove(item); return(all_evaluated_items.Remove(item)); }
public void AddsWithDuplicateRemovalWithMetadata() { ProjectInstance project = ProjectHelpers.CreateEmptyProjectInstance(); ItemDictionary<ProjectItemInstance> table1 = new ItemDictionary<ProjectItemInstance>(); // Two items, differ only by metadata table1.Add(new ProjectItemInstance(project, "i1", "a1", new KeyValuePair<string, string>[] { new KeyValuePair<string, string>("m1", "m1") }, project.FullPath)); table1.Add(new ProjectItemInstance(project, "i1", "a1", new KeyValuePair<string, string>[] { new KeyValuePair<string, string>("m1", "m2") }, project.FullPath)); Lookup lookup = LookupHelpers.CreateLookup(table1); var scope = lookup.EnterScope("test"); // This one should not get added ProjectItemInstance[] newItems = new ProjectItemInstance[] { new ProjectItemInstance(project, "i1", "a1", project.FullPath), // Should get added new ProjectItemInstance(project, "i1", "a2", new KeyValuePair<string, string>[] { new KeyValuePair<string, string>( "m1", "m1" ) }, project.FullPath), // Should get added new ProjectItemInstance(project, "i1", "a1", new KeyValuePair<string, string>[] { new KeyValuePair<string, string>( "m1", "m1" ) }, project.FullPath), // Should not get added new ProjectItemInstance(project, "i1", "a1", new KeyValuePair<string, string>[] { new KeyValuePair<string, string>( "m1", "m3" ) }, project.FullPath), // Should get added }; // Perform the addition lookup.AddNewItemsOfItemType("i1", newItems, doNotAddDuplicates: true); var group = lookup.GetItems("i1"); // We should have the original two duplicates plus one new addition. Assert.Equal(5, group.Count); // Four of the items will have the a1 include Assert.Equal(4, group.Where(item => item.EvaluatedInclude == "a1").Count()); // One item will have the a2 include Assert.Equal(1, group.Where(item => item.EvaluatedInclude == "a2").Count()); scope.LeaveScope(); group = lookup.GetItems("i1"); // We should have the original two duplicates plus one new addition. Assert.Equal(5, group.Count); // Four of the items will have the a1 include Assert.Equal(4, group.Where(item => item.EvaluatedInclude == "a1").Count()); // One item will have the a2 include Assert.Equal(1, group.Where(item => item.EvaluatedInclude == "a2").Count()); }
public static string GetMetadataValueEscaped(ProjectItemInstance item, string name) { var md = item.Metadata.FirstOrDefault(m => m.Name.Equals(name, StringComparison.OrdinalIgnoreCase)); return(md != null?ProjectCollection.Escape(md.EvaluatedValue) : null); }
public void Removes() { ProjectInstance project = ProjectHelpers.CreateEmptyProjectInstance(); // One item in the project ItemDictionary<ProjectItemInstance> table1 = new ItemDictionary<ProjectItemInstance>(); ProjectItemInstance item1 = new ProjectItemInstance(project, "i1", "a1", project.FullPath); table1.Add(item1); Lookup lookup = LookupHelpers.CreateLookup(table1); // Start a target Lookup.Scope enteredScope = lookup.EnterScope("x"); // Start a task (eg) and add a new item Lookup.Scope enteredScope2 = lookup.EnterScope("x"); ProjectItemInstance item2 = new ProjectItemInstance(project, "i1", "a2", project.FullPath); lookup.AddNewItem(item2); // Remove one item lookup.RemoveItem(item1); // We see one item Assert.Equal(1, lookup.GetItems("i1").Count); Assert.Equal("a2", lookup.GetItems("i1").First().EvaluatedInclude); // Remove the other item lookup.RemoveItem(item2); // We see no items Assert.Equal(0, lookup.GetItems("i1").Count); // Finish the task enteredScope2.LeaveScope(); // We still see no items Assert.Equal(0, lookup.GetItems("i1").Count); // But there's still one item in the project Assert.Equal("a1", table1["i1"].First().EvaluatedInclude); Assert.Equal(1, table1["i1"].Count); // Finish the target enteredScope.LeaveScope(); // We still see no items Assert.Equal(0, lookup.GetItems("i1").Count); // And now there are no items in the project either Assert.Equal(0, table1["i1"].Count); }
/// <summary> /// Creates an expander populated with some ProjectPropertyInstances and ProjectPropertyItems. /// </summary> /// <returns></returns> private Expander<ProjectPropertyInstance, ProjectItemInstance> CreateItemFunctionExpander() { ProjectInstance project = ProjectHelpers.CreateEmptyProjectInstance(); PropertyDictionary<ProjectPropertyInstance> pg = new PropertyDictionary<ProjectPropertyInstance>(); pg.Set(ProjectPropertyInstance.Create("p", "v0")); pg.Set(ProjectPropertyInstance.Create("p", "v1")); pg.Set(ProjectPropertyInstance.Create("Val", "2")); pg.Set(ProjectPropertyInstance.Create("a", "filename")); ItemDictionary<ProjectItemInstance> ig = new ItemDictionary<ProjectItemInstance>(); for (int n = 0; n < 10; n++) { ProjectItemInstance pi = new ProjectItemInstance(project, "i", "i" + n.ToString(), project.FullPath); for (int m = 0; m < 5; m++) { pi.SetMetadata("Meta" + m.ToString(), @"c:\firstdirectory\seconddirectory\file" + m.ToString() + ".ext"); } pi.SetMetadata("Meta9", @"seconddirectory\file.ext"); pi.SetMetadata("Meta10", @";someo%3bherplace\foo.txt;secondd%3brectory\file.ext;"); pi.SetMetadata("MetaBlank", @""); if (n % 2 > 0) { pi.SetMetadata("Even", "true"); pi.SetMetadata("Odd", "false"); } else { pi.SetMetadata("Even", "false"); pi.SetMetadata("Odd", "true"); } ig.Add(pi); } Dictionary<string, string> itemMetadataTable = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase); itemMetadataTable["Culture"] = "abc%253bdef;$(Gee_Aych_Ayee)"; itemMetadataTable["Language"] = "english"; IMetadataTable itemMetadata = new StringMetadataTable(itemMetadataTable); Expander<ProjectPropertyInstance, ProjectItemInstance> expander = new Expander<ProjectPropertyInstance, ProjectItemInstance>(pg, ig, itemMetadata); return expander; }
public void RemoveItemPopulatedInLowerScope() { ProjectInstance project = ProjectHelpers.CreateEmptyProjectInstance(); ItemDictionary<ProjectItemInstance> table1 = new ItemDictionary<ProjectItemInstance>(); Lookup lookup = LookupHelpers.CreateLookup(table1); ProjectItemInstance item1 = new ProjectItemInstance(project, "i1", "a2", project.FullPath); // Start a target Lookup.Scope enteredScope = lookup.EnterScope("x"); // There's one item in this batch lookup.PopulateWithItem(item1); // We see it Assert.Equal(1, lookup.GetItems("i1").Count); // Make a clone so we can keep an eye on that item Lookup lookup2 = lookup.Clone(); // We can see the item in the clone Assert.Equal(1, lookup2.GetItems("i1").Count); // Start a task (eg) Lookup.Scope enteredScope2 = lookup.EnterScope("x"); // We see the item below Assert.Equal(1, lookup.GetItems("i1").Count); // Remove that item lookup.RemoveItem(item1); // We see no items Assert.Equal(0, lookup.GetItems("i1").Count); // The clone is unaffected so far Assert.Equal(1, lookup2.GetItems("i1").Count); // Finish the task enteredScope2.LeaveScope(); // We still see no items Assert.Equal(0, lookup.GetItems("i1").Count); // But now the clone doesn't either Assert.Equal(0, lookup2.GetItems("i1").Count); // Finish the target enteredScope.LeaveScope(); // We still see no items Assert.Equal(0, lookup.GetItems("i1").Count); Assert.Equal(0, lookup2.GetItems("i1").Count); }
private static void AssertItemHasMetadata(Dictionary<string, string> expected, ProjectItemInstance item) { Assert.Equal(expected.Keys.Count, item.DirectMetadataCount); foreach (var key in expected.Keys) { Assert.Equal(expected[key], item.GetMetadataValue(key)); } }
/// <summary> /// Adds a new item to this bucket. /// </summary> internal void AddItem(ProjectItemInstance item) { _lookup.PopulateWithItem(item); }