Example #1
0
        private IPackageFeedSearchJob <IPackageInfo> Compute(string packageId, string version, string tfm)
        {
            IPackageQueryConfiguration config = new PackageQueryConfiguration(tfm);
            List <Tuple <string, Task <IReadOnlyList <IPackageInfo> > > > searchTasks = new List <Tuple <string, Task <IReadOnlyList <IPackageInfo> > > >();
            CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
            CancellationToken       cancellationToken       = cancellationTokenSource.Token;

            foreach (string feedSource in _feedRegistry.ConfiguredFeeds)
            {
                IPackageFeed feed = _factorySelector.GetFeed(feedSource);

                if (feed != null)
                {
                    searchTasks.Add(Tuple.Create(feedSource, feed.GetPackageInfoAsync(packageId, version, config, cancellationToken).ContinueWith(x =>
                    {
                        if (x == null || x.IsFaulted || x.IsCanceled)
                        {
                            return(new IPackageInfo[0]);
                        }

                        return((IReadOnlyList <IPackageInfo>) new[] { x.Result });
                    })));
                }
            }

            return(new PackageFeedSearchJob <IPackageInfo>(searchTasks, cancellationTokenSource));
        }
Example #2
0
        private async Task <LocalPackage[]> DownloadPackages(
            CancellationToken ct,
            IEnumerable <PackageIdentity> packages,
            IPackageFeed sourceFeed,
            string outputPath
            )
        {
            var downloadedPackages = new List <LocalPackage>();

            Directory.CreateDirectory(outputPath);

            foreach (var package in packages)
            {
                var localPackage = await sourceFeed.DownloadPackage(ct, package, outputPath);

                if (localPackage == null)
                {
                    throw new PackageNotFoundException(package, sourceFeed.Url);                     //Shouldn't happen
                }

                downloadedPackages.Add(localPackage);
            }

            return(downloadedPackages.ToArray());
        }
        private PackageFeedEnumerator(
            IPackageFeed packageFeed,
            Task <SearchResult <IPackageSearchMetadata> > searchTask,
            Action <string, Exception> handleException,
            CancellationToken cancellationToken)
        {
            if (packageFeed == null)
            {
                throw new ArgumentNullException(nameof(packageFeed));
            }

            if (searchTask == null)
            {
                throw new ArgumentNullException(nameof(searchTask));
            }

            if (handleException == null)
            {
                throw new ArgumentNullException(nameof(handleException));
            }

            _packageFeed       = packageFeed;
            _startFromTask     = searchTask;
            _handleException   = handleException;
            _cancellationToken = cancellationToken;

            Reset();
        }
Example #4
0
        public static IEnumerable <IPackageSearchMetadata> Enumerate(
            IPackageFeed packageFeed,
            Task <SearchResult <IPackageSearchMetadata> > searchTask,
            CancellationToken cancellationToken)
        {
            var enumerator = new PackageFeedEnumerator(packageFeed, searchTask, cancellationToken);

            return(new PackageFeedEnumerable(enumerator));
        }
Example #5
0
        private async Task <HashSet <PackageIdentity> > GetPackagesWithDependencies(
            CancellationToken ct,
            ISet <PackageIdentity> packages,
            IPackageFeed source,
            ISet <PackageIdentity> knownPackages   = null,
            ISet <PackageIdentity> missingPackages = null
            )
        {
            knownPackages   = knownPackages ?? new HashSet <PackageIdentity>();
            missingPackages = missingPackages ?? new HashSet <PackageIdentity>();

            //Assume we will have to download the packages passed
            var packagesToDonwload = new HashSet <PackageIdentity>(packages);

            foreach (var package in packages)
            {
                try
                {
                    var packageDependencies = await source.GetDependencies(ct, package);

                    _log.LogInformation($"Found {packageDependencies.Length} dependencies for {package} in {source.Url}");

                    //TODO: make the version used parametrable (Use MaxVersion or MinVersion)
                    packagesToDonwload.AddRange(packageDependencies.Select(d => new PackageIdentity(d.Id, d.VersionRange.MinVersion)));

                    knownPackages.Add(package);
                }
                catch (PackageNotFoundException ex)
                {
                    _log.LogInformation(ex.Message);

                    missingPackages.Add(package);
                }
            }

            //Take all the dependencies found
            var unknownPackages = new HashSet <PackageIdentity>(packagesToDonwload);

            //Remove the packages that we already know are missing
            unknownPackages.ExceptWith(missingPackages);
            //Remove the packages we already have dependencies for
            unknownPackages.ExceptWith(knownPackages);

            if (unknownPackages.Any())
            {
                //Get the dependencies for the rest
                var subDependencies = await GetPackagesWithDependencies(ct, unknownPackages, source, knownPackages, missingPackages);

                //Add those to the packages to download
                packagesToDonwload.UnionWith(subDependencies);
            }

            //Remove the packages that we know are missing
            packagesToDonwload.ExceptWith(missingPackages);

            return(packagesToDonwload);
        }
