public bool Compatible(PathMatch match) // The specified match is compatible with (does not contradicts to) this match { // Main rule: if a coverage condition holds for one path (in one or another direction) then it must hold for the other path (in the same direction) // SourcePath -> TargetPath if (match.SourcePath.StartsWith(SourcePath)) // The specified match continues this path { return(match.TargetPath.StartsWith(TargetPath)); // The same must be true for the other paths } else if (SourcePath.StartsWith(match.SourcePath)) // Opposite { return(TargetPath.StartsWith(match.TargetPath)); // The same must be true for the other paths } // TargetPath -> SourcePath if (match.TargetPath.StartsWith(TargetPath)) { return(match.SourcePath.StartsWith(SourcePath)); } else if (TargetPath.StartsWith(match.TargetPath)) { return(SourcePath.StartsWith(match.SourcePath)); } // Neither source path nor target paths cover. // This means they have some intersection (meet table they both continue). // This meet point defines an implicit match which we do not check but it might contradict to other matches. return(true); }
public PackageItem(ITaskItem item) { OriginalItem = item; SourcePath = item.GetMetadata("FullPath"); SourceProject = GetMetadata("MSBuildSourceProjectFile"); string value = GetMetadata("TargetFramework"); if (!String.IsNullOrWhiteSpace(value)) { TargetFramework = NuGetFramework.Parse(value); } TargetPath = item.GetMetadata(nameof(TargetPath)); AdditionalProperties = GetMetadata(nameof(AdditionalProperties)); UndefineProperties = GetMetadata(nameof(UndefineProperties)); HarvestedFrom = GetMetadata(nameof(HarvestedFrom)); Package = GetMetadata("PackageId"); PackageVersion = GetMetadata("PackageVersion"); IsDll = Path.GetExtension(SourcePath).Equals(".dll", StringComparison.OrdinalIgnoreCase); IsPlaceholder = NuGetAssetResolver.IsPlaceholder(SourcePath); IsRef = TargetPath.StartsWith("ref/", StringComparison.OrdinalIgnoreCase); // determine if we need to append filename to TargetPath // see https://docs.nuget.org/create/nuspec-reference#specifying-files-to-include-in-the-package // SourcePath specifies file and target specifies file - do nothing // SourcePath specifies file and Target specifies directory - copy filename // SourcePath specifies wildcard files - copy wildcard // SourcePath specifies recursive wildcard - do not allow, recursive directory may impact asset selection // we don't want to attempt to expand the wildcard since the build may not yet be complete. if (SourcePath.Contains("**")) { throw new ArgumentException($"Recursive wildcards \"**\" are not permitted in source paths for packages: {SourcePath}. Recursive directory may impact asset selection and we don't want to attempt to expand the wildcard since the build may not yet be complete."); } string sourceFile = Path.GetFileName(SourcePath); if (!Path.GetExtension(TargetPath).Equals(Path.GetExtension(sourceFile), StringComparison.OrdinalIgnoreCase) || sourceFile.Contains("*")) { TargetPath = Path.Combine(TargetPath, sourceFile); } // standardize to / TargetPath = TargetPath.Replace('\\', '/'); int dirLength = TargetPath.LastIndexOf('/'); TargetDirectory = (dirLength > 0) ? TargetPath.Substring(0, dirLength) : String.Empty; }
public bool MatchesTarget(ColumnPath path) // This is more specific (longer) than argument { return(TargetPath.StartsWith(path)); }