Exemplo n.º 1
0
        public void Populate(ManifestMetadata manifestMetadata)
        {
            IPackageMetadata metadata = manifestMetadata;

            Id      = metadata.Id;
            Version = metadata.Version;
            Title   = metadata.Title;
            Authors.AddRange(metadata.Authors);
            Owners.AddRange(metadata.Owners);
            IconUrl    = metadata.IconUrl;
            LicenseUrl = metadata.LicenseUrl;
            ProjectUrl = metadata.ProjectUrl;
            RequireLicenseAcceptance = metadata.RequireLicenseAcceptance;
            // DevelopmentDependency = metadata.DevelopmentDependency;
            Description      = metadata.Description;
            Summary          = metadata.Summary;
            ReleaseNotes     = metadata.ReleaseNotes;
            Language         = metadata.Language;
            Copyright        = metadata.Copyright;
            MinClientVersion = metadata.MinClientVersion;

            if (metadata.Tags != null)
            {
                Tags.AddRange(ParseTags(metadata.Tags));
            }

            DependencySets.AddRange(metadata.DependencySets);
            FrameworkReferences.AddRange(metadata.FrameworkAssemblies);

            if (manifestMetadata.ReferenceSets != null)
            {
                PackageAssemblyReferences.AddRange(manifestMetadata.ReferenceSets.Select(r => new PackageReferenceSet(r)));
            }
        }
        public void Save(Stream stream)
        {
            // Make sure we're saving a valid package id
            PackageIdValidator.ValidatePackageId(Id);

            // Throw if the package doesn't contain any dependencies nor content
            if (!Files.Any() && !DependencySets.Any() && !FrameworkReferences.Any())
            {
                throw new InvalidOperationException(NuGetResources.CannotCreateEmptyPackage);
            }

            ValidateDependencySets(Version, DependencySets);
            ValidateReferenceAssemblies(Files, PackageAssemblyReferences);

            using (Package package = Package.Open(stream, FileMode.Create))
            {
                // Validate and write the manifest
                WriteManifest(package, DetermineMinimumSchemaVersion(Files));

                // Write the files to the package
                WriteFiles(package);

                // Copy the metadata properties back to the package
                package.PackageProperties.Creator     = String.Join(",", Authors);
                package.PackageProperties.Description = Description;
                package.PackageProperties.Identifier  = Id;
                package.PackageProperties.Version     = Version.ToString();
                package.PackageProperties.Language    = Language;
                package.PackageProperties.Keywords    = ((IPackageMetadata)this).Tags;
                package.PackageProperties.Title       = Title;
                package.PackageProperties.Subject     = "NuGet Package Explorer";
            }
        }
Exemplo n.º 3
0
        public void Save(Stream stream)
        {
            // Make sure we're saving a valid package id
            PackageIdValidator.ValidatePackageId(Id);

            // Throw if the package doesn't contain any dependencies nor content
            if (!Files.Any() && !DependencySets.SelectMany(d => d.Dependencies).Any() && !FrameworkAssemblies.Any())
            {
                // TODO: Resources
                throw new InvalidOperationException("NuGetResources.CannotCreateEmptyPackage");
            }

            if (!ValidateSpecialVersionLength(Version))
            {
                // TODO: Resources
                throw new InvalidOperationException("NuGetResources.SemVerSpecialVersionTooLong");
            }

            ValidateDependencySets(Version, DependencySets);
            ValidateReferenceAssemblies(Files, PackageAssemblyReferences);

            using (var package = new ZipArchive(stream, ZipArchiveMode.Create))
            {
                // Validate and write the manifest
                WriteManifest(package, ManifestVersionUtility.DefaultVersion);

                // Write the files to the package
                var extensions = WriteFiles(package);

                extensions.Add("nuspec");

                WriteOpcContentTypes(package, extensions);
            }
        }
