Example #1
0
        // Parses the Project attribute from an Import,
        // and returns the import filenames that match.
        // This handles wildcards also
        static IEnumerable <string> GetImportPathsFromString(string import_string, Project project, DirectoryInfo base_dir_info)
        {
            string parsed_import = Expression.ParseAs <string> (import_string, ParseOptions.AllowItemsNoMetadataAndSplit, project);

            if (parsed_import != null)
            {
                parsed_import = parsed_import.Trim();
            }

            if (String.IsNullOrEmpty(parsed_import))
            {
                throw new InvalidProjectFileException("The required attribute \"Project\" in Import is empty");
            }

#if NET_4_0
            if (DirectoryScanner.HasWildcard(parsed_import))
            {
                var directoryScanner = new DirectoryScanner()
                {
                    Includes      = new ITaskItem [] { new TaskItem(parsed_import) },
                    BaseDirectory = base_dir_info
                };
                directoryScanner.Scan();

                foreach (ITaskItem matchedItem in directoryScanner.MatchedItems)
                {
                    yield return(matchedItem.ItemSpec);
                }
            }
            else
#endif
            yield return(parsed_import);
        }
Example #2
0
        internal void Evaluate(Project project, bool evaluatedTo)
        {
            // FIXME: maybe make Expression.ConvertTo (null, ...) work as MSBuildUtils.Unescape ()?
            if (project == null)
            {
                this.finalItemSpec = MSBuildUtils.Unescape(Include);
                return;
            }

            foreach (XmlNode xn in itemElement.ChildNodes)
            {
                XmlElement xe = xn as XmlElement;
                if (xe != null && ConditionParser.ParseAndEvaluate(xe.GetAttribute("Condition"), project))
                {
                    AddMetadata(xe.Name, xe.InnerText);
                }
            }

            DirectoryScanner directoryScanner;
            Expression       includeExpr, excludeExpr;

            ITaskItem[] includes, excludes;

            includeExpr = new Expression();
            includeExpr.Parse(Include, ParseOptions.AllowItemsNoMetadataAndSplit);
            excludeExpr = new Expression();
            excludeExpr.Parse(Exclude, ParseOptions.AllowItemsNoMetadataAndSplit);

            includes = (ITaskItem[])includeExpr.ConvertTo(project, typeof(ITaskItem[]),
                                                          ExpressionOptions.ExpandItemRefs);
            excludes = (ITaskItem[])excludeExpr.ConvertTo(project, typeof(ITaskItem[]),
                                                          ExpressionOptions.ExpandItemRefs);

            this.finalItemSpec = (string)includeExpr.ConvertTo(project, typeof(string),
                                                               ExpressionOptions.ExpandItemRefs);

            directoryScanner = new DirectoryScanner();

            directoryScanner.Includes = includes;
            directoryScanner.Excludes = excludes;

            if (project.FullFileName != String.Empty)
            {
                directoryScanner.BaseDirectory = new DirectoryInfo(Path.GetDirectoryName(project.FullFileName));
            }
            else
            {
                directoryScanner.BaseDirectory = new DirectoryInfo(Directory.GetCurrentDirectory());
            }

            directoryScanner.Scan();

            foreach (ITaskItem matchedItem in directoryScanner.MatchedItems)
            {
                AddEvaluatedItem(project, evaluatedTo, matchedItem);
            }
        }
Example #3
0
        void RemoveItems(Project project)
        {
            BuildItemGroup group;

            if (!project.TryGetEvaluatedItemByNameBatched(Name, out group))
            {
                return;
            }

            var removeExpr = new Expression();

            removeExpr.Parse(Remove, ParseOptions.AllowItemsNoMetadataAndSplit);

            var removes = (ITaskItem[])removeExpr.ConvertTo(
                project, typeof(ITaskItem[]), ExpressionOptions.ExpandItemRefs);

            var directoryScanner = new DirectoryScanner();

            directoryScanner.Includes = removes;

            if (project.FullFileName != String.Empty)
            {
                directoryScanner.BaseDirectory = new DirectoryInfo(Path.GetDirectoryName(project.FullFileName));
            }
            else
            {
                directoryScanner.BaseDirectory = new DirectoryInfo(Directory.GetCurrentDirectory());
            }

            directoryScanner.Scan();

            foreach (ITaskItem matchedItem in directoryScanner.MatchedItems)
            {
                group.RemoveItem(matchedItem);
            }
        }
