示例#1
0
        public PackageMetadata(
            Dictionary <string, string> metadata,
            IEnumerable <PackageDependencyGroup> dependencyGroups,
            IEnumerable <FrameworkSpecificGroup> frameworkGroups,
            IEnumerable <NuGet.Packaging.Core.PackageType> packageTypes,
            NuGetVersion minClientVersion,
            RepositoryMetadata repositoryMetadata,
            LicenseMetadata licenseMetadata = null)
        {
            _metadata                 = new Dictionary <string, string>(metadata, StringComparer.OrdinalIgnoreCase);
            _dependencyGroups         = dependencyGroups.ToList().AsReadOnly();
            _frameworkReferenceGroups = frameworkGroups.ToList().AsReadOnly();
            _packageTypes             = packageTypes.ToList().AsReadOnly();

            SetPropertiesFromMetadata();
            MinClientVersion = minClientVersion;

            if (repositoryMetadata != null)
            {
                Uri.TryCreate(repositoryMetadata.Url, UriKind.Absolute, out var repoUrl);
                RepositoryUrl  = repoUrl;
                RepositoryType = repositoryMetadata.Type;
            }

            LicenseMetadata = licenseMetadata;
        }
示例#2
0
        public void PackageLicenseUtility_GeneratesLinkForFiles()
        {
            // Setup
            var licenseFileLocation = "License.txt";
            var licenseFileHeader   = "header";
            var licenseData         = new LicenseMetadata(LicenseType.File, licenseFileLocation, null, null, LicenseMetadata.CurrentVersion);
            var licenseContent      = "License content";

            // Act
            var links = PackageLicenseUtilities.GenerateLicenseLinks(
                licenseData,
                licenseFileHeader,
                delegate(string value)
            {
                if (value.Equals(licenseFileLocation))
                {
                    return(licenseContent);
                }
                return(null);
            });

            Assert.Equal(1, links.Count);
            Assert.True(links[0] is LicenseFileText);
            var licenseFileText = links[0] as LicenseFileText;

            Assert.Equal(Resources.Text_ViewLicense, licenseFileText.Text);
            Assert.Equal(Resources.LicenseFile_Loading, ((Run)((Paragraph)licenseFileText.LicenseText.Blocks.AsEnumerable().First()).Inlines.First()).Text);
        }
示例#3
0
        /// <summary>
        /// Creates a new package.
        /// </summary>
        /// <param name="name">The name or ID of the package.</param>
        /// <param name="version">The semantic version of the package.</param>
        /// <param name="authors">An optional semicolon delimited list of authors of the package.  The default value is &quot;UserA&quot;</param>
        /// <param name="description">An optional description of the package.  The default value is &quot;Description&quot;</param>
        /// <param name="copyright">An optional copyright of the package.</param>
        /// <param name="developmentDependency">An optional value indicating whether or not the package is a development dependency.  The default value is <code>false</code>.</param>
        /// <param name="iconUrl">An optional URL to the icon of the package.</param>
        /// <param name="language">An optional language of the package.</param>
        /// <param name="licenseUrl">An optional URL to the license of the package.</param>
        /// <param name="licenseMetadata">An optional <see cref="LicenseMetadata" /> of the package.</param>
        /// <param name="owners">An optional semicolon delimited list of owners of the package.</param>
        /// <param name="packageTypes">An optional <see cref="IEnumerable{PackageType}" /> containing the package types of the package.</param>
        /// <param name="projectUrl">An optional URL to the project of the package.</param>
        /// <param name="releaseNotes">An optional value specifying release notes of the package.</param>
        /// <param name="repositoryType">An optional value specifying the type of source code repository of the package.</param>
        /// <param name="repositoryUrl">An optional value specifying the URL of the source code repository of the package.</param>
        /// <param name="repositoryBranch">An optional value specifying the branch of the source code repository of the package.</param>
        /// <param name="repositoryCommit">An optional value specifying the commit of the source code repository of the package.</param>
        /// <param name="requireLicenseAcceptance">An optional value indicating whether or not the package requires license acceptance  The default value is <code>false</code>.</param>
        /// <param name="serviceable">An option value indicating whether or not the package is serviceable.  The default value is <code>false</code>.</param>
        /// <param name="summary">An optional summary of the package.</param>
        /// <param name="tags">An optional set of tags of the package.</param>
        /// <param name="title">An optional title of the package.</param>
        /// <returns>The current <see cref="PackageRepository" />.</returns>
