private string GetLicenseUrl()
        {
            INode subject = _catalogItem.CreateUriNode(_catalogUri);

            string packageId         = GetRequiredObject(_catalogItem, subject, Schema.Predicates.Id);
            string packageVersion    = NuGetVersionUtility.NormalizeVersion(GetRequiredObject(_catalogItem, subject, Schema.Predicates.Version));
            string licenseExpression = GetOptionalObject(_catalogItem, subject, Schema.Predicates.LicenseExpression);
            string licenseFile       = GetOptionalObject(_catalogItem, subject, Schema.Predicates.LicenseFile);
            string licenseUrl        = GetOptionalObject(_catalogItem, subject, Schema.Predicates.LicenseUrl);

            if (_galleryBaseAddress != null &&
                !string.IsNullOrWhiteSpace(packageId) &&
                !string.IsNullOrWhiteSpace(packageVersion) &&
                (!string.IsNullOrWhiteSpace(licenseExpression) ||
                 !string.IsNullOrWhiteSpace(licenseFile)))
            {
                return(LicenseHelper.GetGalleryLicenseUrl(packageId, packageVersion, _galleryBaseAddress));
            }

            if (!string.IsNullOrWhiteSpace(licenseUrl))
            {
                return(licenseUrl);
            }

            return(string.Empty);
        }
Beispiel #2
0
        public async Task AddPackageAsync_WithValidVersion_PopulatesStorageWithNupkgAndNuspec(string version)
        {
            var catalogToDnxStorage        = new MemoryStorage();
            var catalogToDnxStorageFactory = new TestStorageFactory(name => catalogToDnxStorage.WithName(name));
            var maker             = new DnxMaker(catalogToDnxStorageFactory);
            var normalizedVersion = NuGetVersionUtility.NormalizeVersion(version);

            using (var nupkgStream = CreateFakePackageStream(_nupkgData))
            {
                var dnxEntry = await maker.AddPackageAsync(nupkgStream, _nuspecData, _packageId, version, CancellationToken.None);

                var expectedNuspec    = new Uri($"{catalogToDnxStorage.BaseAddress}{_packageId}/{normalizedVersion}/{_packageId}.nuspec");
                var expectedNupkg     = new Uri($"{catalogToDnxStorage.BaseAddress}{_packageId}/{normalizedVersion}/{_packageId}.{normalizedVersion}.nupkg");
                var storageForPackage = (MemoryStorage)catalogToDnxStorageFactory.Create(_packageId);

                Assert.Equal(expectedNuspec, dnxEntry.Nuspec);
                Assert.Equal(expectedNupkg, dnxEntry.Nupkg);
                Assert.Equal(2, catalogToDnxStorage.Content.Count);
                Assert.Equal(2, storageForPackage.Content.Count);

                Verify(catalogToDnxStorage, expectedNupkg, _nupkgData, _expectedCacheControl, _expectedPackageContentType);
                Verify(catalogToDnxStorage, expectedNuspec, _nuspecData, _expectedCacheControl, _expectedNuspecContentType);
                Verify(storageForPackage, expectedNupkg, _nupkgData, _expectedCacheControl, _expectedPackageContentType);
                Verify(storageForPackage, expectedNuspec, _nuspecData, _expectedCacheControl, _expectedNuspecContentType);
            }
        }
