Exemplo n.º 1
0
        protected override void ExecuteCore()
        {
            if (Items.Length == 0 || (PackageFolders.Length == 0 && string.IsNullOrEmpty(AssetsFileWithAdditionalPackageFolders)))
            {
                Output = Items;
                return;
            }

            if (!string.IsNullOrEmpty(AssetsFileWithAdditionalPackageFolders))
            {
                var lockFileCache = new LockFileCache(this);
                var lockFile      = lockFileCache.GetLockFile(AssetsFileWithAdditionalPackageFolders);
                PackageFolders = PackageFolders.Concat(lockFile.PackageFolders.Select(p => p.Path)).ToArray();
            }

            var packageResolver = NuGetPackageResolver.CreateResolver(PackageFolders);

            int index        = 0;
            var updatedItems = new ITaskItem[Items.Length];

            foreach (var item in Items)
            {
                string packageName    = item.GetMetadata(MetadataKeys.NuGetPackageId);
                string packageVersion = item.GetMetadata(MetadataKeys.PackageVersion);

                if (string.IsNullOrEmpty(packageName) || string.IsNullOrEmpty(packageVersion) ||
                    !string.IsNullOrEmpty(item.GetMetadata(MetadataKeys.PackageDirectory)))
                {
                    updatedItems[index++] = item;
                    continue;
                }

                var    parsedPackageVersion = NuGetVersion.Parse(packageVersion);
                string packageDirectory     = packageResolver.GetPackageDirectory(packageName, parsedPackageVersion);

                if (packageDirectory == null)
                {
                    updatedItems[index++] = item;
                    continue;
                }

                var newItem = new TaskItem(item);
                newItem.SetMetadata(MetadataKeys.PackageDirectory, packageDirectory);
                updatedItems[index++] = newItem;
            }

            Output = updatedItems;
        }
Exemplo n.º 2
0
        public bool Equals(LockFile other)
        {
            if (other == null)
            {
                return(false);
            }

            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return(Version == other.Version &&
                   ProjectFileDependencyGroups.OrderedEquals(other.ProjectFileDependencyGroups, group => group.FrameworkName, StringComparer.OrdinalIgnoreCase) &&
                   Libraries.OrderedEquals(other.Libraries, library => library.Name, StringComparer.OrdinalIgnoreCase) &&
                   Targets.OrderedEquals(other.Targets, target => target.Name, StringComparer.Ordinal) &&
                   PackageFolders.SequenceEqual(other.PackageFolders) &&
                   EqualityUtility.EqualsWithNullCheck(PackageSpec, other.PackageSpec));
        }
Exemplo n.º 3
0
        public override bool Execute()
        {
            string indexFilePath = PackageIndexFile.GetMetadata("FullPath");

            PackageIndex index = File.Exists(indexFilePath) ?
                                 index = PackageIndex.Load(indexFilePath) :
                                         new PackageIndex();

            if (PackageIds != null && PackageIds.Any())
            {
                _packageIdsToInclude = new HashSet <string>(PackageIds.Select(i => i.ItemSpec), StringComparer.OrdinalIgnoreCase);
            }

            foreach (var package in Packages.NullAsEmpty().Select(f => f.GetMetadata("FullPath")))
            {
                Log.LogMessage($"Updating from {package}.");
                UpdateFromPackage(index, package);
            }

            foreach (var packageFolder in PackageFolders.NullAsEmpty().Select(f => f.GetMetadata("FullPath")))
            {
                var nupkgs = Directory.EnumerateFiles(packageFolder, "*.nupkg", SearchOption.TopDirectoryOnly);

                if (nupkgs.Any())
                {
                    foreach (var nupkg in nupkgs)
                    {
                        Log.LogMessage($"Updating from {nupkg}.");
                        UpdateFromPackage(index, nupkg, true);
                    }
                }
                else
                {
                    var nuspecFolders = Directory.EnumerateFiles(packageFolder, "*.nuspec", SearchOption.AllDirectories)
                                        .Select(nuspec => Path.GetDirectoryName(nuspec));

                    foreach (var nuspecFolder in nuspecFolders)
                    {
                        Log.LogMessage($"Updating from {nuspecFolder}.");
                        UpdateFromFolderLayout(index, nuspecFolder, true);
                    }
                }
            }

            if (BaselinePackages != null)
            {
                foreach (var baselinePackage in BaselinePackages)
                {
                    var info    = GetOrCreatePackageInfo(index, baselinePackage.ItemSpec);
                    var version = baselinePackage.GetMetadata("Version");

                    info.BaselineVersion = Version.Parse(version);
                }
            }

            if (StablePackages != null)
            {
                foreach (var stablePackage in StablePackages)
                {
                    var info    = GetOrCreatePackageInfo(index, stablePackage.ItemSpec);
                    var version = stablePackage.GetMetadata("Version");

                    info.StableVersions.Add(Version.Parse(version));
                }
            }

            if (ModuleToPackages != null)
            {
                foreach (var moduleToPackage in ModuleToPackages)
                {
                    var package = moduleToPackage.GetMetadata("Package");
                    index.ModulesToPackages[moduleToPackage.ItemSpec] = package;
                }
            }

            if (!String.IsNullOrEmpty(PreRelease))
            {
                index.PreRelease = PreRelease;
            }

            index.Save(indexFilePath);

            return(!Log.HasLoggedErrors);
        }