Exemplo n.º 4
0
        public void Save(Stream stream)
        {
            // Make sure we're saving a valid package id
            PackageIdValidator.ValidatePackageId(Id);

            // Throw if the package doesn't contain any dependencies nor content
            if (!Files.Any() && !DependencySets.SelectMany(d => d.Dependencies).Any() && !FrameworkReferences.Any())
            {
                throw new InvalidOperationException(NuGetResources.CannotCreateEmptyPackage);
            }

            if (!ValidateSpecialVersionLength(Version))
            {
                throw new InvalidOperationException(NuGetResources.SemVerSpecialVersionTooLong);
            }

            ValidateDependencySets(Version, DependencySets);
            ValidateReferenceAssemblies(Files, PackageAssemblyReferences);

            if (PlatformHelper.IsMono)
            {
#if NET45
                // Mono's zip implementation isn't complete as yet
                using (var package = System.IO.Packaging.Package.Open(stream, FileMode.Create))
                {
                    // Validate and write the manifest
                    WriteManifest(package, DetermineMinimumSchemaVersion(Files));

                    // Write the files to the package
                    WriteFiles(package);

                    // Copy the metadata properties back to the package
                    package.PackageProperties.Creator        = String.Join(",", Authors);
                    package.PackageProperties.Description    = Description;
                    package.PackageProperties.Identifier     = Id;
                    package.PackageProperties.Version        = Version.ToString();
                    package.PackageProperties.Language       = Language;
                    package.PackageProperties.Keywords       = ((IPackageMetadata)this).Tags;
                    package.PackageProperties.Title          = Title;
                    package.PackageProperties.LastModifiedBy = CreatorInfo();
                }
#endif
            }
            else
            {
                using (var package = new ZipArchive(stream, ZipArchiveMode.Update))
                {
                    // Validate and write the manifest
                    WriteManifest(package, DetermineMinimumSchemaVersion(Files));

                    // Write the files to the package
                    var extensions = WriteFiles(package);

                    extensions.Add("nuspec");

                    WriteOpcContentTypes(package, extensions);
                }
            }
        }
Exemplo n.º 5
0
        private void ReadManifest(Stream stream, string basePath)
        {
            // Deserialize the document and extract the metadata
            Manifest         manifest = Manifest.ReadFrom(stream);
            IPackageMetadata metadata = manifest.Metadata;

            Id      = metadata.Id;
            Version = metadata.Version;
            Title   = metadata.Title;
            Authors.AddRange(metadata.Authors);
            Owners.AddRange(metadata.Owners);
            IconUrl    = metadata.IconUrl;
            LicenseUrl = metadata.LicenseUrl;
            ProjectUrl = metadata.ProjectUrl;
            RequireLicenseAcceptance = metadata.RequireLicenseAcceptance;
            Description           = metadata.Description;
            Summary               = metadata.Summary;
            ReleaseNotes          = metadata.ReleaseNotes;
            Language              = metadata.Language;
            Copyright             = metadata.Copyright;
            Serviceable           = metadata.Serviceable;
            MinClientVersion      = metadata.MinClientVersion;
            DevelopmentDependency = metadata.DevelopmentDependency;

            if (metadata.Tags != null)
            {
                Tags.AddRange(ParseTags(metadata.Tags));
            }

            DependencySets.AddRange(metadata.DependencySets);
            FrameworkReferences.AddRange(metadata.FrameworkAssemblies);
            if (metadata.PackageAssemblyReferences != null)
            {
                PackageAssemblyReferences.AddRange(metadata.PackageAssemblyReferences);
            }

            // If there's no base path then ignore the files node
            if (basePath != null)
            {
                if (manifest.Files == null)
                {
                    AddFiles(basePath, @"**\*.*", null);
                }
                else
                {
                    foreach (ManifestFile file in manifest.Files)
                    {
                        AddFiles(basePath, file.Source, file.Target, file.Exclude);
                    }
                }
            }
        }
