Exemple #1
0
 public static V2FeedPackageInfo ToV2FeedPackageInfo(
     this NuspecReader reader, PackageDerivedData packageDerivedData, string downloadUrl, long downloadCount)
 {
     return(new V2FeedPackageInfo(
                identity: new PackageIdentity(reader.GetId(), reader.GetVersion()),
                title: reader.GetTitle(),
                summary: reader.GetSummary(),
                description: reader.GetDescription(),
                authors: reader.GetAuthors().Split(','),
                owners: reader.GetOwners().Split(','),
                iconUrl: reader.GetIconUrl(),
                licenseUrl: reader.GetLicenseUrl(),
                projectUrl: reader.GetProjectUrl(),
                reportAbuseUrl: reader.GetProjectUrl(),
                tags: reader.GetTags(),
                created: packageDerivedData.Created,
                lastEdited: packageDerivedData.LastUpdated,
                published: packageDerivedData.LastUpdated,
                dependencies: DependencySetsAsString(reader.GetDependencyGroups()),
                requireLicenseAccept: reader.GetRequireLicenseAcceptance(),
                downloadUrl: downloadUrl,
                downloadCount: downloadCount.ToString(),
                packageHash: packageDerivedData.PackageHash,
                packageHashAlgorithm: packageDerivedData.PackageHashAlgorithm,
                minClientVersion: reader.GetMinClientVersion()
                ));
 }
Exemple #2
0
        public static Package GetPackage(string nupkgPath)
        {
            var result = new Package();

            using (var packageFile = File.Open(nupkgPath, FileMode.Open, FileAccess.Read))
            {
                using (var packageReader = new PackageArchiveReader(packageFile))
                {
                    var manifestReader = new NuspecReader(packageReader.GetNuspec());
                    result.Authors                  = manifestReader.GetAuthors();
                    result.DependencySets           = manifestReader.GetDependencyGroups();
                    result.Description              = manifestReader.GetDescription();
                    result.Id                       = manifestReader.GetIdentity().Id;
                    result.LicenseUrl               = manifestReader.GetLicenseUrl();
                    result.ProjectUrl               = manifestReader.GetProjectUrl();
                    result.Summary                  = manifestReader.GetSummary();
                    result.Version                  = manifestReader.GetIdentity().Version;
                    result.RequireLicenseAcceptance = manifestReader.GetRequireLicenseAcceptance();
                    result.Files                    = packageReader.GetFiles()
                                                      .Where(x => x != "[Content_Types].xml" &&
                                                             x != "_rels/.rels" &&
                                                             !x.EndsWith(".nuspec") &&
                                                             !x.EndsWith(".psmdcp"))
                                                      .Select(x => x.Replace("/", "\\"))
                                                      .OrderBy(x => x).ToList();
                }
            }

            return(result);
        }
Exemple #3
0
 private void ProcessNuspecContent(NuspecReader reader)
 {
     if (Specification.Id == null)
     {
         Update(reader.GetId(), (id) => Specification.Id = id);
     }
     UpdateUrl(reader.GetLicenseUrl(), url => Specification.LicenseUrl    = url, DEFAULT_LICENCE_URL);
     UpdateUrl(reader.GetProjectUrl(), url => Specification.ProjectUrl    = url, DEFAULT_PROJECT_URL);
     UpdateUrl(reader.GetIconUrl(), url => Specification.IconUrl          = url, DEFAULT_ICON_URL);
     UpdateList(reader.GetAuthors(), list => Specification.Authors        = list);
     UpdateList(reader.GetOwners(), list => Specification.Owners          = list);
     Update(reader.GetReleaseNotes(), notes => Specification.ReleaseNotes = notes, DEFAULT_RELEASE_NOTES);
     Update(reader.GetCopyright(), copyright => Specification.Copyright   = copyright);
     UpdateList(reader.GetTags(), list => Specification.Tags           = list, ' ', DEFAULT_TAGS);
     Update(reader.GetDescription(), desc => Specification.Description = desc);
 }
