44using System . Runtime . CompilerServices ;
55using System . Threading ;
66using System . Threading . Tasks ;
7+ using JetBrains . Annotations ;
78using NugetForUnity . Helper ;
89using NugetForUnity . Models ;
910using NugetForUnity . PackageSource ;
@@ -21,11 +22,13 @@ public static class ConfigurationManager
2122 /// <summary>
2223 /// The <see cref="INugetPackageSource" /> to use.
2324 /// </summary>
25+ [ CanBeNull ]
2426 private static INugetPackageSource activePackageSource ;
2527
2628 /// <summary>
2729 /// Backing field for the NuGet.config file.
2830 /// </summary>
31+ [ CanBeNull ]
2932 private static NugetConfigFile nugetConfigFile ;
3033
3134 static ConfigurationManager ( )
@@ -40,11 +43,13 @@ static ConfigurationManager()
4043 /// <remarks>
4144 /// <see cref="NugetConfigFile" />.
4245 /// </remarks>
46+ [ NotNull ]
4347 public static string NugetConfigFilePath { get ; }
4448
4549 /// <summary>
4650 /// Gets the loaded NuGet.config file that holds the settings for NuGet.
4751 /// </summary>
52+ [ NotNull ]
4853 public static NugetConfigFile NugetConfigFile
4954 {
5055 get
@@ -54,13 +59,15 @@ public static NugetConfigFile NugetConfigFile
5459 LoadNugetConfigFile ( ) ;
5560 }
5661
62+ Debug . Assert ( nugetConfigFile != null , nameof ( nugetConfigFile ) + " != null" ) ;
5763 return nugetConfigFile ;
5864 }
5965 }
6066
6167 /// <summary>
6268 /// Gets the path to the directory containing the NuGet.config file.
6369 /// </summary>
70+ [ NotNull ]
6471 internal static string NugetConfigFileDirectoryPath { get ; }
6572
6673 /// <summary>
@@ -70,6 +77,24 @@ public static NugetConfigFile NugetConfigFile
7077 /// </summary>
7178 internal static bool IsVerboseLoggingEnabled => nugetConfigFile ? . Verbose ?? false ;
7279
80+ /// <summary>
81+ /// Gets the <see cref="INugetPackageSource" /> to use.
82+ /// </summary>
83+ [ NotNull ]
84+ private static INugetPackageSource ActivePackageSource
85+ {
86+ get
87+ {
88+ if ( activePackageSource is null )
89+ {
90+ LoadNugetConfigFile ( ) ;
91+ }
92+
93+ Debug . Assert ( activePackageSource != null , nameof ( activePackageSource ) + " != null" ) ;
94+ return activePackageSource ;
95+ }
96+ }
97+
7398 /// <summary>
7499 /// Loads the NuGet.config file.
75100 /// </summary>
@@ -93,7 +118,7 @@ public static void LoadNugetConfigFile()
93118 {
94119 if ( readingSources )
95120 {
96- if ( arg . StartsWith ( "-" ) )
121+ if ( arg . StartsWith ( "-" , StringComparison . Ordinal ) )
97122 {
98123 readingSources = false ;
99124 }
@@ -138,14 +163,16 @@ public static void LoadNugetConfigFile()
138163 /// <param name="numberToSkip">The number of packages to skip before fetching.</param>
139164 /// <param name="cancellationToken">Token that can be used to cancel the asynchronous task.</param>
140165 /// <returns>The list of available packages.</returns>
166+ [ NotNull ]
167+ [ ItemNotNull ]
141168 public static Task < List < INugetPackage > > Search (
142- string searchTerm = "" ,
169+ [ NotNull ] string searchTerm = "" ,
143170 bool includePrerelease = false ,
144171 int numberToGet = 15 ,
145172 int numberToSkip = 0 ,
146173 CancellationToken cancellationToken = default )
147174 {
148- return activePackageSource . Search ( searchTerm , includePrerelease , numberToGet , numberToSkip , cancellationToken ) ;
175+ return ActivePackageSource . Search ( searchTerm , includePrerelease , numberToGet , numberToSkip , cancellationToken ) ;
149176 }
150177
151178 /// <summary>
@@ -156,19 +183,22 @@ public static Task<List<INugetPackage>> Search(
156183 /// <param name="targetFrameworks">The specific frameworks to target?.</param>
157184 /// <param name="versionConstraints">The version constraints?.</param>
158185 /// <returns>A list of all updates available.</returns>
186+ [ NotNull ]
187+ [ ItemNotNull ]
159188 public static List < INugetPackage > GetUpdates (
160- IEnumerable < INugetPackage > packagesToUpdate ,
189+ [ NotNull ] IEnumerable < INugetPackage > packagesToUpdate ,
161190 bool includePrerelease = false ,
162191 string targetFrameworks = "" ,
163192 string versionConstraints = "" )
164193 {
165- return activePackageSource . GetUpdates ( packagesToUpdate , includePrerelease , targetFrameworks , versionConstraints ) ;
194+ return ActivePackageSource . GetUpdates ( packagesToUpdate , includePrerelease , targetFrameworks , versionConstraints ) ;
166195 }
167196
168197 /// <inheritdoc cref="INugetPackageSource.GetSpecificPackage(INugetPackageIdentifier)" />
169- public static INugetPackage GetSpecificPackage ( INugetPackageIdentifier nugetPackageIdentifier )
198+ [ CanBeNull ]
199+ public static INugetPackage GetSpecificPackage ( [ NotNull ] INugetPackageIdentifier nugetPackageIdentifier )
170200 {
171- return activePackageSource . GetSpecificPackage ( nugetPackageIdentifier ) ;
201+ return ActivePackageSource . GetSpecificPackage ( nugetPackageIdentifier ) ;
172202 }
173203 }
174204}
0 commit comments