Exemplo n.º 6
0
        public void Populate(ManifestMetadata manifestMetadata)
        {
            IPackageMetadata metadata = manifestMetadata;

            Id      = metadata.Id;
            Version = metadata.Version;
            Title   = metadata.Title;
            Authors.AddRange(metadata.Authors);
            Owners.AddRange(metadata.Owners);
            IconUrl    = metadata.IconUrl;
            LicenseUrl = metadata.LicenseUrl;
            ProjectUrl = metadata.ProjectUrl;
            RequireLicenseAcceptance = metadata.RequireLicenseAcceptance;
            DevelopmentDependency    = metadata.DevelopmentDependency;
            Description      = metadata.Description;
            Summary          = metadata.Summary;
            ReleaseNotes     = metadata.ReleaseNotes;
            Language         = metadata.Language;
            Copyright        = metadata.Copyright;
            MinClientVersion = metadata.MinClientVersion;
            ContentFiles     = new Collection <ManifestContentFiles>(manifestMetadata.ContentFiles);

            ProjectSourceUrl = metadata.ProjectSourceUrl;
            PackageSourceUrl = metadata.PackageSourceUrl;
            DocsUrl          = metadata.DocsUrl;
            WikiUrl          = metadata.WikiUrl;
            MailingListUrl   = metadata.MailingListUrl;
            BugTrackerUrl    = metadata.BugTrackerUrl;
            Replaces.AddRange(metadata.Replaces);
            Provides.AddRange(metadata.Provides);
            Conflicts.AddRange(metadata.Conflicts);

            SoftwareDisplayName    = metadata.SoftwareDisplayName;
            SoftwareDisplayVersion = metadata.SoftwareDisplayVersion;

            if (metadata.Tags != null)
            {
                Tags.AddRange(ParseTags(metadata.Tags));
            }

            DependencySets.AddRange(metadata.DependencySets);
            FrameworkReferences.AddRange(metadata.FrameworkAssemblies);

            if (manifestMetadata.ReferenceSets != null)
            {
                PackageAssemblyReferences.AddRange(manifestMetadata.ReferenceSets.Select(r => new PackageReferenceSet(r)));
            }
        }
 public DetailedPackageMetadata(UIPackageMetadata serverData, int downloadCount)
 {
     Version         = serverData.Identity.Version;
     Summary         = serverData.Summary;
     Description     = serverData.Description;
     Authors         = serverData.Authors;
     Owners          = serverData.Owners;
     IconUrl         = serverData.IconUrl;
     LicenseUrl      = serverData.LicenseUrl;
     ProjectUrl      = serverData.ProjectUrl;
     ReportAbuseUrl  = serverData.ReportAbuseUrl;
     Tags            = serverData.Tags;
     DownloadCount   = downloadCount;
     Published       = serverData.Published;
     DependencySets  = serverData.DependencySets.Select(e => new PackageDependencySetMetadata(e));
     HasDependencies = DependencySets.Any(
         dependencySet => dependencySet.Dependencies != null && dependencySet.Dependencies.Count > 0);
 }
Exemplo n.º 8
0
        public DetailedPackageMetadata(IPackageSearchMetadata serverData, long?downloadCount)
        {
            Id             = serverData.Identity.Id;
            Version        = serverData.Identity.Version;
            Summary        = serverData.Summary;
            Description    = serverData.Description;
            Authors        = serverData.Authors;
            Owners         = serverData.Owners;
            IconUrl        = serverData.IconUrl;
            LicenseUrl     = serverData.LicenseUrl;
            ProjectUrl     = serverData.ProjectUrl;
            ReportAbuseUrl = serverData.ReportAbuseUrl;
            Tags           = serverData.Tags;
            DownloadCount  = downloadCount;
            Published      = serverData.Published;
            DependencySets = serverData.DependencySets?
                             .Select(e => new PackageDependencySetMetadata(e))
                             ?? new PackageDependencySetMetadata[] { };
            HasDependencies = DependencySets.Any(
                dependencySet => dependencySet.Dependencies != null && dependencySet.Dependencies.Count > 0);
            PrefixReserved      = serverData.PrefixReserved;
            LicenseMetadata     = serverData.LicenseMetadata;
            DeprecationMetadata = serverData.DeprecationMetadata;
            _localMetadata      = serverData as LocalPackageSearchMetadata;

            // Determine the package details URL and text.
            PackageDetailsUrl  = null;
            PackageDetailsText = null;
            if (serverData.PackageDetailsUrl != null &&
                serverData.PackageDetailsUrl.IsAbsoluteUri &&
                serverData.PackageDetailsUrl.Host != null)
            {
                PackageDetailsUrl  = serverData.PackageDetailsUrl;
                PackageDetailsText = serverData.PackageDetailsUrl.Host;

                // Special case the subdomain "www." - we hide it. Other subdomains are not hidden.
                const string wwwDot = "www.";
                if (PackageDetailsText.StartsWith(wwwDot, StringComparison.OrdinalIgnoreCase) &&
                    PackageDetailsText.Length > wwwDot.Length)
                {
                    PackageDetailsText = PackageDetailsText.Substring(wwwDot.Length);
                }
            }
        }
