public Task Invoke(PackageInProject currentPackage, NuGetVersion newVersion, PackageSource packageSource, NuGetSources allSources) { var projectsToUpdate = new Stack <string>(); projectsToUpdate.Push(currentPackage.Path.FullName); while (projectsToUpdate.Count > 0) { var currentProject = projectsToUpdate.Pop(); XDocument xml; using (var projectContents = File.Open(currentProject, FileMode.Open, FileAccess.ReadWrite)) { xml = XDocument.Load(projectContents); } var projectsToCheck = UpdateConditionsOnProjects(xml, currentProject); foreach (var potentialProject in projectsToCheck) { var fullPath = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(currentProject), potentialProject)); if (File.Exists(fullPath)) { projectsToUpdate.Push(fullPath); } } } return(Task.CompletedTask); }
public Task Invoke(PackageInProject currentPackage, NuGetVersion newVersion, PackageSource packageSource, NuGetSources allSources) { if (currentPackage == null) { throw new ArgumentNullException(nameof(currentPackage)); } if (newVersion == null) { throw new ArgumentNullException(nameof(newVersion)); } XDocument xml; using (var xmlInput = File.OpenRead(currentPackage.Path.FullName)) { xml = XDocument.Load(xmlInput); } using (var xmlOutput = File.Open(currentPackage.Path.FullName, FileMode.Truncate)) { UpdateFile(xmlOutput, newVersion, currentPackage, xml); } return(Task.CompletedTask); }
public async Task ApplyAnUpdate( IReadOnlyCollection <PackageUpdateSet> updates, NuGetSources sources) { if (!updates.Any()) { return; } var filtered = await _selection .Filter(updates, p => Task.FromResult(true)); if (!filtered.Any()) { _logger.Detailed("All updates were filtered out"); return; } var candidate = filtered.First(); var reporter = new ConsoleReporter(); _logger.Minimal("Updating " + reporter.Describe(candidate)); await _updateRunner.Update(candidate, sources); }
public async Task ApplyUpdates( IReadOnlyCollection <PackageUpdateSet> updates, IFolder workingFolder, NuGetSources sources, SettingsContainer settings) { if (settings == null) { throw new ArgumentNullException(nameof(settings)); } if (!updates.Any()) { return; } var filtered = _selection .Filter(updates, settings.PackageFilters); if (!filtered.Any()) { _logger.Detailed("All updates were filtered out"); return; } await ApplyUpdates(filtered, workingFolder, sources); }
public async Task <IReadOnlyCollection <PackageUpdateSet> > FindUpdatesForPackages( IReadOnlyCollection <PackageInProject> packages, NuGetSources sources, VersionChange allowedChange) { var packageIds = packages .Select(p => p.Identity) .Distinct(); var latestVersions = await _bulkPackageLookup.FindVersionUpdates( packageIds, sources, allowedChange); var results = new List <PackageUpdateSet>(); foreach (var packageId in latestVersions.Keys) { var latestPackage = latestVersions[packageId]; var matchVersion = latestPackage.Selected().Identity.Version; var updatesForThisPackage = packages .Where(p => p.Id == packageId && p.Version < matchVersion) .ToList(); if (updatesForThisPackage.Count > 0) { var updateSet = new PackageUpdateSet(latestPackage, updatesForThisPackage); results.Add(updateSet); } } return(results); }
public async Task <IDictionary <PackageIdentity, PackageLookupResult> > FindVersionUpdates( IEnumerable <PackageIdentity> packages, NuGetSources sources, VersionChange allowedChange, UsePrerelease usePrerelease ) { var lookupTasks = packages .Distinct() .GroupBy(pi => (pi.Id, MaxVersion: GetMaxVersion(pi, allowedChange))) .Select(HighestVersion) .Select(id => new { Package = id, Update = _packageLookup.FindVersionUpdate(id, sources, allowedChange, usePrerelease) }) .ToList(); await Task.WhenAll(lookupTasks.Select(l => l.Update)); var result = new Dictionary <PackageIdentity, PackageLookupResult>(); foreach (var lookupTask in lookupTasks) { ProcessLookupResult(lookupTask.Package, lookupTask.Update.Result, result); } return(result); }
public async Task Update(PackageUpdateSet updateSet, NuGetSources sources) { if (updateSet == null) { throw new ArgumentNullException(nameof(updateSet)); } var sortedUpdates = Sort(updateSet.CurrentPackages); _logger.Detailed($"Updating '{updateSet.SelectedId}' to {updateSet.SelectedVersion} in {sortedUpdates.Count} projects"); var updateTasks = sortedUpdates.ToList().Select(current => { return(Task.Factory.StartNew(async() => { var updateCommands = GetUpdateCommands(current.Path.PackageReferenceType); foreach (var updateCommand in updateCommands) { await updateCommand.Invoke(current, updateSet.SelectedVersion, updateSet.Selected.Source, sources); } }, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default)); }); await Task.WhenAll(updateTasks); }
private async Task <int> DoTargetUpdates( IGitDriver git, RepositoryData repository, IReadOnlyCollection <PackageUpdateSet> targetUpdates, NuGetSources sources) { if (targetUpdates.Count == 0) { _logger.Terse("No updates can be applied. Exiting."); return(0); } await _solutionsRestore.Restore(git.WorkingFolder, sources); var updatesDone = await UpdateAllTargets(git, repository, targetUpdates, sources); if (updatesDone < targetUpdates.Count) { _logger.Terse($"Attempted {targetUpdates.Count} updates and did {updatesDone}"); } else { _logger.Info($"Done {updatesDone} updates"); } return(updatesDone); }
private async Task <int> DoTargetUpdates( IGitDriver git, RepositoryData repository, IReadOnlyCollection <PackageUpdateSet> targetUpdates, NuGetSources sources, SettingsContainer settings) { if (targetUpdates.Count == 0) { _logger.Minimal("No updates can be applied. Exiting."); return(0); } await _solutionsRestore.CheckRestore(targetUpdates, settings.WorkingFolder ?? git.WorkingFolder, sources); var updatesDone = await _packageUpdater.MakeUpdatePullRequests(git, repository, targetUpdates, sources, settings); if (updatesDone < targetUpdates.Count) { _logger.Minimal($"Attempted {targetUpdates.Count} updates and did {updatesDone}"); } else { _logger.Normal($"Done {updatesDone} updates"); } return(updatesDone); }
private async Task <int> MakeUpdatePullRequests( IGitDriver git, RepositoryData repository, NuGetSources sources, SettingsContainer settings, IReadOnlyCollection <PackageUpdateSet> updates) { _logger.Normal(UpdatesLogger.OldVersionsToBeUpdated(updates)); git.Checkout(repository.DefaultBranch); // branch var branchName = BranchNamer.MakeName(updates); _logger.Detailed($"Using branch name: '{branchName}'"); git.CheckoutNewBranch(branchName); foreach (var updateSet in updates) { await _updateRunner.Update(updateSet, sources); var commitMessage = CommitWording.MakeCommitMessage(updateSet); git.Commit(commitMessage); } git.Push("nukeeper_push", branchName); var title = CommitWording.MakePullRequestTitle(updates); var body = CommitWording.MakeCommitDetails(updates); await _gitHub.CreatePullRequest(repository, title, body, branchName, settings.SourceControlServerSettings.Labels); git.Checkout(repository.DefaultBranch); return(updates.Count); }
public async Task Invoke(FileInfo file, NuGetSources sources) { _logger.Normal($"Nuget restore on {file.DirectoryName} {file.Name}"); if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { _logger.Normal("Cannot run NuGet.exe file restore as OS Platform is not Windows"); return; } var nuget = NuGetPath.FindExecutable(); if (string.IsNullOrWhiteSpace(nuget)) { _logger.Normal("Cannot find NuGet exe for solution restore"); return; } var sourcesCommandLine = sources.CommandLine("-Source"); var arguments = $"restore {file.Name} {sourcesCommandLine}"; _logger.Detailed($"{nuget} {arguments}"); var processOutput = await _externalProcess.Run(file.DirectoryName, nuget, arguments, ensureSuccess : false); if (processOutput.Success) { _logger.Detailed($"Nuget restore on {file.Name} complete"); } else { _logger.Detailed($"Nuget restore failed on {file.DirectoryName} {file.Name}:\n{processOutput.Output}\n{processOutput.ErrorOutput}"); } }
public async Task <IDictionary <string, PackageLookupResult> > FindVersionUpdates( IEnumerable <PackageIdentity> packages, NuGetSources sources, VersionChange allowedChange, UsePrerelease usePrerelease) { var latestOfEach = packages .GroupBy(pi => pi.Id.ToUpperInvariant()) .Select(HighestVersion); var lookupTasks = latestOfEach .Select(id => _packageLookup.FindVersionUpdate(id, sources, allowedChange, usePrerelease)) .ToList(); await Task.WhenAll(lookupTasks); var result = new Dictionary <string, PackageLookupResult>(StringComparer.OrdinalIgnoreCase); foreach (var lookupTask in lookupTasks) { var serverVersions = lookupTask.Result; ProcessLookupResult(serverVersions, result); } return(result); }
private async Task <(int UpdatesMade, bool?ThresholdReached)> DoTargetUpdates( IGitDriver git, RepositoryData repository, IReadOnlyCollection <PackageUpdateSet> targetUpdates, NuGetSources sources, SettingsContainer settings ) { if (targetUpdates.Count == 0) { return(0, null); } await _solutionRestore.CheckRestore(targetUpdates, settings.WorkingFolder ?? git.WorkingFolder, sources); var(updatesDone, thresholdReached) = await _packageUpdater.MakeUpdatePullRequests(git, repository, targetUpdates, sources, settings); if (updatesDone < targetUpdates.Count) { _logger.Minimal($"Attempted {targetUpdates.Count} updates and did {updatesDone}"); } else { _logger.Normal($"Done {updatesDone} updates"); } return(updatesDone, thresholdReached); }
public async Task <int> MakeUpdatePullRequests( IGitDriver git, RepositoryData repository, IReadOnlyCollection <PackageUpdateSet> updates, NuGetSources sources, SettingsContainer settings) { int totalCount = 0; try { var groups = UpdateConsolidator.Consolidate(updates, settings.UserSettings.ConsolidateUpdatesInSinglePullRequest); foreach (var updateSets in groups) { var updatesMade = await MakeUpdatePullRequests( git, repository, sources, settings, updateSets); totalCount += updatesMade; } } catch (Exception ex) { _logger.Error("Updates failed", ex); } return(totalCount); }
public void WriteToDisk() { if (_isWrittenOnDisk) { return; } foreach (var project in Projects.Values) { project.Build(); } foreach (var project in Projects.Values) { _solution.AddProject(project.Build()); } _solution.NugetConfig = _nuGetConfigGenerator?.Generate(NuGetSources.ToArray()); var solutionWriter = new SolutionWriter(_outputWriter); solutionWriter.WriteToFileSystem(_solution, _testProjectFolders.PathToSolutionDirectory); _isWrittenOnDisk = true; }
public void ShouldGenerateCommandLineArguments() { var subject = new NuGetSources("one", "two"); var result = subject.CommandLine("-s"); Assert.AreEqual("-s one -s two", result); }
public void ShouldEscapeLocalPaths() { var subject = new NuGetSources("file://one", "C:/Program Files (x86)/Microsoft SDKs/NuGetPackages/", "http://two"); var result = subject.CommandLine("-s"); Assert.AreEqual("-s file://one -s \"C:/Program Files (x86)/Microsoft SDKs/NuGetPackages/\" -s http://two", result); }
private async Task Restore(IFolder workingFolder, NuGetSources sources) { var solutionFiles = workingFolder.Find("*.sln"); foreach (var sln in solutionFiles) { await _fileRestoreCommand.Invoke(sln, sources); } }
public void OverrideSourcesAreUsedWhenSupplied() { var overrrideSources = new NuGetSources("overrideA"); var reader = MakeNuGetSourcesReader(); var result = reader.Read(_uniqueTemporaryFolder, overrrideSources); Assert.That(result, Is.EqualTo(overrrideSources)); }
public async Task <PackageLookupResult> FindVersionUpdate( PackageIdentity package, NuGetSources sources, VersionChange allowedChange) { var foundVersions = await _packageVersionsLookup.Lookup(package.Id, false, sources); return(VersionChanges.MakeVersions(package.Version, foundVersions, allowedChange)); }
public static void NuGetRemoveSource(this ICakeContext context, string name, string source, NuGetSourcesSettings settings) { if (context == null) { throw new ArgumentNullException("context"); } var runner = new NuGetSources(context.FileSystem, context.Environment, context.ProcessRunner, context.GetToolResolver("NuGet")); runner.RemoveSource(name, source, settings); }
public Solution GetSolution() { foreach (var projectBuilder in Projects.Values) { Project project = projectBuilder.Build(); _solution.AddProject(project); } _solution.NugetConfig = _nuGetConfigGenerator?.Generate(NuGetSources.ToArray()); return(_solution); }
private async Task<IReadOnlyCollection<PackageUpdateSet>> GetSortedUpdates( IFolder folder, NuGetSources sources, VersionChange allowedChange) { var updates = await _updateFinder.FindPackageUpdateSets( folder, sources, allowedChange); return _sorter.Sort(updates) .ToList(); }
public static bool NuGetHasSource(this ICakeContext context, string source, NuGetSourcesSettings settings) { if (context == null) { throw new ArgumentNullException("context"); } var runner = new NuGetSources(context.FileSystem, context.Environment, context.ProcessRunner, context.Globber, context.GetToolResolver("NuGet")); return(runner.HasSource(source, settings)); }
public async Task Update(PackageUpdateSet updateSet, NuGetSources sources) { foreach (var current in updateSet.CurrentPackages) { var updateCommands = GetUpdateCommands(current.Path.PackageReferenceType); foreach (var updateCommand in updateCommands) { await updateCommand.Invoke(current, updateSet.SelectedVersion, updateSet.Selected.Source, sources); } } }
public void OverrideSourcesAreUsedWhenSupplied() { var overrrideSources = new NuGetSources("overrideA"); var reader = MakeNuGetSourcesReader(); var ff = new FolderFactory(Substitute.For <INuKeeperLogger>()); var result = reader.Read(ff.UniqueTemporaryFolder(), overrrideSources); Assert.That(result, Is.EqualTo(overrrideSources)); }
public async Task <PackageLookupResult> FindVersionUpdate( PackageIdentity package, NuGetSources sources, VersionChange allowedChange, UsePrerelease usePrerelease) { var includePrerelease = ShouldAllowPrerelease(package, usePrerelease); var foundVersions = await _packageVersionsLookup.Lookup(package.Id, includePrerelease, sources); return(VersionChanges.MakeVersions(package.Version, foundVersions, allowedChange)); }
public static void NuGetAddSource(this ICakeContext context, string name, string source, NuGetSourcesSettings settings) { if (context == null) { throw new ArgumentNullException(nameof(context)); } var resolver = new NuGetToolResolver(context.FileSystem, context.Environment, context.Tools); var runner = new NuGetSources(context.FileSystem, context.Environment, context.ProcessRunner, context.Tools, resolver); runner.AddSource(name, source, settings); }
public async Task <IReadOnlyCollection <PackageSearchMedatadata> > Lookup( string packageName, bool includePrerelease, NuGetSources sources) { var tasks = sources.Items.Select(s => RunFinderForSource(packageName, includePrerelease, s)); var results = await Task.WhenAll(tasks); return(results .SelectMany(r => r) .Where(p => p?.Identity?.Version != null) .ToList()); }
public async Task Invoke(FileInfo file, NuGetSources sources) { _logger.Normal($"Nuget restore on {file.DirectoryName} {file.Name}"); var nuget = _nuGetPath.Executable; if (string.IsNullOrWhiteSpace(nuget)) { _logger.Normal("Cannot find NuGet.exe for solution restore"); return; } var sourcesCommandLine = sources.CommandLine("-Source"); var restoreCommand = $"restore {file.Name} {sourcesCommandLine} -NonInteractive"; ProcessOutput processOutput; if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { if (await _monoExecutor.CanRun()) { processOutput = await _monoExecutor.Run(file.DirectoryName, nuget, restoreCommand, ensureSuccess : false); } else { _logger.Error("Cannot run NuGet.exe. It requires either Windows OS Platform or Mono installation"); return; } } else { processOutput = await _externalProcess.Run(file.DirectoryName, nuget, restoreCommand, ensureSuccess : false); } if (processOutput.Success) { _logger.Detailed($"Nuget restore on {file.Name} complete"); } else { _logger.Detailed( $"Nuget restore failed on {file.DirectoryName} {file.Name}:\n{processOutput.Output}\n{processOutput.ErrorOutput}"); } }