#else
        /// <summary>
        /// Creates a new package.
        /// </summary>
        /// <param name="name">The name or ID of the package.</param>
        /// <param name="version">The semantic version of the package.</param>
        /// <param name="authors">An optional semicolon delimited list of authors of the package.  The default value is &quot;UserA&quot;</param>
        /// <param name="description">An optional description of the package.  The default value is &quot;Description&quot;</param>
        /// <param name="copyright">An optional copyright of the package.</param>
        /// <param name="developmentDependency">An optional value indicating whether or not the package is a development dependency.  The default value is <code>false</code>.</param>
        /// <param name="icon">An optional path in the package that should be used for the icon of the package.</param>
        /// <param name="iconUrl">An optional URL to the icon of the package.</param>
        /// <param name="language">An optional language of the package.</param>
        /// <param name="licenseUrl">An optional URL to the license of the package.</param>
        /// <param name="licenseMetadata">An optional <see cref="LicenseMetadata" /> of the package.</param>
        /// <param name="owners">An optional semicolon delimited list of owners of the package.</param>
        /// <param name="packageTypes">An optional <see cref="IEnumerable{PackageType}" /> containing the package types of the package.</param>
        /// <param name="projectUrl">An optional URL to the project of the package.</param>
        /// <param name="releaseNotes">An optional value specifying release notes of the package.</param>
        /// <param name="repositoryType">An optional value specifying the type of source code repository of the package.</param>
        /// <param name="repositoryUrl">An optional value specifying the URL of the source code repository of the package.</param>
        /// <param name="repositoryBranch">An optional value specifying the branch of the source code repository of the package.</param>
        /// <param name="repositoryCommit">An optional value specifying the commit of the source code repository of the package.</param>
        /// <param name="requireLicenseAcceptance">An optional value indicating whether or not the package requires license acceptance  The default value is <code>false</code>.</param>
        /// <param name="serviceable">An option value indicating whether or not the package is serviceable.  The default value is <code>false</code>.</param>
        /// <param name="summary">An optional summary of the package.</param>
        /// <param name="tags">An optional set of tags of the package.</param>
        /// <param name="title">An optional title of the package.</param>
        /// <returns>The current <see cref="PackageRepository" />.</returns>
#endif

        public PackageRepository Package(
            string name,
            string version,
            string authors             = null,
            string description         = null,
            string copyright           = null,
            bool developmentDependency = false,
#if !NET46
            string icon = null,
#endif
            string iconUrl    = null,
            string language   = null,
            string licenseUrl = null,
            LicenseMetadata licenseMetadata = null,
            string owners = null,
            IEnumerable <PackageType> packageTypes = null,
            string projectUrl             = null,
            string releaseNotes           = null,
            string repositoryType         = null,
            string repositoryUrl          = null,
            string repositoryBranch       = null,
            string repositoryCommit       = null,
            bool requireLicenseAcceptance = false,
            bool serviceable = false,
            string summary   = null,
            string tags      = null,
            string title     = null)
        {
            return(Package(
                       name,
                       version,
                       out PackageIdentity _,
                       authors,
                       description,
                       copyright,
                       developmentDependency,
#if !NET46
                       icon,
#endif
                       iconUrl,
                       language,
                       licenseUrl,
                       licenseMetadata,
                       owners,
                       packageTypes,
                       projectUrl,
                       releaseNotes,
                       repositoryType,
                       repositoryUrl,
                       repositoryBranch,
                       repositoryCommit,
                       requireLicenseAcceptance,
                       serviceable,
                       summary,
                       tags,
                       title));
        }
示例#4
0
        public async Task IsValid_ReturnsOkForPublicRepositoryWithLicense()
        {
            var license = new LicenseMetadata("key", "node", "name", "spdxID", "url", false);

            var repository = CreateRepository("repomen", false, license);

            var result = await _rule.IsValid(MockClient, repository);

            Assert.IsTrue(result.IsValid);
        }
        // Internal for testing purposes.
        internal static IReadOnlyList <IText> GenerateLicenseLinks(LicenseMetadata metadata)
        {
            var list = new List <IText>();

            if (metadata.WarningsAndErrors != null)
            {
                list.Add(new WarningText(string.Join(Environment.NewLine, metadata.WarningsAndErrors)));
            }

            switch (metadata.Type)
            {
            case LicenseType.Expression:

                if (metadata.LicenseExpression != null && !metadata.LicenseExpression.IsUnlicensed())
                {
                    var identifiers = new List <string>();
                    PopulateLicenseIdentifiers(metadata.LicenseExpression, identifiers);

                    var licenseToBeProcessed = metadata.License;

                    foreach (var identifier in identifiers)
                    {
                        var licenseStart = licenseToBeProcessed.IndexOf(identifier);
                        if (licenseStart != 0)
                        {
                            list.Add(new FreeText(licenseToBeProcessed.Substring(0, licenseStart)));
                        }
                        var license = licenseToBeProcessed.Substring(licenseStart, identifier.Length);
                        list.Add(new LicenseText(license, new Uri(string.Format(LicenseFormat, license))));
                        licenseToBeProcessed = licenseToBeProcessed.Substring(licenseStart + identifier.Length);
                    }

                    if (licenseToBeProcessed.Length != 0)
                    {
                        list.Add(new FreeText(licenseToBeProcessed));
                    }
                }
                else
                {
                    list.Add(new FreeText(metadata.License));
                }

                break;

            case LicenseType.File:

                list.Add(new FreeText(string.Format(CultureInfo.CurrentCulture, Resources.License_FileEmbeddedInPackage, metadata.License)));
                break;

            default:
                break;
            }

            return(list);
        }