Beispiel #3
0
        public async Task AddPackageAsync_WithStorage_WithIStorage_PopulatesStorageWithNupkgAndNuspec(string version)
        {
            var catalogToDnxStorage        = new AzureStorageStub();
            var catalogToDnxStorageFactory = new TestStorageFactory(name => catalogToDnxStorage.WithName(name));
            var maker             = new DnxMaker(catalogToDnxStorageFactory);
            var normalizedVersion = NuGetVersionUtility.NormalizeVersion(version);
            var sourceStorage     = new AzureStorageStub();

            var dnxEntry = await maker.AddPackageAsync(
                sourceStorage,
                _nuspecData,
                _packageId,
                normalizedVersion,
                CancellationToken.None);

            var expectedNuspecUri = new Uri($"{catalogToDnxStorage.BaseAddress}{_packageId}/{normalizedVersion}/{_packageId}.nuspec");
            var expectedNupkgUri  = new Uri($"{catalogToDnxStorage.BaseAddress}{_packageId}/{normalizedVersion}/{_packageId}.{normalizedVersion}.nupkg");
            var expectedSourceUri = new Uri(sourceStorage.BaseAddress, $"{_packageId}.{normalizedVersion}.nupkg");
            var storageForPackage = (MemoryStorage)catalogToDnxStorageFactory.Create(_packageId);

            Assert.Equal(expectedNuspecUri, dnxEntry.Nuspec);
            Assert.Equal(expectedNupkgUri, dnxEntry.Nupkg);
            Assert.Equal(2, catalogToDnxStorage.Content.Count);
            Assert.Equal(2, storageForPackage.Content.Count);

            Verify(catalogToDnxStorage, expectedNupkgUri, expectedSourceUri.AbsoluteUri, _expectedCacheControl, _expectedPackageContentType);
            Verify(catalogToDnxStorage, expectedNuspecUri, _nuspecData, _expectedCacheControl, _expectedNuspecContentType);
            Verify(storageForPackage, expectedNupkgUri, expectedSourceUri.AbsoluteUri, _expectedCacheControl, _expectedPackageContentType);
            Verify(storageForPackage, expectedNuspecUri, _nuspecData, _expectedCacheControl, _expectedNuspecContentType);
        }
Beispiel #4
0
        public string GetIconPath(string id, string version, bool normalize)
        {
            if (id == null)
            {
                throw new ArgumentNullException(nameof(id));
            }

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

            var idLowerCase = id.ToLowerInvariant();

            string versionLowerCase;

            if (normalize)
            {
                versionLowerCase = NuGetVersionUtility.NormalizeVersion(version).ToLowerInvariant();
            }
            else
            {
                versionLowerCase = version.ToLowerInvariant();
            }

            return($"{_container}/{idLowerCase}/{versionLowerCase}/icon");
        }
Beispiel #5
0
        protected override async Task <bool> OnProcessBatchAsync(
            CollectorHttpClient client,
            IEnumerable <JToken> items,
            JToken context,
            DateTime commitTimeStamp,
            bool isLastBatch,
            CancellationToken cancellationToken)
        {
            var catalogEntries = items.Select(
                item => new CatalogEntry(
                    item["nuget:id"].ToString().ToLowerInvariant(),
                    NuGetVersionUtility.NormalizeVersion(item["nuget:version"].ToString()).ToLowerInvariant(),
                    item["@type"].ToString().Replace("nuget:", Schema.Prefixes.NuGet),
                    item))
                                 .ToList();

            // Sanity check:  a single catalog batch should not contain multiple entries for the same package ID and version.
            AssertNoMultipleEntriesForSamePackageIdentity(commitTimeStamp, catalogEntries);

            // Process .nupkg/.nuspec adds and deletes.
            var processedCatalogEntries = await ProcessCatalogEntriesAsync(client, catalogEntries, cancellationToken);

            // Update the package version index with adds and deletes.
            await UpdatePackageVersionIndexAsync(processedCatalogEntries, cancellationToken);

            return(true);
        }