Example #4
0
		void RemoveItems (Project project)
		{
			BuildItemGroup group;
			if (!project.TryGetEvaluatedItemByNameBatched (Name, out group))
				return;

			var removeExpr = new Expression ();
			removeExpr.Parse (Remove, ParseOptions.AllowItemsNoMetadataAndSplit);

			var removes = (ITaskItem[]) removeExpr.ConvertTo (
				project, typeof (ITaskItem[]), ExpressionOptions.ExpandItemRefs);

			var directoryScanner = new DirectoryScanner ();
			
			directoryScanner.Includes = removes;

			if (project.FullFileName != String.Empty)
				directoryScanner.BaseDirectory = new DirectoryInfo (Path.GetDirectoryName (project.FullFileName));
			else
				directoryScanner.BaseDirectory = new DirectoryInfo (Directory.GetCurrentDirectory ());
			
			directoryScanner.Scan ();

			foreach (ITaskItem matchedItem in directoryScanner.MatchedItems) {
				group.RemoveItem (matchedItem);
			}
		}
Example #5
0
		internal void Evaluate (Project project, bool evaluatedTo)
		{
			// FIXME: maybe make Expression.ConvertTo (null, ...) work as MSBuildUtils.Unescape ()?
			if (project == null) {
				this.finalItemSpec = MSBuildUtils.Unescape (Include);
				return;
			}

			foreach (XmlNode xn in itemElement.ChildNodes) {
				XmlElement xe = xn as XmlElement;
				if (xe != null && ConditionParser.ParseAndEvaluate (xe.GetAttribute ("Condition"), project))
					AddMetadata (xe.Name, xe.InnerText);
			}

			if (IsDynamic) {
				if (!evaluatedTo)
					return;

				if (!string.IsNullOrEmpty (Remove)) {
					RemoveItems (project);
					return;
				}

				if (string.IsNullOrEmpty (Include)) {
					UpdateMetadata (project);
					return;
				}
			}
			
			DirectoryScanner directoryScanner;
			Expression includeExpr, excludeExpr;
			ITaskItem[] includes, excludes;

			var options = IsDynamic ?
				ParseOptions.AllowItemsMetadataAndSplit : ParseOptions.AllowItemsNoMetadataAndSplit;

			includeExpr = new Expression ();
			includeExpr.Parse (Include, options);
			excludeExpr = new Expression ();
			excludeExpr.Parse (Exclude, options);
			
			includes = (ITaskItem[]) includeExpr.ConvertTo (project, typeof (ITaskItem[]),
								ExpressionOptions.ExpandItemRefs);
			excludes = (ITaskItem[]) excludeExpr.ConvertTo (project, typeof (ITaskItem[]),
								ExpressionOptions.ExpandItemRefs);

			this.finalItemSpec = (string) includeExpr.ConvertTo (project, typeof (string),
							ExpressionOptions.ExpandItemRefs);

			directoryScanner = new DirectoryScanner ();
			
			directoryScanner.Includes = includes;
			directoryScanner.Excludes = excludes;

			if (project.FullFileName != String.Empty)
				directoryScanner.BaseDirectory = new DirectoryInfo (Path.GetDirectoryName (project.FullFileName));
			else
				directoryScanner.BaseDirectory = new DirectoryInfo (Directory.GetCurrentDirectory ());
			
			directoryScanner.Scan ();
			
			foreach (ITaskItem matchedItem in directoryScanner.MatchedItems)
				AddEvaluatedItem (project, evaluatedTo, matchedItem);
		}
Example #6
0
		// Parses the Project attribute from an Import,
		// and returns the import filenames that match.
		// This handles wildcards also
		static IEnumerable<string> GetImportPathsFromString (string import_string, Project project, DirectoryInfo base_dir_info)
		{
			string parsed_import = Expression.ParseAs<string> (import_string, ParseOptions.AllowItemsNoMetadataAndSplit, project);
			if (parsed_import != null)
				parsed_import = parsed_import.Trim ();

			if (String.IsNullOrEmpty (parsed_import))
				throw new InvalidProjectFileException ("The required attribute \"Project\" in Import is empty");

#if NET_4_0
			if (DirectoryScanner.HasWildcard (parsed_import)) {
				var directoryScanner = new DirectoryScanner () {
					Includes = new ITaskItem [] { new TaskItem (parsed_import) },
					BaseDirectory = base_dir_info
				};
				directoryScanner.Scan ();

				foreach (ITaskItem matchedItem in directoryScanner.MatchedItems)
					yield return matchedItem.ItemSpec;
			} else
#endif
				yield return parsed_import;
		}