Skip to content

Commit

Permalink
Merge pull request #70 from nickrandolph/dev/nr/updateprops
Browse files Browse the repository at this point in the history
chore: Renaming projectProperties to updateProperties
  • Loading branch information
jeanplevesque authored Aug 3, 2023
2 parents 9ac2329 + 76a48a0 commit 211e712
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 21 deletions.
4 changes: 2 additions & 2 deletions src/NvGet.Tools.Shared/Arguments/ConsoleArgsContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ internal static OptionSet CreateOptionsFor(ConsoleArgsContext context = null)
{ "dryrun", "Runs the updater but doesn't write the updates to files.", TrySet(_ => context.Parameters.IsDryRun = true) },
{ "result|r=", "The path to the file where the update result should be saved.", TrySet(x => context.ResultFile = x) },
{ "versionOverrides=", "The path to a JSON file to force specifc versions to be used; format should be the same as the result file", TryParseAndSet(LoadOverrides, x => context.Parameters.VersionOverrides.AddRange(x)) },
{ "projectProperties=", "The path to a JSON file that lists pairs of csproj property names and corresponding package Id, so that updater can update project properties as necessary", TryParseAndSet(LoadProjectProperties, x => context.Parameters.ProjectProperties.AddRange(x)) },
{ "updateProperties=", "The path to a JSON file that lists pairs of csproj property names and corresponding package Id, so that updater can update project properties as necessary", TryParseAndSet(LoadUpdateProperties, x => context.Parameters.UpdateProperties.AddRange(x)) },
};

Action<string> TrySet(Action<string> set)
Expand Down Expand Up @@ -144,7 +144,7 @@ async Task<IEnumerable<UpdateResult>> LoadFromStreamAsync()
}
}