Beispiel #6
0
        public async Task UpdatePackageVersionIndexAsync_WithValidVersion_CreatesIndex(string version)
        {
            var catalogToDnxStorage        = new MemoryStorage();
            var catalogToDnxStorageFactory = new TestStorageFactory(name => catalogToDnxStorage.WithName(name));
            var maker             = new DnxMaker(catalogToDnxStorageFactory);
            var normalizedVersion = NuGetVersionUtility.NormalizeVersion(version);

            await maker.UpdatePackageVersionIndexAsync(_packageId, v => v.Add(NuGetVersion.Parse(version)), CancellationToken.None);

            var storageForPackage = (MemoryStorage)catalogToDnxStorageFactory.Create(_packageId);
            var indexJsonUri      = new Uri(storageForPackage.BaseAddress, "index.json");
            var indexJson         = await storageForPackage.LoadAsync(indexJsonUri, CancellationToken.None);

            var indexObject     = JObject.Parse(indexJson.GetContentString());
            var versions        = indexObject["versions"].ToObject <string[]>();
            var expectedContent = GetExpectedIndexJsonContent(normalizedVersion);

            Assert.Equal(1, catalogToDnxStorage.Content.Count);
            Assert.Equal(1, storageForPackage.Content.Count);

            Verify(catalogToDnxStorage, indexJsonUri, expectedContent, _expectedPackageVersionIndexJsonCacheControl, _expectedPackageVersionIndexJsonContentType);
            Verify(storageForPackage, indexJsonUri, expectedContent, _expectedPackageVersionIndexJsonCacheControl, _expectedPackageVersionIndexJsonContentType);

            Assert.Equal(new[] { normalizedVersion }, versions);
        }
        private string GetLicenseUrl()
        {
            INode subject = _catalogItem.CreateUriNode(_catalogUri);

            string id                = _catalogItem.GetTriplesWithSubjectPredicate(subject, _catalogItem.CreateUriNode(Schema.Predicates.Id)).FirstOrDefault().Object.ToString();
            string version           = NuGetVersionUtility.NormalizeVersion(_catalogItem.GetTriplesWithSubjectPredicate(subject, _catalogItem.CreateUriNode(Schema.Predicates.Version)).FirstOrDefault().Object.ToString());
            Triple licenseExpression = _catalogItem.GetTriplesWithSubjectPredicate(subject, _catalogItem.CreateUriNode(Schema.Predicates.LicenseExpression)).FirstOrDefault();
            Triple licenseFile       = _catalogItem.GetTriplesWithSubjectPredicate(subject, _catalogItem.CreateUriNode(Schema.Predicates.LicenseFile)).FirstOrDefault();
            Triple licenseUrl        = _catalogItem.GetTriplesWithSubjectPredicate(subject, _catalogItem.CreateUriNode(Schema.Predicates.LicenseUrl)).FirstOrDefault();

            if (_galleryBaseAddress != null)
            {
                if (licenseExpression != null && !string.IsNullOrWhiteSpace(licenseExpression.Object.ToString()))
                {
                    return(GetGalleryLicenseUrl(id, version));
                }
                if (licenseFile != null && !string.IsNullOrWhiteSpace(licenseFile.Object.ToString()))
                {
                    return(GetGalleryLicenseUrl(id, version));
                }
            }

            if (licenseUrl != null)
            {
                return(licenseUrl.Object.ToString());
            }

            return(string.Empty);
        }
Beispiel #8
0
        public string GetPackagePath(string id, string version)
        {
            var idLowerCase      = id.ToLowerInvariant();
            var versionLowerCase = NuGetVersionUtility.NormalizeVersion(version).ToLowerInvariant();
            var packageFileName  = PackageUtility.GetPackageFileName(idLowerCase, versionLowerCase);

            return($"{_container}/{idLowerCase}/{versionLowerCase}/{packageFileName}");
        }
