public static async Task <GraphItem <RemoteResolveResult> > FindLibraryEntryAsync( LibraryRange libraryRange, NuGetFramework framework, string runtimeIdentifier, GraphEdge <RemoteResolveResult> outerEdge, RemoteWalkContext context, CancellationToken cancellationToken) { GraphItem <RemoteResolveResult> graphItem = null; var currentCacheContext = context.CacheContext; // Try up to two times to get the package. The second // retry will refresh the cache if a package is listed // but fails to download. This can happen if the feed prunes // the package. for (var i = 0; i < 2 && graphItem == null; i++) { var match = await FindLibraryMatchAsync( libraryRange, framework, runtimeIdentifier, outerEdge, context.RemoteLibraryProviders, context.LocalLibraryProviders, context.ProjectLibraryProviders, context.LockFileLibraries, currentCacheContext, context.Logger, cancellationToken); if (match == null) { return(CreateUnresolvedMatch(libraryRange)); } try { graphItem = await CreateGraphItemAsync(match, framework, currentCacheContext, context.Logger, cancellationToken); } catch (InvalidCacheProtocolException) when(i == 0) { // 1st failure, invalidate the cache and try again. // Clear the on disk and memory caches during the next request. currentCacheContext = currentCacheContext.WithRefreshCacheTrue(); } catch (PackageNotFoundProtocolException ex) when(match.Provider.IsHttp && match.Provider.Source != null) { // 2nd failure, the feed is likely corrupt or removing packages too fast to keep up with. var message = string.Format(CultureInfo.CurrentCulture, Strings.Error_PackageNotFoundWhenExpected, match.Provider.Source, ex.PackageIdentity.ToString()); throw new FatalProtocolException(message, ex); } } return(graphItem); }
public bool Equals(GraphItem <T> x, GraphItem <T> y) { if (x == null) { return(y == null); } return(x.Key.Equals(y.Key)); }
public int GetHashCode(GraphItem <T> obj) { if (obj == null) { throw new ArgumentNullException(nameof(obj)); } return(obj.Key.GetHashCode()); }
private bool KeyCompare(GraphItem <TItem> other) { if (Key == null) { return(other.Key == null); } return(Key.Equals(other.Key)); }
public void Track(GraphItem <TItem> item) { var entry = GetEntry(item); if (!entry.List.Contains(item)) { entry.List.Add(item); } }
private Entry GetEntry(GraphItem <TItem> item) { Entry itemList; if (!_entries.TryGetValue(item.Key.Name, out itemList)) { itemList = new Entry(); _entries[item.Key.Name] = itemList; } return(itemList); }
private GraphItem <Library> Resolve( Dictionary <LibraryRange, GraphItem <Library> > resolvedItems, LibraryRange library, NuGetFramework framework) { GraphItem <Library> item; if (resolvedItems.TryGetValue(library, out item)) { return(item); } Library hit = null; foreach (var dependencyProvider in _dependencyProviders) { // Skip unsupported library type if (!dependencyProvider.SupportsType(library.TypeConstraint)) { continue; } hit = dependencyProvider.GetLibrary(library, framework); if (hit != null) { break; } } if (hit == null) { resolvedItems[library] = null; return(null); } if (resolvedItems.TryGetValue(hit.Identity, out item)) { return(item); } item = new GraphItem <Library>(hit.Identity) { Data = hit }; resolvedItems[library] = item; resolvedItems[hit.Identity] = item; return(item); }
private GraphItem <ResolveResult> Resolve( Dictionary <LibraryRange, GraphItem <ResolveResult> > resolvedItems, LibraryRange packageKey, NuGetFramework framework) { GraphItem <ResolveResult> item; if (resolvedItems.TryGetValue(packageKey, out item)) { return(item); } ResolveResult hit = null; foreach (var dependencyProvider in _dependencyProviders) { var match = dependencyProvider.GetDescription(packageKey, framework); if (match != null) { hit = new ResolveResult { DependencyProvider = dependencyProvider, LibraryDescription = match }; break; } } if (hit == null) { resolvedItems[packageKey] = null; return(null); } if (resolvedItems.TryGetValue(hit.LibraryDescription.Identity, out item)) { return(item); } item = new GraphItem <ResolveResult>(hit.LibraryDescription.Identity) { Data = hit }; resolvedItems[packageKey] = item; resolvedItems[hit.LibraryDescription.Identity] = item; return(item); }
public bool IsBestVersion(GraphItem <TItem> item) { var entry = GetEntry(item); var version = item.Key.Version; foreach (var known in entry.List) { if (version < known.Key.Version) { return(false); } } return(true); }
private Func <string, bool> ChainPredicate(Func <string, bool> predicate, GraphItem <RemoteResolveResult> item, LibraryDependency dependency) { return(name => { if (item.Data.Match.Library.Name == name) { throw new Exception(string.Format("Circular dependency references not supported. Package '{0}'.", name)); } if (item.Data.Dependencies.Any(d => d != dependency && d.Name == name)) { return false; } return predicate(name); }); }
public IEnumerable <GraphItem <TItem> > GetDisputes(GraphItem <TItem> item) => GetEntry(item).List;
public bool IsBestVersion(GraphItem <TItem> item) { var entry = GetEntry(item); return(entry.List.All(known => item.Key.Version >= known.Key.Version)); }
public void MarkAmbiguous(GraphItem <TItem> item) { GetEntry(item).Ambiguous = true; }
public bool IsAmbiguous(GraphItem <TItem> item) { return(GetEntry(item).Ambiguous); }
public bool IsDisputed(GraphItem <TItem> item) { return(GetEntry(item).List.Count > 1); }
public GraphEdge(GraphEdge <TItem> outerEdge, GraphItem <TItem> item, LibraryDependency edge) { OuterEdge = outerEdge; Item = item; Edge = edge; }
public bool Equals(GraphItem <TItem> other) { return(other != null && KeyCompare(other) && IsCentralTransitive == other.IsCentralTransitive); }
public bool Equals(GraphItem <TItem> other) { return(other != null && Key.Equals(other.Key)); }