Exemple #4
0
        public ServerPackage(NuspecReader package, PackageDerivedData packageDerivedData)
        {
            Id         = package.GetId();
            Version    = package.GetVersion();
            Title      = package.GetTitle();
            Authors    = package.GetAuthors();
            Owners     = package.GetOwners();
            IconUrl    = package.GetIconUrl();
            LicenseUrl = package.GetLicenseUrl();
            ProjectUrl = package.GetProjectUrl();
            RequireLicenseAcceptance = package.GetRequireLicenseAcceptance();
            DevelopmentDependency    = package.GetDevelopmentDependency();
            Description             = package.GetDescription();
            Summary                 = package.GetSummary();
            ReleaseNotes            = package.GetReleaseNotes();
            Language                = package.GetLanguage();
            Tags                    = package.GetTags();
            Copyright               = package.GetCopyright();
            MinClientVersion        = package.GetMinClientVersion();
            ReportAbuseUrl          = null;
            DownloadCount           = 0;
            SemVer1IsAbsoluteLatest = false;
            SemVer1IsLatest         = false;
            SemVer2IsAbsoluteLatest = false;
            SemVer2IsLatest         = false;
            //FIXME is this OK?
            Listed = true;

            IsSemVer2 = IsPackageSemVer2(package);

            _dependencySets = package.GetDependencyGroups().ToList();
            Dependencies    = _dependencySets.DependencySetsAsString();

            _supportedFrameworks = package.GetFrameworkReferenceGroups().Select(f => f.TargetFramework).ToList();
            SupportedFrameworks  = string.Join("|", _supportedFrameworks.Select(f => f.GetFrameworkString()));

            PackageSize          = packageDerivedData.PackageSize;
            PackageHash          = packageDerivedData.PackageHash;
            PackageHashAlgorithm = packageDerivedData.PackageHashAlgorithm;
            LastUpdated          = packageDerivedData.LastUpdated;
            Created  = packageDerivedData.Created;
            Path     = packageDerivedData.Path;
            FullPath = packageDerivedData.FullPath;
        }
        /// <summary>
        /// Get the view of installed packages. Use for Get-Package command.
        /// </summary>
        internal static List <PowerShellInstalledPackage> GetPowerShellPackageView(
            Dictionary <NuGetProject, IEnumerable <Packaging.PackageReference> > dictionary,
            ISolutionManager solutionManager,
            Configuration.ISettings settings)
        {
            var views = new List <PowerShellInstalledPackage> ();

            foreach (var entry in dictionary)
            {
                var nugetProject = entry.Key;

                string             packageFolder        = null;
                FolderNuGetProject packageFolderProject = null;

                if (nugetProject is BuildIntegratedNuGetProject)
                {
                    packageFolder = SettingsUtility.GetGlobalPackagesFolder(settings);
                }
                else
                {
                    var project = nugetProject as MSBuildNuGetProject;

                    if (project != null)
                    {
                        packageFolderProject = project.FolderNuGetProject;
                    }
                }

                // entry.Value is an empty list if no packages are installed
                foreach (var package in entry.Value)
                {
                    string installPackagePath = null;
                    string licenseUrl         = null;

                    if (packageFolder != null)
                    {
                        var defaultPackagePathResolver = new VersionFolderPathResolver(packageFolder);
                        installPackagePath = defaultPackagePathResolver.GetPackageFilePath(package.PackageIdentity.Id, package.PackageIdentity.Version);
                    }
                    else if (packageFolderProject != null)
                    {
                        installPackagePath = packageFolderProject.GetInstalledPackageFilePath(package.PackageIdentity);
                    }

                    using (var reader = GetPackageReader(installPackagePath)) {
                        var nuspecReader = new NuspecReader(reader.GetNuspec());
                        licenseUrl = nuspecReader.GetLicenseUrl();
                    }

                    var view = new PowerShellInstalledPackage()
                    {
                        Id = package.PackageIdentity.Id,
                        AsyncLazyVersions = new AsyncLazy <IEnumerable <NuGetVersion> > (() => {
                            return(Task.FromResult <IEnumerable <NuGetVersion> > (new [] { package.PackageIdentity.Version }));
                        }),
                        ProjectName = entry.Key.GetMetadata <string> (NuGetProjectMetadataKeys.Name),
                        LicenseUrl  = licenseUrl
                    };

                    views.Add(view);
                }
            }

            return(views);
        }
        /// <summary>
        /// Get the view of installed packages. Use for Get-Package command.
        /// </summary>
        internal static List <PowerShellInstalledPackage> GetPowerShellPackageView(
            Dictionary <NuGetProject, IEnumerable <PackageReference> > dictionary,
            ISolutionManager SolutionManager,
            Configuration.ISettings settings)
        {
            var views = new List <PowerShellInstalledPackage>();

            foreach (var entry in dictionary)
            {
                var nugetProject = entry.Key;
                var projectName  = entry.Key.GetMetadata <string>(NuGetProjectMetadataKeys.Name);

                FolderNuGetProject          packageFolderProject = null;
                FallbackPackagePathResolver fallbackResolver     = null;

                // Build a project-specific strategy for resolving a package .nupkg path.
                if (nugetProject is INuGetIntegratedProject) // This is technically incorrect for DNX projects,
                                                             // however since that experience is deprecated we don't
                                                             // care.
                {
                    var pathContext = NuGetPathContext.Create(settings);
                    fallbackResolver = new FallbackPackagePathResolver(pathContext);
                }
                else
                {
                    var project = nugetProject as MSBuildNuGetProject;

                    if (project != null)
                    {
                        packageFolderProject = project.FolderNuGetProject;
                    }
                }

                // entry.Value is an empty list if no packages are installed.
                foreach (var package in entry.Value)
                {
                    string installPackagePath = null;
                    string licenseUrl         = null;

                    // Try to get the path to the package .nupkg on disk.
                    if (fallbackResolver != null)
                    {
                        var packageInfo = fallbackResolver.GetPackageInfo(
                            package.PackageIdentity.Id,
                            package.PackageIdentity.Version);

                        installPackagePath = packageInfo?.PathResolver.GetPackageFilePath(
                            package.PackageIdentity.Id,
                            package.PackageIdentity.Version);
                    }
                    else if (packageFolderProject != null)
                    {
                        installPackagePath = packageFolderProject.GetInstalledPackageFilePath(package.PackageIdentity);
                    }

                    // Try to read out the license URL.
                    using (var reader = GetPackageReader(installPackagePath))
                        using (var nuspecStream = reader?.GetNuspec())
                        {
                            if (nuspecStream != null)
                            {
                                var nuspecReader = new NuspecReader(nuspecStream);
                                licenseUrl = nuspecReader.GetLicenseUrl();
                            }
                        }

                    var view = new PowerShellInstalledPackage
                    {
                        Id = package.PackageIdentity.Id,
                        AsyncLazyVersions = new AsyncLazy <IEnumerable <NuGetVersion> >(
                            () => Task.FromResult <IEnumerable <NuGetVersion> >(new[] { package.PackageIdentity.Version }),
                            NuGetUIThreadHelper.JoinableTaskFactory),
                        ProjectName = projectName,
                        LicenseUrl  = licenseUrl
                    };

                    views.Add(view);
                }
            }

            return(views);
        }
        private static async Task WritePackageNotice(StreamWriter writer, NuspecReader package)
        {
            await writer.WriteAsync("License notice for ").ConfigureAwait(false);

            await writer.WriteAsync(package.GetId()).ConfigureAwait(false);

            await writer.WriteAsync(" (v").ConfigureAwait(false);

            await writer.WriteAsync(package.GetVersion().ToFullString()).ConfigureAwait(false);

            await writer.WriteLineAsync(")").ConfigureAwait(false);

            await writer.WriteLineAsync("------------------------------------").ConfigureAwait(false);

            var repository = package.GetRepositoryMetadata();

            if (!string.IsNullOrEmpty(repository?.Url))
            {
                await writer.WriteLineAsync().ConfigureAwait(false);

                await writer.WriteAsync(repository.Url).ConfigureAwait(false);

                if (!string.IsNullOrEmpty(repository.Commit))
                {
                    await writer.WriteAsync(" at ").ConfigureAwait(false);

                    await writer.WriteAsync(repository.Commit).ConfigureAwait(false);
                }

                await writer.WriteLineAsync().ConfigureAwait(false);
            }

            string projectUrl = package.GetProjectUrl();

            if (projectUrl != repository?.Url)
            {
                await WriteIfNotEmpty(writer, string.Empty, projectUrl).ConfigureAwait(false);
            }

            string copyright       = package.GetCopyright();
            string copyrightPrefix = string.Empty;

            if (copyright?.Length > 0 && copyright[0] == '©')
            {
                copyrightPrefix = "Copyright ";
            }

            await WriteIfNotEmpty(writer, copyrightPrefix, copyright).ConfigureAwait(false);

            var license = package.GetLicenseMetadata();

            if (license != null)
            {
                string licenseExpression = license.LicenseExpression?.ToString();
                await WriteIfNotEmpty(writer, "Licensed under ", licenseExpression).ConfigureAwait(false);
                await WriteIfNotEmpty(writer, "Available at ", license.LicenseUrl?.AbsoluteUri).ConfigureAwait(false);

                if (license.License != licenseExpression)
                {
                    await WriteIfNotEmpty(writer, string.Empty, license.License).ConfigureAwait(false);
                }
            }
            else
            {
                await WriteIfNotEmpty(writer, "License available at ", package.GetLicenseUrl()).ConfigureAwait(false);
            }

            await writer.WriteLineAsync().ConfigureAwait(false);

            await writer.WriteLineAsync().ConfigureAwait(false);
        }