示例#6
0
        // Internal for testing purposes.
        internal static IReadOnlyList <IText> GenerateLicenseLinks(LicenseMetadata metadata, string licenseFileHeader, string packagePath, PackageIdentity packageIdentity)
        {
            var list = new List <IText>();

            if (metadata.WarningsAndErrors != null)
            {
                list.Add(new WarningText(string.Join(Environment.NewLine, metadata.WarningsAndErrors)));
            }

            switch (metadata.Type)
            {
            case LicenseType.Expression:

                if (metadata.LicenseExpression != null && !metadata.LicenseExpression.IsUnlicensed())
                {
                    var identifiers = new List <string>();
                    PopulateLicenseIdentifiers(metadata.LicenseExpression, identifiers);

                    var licenseToBeProcessed = metadata.License;

                    foreach (var identifier in identifiers)
                    {
                        var licenseStart = licenseToBeProcessed.IndexOf(identifier, StringComparison.OrdinalIgnoreCase);
                        if (licenseStart != 0)
                        {
                            list.Add(new FreeText(licenseToBeProcessed.Substring(0, licenseStart)));
                        }
                        var license = licenseToBeProcessed.Substring(licenseStart, identifier.Length);
                        list.Add(new LicenseText(license, new Uri(string.Format(LicenseMetadata.LicenseServiceLinkTemplate, license))));
                        licenseToBeProcessed = licenseToBeProcessed.Substring(licenseStart + identifier.Length);
                    }

                    if (licenseToBeProcessed.Length != 0)
                    {
                        list.Add(new FreeText(licenseToBeProcessed));
                    }
                }
                else
                {
                    list.Add(new FreeText(metadata.License));
                }

                break;

            case LicenseType.File:
                list.Add(new LicenseFileText(Resources.Text_ViewLicense, licenseFileHeader, packagePath, metadata.License, packageIdentity));
                break;

            default:
                break;
            }

            return(list);
        }
示例#7
0
        private static Uri CreateEmbeddedLicenseUri(string packagePath, LicenseMetadata licenseMetadata)
        {
            Uri?baseUri = Convert(packagePath);

            var builder = new UriBuilder(baseUri)
            {
                Fragment = licenseMetadata.License
            };

            return(builder.Uri);
        }
        private static XElement GetXElementFromLicenseMetadata(XNamespace ns, LicenseMetadata metadata)
        {
            var attributes = new List <XAttribute>();

            attributes.Add(GetXAttributeFromNameAndValue(NuspecUtility.Type, metadata.Type.ToString().ToLowerInvariant()));
            if (!metadata.Version.Equals(LicenseMetadata.EmptyVersion))
            {
                attributes.Add(GetXAttributeFromNameAndValue(NuspecUtility.Version, metadata.Version));
            }
            attributes = attributes.Where(xAtt => xAtt != null).ToList();

            return(new XElement(ns + NuspecUtility.License, metadata.License, attributes));
        }
        public void PackageLicenseUtility_GeneratesLinkForFiles()
        {
            // Setup
            var licenseData = new LicenseMetadata(LicenseType.File, "License.txt", null, null, LicenseMetadata.CurrentVersion);

            // Act
            var links = PackageLicenseUtilities.GenerateLicenseLinks(licenseData);

            Assert.Equal(1, links.Count);
            Assert.True(links[0] is FreeText);
            Assert.Equal(string.Format(Resources.License_FileEmbeddedInPackage, "License.txt"), links[0].Text);
            Assert.Empty(links.Where(e => e is LicenseText));
        }
        public void PackageLicenseUtility_GeneratesLinkWithHigherVersion()
        {
            var license = "Not so random unparsed license";
            // Setup
            var licenseData = new LicenseMetadata(LicenseType.Expression, license, null, new List <string> {
                "bad license warning"
            }, new System.Version(LicenseMetadata.CurrentVersion.Major + 1, 0, 0));

            // Act
            var links = PackageLicenseUtilities.GenerateLicenseLinks(licenseData);

            Assert.True(links[0] is WarningText);
            Assert.Empty(links.Where(e => e is LicenseText));
        }
示例#11
0
        private static string GetExpectedLicenseUrl(LicenseMetadata licenseMetadata)
        {
            if (licenseMetadata == null || LicenseType.File == licenseMetadata.Type)
            {
                return(GalleryConstants.LicenseDeprecationUrl);
            }

            if (LicenseType.Expression == licenseMetadata.Type)
            {
                return(LicenseExpressionRedirectUrlHelper.GetLicenseExpressionRedirectUrl(licenseMetadata.License));
            }

            throw new InvalidOperationException($"Unsupported license metadata type: {licenseMetadata.Type}");
        }
示例#12
0
 internal static IReadOnlyList <IText> GenerateLicenseLinks(LicenseMetadata licenseMetadata, Uri licenseUrl, string licenseFileHeader, Func <string, string> loadFile)
 {
     if (licenseMetadata != null)
     {
         return(GenerateLicenseLinks(licenseMetadata, licenseFileHeader, loadFile));
     }
     else if (licenseUrl != null)
     {
         return(new List <IText>()
         {
             new LicenseText(Resources.Text_ViewLicense, licenseUrl)
         });
     }
     return(new List <IText>());
 }
 internal static IReadOnlyList <IText> GenerateLicenseLinks(LicenseMetadata licenseMetadata, Uri licenseUrl)
 {
     if (licenseMetadata != null)
     {
         return(GenerateLicenseLinks(licenseMetadata));
     }
     else if (licenseUrl != null)
     {
         return(new List <IText>()
         {
             new LicenseText(Resources.Text_LicenseAcceptance, licenseUrl)
         });
     }
     return(new List <IText>());
 }