Beispiel #9
0
        public void NormalizeVersion(string input, string expected)
        {
            // Arrange & Act
            var actual = NuGetVersionUtility.NormalizeVersion(input);

            // Assert
            Assert.Equal(expected, actual);
        }
        public override Uri GetItemAddress()
        {
            if (_itemAddress == null)
            {
                INode  subject = _catalogItem.CreateUriNode(_catalogUri);
                string version = GetRequiredObject(_catalogItem, subject, Schema.Predicates.Version)
                                 .ToLowerInvariant();

                version = NuGetVersionUtility.NormalizeVersion(version);

                _itemAddress = new Uri(BaseAddress, version + ".json");
            }

            return(_itemAddress);
        }
        private async Task EnqueueAsync(ConcurrentBag <JToken> itemBag, CancellationToken cancellationToken)
        {
            while (itemBag.TryTake(out var item))
            {
                var id      = item["nuget:id"].ToString().ToLowerInvariant();
                var version = NuGetVersionUtility.NormalizeVersion(item["nuget:version"].ToString().ToLowerInvariant());
                var type    = item["@type"].ToString().Replace("nuget:", Schema.Prefixes.NuGet);

                if (type != Schema.DataTypes.PackageDetails.ToString())
                {
                    continue;
                }

                await _queue.AddAsync(new PackageMessage(id, version), cancellationToken);
            }
        }
Beispiel #12
0
        public override Uri GetItemAddress()
        {
            if (_itemAddress == null)
            {
                INode  subject = _catalogItem.CreateUriNode(_catalogUri);
                string version = _catalogItem.GetTriplesWithSubjectPredicate(subject, _catalogItem.CreateUriNode(Schema.Predicates.Version))
                                 .FirstOrDefault()
                                 .Object
                                 .ToString()
                                 .ToLowerInvariant();

                version = NuGetVersionUtility.NormalizeVersion(version);

                _itemAddress = new Uri(BaseAddress, version + ".json");
            }

            return(_itemAddress);
        }
Beispiel #13
0
        public string GetPackagePath(string id, string version)
        {
            if (id == null)
            {
                throw new ArgumentNullException(nameof(id));
            }

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

            var idLowerCase      = id.ToLowerInvariant();
            var versionLowerCase = NuGetVersionUtility.NormalizeVersion(version).ToLowerInvariant();
            var packageFileName  = PackageUtility.GetPackageFileName(idLowerCase, versionLowerCase);

            return($"{_container}/{idLowerCase}/{versionLowerCase}/{packageFileName}");
        }
        public async Task DeletePackageAsync(string id, string version, CancellationToken cancellationToken)
        {
            if (string.IsNullOrEmpty(id))
            {
                throw new ArgumentException(Strings.ArgumentMustNotBeNullOrEmpty, nameof(id));
            }

            if (string.IsNullOrEmpty(version))
            {
                throw new ArgumentException(Strings.ArgumentMustNotBeNullOrEmpty, nameof(version));
            }

            cancellationToken.ThrowIfCancellationRequested();

            var storage           = _storageFactory.Create(id);
            var normalizedVersion = NuGetVersionUtility.NormalizeVersion(version);

            await DeleteNuspecAsync(storage, id, normalizedVersion, cancellationToken);
            await DeleteNupkgAsync(storage, id, normalizedVersion, cancellationToken);
        }