Example #6
0
        public bool TryHandle(string feed, out IPackageFeed instance)
        {
            if (Uri.TryCreate(feed, UriKind.Absolute, out Uri location) && feed.EndsWith("v3/index.json", StringComparison.OrdinalIgnoreCase))
            {
                instance = new NuGetV3ServiceFeed(feed, _webRequestFactory);
                return(true);
            }

            instance = null;
            return(false);
        }
Example #7
0
        public bool TryHandle(string feed, out IPackageFeed instance)
        {
            if (!_fileSystem.DirectoryExists(feed))
            {
                instance = null;
                return(false);
            }

            instance = Instances.GetOrAdd(feed, x => CreateInstance(x));
            return(instance != null);
        }
Example #8
0
        public virtual bool TryHandle(string feed, out IPackageFeed instance)
        {
            if (!CanHandle(feed))
            {
                instance = null;
                return(false);
            }

            instance = Instances.GetOrAdd(feed, Create);
            return(true);
        }
Example #9
0
        private PackageFeedEnumerator(PackageFeedEnumerator other)
        {
            if (other == null)
            {
                throw new ArgumentNullException(nameof(other));
            }
            _packageFeed       = other._packageFeed;
            _startFromTask     = other._startFromTask;
            _cancellationToken = other._cancellationToken;

            Reset();
        }
Example #10
0
 public CodeGenerator(ITemplateEngine templateEngine,
                      IPackageFeed packageFeed,
                      IMerge merge,
                      FileMerge fileMerge,
                      ILogger <CodeGenerator> logger)
 {
     _templateEngine = templateEngine;
     _packageFeed    = packageFeed;
     _merge          = merge;
     _fileMerge      = fileMerge;
     _logger         = logger;
 }
Example #11
0
        public SearchObject(
            IPackageFeed mainFeed,
            IPackageFeed?recommenderFeed,
            IPackageMetadataProvider packageMetadataProvider,
            IReadOnlyCollection <PackageSourceContextInfo> packageSources,
            MemoryCache?searchCache)
        {
            Assumes.NotNull(mainFeed);
            Assumes.NotNull(packageMetadataProvider);
            Assumes.NotNullOrEmpty(packageSources);

            _mainFeed                = mainFeed;
            _recommenderFeed         = recommenderFeed;
            _packageSources          = packageSources;
            _packageMetadataProvider = packageMetadataProvider;
            _inMemoryObjectCache     = searchCache;
        }
Example #12
0
        private IPackageFeedSearchJob <Tuple <string, FeedKind> > SearchPackageNamesInternal(string prefix, string tfm, IPackageQueryConfiguration config)
        {
            List <Tuple <string, Task <IReadOnlyList <Tuple <string, FeedKind> > > > > searchTasks = new List <Tuple <string, Task <IReadOnlyList <Tuple <string, FeedKind> > > > >();
            CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
            CancellationToken       cancellationToken       = cancellationTokenSource.Token;

            foreach (string feedSource in _feedRegistry.ConfiguredFeeds)
            {
                IPackageFeed feed = _factorySelector.GetFeed(feedSource);

                if (feed != null)
                {
                    searchTasks.Add(new Tuple <string, Task <IReadOnlyList <Tuple <string, FeedKind> > > >(feed.DisplayName, feed.GetPackageNamesAsync(prefix, config, cancellationToken).ContinueWith(TransformToPackageInfo)));
                }
            }

            return(new PackageFeedSearchJob <Tuple <string, FeedKind> >(searchTasks, cancellationTokenSource));
        }
Example #13
0
        public PackageItemLoader(
            PackageLoadContext context,
            IPackageFeed packageFeed,
            string searchText      = null,
            bool includePrerelease = true)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            _context = context;

            if (packageFeed == null)
            {
                throw new ArgumentNullException(nameof(packageFeed));
            }
            _packageFeed = packageFeed;

            _searchText        = searchText ?? string.Empty;
            _includePrerelease = includePrerelease;
        }
Example #14
0
File: Feed.cs Project: yongaru/uno
        public override void Execute(IEnumerable <string> args)
        {
            IPackageFeed source  = null;
            string       version = null;
            var          input   = new OptionSet {
                { "i|installed", value => source = PackageManager.CacheFeed },
                { "s=|source=", value => source = new PackageManager(Log).GetSource(value) },
                { "n=|version=", value => version = value }
            }.Parse(args);

            if (source == null)
            {
                source = new PackageManager(Log);
            }

            input.CheckArguments();
            FilterPackageArguments(input, ref version, ref source);
            Log.StartAnimation();

            var first = true;

            foreach (var p in source.FindPackages(input, version))
            {
                if (first)
                {
                    WriteHead("Package".PadRight(32) + " " + "Version".PadRight(32) + " Source");
                    first = false;
                }

                WriteLine(p.Name.PadRight(32) + " " + p.Version.PadRight(32) + " " + p.Source);
            }

            if (first)
            {
                throw new ArgumentException("No packages found");
            }
        }
