private Task <RemoteMatch> FindProjectMatch( LibraryRange libraryRange, NuGetFramework framework, GraphEdge <RemoteResolveResult> outerEdge, CancellationToken cancellationToken) { RemoteMatch result = null; // Check if projects are allowed for this dependency if (libraryRange.TypeConstraintAllowsAnyOf( (LibraryDependencyTarget.Project | LibraryDependencyTarget.ExternalProject))) { foreach (var provider in _context.ProjectLibraryProviders) { if (provider.SupportsType(libraryRange.TypeConstraint)) { var match = provider.GetLibrary(libraryRange, framework); if (match != null) { result = new LocalMatch { LocalLibrary = match, Library = match.Identity, LocalProvider = provider, Provider = new LocalDependencyProvider(provider), Path = match.Path, }; } } } } return(Task.FromResult <RemoteMatch>(result)); }
public static Task <RemoteMatch> FindProjectMatchAsync( LibraryRange libraryRange, NuGetFramework framework, IEnumerable <IDependencyProvider> projectProviders, CancellationToken cancellationToken) { RemoteMatch result = null; // Check if projects are allowed for this dependency if (libraryRange.TypeConstraintAllowsAnyOf( (LibraryDependencyTarget.Project | LibraryDependencyTarget.ExternalProject))) { foreach (var provider in projectProviders) { if (provider.SupportsType(libraryRange.TypeConstraint)) { var match = provider.GetLibrary(libraryRange, framework); if (match != null) { result = new LocalMatch { LocalLibrary = match, Library = match.Identity, LocalProvider = provider, Provider = new LocalDependencyProvider(provider), Path = match.Path, }; } } } } return(Task.FromResult <RemoteMatch>(result)); }
private static async Task <RemoteMatch> FindLibrary( LibraryRange libraryRange, IEnumerable <IRemoteDependencyProvider> providers, Func <IRemoteDependencyProvider, Task <RemoteMatch> > action) { var tasks = new List <Task <RemoteMatch> >(); foreach (var provider in providers) { tasks.Add(action(provider)); } RemoteMatch bestMatch = null; var matches = await Task.WhenAll(tasks); foreach (var match in matches) { if (libraryRange.VersionRange.IsBetter( current: bestMatch?.Library?.Version, considering: match?.Library?.Version)) { bestMatch = match; } } return(bestMatch); }
private static async Task <RemoteMatch> FindLibrary( LibraryRange libraryRange, IEnumerable <IRemoteDependencyProvider> providers, Func <IRemoteDependencyProvider, Task <LibraryIdentity> > action) { var tasks = new List <Task <RemoteMatch> >(); foreach (var provider in providers) { Func <Task <RemoteMatch> > taskWrapper = async() => { var library = await action(provider); if (library != null) { return(new RemoteMatch { Provider = provider, Library = library }); } return(null); }; tasks.Add(taskWrapper()); } RemoteMatch bestMatch = null; while (tasks.Count > 0) { var task = await Task.WhenAny(tasks); tasks.Remove(task); var match = await task; // If we found an exact match then use it. // This allows us to shortcircuit slow feeds even if there's an exact match if (!libraryRange.VersionRange.IsFloating && match?.Library?.Version != null && libraryRange.VersionRange.IsMinInclusive && match.Library.Version.Equals(libraryRange.VersionRange.MinVersion)) { return(match); } // Otherwise just find the best out of the matches if (libraryRange.VersionRange.IsBetter( current: bestMatch?.Library?.Version, considering: match?.Library?.Version)) { bestMatch = match; } } return(bestMatch); }
private static async Task <GraphItem <RemoteResolveResult> > CreateGraphItemAsync( RemoteMatch match, NuGetFramework framework, SourceCacheContext cacheContext, ILogger logger, CancellationToken cancellationToken) { LibraryDependencyInfo dependencies; // For local matches such as projects get the dependencies from the LocalLibrary property. var localMatch = match as LocalMatch; if (localMatch != null) { dependencies = LibraryDependencyInfo.Create( localMatch.LocalLibrary.Identity, framework, localMatch.LocalLibrary.Dependencies); } else { // Look up the dependencies from the source, this will download the package if needed. dependencies = await match.Provider.GetDependenciesAsync( match.Library, framework, cacheContext, logger, cancellationToken); } // Copy the original identity to the remote match. // This ensures that the correct casing is used for // the id/version. match.Library = dependencies.Library; return(new GraphItem <RemoteResolveResult>(match.Library) { Data = new RemoteResolveResult { Match = match, Dependencies = dependencies.Dependencies.ToList() }, }); }
private static async Task <RemoteMatch> FindLibraryFromSourcesAsync( LibraryRange libraryRange, IEnumerable <IRemoteDependencyProvider> providers, NuGetFramework framework, SourceCacheContext cacheContext, ILogger logger, CancellationToken token) { var tasks = new List <Task <RemoteMatch> >(); foreach (var provider in providers) { tasks.Add(FindLibraryFromProviderAsync(provider, libraryRange, framework, cacheContext, logger, token)); } RemoteMatch bestMatch = null; while (tasks.Count > 0) { var task = await Task.WhenAny(tasks); tasks.Remove(task); var match = await task; // If we found an exact match then use it. // This allows us to shortcircuit slow feeds even if there's an exact match if (!libraryRange.VersionRange.IsFloating && match?.Library?.Version != null && libraryRange.VersionRange.IsMinInclusive && match.Library.Version.Equals(libraryRange.VersionRange.MinVersion)) { return(match); } // Otherwise just find the best out of the matches if (libraryRange.VersionRange.IsBetter( current: bestMatch?.Library?.Version, considering: match?.Library?.Version)) { bestMatch = match; } }
private Task <RemoteMatch> FindProjectMatch( LibraryRange libraryRange, NuGetFramework framework, GraphEdge <RemoteResolveResult> outerEdge, CancellationToken cancellationToken) { RemoteMatch result = null; // Check if projects are allowed for this dependency if (libraryRange.TypeConstraintAllowsAnyOf( (LibraryDependencyTarget.Project | LibraryDependencyTarget.ExternalProject))) { // Find the root directory of the parent project if one exists. // This is used for resolving global json. var parentProjectRoot = GetRootPathForParentProject(outerEdge); foreach (var provider in _context.ProjectLibraryProviders) { if (provider.SupportsType(libraryRange.TypeConstraint)) { var match = provider.GetLibrary(libraryRange, framework, parentProjectRoot); if (match != null) { result = new LocalMatch { LocalLibrary = match, Library = match.Identity, LocalProvider = provider, Provider = new LocalDependencyProvider(provider), Path = match.Path, }; } } } } return(Task.FromResult <RemoteMatch>(result)); }
public Task CopyToAsync(RemoteMatch match, Stream stream) { // We never call this on local providers throw new NotImplementedException(); }
public Task <IEnumerable <LibraryDependency> > GetDependencies(RemoteMatch match, NuGetFramework targetFramework) { var description = _dependencyProvider.GetDescription(match.Library, targetFramework); return(Task.FromResult(description.Dependencies)); }