Exemplo n.º 9
0
        public void Save(Stream stream)
        {
            // Make sure we're saving a valid package id
            PackageIdValidator.ValidatePackageId(Id);

            // Throw if the package doesn't contain any dependencies nor content
            if (!Files.Any() && !DependencySets.SelectMany(d => d.Dependencies).Any() && !FrameworkReferences.Any())
            {
                throw new InvalidOperationException(NuGetResources.CannotCreateEmptyPackage);
            }

            if (!ValidateSpecialVersionLength(Version))
            {
                throw new InvalidOperationException(NuGetResources.SemVerSpecialVersionTooLong);
            }

            ValidateDependencySets(Version, DependencySets);
            ValidateReferenceAssemblies(Files, PackageAssemblyReferences);

            bool requiresV4TargetFrameworkSchema = RequiresV4TargetFrameworkSchema(Files);

            using (Package package = Package.Open(stream, FileMode.Create))
            {
                // Validate and write the manifest
                WriteManifest(package,
                              requiresV4TargetFrameworkSchema ?
                              ManifestVersionUtility.TargetFrameworkSupportVersion :
                              ManifestVersionUtility.DefaultVersion);

                // Write the files to the package
                WriteFiles(package);

                // Copy the metadata properties back to the package
                package.PackageProperties.Creator     = String.Join(",", Authors);
                package.PackageProperties.Description = Description;
                package.PackageProperties.Identifier  = Id;
                package.PackageProperties.Version     = Version.ToString();
                package.PackageProperties.Language    = Language;
                package.PackageProperties.Keywords    = ((IPackageMetadata)this).Tags;
                package.PackageProperties.Title       = Title;
            }
        }
Exemplo n.º 10
0
        public ServerPackage(string id, SemanticVersion version, string title, IEnumerable <string> authors, IEnumerable <string> owners, Uri iconUrl, Uri licenseUrl, Uri projectUrl, bool requireLicenseAcceptance, bool developmentDependency, string description, string summary, string releaseNotes, string language, string tags, string copyright, string dependencies, Version minClientVersion, Uri reportAbuseUrl, int downloadCount, string supportedFrameworks, bool isAbsoluteLatestVersion, bool isLatestVersion, bool listed, DateTimeOffset?published, long packageSize, string packageHash, string packageHashAlgorithm, DateTimeOffset lastUpdated, DateTimeOffset created, string path, string fullPath)
        {
            Id         = id;
            Version    = version;
            Title      = title;
            Authors    = authors;
            Owners     = owners;
            IconUrl    = iconUrl;
            LicenseUrl = licenseUrl;
            ProjectUrl = projectUrl;
            RequireLicenseAcceptance = requireLicenseAcceptance;
            DevelopmentDependency    = developmentDependency;
            Description             = description;
            Summary                 = summary;
            ReleaseNotes            = releaseNotes;
            Language                = language;
            Tags                    = tags;
            Copyright               = copyright;
            Dependencies            = dependencies;
            MinClientVersion        = minClientVersion;
            ReportAbuseUrl          = reportAbuseUrl;
            DownloadCount           = downloadCount;
            SupportedFrameworks     = supportedFrameworks;
            IsAbsoluteLatestVersion = isAbsoluteLatestVersion;
            IsLatestVersion         = isLatestVersion;
            Listed                  = listed;
            Published               = published;
            PackageSize             = packageSize;
            PackageHash             = packageHash;
            PackageHashAlgorithm    = packageHashAlgorithm;
            LastUpdated             = lastUpdated;
            Created                 = created;
            Path                    = path;
            FullPath                = fullPath;

            // Preload collections
            DependencySets.Any();
            SupportedFrameworks.Any();
        }
Exemplo n.º 11
0
 public DetailedPackageMetadata(IPackageSearchMetadata serverData, long?downloadCount)
 {
     Id             = serverData.Identity.Id;
     Version        = serverData.Identity.Version;
     Summary        = serverData.Summary;
     Description    = serverData.Description;
     Authors        = serverData.Authors;
     Owners         = serverData.Owners;
     IconUrl        = serverData.IconUrl;
     LicenseUrl     = serverData.LicenseUrl;
     ProjectUrl     = serverData.ProjectUrl;
     ReportAbuseUrl = serverData.ReportAbuseUrl;
     Tags           = serverData.Tags;
     DownloadCount  = downloadCount;
     Published      = serverData.Published;
     DependencySets = serverData.DependencySets?
                      .Select(e => new PackageDependencySetMetadata(e))
                      ?? new PackageDependencySetMetadata[] { };
     HasDependencies = DependencySets.Any(
         dependencySet => dependencySet.Dependencies != null && dependencySet.Dependencies.Count > 0);
     PrefixReserved  = serverData.PrefixReserved;
     LicenseMetadata = serverData.LicenseMetadata;
     _localMetadata  = serverData as LocalPackageSearchMetadata;
 }
Exemplo n.º 12
0
 /// <inheritdoc />
 /// <summary>
 /// Gets the enumerator which enumerates sets of dependencies, where a set can be loaded in any order.
 /// </summary>
 IEnumerator <ISet <Dependency> > IEnumerable <ISet <Dependency> > .GetEnumerator()
 {
     return(DependencySets.GetEnumerator());
 }