public void PredictInputsAndOutputs(ProjectGraphNode projectGraphNode, ProjectPredictionReporter predictionReporter) { foreach (ProjectGraphNode dependency in projectGraphNode.ProjectReferences) { var dependencyDir = dependency.ProjectInstance.Directory; foreach (string item in _inputFiles) { predictionReporter.ReportInputFile(Path.GetFullPath(Path.Combine(dependencyDir, item))); } foreach (string item in _inputDirectories) { predictionReporter.ReportInputDirectory(Path.GetFullPath(Path.Combine(dependencyDir, item))); } foreach (string item in _outputFiles) { predictionReporter.ReportOutputFile(Path.GetFullPath(Path.Combine(dependencyDir, item))); } foreach (string item in _outputDirectories) { predictionReporter.ReportOutputDirectory(Path.GetFullPath(Path.Combine(dependencyDir, item))); } } }
private void ReportInputsForItemType(ProjectPredictionReporter reporter, ProjectInstance projectInstance, string itemType, HashSet <string> reportedIncludes) { ICollection <ProjectItemInstance> items = projectInstance.GetItems(itemType); if (items.Count == 0) { return; } foreach (ProjectItemInstance item in items) { if (item.GetMetadataValue(ExcludedFromBuildMetadata).Equals(bool.TrueString, StringComparison.OrdinalIgnoreCase)) { continue; } string[] additionalIncludeDirectories = item.GetMetadataValue(AdditionalIncludeDirectoriesMetadata) .Split(IncludePathsSeparator, StringSplitOptions.RemoveEmptyEntries); foreach (string directory in additionalIncludeDirectories) { string trimmedDirectory = directory.Trim(); if (!string.IsNullOrEmpty(trimmedDirectory) && reportedIncludes.Add(trimmedDirectory)) { reporter.ReportInputDirectory(trimmedDirectory); } } } }
private void ReportInputs(ProjectPredictionReporter reporter, ProjectItemInstance masmItem, HashSet <string> reportedIncludes) { reporter.ReportInputFile(masmItem.EvaluatedInclude); string[] includePaths = masmItem.GetMetadataValue(IncludePathsMetadata) .Split(IncludePathsSeparator, StringSplitOptions.RemoveEmptyEntries); // Avoid reporting paths that we've already reported for this project. foreach (string includePath in includePaths) { string trimmedPath = includePath.Trim(); if (!string.IsNullOrEmpty(trimmedPath) && reportedIncludes.Add(trimmedPath)) { reporter.ReportInputDirectory(trimmedPath); } } }
/// <inheritdoc/> public void PredictInputsAndOutputs(ProjectInstance projectInstance, ProjectPredictionReporter predictionReporter) { // This predictor only applies when StyleCop exists and is enabled. if (!projectInstance.Targets.ContainsKey(StyleCopTargetName) || projectInstance.GetPropertyValue(StyleCopEnabledPropertyName).Equals("false", StringComparison.OrdinalIgnoreCase)) { return; } // Find the StyleCop settings file as an input. If the override settings file is specified and valid, // it's used. Else fall back to finding the project settings file. Note that the validation or lack thereof // mimics what StyleCop actually does. string styleCopSettingsFile = TryGetOverrideSettingsFile(projectInstance, out string styleCopOverrideSettingsFile) ? styleCopOverrideSettingsFile : GetProjectSettingsFile(projectInstance.Directory); if (!string.IsNullOrEmpty(styleCopSettingsFile)) { predictionReporter.ReportInputFile(styleCopSettingsFile); } // For Completeness we should consider Compile items as well since they're passed to StyleCop, but in practice another predictor will take care of that. // StyleCop addins as input directories foreach (ProjectItemInstance item in projectInstance.GetItems(StyleCopAdditionalAddinPathsItemName)) { string addinPath = item.GetMetadataValue("FullPath"); string expandedAddinPath = Environment.ExpandEnvironmentVariables(addinPath); if (Directory.Exists(expandedAddinPath)) { predictionReporter.ReportInputDirectory(expandedAddinPath); } } // StyleCop violations file as an output string styleCopOutputFile = projectInstance.GetPropertyValue(StyleCopOutputFilePropertyName); if (!string.IsNullOrEmpty(styleCopOutputFile)) { predictionReporter.ReportOutputFile(styleCopOutputFile); } // When StyleCopCacheResults is true, a StyleCop.Cache file is written adjacent to the project. // Currently we want to avoid predicting this as predicting outputs to non-output directories generally leads to problems in the consumers of this library. // If the need for absolute completeness arises, it should be added and those consumers will just need to deal. }
private void ReportInputsForItemType(ProjectPredictionReporter reporter, ProjectInstance projectInstance, string itemType, HashSet <string> reportedInputs) { ICollection <ProjectItemInstance> items = projectInstance.GetItems(itemType); if (items.Count == 0) { return; } foreach (ProjectItemInstance item in items) { string moduleDefinitionFile = item.GetMetadataValue(ModuleDefinitionFileMetadata).Trim(); if (!string.IsNullOrEmpty(moduleDefinitionFile) && reportedInputs.Add(moduleDefinitionFile)) { reporter.ReportInputDirectory(moduleDefinitionFile); } } }
public void PredictInputsAndOutputs( ProjectInstance projectInstance, ProjectPredictionReporter predictionReporter) { foreach (var item in _inputFiles) { predictionReporter.ReportInputFile(item); } foreach (var item in _inputDirectories) { predictionReporter.ReportInputDirectory(item); } foreach (var item in _outputFiles) { predictionReporter.ReportOutputFile(item); } foreach (var item in _outputDirectories) { predictionReporter.ReportOutputDirectory(item); } }
private static void ProcessItems(ICollection <ProjectItemInstance> items, ProjectPredictionReporter predictionReporter) { foreach (ProjectItemInstance item in items) { string source = item.EvaluatedInclude; string[] destinationFolders = item.GetMetadataValue(DestinationFolderMetadata).Split(DestinationFolderSeparator, StringSplitOptions.RemoveEmptyEntries); if (string.IsNullOrEmpty(source) || destinationFolders.Length == 0) { // Ignore invalid items. continue; } // Make absolute source = Path.GetFullPath(Path.Combine(item.Project.Directory, source)).TrimEnd(DirectorySeparatorChars); if (File.Exists(source)) { // If the source is a known file, we can easily predict the inputs and outputs ProcessFile(source, Path.GetFileName(source), destinationFolders, null, predictionReporter); } else if (Directory.Exists(source)) { // If the source is a known directory, we can use the rest of the metadata to do a precise prediction. var matcher = new Matcher(item, source); // This value defaults to true, so check that it's not explicitly false bool isRecursive = !string.Equals(item.GetMetadataValue(IsRecursiveMetadata), "false", StringComparison.OrdinalIgnoreCase); ProcessDirectory( matcher, isRecursive, matcher.SearchPattern, source, destinationFolders, null, predictionReporter); } else { // The source doesn't exist, so is probably a file or folder generated at build time. Based on presence // of certain metadata, make a best guess as to whether this is probably a file or folder artifact, and // do vague predictions. bool isProbablyDirectory = !string.IsNullOrEmpty(item.GetMetadataValue(FileMatchMetadata)) || !string.IsNullOrEmpty(item.GetMetadataValue(FileExcludeMetadata)) || !string.IsNullOrEmpty(item.GetMetadataValue(DirExcludeMetadata)) || string.Equals(item.GetMetadataValue(IsRecursiveMetadata), "true", StringComparison.OrdinalIgnoreCase); if (isProbablyDirectory) { // We don't know anything about the file which might be copied, so just predict the source and destination directories predictionReporter.ReportInputDirectory(source); foreach (string destination in destinationFolders) { predictionReporter.ReportOutputDirectory(destination); } } else { ProcessFile(source, Path.GetFileName(source), destinationFolders, null, predictionReporter); } } } }