示例#14
0
 internal static IReadOnlyList <IText> GenerateLicenseLinks(LicenseMetadata licenseMetadata, Uri licenseUrl, string licenseFileHeader, string packagePath, PackageIdentity packageIdentity)
 {
     if (licenseMetadata != null)
     {
         return(GenerateLicenseLinks(licenseMetadata, licenseFileHeader, packagePath, packageIdentity));
     }
     else if (licenseUrl != null)
     {
         return(new List <IText>()
         {
             new LicenseText(Resources.Text_ViewLicense, licenseUrl)
         });
     }
     return(new List <IText>());
 }
示例#15
0
        public void SerializeThenDeserialize_WithValidArguments_RoundTrips(LicenseMetadata expectedResult)
        {
            var formatters = new IMessagePackFormatter[]
            {
                LicenseMetadataFormatter.Instance,
            };
            var resolvers = new IFormatterResolver[] { MessagePackSerializerOptions.Standard.Resolver };
            var options   = MessagePackSerializerOptions.Standard.WithSecurity(MessagePackSecurity.UntrustedData).WithResolver(CompositeResolver.Create(formatters, resolvers));

            LicenseMetadata?actualResult = SerializeThenDeserialize(LicenseMetadataFormatter.Instance, expectedResult, options);

            Assert.NotNull(actualResult);
            Assert.Equal(expectedResult.License, actualResult !.License);
            Assert.Equal(expectedResult.Type, actualResult.Type);
            Assert.Equal(expectedResult.Version, actualResult.Version);
            Assert.Equal(expectedResult.WarningsAndErrors, actualResult.WarningsAndErrors);
        }
示例#16
0
        public void PackageLicenseUtility_GenerateCorrectLink()
        {
            // Setup
            var license     = "MIT";
            var expression  = NuGetLicenseExpression.Parse(license);
            var licenseData = new LicenseMetadata(LicenseType.Expression, license, expression, null, LicenseMetadata.EmptyVersion);

            // Act
            var links = PackageLicenseUtilities.GenerateLicenseLinks(licenseData, licenseFileHeader: null, packagePath: null, packageIdentity: null);

            // Assert
            Assert.Equal(1, links.Count);
            var licenseText = links[0] as LicenseText;

            Assert.NotNull(licenseText);
            Assert.Equal(license, licenseText.Text);
            Assert.Equal("https://licenses.nuget.org/MIT", licenseText.Link.AbsoluteUri);
        }
        public void PackageLicenseUtility_GeneratesBasicLink(string license, int partsCount, string[] linkedText, bool hasWarnings)
        {
            // Setup
            var expression = NuGetLicenseExpression.Parse(license);
            IReadOnlyList <string> warnings = null;

            if (hasWarnings)
            {
                warnings = new List <string> {
                    "Random warning"
                };
            }

            var licenseData = new LicenseMetadata(LicenseType.Expression, license, expression, warnings, LicenseMetadata.EmptyVersion);

            // Act
            var links = PackageLicenseUtilities.GenerateLicenseLinks(licenseData);

            // Assert
            Assert.Equal(partsCount, links.Count);

            var partsWithLinks = new List <LicenseText>();

            foreach (var part in links)
            {
                if (part is LicenseText licenseText)
                {
                    partsWithLinks.Add(licenseText);
                }
            }
            Assert.Equal(linkedText.Count(), partsWithLinks.Count);
            for (var i = 0; i < partsWithLinks.Count; i++)
            {
                Assert.Equal(linkedText[i], partsWithLinks[i].Text);
            }

            Assert.Equal(license, string.Join("", links.Where(e => !(e is WarningText)).Select(e => e.Text)));
            if (hasWarnings)
            {
                Assert.NotNull(links[0] as WarningText);
            }
        }
示例#18
0
        public async Task NoLicenseChoiceWithExit()
        {
            var licenseApi     = Substitute.For <IGitHubLicenseApi>();
            var consoleService = Substitute.For <IConsoleService>();
            var fileService    = Substitute.For <IFileService>();
            var service        = new LicenseService(licenseApi, consoleService, fileService);

            consoleService.ReadInputNumber(min: 1, max: 2).Returns(Option.None <int>());
            var expectedLicenseMetadata = new LicenseMetadata("gpl", "gpl", "gpl", "idx2", "url2", false);

            licenseApi.ListAsync().Returns(new List <LicenseMetadata>()
            {
                new LicenseMetadata("mit", "mit", "mit", "idx", "url", false),
                expectedLicenseMetadata
            });

            var result = await service.PickLicenseAsync();

            Assert.Null(result.ValueOrDefault());
        }
        public void PackageLicenseUtility_UnlicensedGeneratesNoLinksAndAWarning()
        {
            var license = "UNLICENSED";
            NuGetLicenseExpression expression = null;
            var warnings = new List <string>();

            try
            {
                expression = NuGetLicenseExpression.Parse(license);
            }
            catch (NuGetLicenseExpressionParsingException e)
            {
                warnings.Add(e.Message);
            }
            // Setup
            var licenseData = new LicenseMetadata(LicenseType.Expression, license, expression, warnings, LicenseMetadata.CurrentVersion);

            // Act
            var links = PackageLicenseUtilities.GenerateLicenseLinks(licenseData);

            Assert.Equal(links.Count, 2);
            Assert.True(links[0] is WarningText);
            Assert.True(links[1] is FreeText);
        }
