Skip to content

Commit f698288

Browse files
authored
NuGet v3 populate dependencies (#1778)
1 parent 4543918 commit f698288

9 files changed

+455
-406
lines changed

src/code/FindHelper.cs

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public IEnumerable<PSResourceInfo> FindByResourceName(
105105
if (repository != null)
106106
{
107107
// Write error and disregard repository entries containing wildcards.
108-
repository = Utils.ProcessNameWildcards(repository, removeWildcardEntries:false, out string[] errorMsgs, out _repositoryNameContainsWildcard);
108+
repository = Utils.ProcessNameWildcards(repository, removeWildcardEntries: false, out string[] errorMsgs, out _repositoryNameContainsWildcard);
109109
foreach (string error in errorMsgs)
110110
{
111111
_cmdletPassedIn.WriteError(new ErrorRecord(
@@ -156,7 +156,7 @@ public IEnumerable<PSResourceInfo> FindByResourceName(
156156
if (repositoriesToSearch != null && repositoriesToSearch.Count == 0)
157157
{
158158
_cmdletPassedIn.ThrowTerminatingError(new ErrorRecord(
159-
new PSArgumentException ("Cannot resolve -Repository name. Run 'Get-PSResourceRepository' to view all registered repositories."),
159+
new PSArgumentException("Cannot resolve -Repository name. Run 'Get-PSResourceRepository' to view all registered repositories."),
160160
"RepositoryNameIsNotResolved",
161161
ErrorCategory.InvalidArgument,
162162
this));
@@ -222,7 +222,8 @@ public IEnumerable<PSResourceInfo> FindByResourceName(
222222
bool shouldReportErrorForEachRepo = !suppressErrors && !_repositoryNameContainsWildcard;
223223
foreach (PSResourceInfo currentPkg in SearchByNames(currentServer, currentResponseUtil, currentRepository, shouldReportErrorForEachRepo))
224224
{
225-
if (currentPkg == null) {
225+
if (currentPkg == null)
226+
{
226227
_cmdletPassedIn.WriteDebug("No packages returned from server");
227228
continue;
228229
}
@@ -244,7 +245,7 @@ public IEnumerable<PSResourceInfo> FindByResourceName(
244245
{
245246
// Scenarios: Find-PSResource -Name "pkg" -> write error only if pkg wasn't found in any registered repositories
246247
// Scenarios: Find-PSResource -Name "pkg" -Repository *Gallery -> write error if only if pkg wasn't found in any matching repositories.
247-
foreach(string pkgName in pkgsDiscovered)
248+
foreach (string pkgName in pkgsDiscovered)
248249
{
249250
var msg = repository == null ? $"Package '{pkgName}' could not be found in any registered repositories." :
250251
$"Package '{pkgName}' could not be found in registered repositories: '{string.Join(", ", repositoryNamesToSearch)}'.";
@@ -256,7 +257,7 @@ public IEnumerable<PSResourceInfo> FindByResourceName(
256257
this));
257258
}
258259
}
259-
}
260+
}
260261

261262
public IEnumerable<PSCommandResourceInfo> FindByCommandOrDscResource(
262263
bool isSearchingForCommands,
@@ -283,12 +284,12 @@ public IEnumerable<PSCommandResourceInfo> FindByCommandOrDscResource(
283284
// Error out if repository array of names to be searched contains wildcards.
284285
if (repository != null)
285286
{
286-
repository = Utils.ProcessNameWildcards(repository, removeWildcardEntries:false, out string[] errorMsgs, out _repositoryNameContainsWildcard);
287+
repository = Utils.ProcessNameWildcards(repository, removeWildcardEntries: false, out string[] errorMsgs, out _repositoryNameContainsWildcard);
287288

288289
if (string.Equals(repository[0], "*"))
289290
{
290291
_cmdletPassedIn.ThrowTerminatingError(new ErrorRecord(
291-
new PSArgumentException ("-Repository parameter does not support entry '*' with -CommandName and -DSCResourceName parameters."),
292+
new PSArgumentException("-Repository parameter does not support entry '*' with -CommandName and -DSCResourceName parameters."),
292293
"RepositoryDoesNotSupportWildcardEntryWithCmdOrDSCName",
293294
ErrorCategory.InvalidArgument,
294295
this));
@@ -337,7 +338,7 @@ public IEnumerable<PSCommandResourceInfo> FindByCommandOrDscResource(
337338
if (repositoriesToSearch != null && repositoriesToSearch.Count == 0)
338339
{
339340
_cmdletPassedIn.ThrowTerminatingError(new ErrorRecord(
340-
new PSArgumentException ("Cannot resolve -Repository name. Run 'Get-PSResourceRepository' to view all registered repositories."),
341+
new PSArgumentException("Cannot resolve -Repository name. Run 'Get-PSResourceRepository' to view all registered repositories."),
341342
"RepositoryNameIsNotResolved",
342343
ErrorCategory.InvalidArgument,
343344
this));
@@ -487,12 +488,12 @@ public IEnumerable<PSResourceInfo> FindByTag(
487488

488489
if (repository != null)
489490
{
490-
repository = Utils.ProcessNameWildcards(repository, removeWildcardEntries:false, out string[] errorMsgs, out _repositoryNameContainsWildcard);
491+
repository = Utils.ProcessNameWildcards(repository, removeWildcardEntries: false, out string[] errorMsgs, out _repositoryNameContainsWildcard);
491492

492493
if (string.Equals(repository[0], "*"))
493494
{
494495
_cmdletPassedIn.ThrowTerminatingError(new ErrorRecord(
495-
new PSArgumentException ("-Repository parameter does not support entry '*' with -Tag parameter."),
496+
new PSArgumentException("-Repository parameter does not support entry '*' with -Tag parameter."),
496497
"RepositoryDoesNotSupportWildcardEntryWithTag",
497498
ErrorCategory.InvalidArgument,
498499
this));
@@ -541,7 +542,7 @@ public IEnumerable<PSResourceInfo> FindByTag(
541542
if (repositoriesToSearch != null && repositoriesToSearch.Count == 0)
542543
{
543544
_cmdletPassedIn.ThrowTerminatingError(new ErrorRecord(
544-
new PSArgumentException ("Cannot resolve -Repository name. Run 'Get-PSResourceRepository' to view all registered repositories."),
545+
new PSArgumentException("Cannot resolve -Repository name. Run 'Get-PSResourceRepository' to view all registered repositories."),
545546
"RepositoryNameIsNotResolved",
546547
ErrorCategory.InvalidArgument,
547548
this));
@@ -635,7 +636,7 @@ public IEnumerable<PSResourceInfo> FindByTag(
635636
if (currentResult.exception != null && !currentResult.exception.Message.Equals(string.Empty))
636637
{
637638
errRecord = new ErrorRecord(
638-
new ResourceNotFoundException($"Tags '{String.Join(", ", _tag)}' could not be found" , currentResult.exception),
639+
new ResourceNotFoundException($"Tags '{String.Join(", ", _tag)}' could not be found", currentResult.exception),
639640
"FindTagConvertToPSResourceFailure",
640641
ErrorCategory.InvalidResult,
641642
this);
@@ -729,7 +730,7 @@ private IEnumerable<PSResourceInfo> SearchByNames(ServerApiCall currentServer, R
729730
}
730731
}
731732
}
732-
else if(pkgName.Contains("*"))
733+
else if (pkgName.Contains("*"))
733734
{
734735
// Example: Find-PSResource -Name "Az*"
735736
// Example: Find-PSResource -Name "Az*" -Tag "Storage"
@@ -1000,12 +1001,6 @@ private IEnumerable<PSResourceInfo> SearchByNames(ServerApiCall currentServer, R
10001001
// After retrieving all packages find their dependencies
10011002
if (_includeDependencies)
10021003
{
1003-
if (currentServer.Repository.ApiVersion == PSRepositoryInfo.APIVersion.V3)
1004-
{
1005-
_cmdletPassedIn.WriteWarning("Installing dependencies is not currently supported for V3 server protocol repositories. The package will be installed without installing dependencies.");
1006-
yield break;
1007-
}
1008-
10091004
foreach (PSResourceInfo currentPkg in parentPkgs)
10101005
{
10111006
_cmdletPassedIn.WriteDebug($"Finding dependency packages for '{currentPkg.Name}'");
@@ -1102,7 +1097,8 @@ internal IEnumerable<PSResourceInfo> FindDependencyPackages(
11021097
{
11031098
_cmdletPassedIn.WriteVerbose(errRecord.Exception.Message);
11041099
}
1105-
else {
1100+
else
1101+
{
11061102
_cmdletPassedIn.WriteError(errRecord);
11071103
}
11081104
yield return null;
@@ -1164,7 +1160,8 @@ internal IEnumerable<PSResourceInfo> FindDependencyPackages(
11641160
{
11651161
_cmdletPassedIn.WriteVerbose(errRecord.Exception.Message);
11661162
}
1167-
else {
1163+
else
1164+
{
11681165
_cmdletPassedIn.WriteError(errRecord);
11691166
}
11701167
yield return null;
@@ -1199,7 +1196,8 @@ internal IEnumerable<PSResourceInfo> FindDependencyPackages(
11991196
// Check to see if version falls within version range
12001197
PSResourceInfo foundDep = currentResult.returnedObject;
12011198
string depVersionStr = $"{foundDep.Version}";
1202-
if (foundDep.IsPrerelease) {
1199+
if (foundDep.IsPrerelease)
1200+
{
12031201
depVersionStr += $"-{foundDep.Prerelease}";
12041202
}
12051203

@@ -1222,7 +1220,8 @@ internal IEnumerable<PSResourceInfo> FindDependencyPackages(
12221220
yield return depRes;
12231221
}
12241222
}
1225-
else {
1223+
else
1224+
{
12261225
List<string> pkgVersions = _packagesFound[depPkg.Name] as List<string>;
12271226
// _packagesFound has depPkg.name in it, but the version is not the same
12281227
if (!pkgVersions.Contains(FormatPkgVersionString(depPkg)))

src/code/InstallHelper.cs

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ private List<PSResourceInfo> ProcessRepositories(
187187
if (repository != null && repository.Length != 0)
188188
{
189189
// Write error and disregard repository entries containing wildcards.
190-
repository = Utils.ProcessNameWildcards(repository, removeWildcardEntries:false, out string[] errorMsgs, out _);
190+
repository = Utils.ProcessNameWildcards(repository, removeWildcardEntries: false, out string[] errorMsgs, out _);
191191
foreach (string error in errorMsgs)
192192
{
193193
_cmdletPassedIn.WriteError(new ErrorRecord(
@@ -231,7 +231,7 @@ private List<PSResourceInfo> ProcessRepositories(
231231
if (repositoriesToSearch != null && repositoriesToSearch.Count == 0)
232232
{
233233
_cmdletPassedIn.ThrowTerminatingError(new ErrorRecord(
234-
new PSArgumentException ("Cannot resolve -Repository name. Run 'Get-PSResourceRepository' to view all registered repositories."),
234+
new PSArgumentException("Cannot resolve -Repository name. Run 'Get-PSResourceRepository' to view all registered repositories."),
235235
"RepositoryNameIsNotResolved",
236236
ErrorCategory.InvalidArgument,
237237
_cmdletPassedIn));
@@ -305,7 +305,8 @@ private List<PSResourceInfo> ProcessRepositories(
305305
bool installDepsForRepo = skipDependencyCheck;
306306

307307
// If no more packages to install, then return
308-
if (_pkgNamesToInstall.Count == 0) {
308+
if (_pkgNamesToInstall.Count == 0)
309+
{
309310
return allPkgsInstalled;
310311
}
311312

@@ -329,14 +330,9 @@ private List<PSResourceInfo> ProcessRepositories(
329330
}
330331

331332
repositoryNamesToSearch.Add(repoName);
332-
if ((currentRepository.ApiVersion == PSRepositoryInfo.APIVersion.V3) && (!installDepsForRepo))
333-
{
334-
_cmdletPassedIn.WriteWarning("Installing dependencies is not currently supported for V3 server protocol repositories. The package will be installed without installing dependencies.");
335-
installDepsForRepo = true;
336-
}
337333

338-
var installedPkgs = InstallPackages(_pkgNamesToInstall.ToArray(), currentRepository, currentServer, currentResponseUtil, scope, skipDependencyCheck, findHelper);
339-
foreach (var pkg in installedPkgs)
334+
List<PSResourceInfo> installedPkgs = InstallPackages(_pkgNamesToInstall.ToArray(), currentRepository, currentServer, currentResponseUtil, scope, skipDependencyCheck, findHelper);
335+
foreach (PSResourceInfo pkg in installedPkgs)
340336
{
341337
_pkgNamesToInstall.RemoveAll(x => x.Equals(pkg.Name, StringComparison.InvariantCultureIgnoreCase));
342338
}
@@ -535,8 +531,10 @@ private void MoveFilesIntoInstallPath(
535531
File.Delete(Path.Combine(finalModuleVersionDir, pkgInfo.Name + PSScriptFileExt));
536532
}
537533
}
538-
else {
539-
if (_includeXml) {
534+
else
535+
{
536+
if (_includeXml)
537+
{
540538
_cmdletPassedIn.WriteVerbose(string.Format("Moving '{0}' to '{1}'", Path.Combine(dirNameVersion, scriptXML), Path.Combine(installPath, scriptXML)));
541539
Utils.MoveFiles(Path.Combine(dirNameVersion, scriptXML), Path.Combine(installPath, scriptXML));
542540
}
@@ -614,11 +612,6 @@ private List<PSResourceInfo> InstallPackages(
614612

615613
if (!skipDependencyCheck)
616614
{
617-
if (currentServer.Repository.ApiVersion == PSRepositoryInfo.APIVersion.V3)
618-
{
619-
_cmdletPassedIn.WriteWarning("Installing dependencies is not currently supported for V3 server protocol repositories. The package will be installed without installing dependencies.");
620-
}
621-
622615
// Get the dependencies from the installed package.
623616
if (parentPkgObj.Dependencies.Length > 0)
624617
{
@@ -748,7 +741,7 @@ private Hashtable BeginPackageInstall(
748741
return packagesHash;
749742
}
750743

751-
break;
744+
break;
752745

753746
case VersionType.SpecificVersion:
754747
string nugetVersionString = specificVersion.ToNormalizedString(); // 3.0.17-beta
@@ -802,7 +795,9 @@ private Hashtable BeginPackageInstall(
802795

803796
break;
804797
}
805-
} else {
798+
}
799+
else
800+
{
806801
pkgToInstall = currentResult.returnedObject;
807802

808803
break;
@@ -816,11 +811,13 @@ private Hashtable BeginPackageInstall(
816811

817812
pkgToInstall.RepositorySourceLocation = repository.Uri.ToString();
818813
pkgToInstall.AdditionalMetadata.TryGetValue("NormalizedVersion", out string pkgVersion);
819-
if (pkgVersion == null) {
814+
if (pkgVersion == null)
815+
{
820816
// Not all NuGet providers (e.g. Artifactory, possibly others) send NormalizedVersion in NuGet package responses.
821817
// If they don't, we need to manually construct the combined version+prerelease from pkgToInstall.Version and the prerelease string.
822818
pkgVersion = pkgToInstall.Version.ToString();
823-
if (!String.IsNullOrEmpty(pkgToInstall.Prerelease)) {
819+
if (!String.IsNullOrEmpty(pkgToInstall.Prerelease))
820+
{
824821
pkgVersion += $"-{pkgToInstall.Prerelease}";
825822
}
826823
}
@@ -921,11 +918,11 @@ private string CreateInstallationTempPath()
921918
try
922919
{
923920
var dir = Directory.CreateDirectory(tempInstallPath); // should check it gets created properly
924-
// To delete file attributes from the existing ones get the current file attributes first and use AND (&) operator
925-
// with a mask (bitwise complement of desired attributes combination).
926-
// TODO: check the attributes and if it's read only then set it
927-
// attribute may be inherited from the parent
928-
// TODO: are there Linux accommodations we need to consider here?
921+
// To delete file attributes from the existing ones get the current file attributes first and use AND (&) operator
922+
// with a mask (bitwise complement of desired attributes combination).
923+
// TODO: check the attributes and if it's read only then set it
924+
// attribute may be inherited from the parent
925+
// TODO: are there Linux accommodations we need to consider here?
929926
dir.Attributes &= ~FileAttributes.ReadOnly;
930927
}
931928
catch (Exception e)
@@ -1003,7 +1000,8 @@ private bool TryInstallToTempPath(
10031000
bool isModule = File.Exists(moduleManifest);
10041001
bool isScript = File.Exists(scriptPath);
10051002

1006-
if (!isModule && !isScript) {
1003+
if (!isModule && !isScript)
1004+
{
10071005
scriptPath = "";
10081006
}
10091007

@@ -1433,7 +1431,7 @@ private bool CallAcceptLicense(PSResourceInfo p, string moduleManifest, string t
14331431
"ForceAcceptLicense",
14341432
ErrorCategory.InvalidArgument,
14351433
_cmdletPassedIn);
1436-
1434+
14371435
return false;
14381436
}
14391437
}

0 commit comments

Comments
 (0)