コード例 #1
0
        public static void GenerateNupkgMetadataFile(string nupkgPath, string installPath, string hashPath, string nupkgMetadataPath)
        {
            ConcurrencyUtilities.ExecuteWithFileLocked(nupkgPath,
                                                       action: () =>
            {
                // make sure new hash file doesn't exists within File lock before actually creating it.
                if (!File.Exists(nupkgMetadataPath))
                {
                    var tempNupkgMetadataFilePath = Path.Combine(installPath, Path.GetRandomFileName());
                    using (var stream = File.Open(nupkgPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                        using (var packageReader = new PackageArchiveReader(stream))
                        {
                            // get hash of unsigned content of signed package
                            var packageHash = packageReader.GetContentHashForSignedPackage(CancellationToken.None);

                            // if null, then it's unsigned package so just read the existing sha512 file
                            if (string.IsNullOrEmpty(packageHash))
                            {
                                packageHash = File.ReadAllText(hashPath);
                            }

                            // write the new hash file
                            var hashFile = new NupkgMetadataFile()
                            {
                                ContentHash = packageHash
                            };

                            NupkgMetadataFileFormat.Write(tempNupkgMetadataFilePath, hashFile);
                            File.Move(tempNupkgMetadataFilePath, nupkgMetadataPath);
                        }
                }
            });
        }
コード例 #2
0
        private void WriteNupkgMetadata(string nupkgPath, string contentHash)
        {
            var metadataPath = GetNupkgMetadataPath(nupkgPath);

            var metadata = new NupkgMetadataFile()
            {
                ContentHash = contentHash
            };

            NupkgMetadataFileFormat.Write(metadataPath, metadata);
        }
コード例 #3
0
        public void NupkgMetadataFileFormat_Write()
        {
            var nupkgMetadataFileContent = @"{
                ""version"": 1,
                ""contentHash"": ""NhfNp80eWq5ms7fMrjuRqpwhL1H56IVzXF9d+OIDcEfQ92m1DyE0c+ufUE1ogB09+sYLd58IO4eJ8jyn7AifbA==""
            }";

            NupkgMetadataFile metadataFile = null;

            using (var reader = new StringReader(nupkgMetadataFileContent))
            {
                metadataFile = NupkgMetadataFileFormat.Read(reader, NullLogger.Instance, string.Empty);
            }

            using (var writer = new StringWriter())
            {
                NupkgMetadataFileFormat.Write(writer, metadataFile);
                var output   = JObject.Parse(writer.ToString());
                var expected = JObject.Parse(nupkgMetadataFileContent);

                Assert.Equal(expected.ToString(), output.ToString());
            }
        }
コード例 #4
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,
            });
        }