diff --git a/src/NuGet.Core/NuGet.Credentials/PublicAPI/net8.0/PublicAPI.Unshipped.txt b/src/NuGet.Core/NuGet.Credentials/PublicAPI/net8.0/PublicAPI.Unshipped.txt index bda68031b3c..7dc5c58110b 100644 --- a/src/NuGet.Core/NuGet.Credentials/PublicAPI/net8.0/PublicAPI.Unshipped.txt +++ b/src/NuGet.Core/NuGet.Credentials/PublicAPI/net8.0/PublicAPI.Unshipped.txt @@ -1,3 +1 @@ #nullable enable -~NuGet.Protocol.Plugins.IPluginFactory.GetOrCreateNetToolsPluginAsync(string filePath, System.Collections.Generic.IEnumerable arguments, NuGet.Protocol.Plugins.IRequestHandlers requestHandlers, NuGet.Protocol.Plugins.ConnectionOptions options, System.Threading.CancellationToken sessionCancellationToken) -> System.Threading.Tasks.Task -~NuGet.Protocol.Plugins.PluginFactory.GetOrCreateNetToolsPluginAsync(string filePath, System.Collections.Generic.IEnumerable arguments, NuGet.Protocol.Plugins.IRequestHandlers requestHandlers, NuGet.Protocol.Plugins.ConnectionOptions options, System.Threading.CancellationToken sessionCancellationToken) -> System.Threading.Tasks.Task diff --git a/src/NuGet.Core/NuGet.Protocol/GlobalSuppressions.cs b/src/NuGet.Core/NuGet.Protocol/GlobalSuppressions.cs index c8e0b1cab94..fbb29505816 100644 --- a/src/NuGet.Core/NuGet.Protocol/GlobalSuppressions.cs +++ b/src/NuGet.Core/NuGet.Protocol/GlobalSuppressions.cs @@ -133,6 +133,7 @@ [assembly: SuppressMessage("Build", "CA1031:Modify 'FireBeforeClose' to catch a more specific allowed exception type, or rethrow the exception.", Justification = "", Scope = "member", Target = "~M:NuGet.Protocol.Plugins.Plugin.FireBeforeClose")] [assembly: SuppressMessage("Build", "CA1031:Modify 'FireClosed' to catch a more specific allowed exception type, or rethrow the exception.", Justification = "", Scope = "member", Target = "~M:NuGet.Protocol.Plugins.Plugin.FireClosed")] [assembly: SuppressMessage("Build", "CA2000:Call System.IDisposable.Dispose on object created by 'new MonitorNuGetProcessExitRequestHandler(plugin)' before all references to it are out of scope.", Justification = "", Scope = "member", Target = "~M:NuGet.Protocol.Plugins.PluginFactory.CreateFromCurrentProcessAsync(NuGet.Protocol.Plugins.IRequestHandlers,NuGet.Protocol.Plugins.ConnectionOptions,System.Threading.CancellationToken)~System.Threading.Tasks.Task{NuGet.Protocol.Plugins.IPlugin}")] +[assembly: SuppressMessage("Build", "CA2000:Use recommended dispose pattern to ensure that object created by 'new PluginProcess(startInfo)' is disposed on all paths. If possible, wrap the creation within a 'using' statement or a 'using' declaration. Otherwise, use a try-finally pattern, with a dedicated local variable declared before the try region and an unconditional Dispose invocation on non-null value in the 'finally' region, say 'x?.Dispose()'. If the object is explicitly disposed within the try region or the dispose ownership is transfered to another object or method, assign 'null' to the local variable just after such an operation to prevent double dispose in 'finally'.", Justification = "The responsibility to dispose the object is transferred to another object or wrapper that's created in the method and returned to the caller", Scope = "member", Target = "~M:NuGet.Protocol.Plugins.PluginFactory.CreatePluginAsync(System.String,System.Collections.Generic.IEnumerable{System.String},NuGet.Protocol.Plugins.IRequestHandlers,NuGet.Protocol.Plugins.ConnectionOptions,System.Threading.CancellationToken)~System.Threading.Tasks.Task{NuGet.Protocol.Plugins.IPlugin}")] [assembly: SuppressMessage("Build", "CA1031:Modify 'SendCloseRequest' to catch a more specific allowed exception type, or rethrow the exception.", Justification = "", Scope = "member", Target = "~M:NuGet.Protocol.Plugins.PluginFactory.SendCloseRequest(NuGet.Protocol.Plugins.IPlugin)")] [assembly: SuppressMessage("Build", "CA1822:Member GetPluginOperationClaimsAsync does not access instance data and can be marked as static (Shared in VisualBasic)", Justification = "", Scope = "member", Target = "~M:NuGet.Protocol.Plugins.PluginManager.GetPluginOperationClaimsAsync(NuGet.Protocol.Plugins.IPlugin,System.String,Newtonsoft.Json.Linq.JObject,System.Threading.CancellationToken)~System.Threading.Tasks.Task{System.Collections.Generic.IReadOnlyList{NuGet.Protocol.Plugins.OperationClaim}}")] [assembly: SuppressMessage("Build", "CA1031:Modify 'TryCreatePluginAsync' to catch a more specific allowed exception type, or rethrow the exception.", Justification = "", Scope = "member", Target = "~M:NuGet.Protocol.Plugins.PluginManager.TryCreatePluginAsync(NuGet.Protocol.Plugins.PluginDiscoveryResult,NuGet.Protocol.Plugins.OperationClaim,NuGet.Protocol.Plugins.PluginManager.PluginRequestKey,System.String,Newtonsoft.Json.Linq.JObject,System.Threading.CancellationToken)~System.Threading.Tasks.Task{System.Tuple{System.Boolean,NuGet.Protocol.Plugins.PluginCreationResult}}")] diff --git a/src/NuGet.Core/NuGet.Protocol/NuGet.Protocol.csproj b/src/NuGet.Core/NuGet.Protocol/NuGet.Protocol.csproj index e504ef49ba8..e50053d75f3 100644 --- a/src/NuGet.Core/NuGet.Protocol/NuGet.Protocol.csproj +++ b/src/NuGet.Core/NuGet.Protocol/NuGet.Protocol.csproj @@ -1,6 +1,6 @@ - $(TargetFrameworksLibraryForSigning); + $(TargetFrameworksLibraryForSigning) $(NoWarn);CS1591;CS1573;CS0012;RS0041 nuget protocol diff --git a/src/NuGet.Core/NuGet.Protocol/Plugins/PluginDiscoverer.cs b/src/NuGet.Core/NuGet.Protocol/Plugins/PluginDiscoverer.cs index cc98aec1bf4..d342827a370 100644 --- a/src/NuGet.Core/NuGet.Protocol/Plugins/PluginDiscoverer.cs +++ b/src/NuGet.Core/NuGet.Protocol/Plugins/PluginDiscoverer.cs @@ -44,7 +44,6 @@ internal PluginDiscoverer(IEnvironmentVariableReader environmentVariableReader) } _semaphore = new SemaphoreSlim(initialCount: 1, maxCount: 1); - _environmentVariableReader = environmentVariableReader; } /// @@ -186,8 +185,6 @@ internal List GetPluginsInNuGetPluginPaths() var pluginFiles = new List(); string[] paths = _nuGetPluginPaths?.Split(Path.PathSeparator) ?? Array.Empty(); - paths = nugetPluginPaths?.Split(Path.PathSeparator) ?? Array.Empty(); - foreach (var path in paths) { if (PathValidator.IsValidLocalPath(path) || PathValidator.IsValidUncPath(path)) diff --git a/src/NuGet.Core/NuGet.Protocol/Plugins/PluginManager.cs b/src/NuGet.Core/NuGet.Protocol/Plugins/PluginManager.cs index 18e1cd9a8ff..295479c664d 100644 --- a/src/NuGet.Core/NuGet.Protocol/Plugins/PluginManager.cs +++ b/src/NuGet.Core/NuGet.Protocol/Plugins/PluginManager.cs @@ -118,7 +118,7 @@ public async Task> CreatePluginsAsync( var pluginCreationResults = new List(); // Fast path - if (source.PackageSource.IsHttp) + if (source.PackageSource.IsHttp && IsPluginPossiblyAvailable()) { var serviceIndex = await source.GetResourceAsync(cancellationToken); @@ -325,6 +325,7 @@ private void Initialize(IEnvironmentVariableReader reader, { throw new ArgumentNullException(nameof(pluginFactoryCreator)); } + _connectionOptions = ConnectionOptions.CreateDefault(reader); var idleTimeoutInSeconds = EnvironmentVariableReader.GetEnvironmentVariable(EnvironmentVariableConstants.IdleTimeout); diff --git a/test/NuGet.Core.Tests/NuGet.Protocol.Tests/Plugins/PluginDiscovererTests.cs b/test/NuGet.Core.Tests/NuGet.Protocol.Tests/Plugins/PluginDiscovererTests.cs index 07e8132f4a2..f27749db149 100644 --- a/test/NuGet.Core.Tests/NuGet.Protocol.Tests/Plugins/PluginDiscovererTests.cs +++ b/test/NuGet.Core.Tests/NuGet.Protocol.Tests/Plugins/PluginDiscovererTests.cs @@ -245,43 +245,6 @@ public async Task DiscoverAsync_WithPluginPathSpecifiedInNuGetPluginPathsEnvVari } } - [PlatformTheory(Platform.Windows)] - [InlineData("nuget-plugin-myPlugin.exe")] - [InlineData("nuget-plugin-myPlugin.bat")] - public async Task DiscoverAsync_WithPluginPathSpecifiedInNuGetPluginPathsEnvVariableWindows_FindsThePlugin(string fileName) - { - using (var testDirectory = TestDirectory.Create()) - { - // Arrange - var pluginPath = Path.Combine(testDirectory.Path, "myPlugin"); - Directory.CreateDirectory(pluginPath); - var myPlugin = Path.Combine(pluginPath, fileName); - Mock environmentalVariableReader = new Mock(); - environmentalVariableReader.Setup(env => env.GetEnvironmentVariable("NUGET_PLUGIN_PATHS")).Returns(pluginPath); - environmentalVariableReader.Setup(env => env.GetEnvironmentVariable("PATHS")).Returns(""); - File.WriteAllText(myPlugin, string.Empty); - var verifierSpy = new Mock(); - verifierSpy.Setup(spy => spy.IsValid(It.IsAny())) - .Returns(true); - - using (var discoverer = new PluginDiscoverer("", verifierSpy.Object, environmentalVariableReader.Object)) - { - // Act - var result = await discoverer.DiscoverAsync(CancellationToken.None); - - // Assert - var discovered = false; - - foreach (PluginDiscoveryResult discoveryResult in result) - { - if (myPlugin == discoveryResult.PluginFile.Path) discovered = true; - } - - Assert.True(discovered); - } - } - } - [PlatformTheory(Platform.Windows)] [InlineData("nugetplugin-myPlugin.exe")] [InlineData("nugetplugin-myPlugin.bat")] @@ -407,56 +370,6 @@ public async Task DiscoverAsync_WithPluginPathSpecifiedInNuGetPluginPathsEnvVari } } - [PlatformFact(Platform.Linux)] - public async Task DiscoverAsync_WithPluginPathSpecifiedInNuGetPluginPathsEnvVariableLinux_FindsThePlugin() - { - using (var testDirectory = TestDirectory.Create()) - { - // Arrange - var pluginPath = Path.Combine(testDirectory.Path, "myPlugins"); - Directory.CreateDirectory(pluginPath); - var myPlugin = Path.Combine(pluginPath, "nuget-plugin-MyPlugin"); - File.WriteAllText(myPlugin, string.Empty); - Mock environmentalVariableReader = new Mock(); - environmentalVariableReader.Setup(env => env.GetEnvironmentVariable("NUGET_PLUGIN_PATHS")).Returns(pluginPath); - environmentalVariableReader.Setup(env => env.GetEnvironmentVariable("PATHS")).Returns(""); - - using (var process = new Process()) - { - // Use a shell command to make the file executable - process.StartInfo.FileName = "/bin/bash"; - process.StartInfo.Arguments = $"-c \"chmod +x {myPlugin}\""; - process.StartInfo.UseShellExecute = false; - process.StartInfo.RedirectStandardOutput = true; - process.Start(); - process.WaitForExit(); - - if (process.ExitCode == 0) - { - var verifierSpy = new Mock(); - verifierSpy.Setup(spy => spy.IsValid(It.IsAny())) - .Returns(true); - - using (var discoverer = new PluginDiscoverer("", verifierSpy.Object, environmentalVariableReader.Object)) - { - // Act - var result = await discoverer.DiscoverAsync(CancellationToken.None); - - // Assert - var discovered = false; - - foreach (PluginDiscoveryResult discoveryResult in result) - { - if (myPlugin == discoveryResult.PluginFile.Path) discovered = true; - } - - Assert.True(discovered); - } - } - } - } - } - [PlatformFact(Platform.Linux)] public async Task DiscoverAsync_withNoExecutableValidDotNetToolsPluginLinux_DoesNotFindThePlugin() { @@ -526,28 +439,6 @@ public void GetPluginsInNuGetPluginPaths_WithNuGetPluginPathsSet_ReturnsPluginsI Assert.True(plugins[0].IsDotnetToolsPlugin); } - [PlatformFact(Platform.Windows)] - public void GetPluginsInNuGetPluginPathsAndPath_WithoutNuGetPluginPaths_FallsBackToPath() - { - // Arrange - var pathDirectory = TestDirectory.Create(); - var pluginFilePath = Path.Combine(pathDirectory.Path, "nuget-plugin-fallback.exe"); - File.Create(pluginFilePath); - - var environmentalVariableReader = new Mock(); - environmentalVariableReader.Setup(env => env.GetEnvironmentVariable(EnvironmentVariableConstants.PluginPaths)).Returns(string.Empty); - environmentalVariableReader.Setup(env => env.GetEnvironmentVariable("PATH")).Returns(pathDirectory.Path); - - var pluginDiscoverer = new PluginDiscoverer("", Mock.Of(), environmentalVariableReader.Object); - - // Act - var plugins = pluginDiscoverer.GetPluginsInNuGetPluginPathsAndPath(); - - // Assert - Assert.Single(plugins); - Assert.Equal(pluginFilePath, plugins[0].Path); - } - [PlatformFact(Platform.Windows)] public void GetPluginsInNuGetPluginPaths_WithoutNuGetPluginPaths_ReturnsEmpty() { diff --git a/test/NuGet.Core.Tests/NuGet.Protocol.Tests/Plugins/PluginResourceProviderTests.cs b/test/NuGet.Core.Tests/NuGet.Protocol.Tests/Plugins/PluginResourceProviderTests.cs index d436de575e7..787f6b6db73 100644 --- a/test/NuGet.Core.Tests/NuGet.Protocol.Tests/Plugins/PluginResourceProviderTests.cs +++ b/test/NuGet.Core.Tests/NuGet.Protocol.Tests/Plugins/PluginResourceProviderTests.cs @@ -267,7 +267,6 @@ internal PluginResourceProviderNegativeTest(string serviceIndexJson, string sour _pluginDiscoverer.Setup(x => x.DiscoverAsync(It.IsAny())) .ReturnsAsync(pluginDiscoveryResults); - _pluginDiscoverer.Setup(x => x.Dispose()); _testDirectory = TestDirectory.Create();