Beispiel #15
0
        private static XElement ToODataEntryXElement(ODataPackage package, Uri baseUri)
        {
            string     nsAtom        = "http://www.w3.org/2005/Atom";
            XNamespace nsDataService = "http://schemas.microsoft.com/ado/2007/08/dataservices";
            string     nsMetadata    = "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata";
            string     downloadUrl   = string.Format(
                CultureInfo.InvariantCulture,
                "{0}package/{1}/{2}", baseUri, package.Id, NuGetVersionUtility.NormalizeVersion(package.Version));
            string entryId = string.Format(
                CultureInfo.InvariantCulture,
                "{0}Packages(Id='{1}',Version='{2}')",
                baseUri, package.Id, NuGetVersionUtility.NormalizeVersion(package.Version));

            const string FeedDateTimeFormat = "yyyy-MM-ddTHH:mm:ss.FFF";

            var entry = new XElement(XName.Get("entry", nsAtom),
                                     new XAttribute(XNamespace.Xmlns + "d", nsDataService.ToString()),
                                     new XAttribute(XNamespace.Xmlns + "m", nsMetadata),
                                     new XElement(XName.Get("id", nsAtom), entryId),
                                     new XElement(XName.Get("title", nsAtom), package.Id),
                                     new XElement(XName.Get("content", nsAtom),
                                                  new XAttribute("type", "application/zip"),
                                                  new XAttribute("src", downloadUrl)),
                                     new XElement(XName.Get("properties", nsMetadata),
                                                  new XElement(nsDataService + "Id", package.Id),
                                                  new XElement(nsDataService + "NormalizedVersion", package.Version),
                                                  new XElement(nsDataService + "Version", package.Version),
                                                  new XElement(nsDataService + "PackageHash", "dummy"),
                                                  new XElement(nsDataService + "PackageHashAlgorithm", "dummy"),
                                                  new XElement(nsDataService + "Description", package.Description),
                                                  new XElement(nsDataService + "Listed", package.Listed),


                                                  new XElement(nsDataService + "Created", package.Created.ToString(FeedDateTimeFormat)),
                                                  new XElement(nsDataService + "LastEdited", package.LastEdited?.ToString(FeedDateTimeFormat)),
                                                  new XElement(nsDataService + "Published", package.Published.ToString(FeedDateTimeFormat)),
                                                  new XElement(nsDataService + "LicenseNames", package.LicenseNames),
                                                  new XElement(nsDataService + "LicenseReportUrl", package.LicenseReportUrl)));

            return(entry);
        }
        private string GetIconUrl()
        {
            var subject = _catalogItem.CreateUriNode(_catalogUri);

            var packageId      = GetRequiredObject(_catalogItem, subject, Schema.Predicates.Id);
            var packageVersion = NuGetVersionUtility.NormalizeVersion(GetRequiredObject(_catalogItem, subject, Schema.Predicates.Version));
            var iconUrl        = GetOptionalObject(_catalogItem, subject, Schema.Predicates.IconUrl);
            var iconFile       = GetOptionalObject(_catalogItem, subject, Schema.Predicates.IconFile);

            var shouldUsePathProvider = !string.IsNullOrWhiteSpace(iconFile) || (_forcePathProviderForIcons && !string.IsNullOrWhiteSpace(iconUrl));

            if (shouldUsePathProvider && !string.IsNullOrWhiteSpace(packageId) && !string.IsNullOrWhiteSpace(packageVersion))
            {
                // The embedded icon file case. We assume here that catalog2dnx did its job
                // and extracted the icon file to the appropriate location.
                string path = PackagePathProvider.GetIconPath(packageId, packageVersion);
                return(new Uri(_packageContentBaseAddress, path).AbsoluteUri);
            }

            return(_forcePathProviderForIcons || iconUrl == null ? string.Empty : iconUrl);
        }
        protected void SetIdVersionFromGraph(IGraph graph)
        {
            INode idPredicate      = graph.CreateUriNode(Schema.Predicates.Id);
            INode versionPredicate = graph.CreateUriNode(Schema.Predicates.Version);

            INode  rdfTypePredicate = graph.CreateUriNode(Schema.Predicates.Type);
            Triple resource         = graph.GetTriplesWithPredicateObject(rdfTypePredicate, graph.CreateUriNode(GetItemType())).First();
            Triple id = graph.GetTriplesWithSubjectPredicate(resource.Subject, idPredicate).FirstOrDefault();

            if (id != null)
            {
                _id = ((ILiteralNode)id.Object).Value;
            }

            Triple version = graph.GetTriplesWithSubjectPredicate(resource.Subject, versionPredicate).FirstOrDefault();

            if (version != null)
            {
                _fullVersion       = ((ILiteralNode)version.Object).Value;
                _normalizedVersion = NuGetVersionUtility.NormalizeVersion(_fullVersion);
            }
        }
 public RegistrationEntryKey(RegistrationKey registrationKey, string version)
 {
     RegistrationKey    = registrationKey;
     Version            = version;
     _normalizedVersion = NuGetVersionUtility.NormalizeVersion(version).ToLowerInvariant();
 }
 public string NormalizeVersion(string original)
 {
     return(NuGetVersionUtility.NormalizeVersion(original));
 }