internal static IEnumerable<(string PropertyName, string PackageId)> LoadProjectProperties(string inputPathOrUrl)
internal static IEnumerable<(string PropertyName, string PackageId)> LoadUpdateProperties(string inputPathOrUrl)
{
var results =
LoadFromStreamAsync()
Expand Down
2 changes: 1 addition & 1 deletion src/NvGet.Tools.Updater/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ versions.json example:
```

```
nugetupdater -s=MySolution.sln -n -v=dev -v=stable --allowDowngrade --projectProperties=properties.json
nugetupdater -s=MySolution.sln -n -v=dev -v=stable --allowDowngrade --updateProperties=properties.json
```
properties.json example:
```
Expand Down
6 changes: 3 additions & 3 deletions src/NvGet/Extensions/XmlDocumentExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ namespace NvGet.Extensions
public static class XmlDocumentExtensions
{
/// <summary>
/// Retrieves the ProjectProperties that need updating from the given XmlDocument.
/// Retrieves the UpdateProperties that need updating from the given XmlDocument.
/// </summary>
/// <param name="document"></param>
/// <returns>A Dictionary where the key is the id of a package and the value its version.</returns>
public static PackageIdentity[] GetProjectProperties(this XmlDocument document, ICollection<(string PropertyName, string PackageId)> projectProperties)
public static PackageIdentity[] GetUpdateProperties(this XmlDocument document, ICollection<(string PropertyName, string PackageId)> updateProperties)
{
var references = new List<PackageIdentity>();

foreach(var prop in projectProperties)
foreach(var prop in updateProperties)
{
var docProp = document.SelectElements(prop.PropertyName).FirstOrDefault();
if(docProp is null)
Expand Down
18 changes: 9 additions & 9 deletions src/NvGet/Helpers/SolutionHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ public static async Task<PackageReference[]> GetPackageReferences(
string solutionPath,
FileType fileType,
ILogger log,
ICollection<(string PropertyName, string PackageId)>? projectProperties = default
ICollection<(string PropertyName, string PackageId)>? updateProperties = default
)
{
projectProperties ??= Array.Empty<(string PropertyName, string PackageId)>();
updateProperties ??= Array.Empty<(string PropertyName, string PackageId)>();

log.LogInformation($"Retrieving references from files in {solutionPath}");

Expand All @@ -38,7 +38,7 @@ public static async Task<PackageReference[]> GetPackageReferences(
{
foreach(var f in await GetProjectFiles(ct, solutionPath, log))
{
packages.AddRange(await GetFileReferences(ct, f, FileType.Csproj, projectProperties));
packages.AddRange(await GetFileReferences(ct, f, FileType.Csproj, updateProperties));
}
}

Expand All @@ -48,7 +48,7 @@ public static async Task<PackageReference[]> GetPackageReferences(

foreach(var file in await GetDirectoryFiles(ct, solutionPath, currentTarget, log))
{
packages.AddRange(await GetFileReferences(ct, file, currentTarget, projectProperties));
packages.AddRange(await GetFileReferences(ct, file, currentTarget, updateProperties));
}
}

Expand All @@ -58,7 +58,7 @@ public static async Task<PackageReference[]> GetPackageReferences(

foreach(var file in await GetDirectoryFiles(ct, solutionPath, currentTarget, log))
{
packages.AddRange(await GetFileReferences(ct, file, currentTarget, projectProperties));
packages.AddRange(await GetFileReferences(ct, file, currentTarget, updateProperties));
}
}

Expand All @@ -68,15 +68,15 @@ public static async Task<PackageReference[]> GetPackageReferences(

foreach(var file in await GetDirectoryFiles(ct, solutionPath, currentTarget, log))
{
packages.AddRange(await GetFileReferences(ct, file, currentTarget, projectProperties));
packages.AddRange(await GetFileReferences(ct, file, currentTarget, updateProperties));
}
}

if(fileType.HasFlag(FileType.Nuspec))
{
foreach(var f in await GetNuspecFiles(ct, solutionPath, log))
{
packages.AddRange(await GetFileReferences(ct, f, FileType.Nuspec, projectProperties));
packages.AddRange(await GetFileReferences(ct, f, FileType.Nuspec, updateProperties));
}
}

Expand Down Expand Up @@ -164,7 +164,7 @@ private static async Task<string[]> GetNuspecFiles(CancellationToken ct, string
return files;
}

private static async Task<PackageReference[]> GetFileReferences(CancellationToken ct, string file, FileType target, ICollection<(string PropertyName, string PackageId)> projectProperties)
private static async Task<PackageReference[]> GetFileReferences(CancellationToken ct, string file, FileType target, ICollection<(string PropertyName, string PackageId)> updateProperties)
{
if(file.IsNullOrEmpty())
{
Expand All @@ -176,7 +176,7 @@ private static async Task<PackageReference[]> GetFileReferences(CancellationToke

if(target.HasAnyFlag(FileType.Csproj, FileType.DirectoryProps, FileType.DirectoryTargets, FileType.CentralPackageManagement))
{
references = document.GetPackageReferences().Concat(document.GetProjectProperties(projectProperties)).ToArray();
references = document.GetPackageReferences().Concat(document.GetUpdateProperties(updateProperties)).ToArray();
}
else if(target.HasFlag(FileType.Nuspec))
{
Expand Down
2 changes: 1 addition & 1 deletion src/NvGet/Tools/Updater/Entities/UpdaterParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public class UpdaterParameters
/// <summary>
/// Gets the csproj properties that should be updated for corresponding package.
/// </summary>
public ICollection<(string PropertyName, string PackageId)> ProjectProperties { get; } = new List<(string PropertyNaem, string PackageId)>();
public ICollection<(string PropertyName, string PackageId)> UpdateProperties { get; } = new List<(string PropertyNaem, string PackageId)>();

/// <summary>
/// Gets or sets a value indicating whether to actually write the updates to the files.
Expand Down
6 changes: 3 additions & 3 deletions src/NvGet/Tools/Updater/Extensions/XmlDocumentExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ public static class XmlDocumentExtensions
/// <param name="document"></param>
/// <param name="operation"></param>
/// <returns></returns>
public static IEnumerable<UpdateOperation> UpdateProjectProperties(
public static IEnumerable<UpdateOperation> UpdateUpdateProperties(
this XmlDocument document,
UpdateOperation operation,
ICollection<(string PropertyName, string PackageId)> projectProperties)
ICollection<(string PropertyName, string PackageId)> updateProperties)
{
var operations = new List<UpdateOperation>();

var packageId = operation.PackageId;

foreach(var prop in projectProperties.Where(x=> x.PackageId == packageId))
foreach(var prop in updateProperties.Where(x=> x.PackageId == packageId))
{
var docProp = document.SelectElements(prop.PropertyName).FirstOrDefault();
if(docProp is null)
Expand Down
4 changes: 2 additions & 2 deletions src/NvGet/Tools/Updater/NuGetUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public async Task<IEnumerable<UpdateResult>> UpdatePackages(CancellationToken ct
internal async Task<UpdaterPackage[]> GetPackages(CancellationToken ct)
{
var packages = new List<UpdaterPackage>();
var references = await SolutionHelper.GetPackageReferences(ct, _parameters.SolutionRoot, _parameters.UpdateTarget, _log, _parameters.ProjectProperties);
var references = await SolutionHelper.GetPackageReferences(ct, _parameters.SolutionRoot, _parameters.UpdateTarget, _log, _parameters.UpdateProperties);

_log.Write($"Found {references.Length} references");

Expand Down Expand Up @@ -173,7 +173,7 @@ Dictionary<string, XmlDocument> documents
else if(fileType.HasAnyFlag(FileType.DirectoryProps, FileType.DirectoryTargets, FileType.Csproj, FileType.CentralPackageManagement))
{
updates = document.UpdatePackageReferences(currentOperation);
var propertyUpdates = document.UpdateProjectProperties(currentOperation, _parameters.ProjectProperties);
var propertyUpdates = document.UpdateUpdateProperties(currentOperation, _parameters.UpdateProperties);
updates = updates.Concat(propertyUpdates);
}

Expand Down

0 comments on commit 211e712

Please sign in to comment.