Exemplo n.º 4
0
        public override bool Execute()
        {
            string indexFilePath = PackageIndexFile.GetMetadata("FullPath");

            PackageIndex index = File.Exists(indexFilePath) ?
                                 index = PackageIndex.Load(indexFilePath) :
                                         new PackageIndex();

            if (PackageIds != null && PackageIds.Any())
            {
                _packageIdsToInclude = new HashSet <string>(PackageIds.Select(i => i.ItemSpec), StringComparer.OrdinalIgnoreCase);
            }

            foreach (var package in Packages.NullAsEmpty().Select(f => f.GetMetadata("FullPath")))
            {
                Log.LogMessage($"Updating from {package}.");
                UpdateFromPackage(index, package);
            }

            foreach (var packageFolder in PackageFolders.NullAsEmpty().Select(f => f.GetMetadata("FullPath")))
            {
                var nupkgs = Directory.EnumerateFiles(packageFolder, "*.nupkg", SearchOption.TopDirectoryOnly);

                if (nupkgs.Any())
                {
                    foreach (var nupkg in nupkgs)
                    {
                        Log.LogMessage($"Updating from {nupkg}.");
                        UpdateFromPackage(index, nupkg, true);
                    }
                }
                else
                {
                    var nuspecFolders = Directory.EnumerateFiles(packageFolder, "*.nuspec", SearchOption.AllDirectories)
                                        .Select(nuspec => Path.GetDirectoryName(nuspec));

                    foreach (var nuspecFolder in nuspecFolders)
                    {
                        Log.LogMessage($"Updating from {nuspecFolder}.");
                        UpdateFromFolderLayout(index, nuspecFolder, true);
                    }
                }
            }

            if (BaselinePackages != null)
            {
                foreach (var baselinePackage in BaselinePackages)
                {
                    var info    = GetOrCreatePackageInfo(index, baselinePackage.ItemSpec);
                    var version = baselinePackage.GetMetadata("Version");

                    info.BaselineVersion = Version.Parse(version);
                }
            }

            if (StablePackages != null)
            {
                foreach (var stablePackage in StablePackages)
                {
                    var info    = GetOrCreatePackageInfo(index, stablePackage.ItemSpec);
                    var version = stablePackage.GetMetadata("Version");

                    info.StableVersions.Add(Version.Parse(version));
                }
            }

            if (ModuleToPackages != null)
            {
                foreach (var moduleToPackage in ModuleToPackages)
                {
                    var package = moduleToPackage.GetMetadata("Package");
                    index.ModulesToPackages[moduleToPackage.ItemSpec] = package;
                }
            }

            if (InboxFrameworkListFolder != null)
            {
                index.MergeFrameworkLists(InboxFrameworkListFolder.GetMetadata("FullPath"));
            }

            if (InboxFrameworkLayoutFolders != null)
            {
                foreach (var inboxFrameworkLayoutFolder in InboxFrameworkLayoutFolders)
                {
                    var layoutDirectory = inboxFrameworkLayoutFolder.GetMetadata("FullPath");
                    var targetFramework = NuGetFramework.Parse(inboxFrameworkLayoutFolder.GetMetadata("TargetFramework"));

                    index.MergeInboxFromLayout(targetFramework, layoutDirectory);
                }
            }

            if (SetBaselineVersionsToLatestStableVersion)
            {
                foreach (var packageInfo in index.Packages.Values)
                {
                    var maxVersion = packageInfo.StableVersions.Max();
                    packageInfo.BaselineVersion = maxVersion;
                }
            }

            if (UpdateStablePackageInfo && Packages == null && PackageFolders == null)
            {
                // Given we will query the web for every package, we should run in parallel to try to optimize the performance.
                Parallel.ForEach(index.Packages, (package) =>
                {
                    IEnumerable <Version> stablePackageVersions = NuGetUtility.GetAllVersionsForPackageId(package.Key, includePrerelease: false, includeUnlisted: false, Log, CancellationToken.None);
                    package.Value.StableVersions.Clear();
                    package.Value.StableVersions.AddRange(stablePackageVersions);
                });
            }

            if (!String.IsNullOrEmpty(PreRelease))
            {
                index.PreRelease = PreRelease;
            }

            index.Save(indexFilePath);

            return(!Log.HasLoggedErrors);
        }