Example #15
0
 public RemoteWalkProvider(IPackageFeed source)
 {
     _source = source;
     IsHttp = IsHttpSource(source);
 }
Example #16
0
 private static bool IsHttpSource(IPackageFeed source)
 {
     return source.Source.StartsWith("http://", StringComparison.OrdinalIgnoreCase) ||
         source.Source.StartsWith("https://", StringComparison.OrdinalIgnoreCase);
 }
Example #17
0
 public RemoteWalkProvider(IPackageFeed source)
 {
     _source = source;
     IsHttp  = IsHttpSource(source);
 }
Example #18
0
 public RemoteWalkProvider(IPackageFeed source)
 {
     _source = source;
 }
Example #19
0
        private async Task <LocalPackage[]> PushPackages(CancellationToken ct, IEnumerable <LocalPackage> packages, IPackageFeed targetFeed)
        {
            var pushedPackages = new List <LocalPackage>();

            if (targetFeed != null)
            {
                _log.LogInformation($"Pushing packages to {targetFeed.Url}");

                foreach (var package in packages)
                {
                    if (await targetFeed.PushPackage(ct, package))
                    {
                        pushedPackages.Add(package);
                    }
                }
            }

            return(pushedPackages.ToArray());
        }
Example #20
0
        private async Task <IEnumerable <PackageIdentity> > GetPackagesToDownload(CancellationToken ct, string solutionPath, IPackageFeed source)
        {
            var references = await SolutionHelper.GetPackageReferences(ct, solutionPath, FileType.All, _log);

            var identities = new HashSet <PackageIdentity>(references.Select(r => r.Identity));

            return(await GetPackagesWithDependencies(ct, identities, source));
        }
 public RemoteDependencyProvider(IPackageFeed source)
 {
     _source = source;
     IsHttp  = IsHttpSource(source);
 }
Example #22
0
File: Feed.cs Project: yongaru/uno
        internal static void FilterPackageArguments(List <string> args, ref string version, ref IPackageFeed source)
        {
            for (int i = 0; i < args.Count; i++)
            {
                var arg = args[i];
                if (arg.Length > 0 && char.IsNumber(arg[0]))
                {
                    if (version != null)
                    {
                        Log.Warning("Overwriting old 'version'");
                    }
                    version = arg;
                    args.RemoveAt(i--);
                }
                else if (arg.Contains("://"))
                {
                    if (source != null)
                    {
                        Log.Warning("Overwriting old 'source'");
                    }

                    source = new PackageManager(Log).GetSource(arg);
                    args.RemoveAt(i--);
                }
            }
        }
Example #23
0
        public override void Execute(IEnumerable <string> args)
        {
            string       version = null;
            IPackageFeed source  = null;
            var          force   = false;
            var          input   = new OptionSet {
                { "n=|version=", value => version = value },
                { "f|force", value => force = true }
            }.Parse(args);

            if (input.Count == 0)
            {
                throw new ArgumentException("No packages specified");
            }

            input.CheckArguments();
            Feed.FilterPackageArguments(input, ref version, ref source);

            var cache    = new PackageCache();
            var versions = new List <DirectoryInfo>();

            foreach (var package in input)
            {
                versions.AddRange(cache.EnumerateVersions(package, version));
            }

            if (versions.Count == 0)
            {
                if (force)
                {
                    return;
                }
                throw new ArgumentException("No packages found");
            }

            if (!force && versions.Count > 1)
            {
                foreach (var dir in versions)
                {
                    WriteLine(dir.FullName.ToRelativePath());
                }

                if (!Confirm("The search returned more than one package -- delete all of them?"))
                {
                    return;
                }
            }

            foreach (var dir in versions)
            {
                Disk.DeleteDirectory(dir.FullName, true);
            }

            // Delete any remaining empty directories
            foreach (var package in input)
            {
                foreach (var dir in cache.EnumeratePackages(package))
                {
                    if (dir.EnumerateFileSystemInfos().FirstOrDefault() == null)
                    {
                        Disk.DeleteDirectory(dir.FullName, true);
                    }
                }
            }
        }
Example #24
0
 private static bool IsHttpSource(IPackageFeed source)
 {
     return(source.Source.StartsWith("http://", StringComparison.OrdinalIgnoreCase) ||
            source.Source.StartsWith("https://", StringComparison.OrdinalIgnoreCase));
 }