Beispiel #1
0
 public async Task <IEnumerable <LibraryDependency> > GetDependencies(WalkProviderMatch match, FrameworkName targetFramework)
 {
     using (var stream = await _source.OpenNuspecStreamAsync(new PackageInfo
     {
         Id = match.Library.Name,
         Version = match.Library.Version,
         ContentUri = match.Path
     }))
     {
         var metadata = (IPackageMetadata)Manifest.ReadFrom(stream, validateSchema: false).Metadata;
         IEnumerable <PackageDependencySet> dependencySet;
         if (VersionUtility.GetNearest(targetFramework, metadata.DependencySets, out dependencySet))
         {
             return(dependencySet
                    .SelectMany(ds => ds.Dependencies)
                    .Select(d => new LibraryDependency
             {
                 LibraryRange = new LibraryRange(d.Id, frameworkReference: false)
                 {
                     VersionRange = d.VersionSpec == null ? null : new SemanticVersionRange(d.VersionSpec)
                 }
             })
                    .ToList());
         }
     }
     return(Enumerable.Empty <LibraryDependency>());
 }
Beispiel #2
0
        private static async Task <WalkProviderMatch> FindLibrary(
            LibraryRange libraryRange,
            IEnumerable <IWalkProvider> providers,
            Func <IWalkProvider, Task <WalkProviderMatch> > action)
        {
            var tasks = new List <Task <WalkProviderMatch> >();

            foreach (var provider in providers)
            {
                tasks.Add(action(provider));
            }

            WalkProviderMatch bestMatch = null;
            var matches = await Task.WhenAll(tasks);

            foreach (var match in matches)
            {
                if (VersionUtility.ShouldUseConsidering(
                        current: bestMatch?.Library?.Version,
                        considering: match?.Library?.Version,
                        ideal: libraryRange.VersionRange))
                {
                    bestMatch = match;
                }
            }

            return(bestMatch);
        }
Beispiel #3
0
 public async Task CopyToAsync(WalkProviderMatch match, Stream stream)
 {
     using (var nupkgStream = await _source.OpenNupkgStreamAsync(new PackageInfo
     {
         Id = match.Library.Name,
         Version = match.Library.Version,
         ContentUri = match.Path
     }))
     {
         await nupkgStream.CopyToAsync(stream);
     }
 }
Beispiel #4
0
        private static async Task <WalkProviderMatch> FindLibrary(
            LibraryRange libraryRange,
            IEnumerable <IWalkProvider> providers,
            Func <IWalkProvider, Task <WalkProviderMatch> > action)
        {
            var tasks = new List <Task <WalkProviderMatch> >();

            foreach (var provider in providers)
            {
                tasks.Add(action(provider));
            }

            WalkProviderMatch bestMatch = null;
            var matches = new List <WalkProviderMatch>();

            // Short circuit if we find an exact match
            while (tasks.Any())
            {
                var task = await Task.WhenAny(tasks);

                tasks.Remove(task);
                var match = await task;

                // If we found an exact match then use it
                if (libraryRange.VersionRange.VersionFloatBehavior == SemanticVersionFloatBehavior.None &&
                    match != null &&
                    match.Library.Version.Equals(libraryRange.VersionRange.MinVersion))
                {
                    return(match);
                }

                matches.Add(match);
            }

            foreach (var match in matches)
            {
                if (VersionUtility.ShouldUseConsidering(
                        current: bestMatch?.Library?.Version,
                        considering: match?.Library?.Version,
                        ideal: libraryRange.VersionRange))
                {
                    bestMatch = match;
                }
            }

            return(bestMatch);
        }
Beispiel #5
0
 public async Task <RuntimeFile> GetRuntimes(WalkProviderMatch match, FrameworkName targetFramework)
 {
     using (var stream = await _source.OpenRuntimeStreamAsync(new PackageInfo
     {
         Id = match.Library.Name,
         Version = match.Library.Version,
         ContentUri = match.Path
     }))
     {
         if (stream != null)
         {
             var formatter = new RuntimeFileFormatter();
             using (var reader = new StreamReader(stream))
             {
                 return(formatter.ReadRuntimeFile(reader));
             }
         }
     }
     return(null);
 }
Beispiel #6
0
        public Task <RuntimeFile> GetRuntimes(WalkProviderMatch match, FrameworkName targetFramework)
        {
            foreach (var path in _dependencyProvider.GetAttemptedPaths(targetFramework))
            {
                var runtimeJsonPath = path
                                      .Replace("{name}.nuspec", "runtime.json")
                                      .Replace("project.json", "runtime.json")
                                      .Replace("{name}", match.Library.Name)
                                      .Replace("{version}", match.Library.Version.ToString());

                // Console.WriteLine("*** {0}", runtimeJsonPath);
                if (File.Exists(runtimeJsonPath))
                {
                    Console.WriteLine("*** READING {0}", runtimeJsonPath);
                    var formatter = new RuntimeFileFormatter();
                    return(Task.FromResult(formatter.ReadRuntimeFile(runtimeJsonPath)));
                }
            }
            return(Task.FromResult <RuntimeFile>(null));
        }
Beispiel #7
0
 public async Task <IEnumerable <LibraryDependency> > GetDependencies(WalkProviderMatch match, FrameworkName targetFramework)
 {
     using (var stream = await _source.OpenNuspecStreamAsync(new PackageInfo
     {
         Id = match.Library.Name,
         Version = match.Library.Version,
         ContentUri = match.Path
     }))
     {
         var metadata = (IPackageMetadata)Manifest.ReadFrom(stream, validateSchema: false).Metadata;
         IEnumerable <PackageDependencySet> dependencySet;
         if (VersionUtility.TryGetCompatibleItems(targetFramework, metadata.DependencySets, out dependencySet))
         {
             return(dependencySet
                    .SelectMany(x => x.Dependencies)
                    .Select(x => new LibraryDependency(name: x.Id,
                                                       version: x.VersionSpec != null ? x.VersionSpec.MinVersion : null))
                    .ToList());
         }
     }
     return(Enumerable.Empty <LibraryDependency>());
 }
        private async Task <WalkProviderMatch> FindLibraryByVersion(RestoreContext context, Library library, IEnumerable <IWalkProvider> providers)
        {
            List <Task <WalkProviderMatch> > tasks = new List <Task <WalkProviderMatch> >();

            foreach (var provider in providers)
            {
                tasks.Add(provider.FindLibraryByVersion(library, context.FrameworkName));
            }
            var matches = await Task.WhenAll(tasks);

            WalkProviderMatch bestMatch = null;

            foreach (var match in matches)
            {
                if (VersionUtility.ShouldUseConsidering(
                        current: (bestMatch == null || bestMatch.Library == null) ? null : bestMatch.Library.Version,
                        considering: (match == null || match.Library == null) ? null : match.Library.Version,
                        ideal: library.Version))
                {
                    bestMatch = match;
                }
            }
            return(bestMatch);
        }
Beispiel #9
0
        public Task <IEnumerable <Library> > GetDependencies(WalkProviderMatch match, FrameworkName targetFramework)
        {
            var description = _dependencyProvider.GetDescription(match.Library.Name, match.Library.Version, targetFramework);

            return(Task.FromResult(description.Dependencies));
        }
Beispiel #10
0
 public Task CopyToAsync(WalkProviderMatch match, Stream stream)
 {
     throw new NotImplementedException();
 }
Beispiel #11
0
 public Task CopyToAsync(WalkProviderMatch match, Stream stream)
 {
     // We never call this on local providers
     throw new NotImplementedException();
 }