示例#20
0
        public async Task ChooseFirstLicense()
        {
            var licenseApi     = Substitute.For <IGitHubLicenseApi>();
            var consoleService = Substitute.For <IConsoleService>();
            var fileService    = Substitute.For <IFileService>();
            var service        = new LicenseService(licenseApi, consoleService, fileService);

            consoleService.ReadInputNumber(min: 1, max: 2).Returns(Option.Some(1));
            var expectedLicenseMetadata = new LicenseMetadata("gpl", "gpl", "gpl", "idx2", "url2", false);

            licenseApi.ListAsync().Returns(new List <LicenseMetadata>()
            {
                new LicenseMetadata("mit", "mit", "mit", "idx", "url", false),
                expectedLicenseMetadata
            });

            licenseApi.DownloadLicenseContentAsync(Arg.Is <LicenseMetadata>(a => a.Key == "gpl")).Returns("license content");

            var result = await service.PickLicenseAsync();

            await licenseApi.Received(1).DownloadLicenseContentAsync(expectedLicenseMetadata);

            Assert.Equal("LICENSE", result.ValueOrDefault());
        }
示例#21
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PackageManifest"/> class.
        /// </summary>
        /// <param name="fullPath">The full path to the manifest file.</param>
        /// <param name="name">The name or ID of the package.</param>
        /// <param name="version">The semantic version of the package.</param>
        /// <param name="authors">An optional semicolon delimited list of authors of the package.  The default value is &quot;UserA&quot;</param>
        /// <param name="description">An optional description of the package.  The default value is &quot;Description&quot;</param>
        /// <param name="copyright">An optional copyright of the package.</param>
        /// <param name="developmentDependency">An optional value indicating whether or not the package is a development dependency.  The default value is <code>false</code>.</param>
        /// <param name="iconUrl">An optional URL to the icon of the package.</param>
        /// <param name="language">An optional language of the package.</param>
        /// <param name="licenseUrl">An optional URL to the license of the package.</param>
        /// <param name="licenseMetadata">An optional <see cref="LicenseMetadata" /> of the package.</param>
        /// <param name="owners">An optional semicolon delimited list of owners of the package.</param>
        /// <param name="packageTypes">An optional <see cref="IEnumerable{PackageType}" /> containing the package types of the package.</param>
        /// <param name="projectUrl">An optional URL to the project of the package.</param>
        /// <param name="releaseNotes">An optional value specifying release notes of the package.</param>
        /// <param name="repositoryType">An optional value specifying the type of source code repository of the package.</param>
        /// <param name="repositoryUrl">An optional value specifying the URL of the source code repository of the package.</param>
        /// <param name="repositoryBranch">An optional value specifying the branch of the source code repository of the package.</param>
        /// <param name="repositoryCommit">An optional value specifying the commit of the source code repository of the package.</param>
        /// <param name="requireLicenseAcceptance">An optional value indicating whether or not the package requires license acceptance  The default value is <code>false</code>.</param>
        /// <param name="serviceable">An option value indicating whether or not the package is serviceable.  The default value is <code>false</code>.</param>
        /// <param name="summary">An optional summary of the package.</param>
        /// <param name="tags">An optional set of tags of the package.</param>
        /// <param name="title">An optional title of the package.</param>
#else
        /// <summary>
        /// Initializes a new instance of the <see cref="PackageManifest"/> class.
        /// </summary>
        /// <param name="fullPath">The full path to the manifest file.</param>
        /// <param name="name">The name or ID of the package.</param>
        /// <param name="version">The semantic version of the package.</param>
        /// <param name="authors">An optional semicolon delimited list of authors of the package.  The default value is &quot;UserA&quot;</param>
        /// <param name="description">An optional description of the package.  The default value is &quot;Description&quot;</param>
        /// <param name="copyright">An optional copyright of the package.</param>
        /// <param name="developmentDependency">An optional value indicating whether or not the package is a development dependency.  The default value is <code>false</code>.</param>
        /// <param name="icon">An optional path in the package that should be used for the icon of the package.</param>
        /// <param name="iconUrl">An optional URL to the icon of the package.</param>
        /// <param name="language">An optional language of the package.</param>
        /// <param name="licenseUrl">An optional URL to the license of the package.</param>
        /// <param name="licenseMetadata">An optional <see cref="LicenseMetadata" /> of the package.</param>
        /// <param name="owners">An optional semicolon delimited list of owners of the package.</param>
        /// <param name="packageTypes">An optional <see cref="IEnumerable{PackageType}" /> containing the package types of the package.</param>
        /// <param name="projectUrl">An optional URL to the project of the package.</param>
        /// <param name="releaseNotes">An optional value specifying release notes of the package.</param>
        /// <param name="repositoryType">An optional value specifying the type of source code repository of the package.</param>
        /// <param name="repositoryUrl">An optional value specifying the URL of the source code repository of the package.</param>
        /// <param name="repositoryBranch">An optional value specifying the branch of the source code repository of the package.</param>
        /// <param name="repositoryCommit">An optional value specifying the commit of the source code repository of the package.</param>
        /// <param name="requireLicenseAcceptance">An optional value indicating whether or not the package requires license acceptance  The default value is <code>false</code>.</param>
        /// <param name="serviceable">An option value indicating whether or not the package is serviceable.  The default value is <code>false</code>.</param>
        /// <param name="summary">An optional summary of the package.</param>
        /// <param name="tags">An optional set of tags of the package.</param>
        /// <param name="title">An optional title of the package.</param>
