Example #1
0
        /// <summary>
        /// Determine the type of a nuget source. This works for both offline and online sources.
        /// </summary>
        public static FeedType GetFeedType(PackageSource packageSource)
        {
            // If the feed type is already specified, use that value
            if (packageSource is FeedTypePackageSource feedTypePackageSource)
            {
                return(feedTypePackageSource.FeedType);
            }

            // Default to unknown file system
            var type = FeedType.FileSystemUnknown;

            if (packageSource.IsHttp)
            {
                if (packageSource.Source.EndsWith(".json", StringComparison.OrdinalIgnoreCase))
                {
                    type = FeedType.HttpV3;
                }
                else
                {
                    type = FeedType.HttpV2;
                }
            }
            else if (packageSource.IsLocal)
            {
                var path = UriUtility.GetLocalPath(packageSource.Source);

                if (!Directory.Exists(path))
                {
                    // If the directory doesn't exist check again later
                    type = FeedType.FileSystemUnknown;
                }
                else
                {
                    // Try to determine the actual folder feed type by looking for nupkgs
                    type = LocalFolderUtility.GetLocalFeedType(path, NullLogger.Instance);
                }
            }

            return(type);
        }
        private static IReadOnlyList <LocalPackageInfo> GetPackagesCore(string root)
        {
            var rootDirInfo = LocalFolderUtility.GetAndVerifyRootDirectory(root);

            if (!rootDirInfo.Exists)
            {
                return(new List <LocalPackageInfo>());
            }

            var files       = rootDirInfo.GetFiles("*" + PackagingCoreConstants.NupkgExtension, SearchOption.TopDirectoryOnly);
            var directories = rootDirInfo.GetDirectories("*", SearchOption.TopDirectoryOnly);

            // Find all packages that have both a nupkg and a directory
            var validSet = new HashSet <string>(directories.Select(dir => dir.Name), StringComparer.OrdinalIgnoreCase);

            validSet.IntersectWith(files.Select(file => Path.GetFileNameWithoutExtension(file.Name)));

            var result = new List <LocalPackageInfo>(validSet.Count);

            foreach (var name in validSet)
            {
                var nuspec    = GetNuspec(rootDirInfo, name);
                var nupkgPath = Path.Combine(rootDirInfo.FullName, $"{name}{PackagingCoreConstants.NupkgExtension}");

                var localPackage = new LocalPackageInfo(
                    nuspec.GetIdentity(),
                    nupkgPath,
                    DateTime.UtcNow,
                    new Lazy <NuspecReader>(() => nuspec),
                    useFolder: true
                    );

                result.Add(localPackage);
            }

            return(result);
        }
        public LocalV2FindPackageByIdResource(PackageSource packageSource)
        {
            var rootDirInfo = LocalFolderUtility.GetAndVerifyRootDirectory(packageSource.Source);

            _source = rootDirInfo.FullName;
        }
        public override LocalPackageInfo GetPackage(PackageIdentity identity, ILogger logger, CancellationToken token)
        {
            token.ThrowIfCancellationRequested();

            return(LocalFolderUtility.GetPackageV2(Root, identity, logger, token));
        }
        public override LocalPackageInfo GetPackage(Uri path, ILogger logger, CancellationToken token)
        {
            token.ThrowIfCancellationRequested();

            return(LocalFolderUtility.GetPackage(path, logger));
        }
        public override IEnumerable <LocalPackageInfo> GetPackages(ILogger logger, CancellationToken token)
        {
            token.ThrowIfCancellationRequested();

            return(LocalFolderUtility.GetPackagesV3(Root, logger));
        }
 public override LocalPackageInfo GetPackage(PackageIdentity identity, ILogger logger, CancellationToken token)
 {
     return(LocalFolderUtility.GetPackagesConfigFolderPackage(Root, identity, logger));
 }
 public override LocalPackageInfo GetPackage(Uri path, ILogger logger, CancellationToken token)
 {
     return(LocalFolderUtility.GetPackage(path, logger));
 }
Example #9
0
        public override IEnumerable <LocalPackageInfo> FindPackagesById(string id, ILogger logger, CancellationToken token)
        {
            token.ThrowIfCancellationRequested();

            return(LocalFolderUtility.GetPackagesV3(Root, id, logger, token));
        }