#endif

        public PackageManifest(
            string fullPath,
            string name,
            string version,
            string authors             = null,
            string description         = null,
            string copyright           = null,
            bool developmentDependency = false,
#if !NET46
            string icon = null,
#endif
            string iconUrl    = null,
            string language   = null,
            string licenseUrl = null,
            LicenseMetadata licenseMetadata = null,
            string owners = null,
            IEnumerable <PackageType> packageTypes = null,
            string projectUrl             = null,
            string releaseNotes           = null,
            string repositoryType         = null,
            string repositoryUrl          = null,
            string repositoryBranch       = null,
            string repositoryCommit       = null,
            bool requireLicenseAcceptance = false,
            bool serviceable = false,
            string summary   = null,
            string tags      = null,
            string title     = null)
            : base(
                GetManifestMetadata(
                    name,
                    version,
                    authors,
                    description,
                    copyright,
                    developmentDependency,
#if !NET46
                    icon,
#endif
                    iconUrl,
                    language,
                    licenseUrl,
                    licenseMetadata,
                    owners,
                    packageTypes,
                    projectUrl,
                    releaseNotes,
                    repositoryType,
                    repositoryUrl,
                    repositoryBranch,
                    repositoryCommit,
                    requireLicenseAcceptance,
                    serviceable,
                    summary,
                    tags,
                    title))
        {
            if (string.IsNullOrWhiteSpace(fullPath))
            {
                throw new ArgumentNullException(nameof(fullPath));
            }

            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentNullException(nameof(name));
            }

            if (string.IsNullOrWhiteSpace(version))
            {
                throw new ArgumentNullException(nameof(version));
            }

            FullPath = fullPath;

            Directory = Path.GetDirectoryName(fullPath);

            Save();

            NupkgMetadataFileFormat.Write(
                Path.Combine(Directory, PackagingCoreConstants.NupkgMetadataFileExtension),
                new NupkgMetadataFile
            {
                ContentHash = string.Empty,
                Version     = NupkgMetadataFileFormat.Version,
            });
        }
示例#22
0
        public async Task <string> DownloadLicenseContentAsync(LicenseMetadata metadata)
        {
            var license = await _client.Miscellaneous.GetLicense(metadata.Key);

            return(license?.Body);
        }
示例#23
0
 public static LicenseCacheItem Create(LicenseMetadata licenseMetadata)
 {
     return(new LicenseCacheItem {
         Key = licenseMetadata.Key, Name = licenseMetadata.Name
     });
 }
        /// <summary>
        /// Return the list of <see cref="PackageToPrepare"/> in the ordered form
        /// for which we want to run all the tasks sequentially
        /// </summary>
        /// <returns>Ordered list of tasks to run for <see cref="PackageToPrepare"/></returns>
        private async Task <List <PackageToPrepare> > InitializePackagesAsync(PackageType packageType, ITestOutputHelper logger)
        {
            var                     id = GetPackageId(packageType);
            LicenseMetadata         licenseMetadata;
            PackageToPrepare        packageToPrepare;
            List <PackageToPrepare> packagesToPrepare = new List <PackageToPrepare>();

            switch (packageType)
            {
            case PackageType.SemVer2DueToSemVer2Dep:
                packageToPrepare = new PackageToPrepare(Package.Create(new PackageCreationContext
                {
                    Id = id,
                    NormalizedVersion = "1.0.0-beta",
                    FullVersion       = "1.0.0-beta",
                    DependencyGroups  = new[]
                    {
                        new PackageDependencyGroup(
                            TestData.TargetFramework,
                            new[]
                        {
                            new PackageDependency(
                                GetPackageId(PackageType.SemVer2Prerel),
                                VersionRange.Parse(SemVer2PrerelVersion))
                        })
                    },
                    Properties = new PackageProperties(packageType)
                }));
                break;

            case PackageType.SemVer2StableMetadataUnlisted:
                packageToPrepare = new PackageToPrepare(
                    Package.Create(packageType, id, "1.0.0", "1.0.0+metadata"),
                    unlist: true);
                break;

            case PackageType.SemVer2StableMetadata:
                packageToPrepare = new PackageToPrepare(Package.Create(packageType, id, "1.0.0", "1.0.0+metadata"));
                break;

            case PackageType.SemVer2PrerelUnlisted:
                packageToPrepare = new PackageToPrepare(
                    Package.Create(packageType, id, "1.0.0-alpha.1"),
                    unlist: true);
                break;

            case PackageType.SemVer2Prerel:
                packageToPrepare = new PackageToPrepare(Package.Create(packageType, id, SemVer2PrerelVersion));
                break;

            case PackageType.SemVer2PrerelRelisted:
                packageToPrepare = new PackageToPrepare(Package.Create(packageType, id, "1.0.0-alpha.1"),
                                                        unlist: true);
                break;

            case PackageType.SemVer1StableUnlisted:
                packageToPrepare = new PackageToPrepare(
                    Package.Create(packageType, id, "1.0.0"),
                    unlist: true);
                break;

            case PackageType.Signed:
                packageToPrepare = new PackageToPrepare(Package.SignedPackage());
                break;

            case PackageType.SymbolsPackage:
                return(await PrepareSymbolsPackageAsync(id, "1.0.0", logger));

            case PackageType.LicenseExpression:
                licenseMetadata  = new LicenseMetadata(LicenseType.Expression, "MIT", null, null, LicenseMetadata.EmptyVersion);
                packageToPrepare = new PackageToPrepare(Package.Create(new PackageCreationContext
                {
                    Id = id,
                    NormalizedVersion = "1.0.0",
                    FullVersion       = "1.0.0",
                    Properties        = new PackageProperties(packageType, licenseMetadata)
                }));
                break;

            case PackageType.LicenseFile:
                var licenseFilePath    = "license.txt";
                var licenseFileContent = "It's a license";
                licenseMetadata  = new LicenseMetadata(LicenseType.File, licenseFilePath, null, null, LicenseMetadata.EmptyVersion);
                packageToPrepare = new PackageToPrepare(Package.Create(new PackageCreationContext
                {
                    Id = id,
                    NormalizedVersion = "1.0.0",
                    FullVersion       = "1.0.0",
                    Properties        = new PackageProperties(packageType, licenseMetadata, licenseFileContent),
                    Files             = new List <PhysicalPackageFile> {
                        new PhysicalPackageFile(new MemoryStream(Encoding.UTF8.GetBytes(licenseFileContent)))
                        {
                            TargetPath = licenseFilePath
                        }
                    }
                }));
                break;

            case PackageType.LicenseUrl:
                var licenseUrl = new Uri("https://testLicenseUrl");
                packageToPrepare = new PackageToPrepare(Package.Create(new PackageCreationContext
                {
                    Id = id,
                    NormalizedVersion = "1.0.0",
                    FullVersion       = "1.0.0",
                    Properties        = new PackageProperties(packageType, licenseUrl: licenseUrl)
                }));
                break;

            case PackageType.EmbeddedIconJpeg:
                packageToPrepare = new PackageToPrepare(Package.Create(new PackageCreationContext
                {
                    Id = id,
                    NormalizedVersion = "1.0.0",
                    FullVersion       = "1.0.0",
                    Properties        = new PackageProperties(packageType)
                    {
                        EmbeddedIconFilename = "icon.jpg"
                    },
                }));
                break;

            case PackageType.EmbeddedIconPng:
                packageToPrepare = new PackageToPrepare(Package.Create(new PackageCreationContext
                {
                    Id = id,
                    NormalizedVersion = "1.0.0",
                    FullVersion       = "1.0.0",
                    Properties        = new PackageProperties(packageType)
                    {
                        EmbeddedIconFilename = "icon.png"
                    },
                }));
                break;

            case PackageType.Deprecated:
                packageToPrepare = new PackageToPrepare(
                    Package.Create(packageType, id, "1.0.0"),
                    PackageDeprecationContext.Default);
                break;

            case PackageType.DotnetTool:
                return(await PrepareDotnetToolPackageAsync(id, "1.0.0", logger));

            case PackageType.SemVer1Stable:
            case PackageType.FullValidation:
            default:
                packageToPrepare = new PackageToPrepare(Package.Create(packageType, id, "1.0.0"));
                break;
            }

            packagesToPrepare.Add(packageToPrepare);
            return(packagesToPrepare);
        }
示例#25
0
 public PackageProperties(PackageType packageType, LicenseMetadata licenseMetadata, string licenseFileContent)
 {
     Type               = packageType;
     LicenseMetadata    = licenseMetadata;
     LicenseFileContent = licenseFileContent;
 }
示例#26
0
 public static LicenseCacheItem Create(LicenseMetadata licenseMetadata)
 {
     return(new LicenseCacheItem {
         Key = licenseMetadata.Key, Name = licenseMetadata.Name, Timestamp = DateTime.Now
     });
 }
示例#27
0
        /// <summary>
        /// Creates a new package.
        /// </summary>
        /// <param name="name">The name or ID of the package.</param>
        /// <param name="version">The semantic version of the package.</param>
        /// <param name="package">Receives the <see cref="PackageIdentity" /> of the package.</param>
        /// <param name="authors">An optional semicolon delimited list of authors of the package.  The default value is &quot;UserA&quot;</param>
        /// <param name="description">An optional description of the package.  The default value is &quot;Description&quot;</param>
        /// <param name="copyright">An optional copyright of the package.</param>
        /// <param name="developmentDependency">An optional value indicating whether or not the package is a development dependency.  The default value is <code>false</code>.</param>
        /// <param name="iconUrl">An optional URL to the icon of the package.</param>
        /// <param name="language">An optional language of the package.</param>
        /// <param name="licenseUrl">An optional URL to the license of the package.</param>
        /// <param name="licenseMetadata">An optional <see cref="LicenseMetadata" /> of the package.</param>
        /// <param name="owners">An optional semicolon delimited list of owners of the package.</param>
        /// <param name="packageTypes">An optional <see cref="IEnumerable{PackageType}" /> containing the package types of the package.</param>
        /// <param name="projectUrl">An optional URL to the project of the package.</param>
        /// <param name="releaseNotes">An optional value specifying release notes of the package.</param>
        /// <param name="repositoryType">An optional value specifying the type of source code repository of the package.</param>
        /// <param name="repositoryUrl">An optional value specifying the URL of the source code repository of the package.</param>
        /// <param name="repositoryBranch">An optional value specifying the branch of the source code repository of the package.</param>
        /// <param name="repositoryCommit">An optional value specifying the commit of the source code repository of the package.</param>
        /// <param name="requireLicenseAcceptance">An optional value indicating whether or not the package requires license acceptance  The default value is <code>false</code>.</param>
        /// <param name="serviceable">An option value indicating whether or not the package is serviceable.  The default value is <code>false</code>.</param>
        /// <param name="summary">An optional summary of the package.</param>
        /// <param name="tags">An optional set of tags of the package.</param>
        /// <param name="title">An optional title of the package.</param>
        /// <returns>The current <see cref="PackageRepository" />.</returns>
#else
        /// <summary>
        /// Creates a new package.
        /// </summary>
        /// <param name="name">The name or ID of the package.</param>
        /// <param name="version">The semantic version of the package.</param>
        /// <param name="package">Receives the <see cref="PackageIdentity" /> of the package.</param>
        /// <param name="authors">An optional semicolon delimited list of authors of the package.  The default value is &quot;UserA&quot;</param>
        /// <param name="description">An optional description of the package.  The default value is &quot;Description&quot;</param>
        /// <param name="copyright">An optional copyright of the package.</param>
        /// <param name="developmentDependency">An optional value indicating whether or not the package is a development dependency.  The default value is <code>false</code>.</param>
        /// <param name="icon">An optional path in the package that should be used for the icon of the package.</param>
        /// <param name="iconUrl">An optional URL to the icon of the package.</param>
        /// <param name="language">An optional language of the package.</param>
        /// <param name="licenseUrl">An optional URL to the license of the package.</param>
        /// <param name="licenseMetadata">An optional <see cref="LicenseMetadata" /> of the package.</param>
        /// <param name="owners">An optional semicolon delimited list of owners of the package.</param>
        /// <param name="packageTypes">An optional <see cref="IEnumerable{PackageType}" /> containing the package types of the package.</param>
        /// <param name="projectUrl">An optional URL to the project of the package.</param>
        /// <param name="releaseNotes">An optional value specifying release notes of the package.</param>
        /// <param name="repositoryType">An optional value specifying the type of source code repository of the package.</param>
        /// <param name="repositoryUrl">An optional value specifying the URL of the source code repository of the package.</param>
        /// <param name="repositoryBranch">An optional value specifying the branch of the source code repository of the package.</param>
        /// <param name="repositoryCommit">An optional value specifying the commit of the source code repository of the package.</param>
        /// <param name="requireLicenseAcceptance">An optional value indicating whether or not the package requires license acceptance  The default value is <code>false</code>.</param>
        /// <param name="serviceable">An option value indicating whether or not the package is serviceable.  The default value is <code>false</code>.</param>
        /// <param name="summary">An optional summary of the package.</param>
        /// <param name="tags">An optional set of tags of the package.</param>
        /// <param name="title">An optional title of the package.</param>
        /// <returns>The current <see cref="PackageRepository" />.</returns>
#endif
        public PackageRepository Package(
            string name,
            string version,
            out PackageIdentity package,
            string authors             = null,
            string description         = null,
            string copyright           = null,
            bool developmentDependency = false,
#if !NET46
            string icon = null,
#endif
            string iconUrl    = null,
            string language   = null,
            string licenseUrl = null,
            LicenseMetadata licenseMetadata = null,
            string owners = null,
            IEnumerable <PackageType> packageTypes = null,
            string projectUrl             = null,
            string releaseNotes           = null,
            string repositoryType         = null,
            string repositoryUrl          = null,
            string repositoryBranch       = null,
            string repositoryCommit       = null,
            bool requireLicenseAcceptance = false,
            bool serviceable = false,
            string summary   = null,
            string tags      = null,
            string title     = null)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentNullException(nameof(name));
            }

            if (string.IsNullOrWhiteSpace(version))
            {
                throw new ArgumentNullException(nameof(version));
            }

            package = new PackageIdentity(name, NuGetVersion.Parse(version));

            string manifestFilePath = _versionFolderPathResolver.GetManifestFilePath(package.Id, package.Version);

            if (System.IO.File.Exists(manifestFilePath))
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Strings.ErrorPackageAlreadyCreated, name, version));
            }

            _packageManifest = new PackageManifest(
                manifestFilePath,
                name,
                version,
                authors,
                description,
                copyright,
                developmentDependency,
#if !NET46
                icon,
#endif
                iconUrl,
                language,
                licenseUrl,
                licenseMetadata,
                owners,
                packageTypes,
                projectUrl,
                releaseNotes,
                repositoryType,
                repositoryUrl,
                repositoryBranch,
                repositoryCommit,
                requireLicenseAcceptance,
                serviceable,
                summary,
                tags,
                title);

            _packages.Add(package);

            return(this);
        }
示例#28
0
 public HttpResponseMessage NewLicense(LicenseMetadata licenseMetadata)
 {
     // .. rest of your code ..
 }
示例#29
0
 private Repository CreateRepository(string name, bool isPrivate, LicenseMetadata license)
 {
     return(new Repository(null, null, null, null, null, null, null, 0, null, null, name, null, false, null, null, null, isPrivate, false, 0, 0, MainBranch, 0, null, DateTime.UtcNow, DateTime.UtcNow, null, null, null, license, false, false, false, false, 0, 0, null, null, null, false, 0, false, RepositoryVisibility.Public));
 }
示例#30
0
 public PackageProperties(PackageType packageType, LicenseMetadata licenseMetadata)
     : this(packageType, licenseMetadata, null)
 {
 }