Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/monodevelop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/main/src
diff options
context:
space:
mode:
authorMatt Ward <matt.ward@microsoft.com>2020-01-07 22:36:20 +0300
committerMatt Ward <matt.ward@microsoft.com>2020-01-08 16:00:10 +0300
commit7dfcadd19aafe84d65c688798eeb56087dbfdd47 (patch)
treeab9be75485289cb366717aa3e3564fb109ed4856 /main/src
parent14686dcd0834b8962b6ffd2bd9a1548d482b3883 (diff)
[NuGet] Support .NET Framework exe credential providers
NuGet's PluginFactory does not launch a .NET Framework .exe with Mono which causes the IDE to run launch another instance of itself when run from the Mac bundle. To workaround this the command line arguments are modified if an .exe is being run so it is launched with the current Mono.
Diffstat (limited to 'main/src')
-rw-r--r--main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.csproj1
-rw-r--r--main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/MonoDevelopPluginFactory.cs100
-rw-r--r--main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/PackageManagementCredentialService.cs2
-rw-r--r--main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/PackageManagementServices.cs29
4 files changed, 130 insertions, 2 deletions
diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.csproj b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.csproj
index 1065766e15..bd9be153c4 100644
--- a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.csproj
+++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.csproj
@@ -368,6 +368,7 @@
<Compile Include="MonoDevelop.PackageManagement\PackageManagementCanReferenceProjectExtension.cs" />
<Compile Include="MonoDevelop.PackageManagement\UpdateMultipleNuGetPackagesAction.cs" />
<Compile Include="MonoDevelop.PackageManagement\ProjectReferenceMaintainerCollection.cs" />
+ <Compile Include="MonoDevelop.PackageManagement\MonoDevelopPluginFactory.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="MonoDevelop.PackageManagement.addin.xml" />
diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/MonoDevelopPluginFactory.cs b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/MonoDevelopPluginFactory.cs
new file mode 100644
index 0000000000..9d8ce28c58
--- /dev/null
+++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/MonoDevelopPluginFactory.cs
@@ -0,0 +1,100 @@
+//
+// MonoDevelopPluginFactory.cs
+//
+// Author:
+// Matt Ward <matt.ward@microsoft.com>
+//
+// Copyright (c) 2020 Microsoft Corporation
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Threading;
+using System.Threading.Tasks;
+using MonoDevelop.Core;
+using MonoDevelop.Core.Assemblies;
+using NuGet.Protocol.Plugins;
+
+namespace MonoDevelop.PackageManagement
+{
+ sealed class MonoDevelopPluginFactory : IPluginFactory
+ {
+ readonly PluginFactory pluginFactory;
+
+ public MonoDevelopPluginFactory (TimeSpan idleTimeout)
+ {
+ pluginFactory = new PluginFactory (idleTimeout);
+ }
+
+ public void Dispose ()
+ {
+ pluginFactory.Dispose ();
+ }
+
+ public Task<IPlugin> GetOrCreateAsync (
+ string filePath,
+ IEnumerable<string> arguments,
+ IRequestHandlers requestHandlers,
+ ConnectionOptions options,
+ CancellationToken sessionCancellationToken)
+ {
+ if (!Platform.IsWindows) {
+ var modifiedCommandLine = GetModifiedCommandLine (filePath, arguments);
+ if (modifiedCommandLine != null) {
+ filePath = modifiedCommandLine.FilePath;
+ arguments = modifiedCommandLine.Arguments;
+ }
+ }
+
+ return pluginFactory.GetOrCreateAsync (filePath, arguments, requestHandlers, options, sessionCancellationToken);
+ }
+
+ ModifiedCommandLineArguments GetModifiedCommandLine (string filePath, IEnumerable<string> arguments)
+ {
+ string extension = Path.GetExtension (filePath);
+ if (!StringComparer.OrdinalIgnoreCase.Equals (".exe", extension)) {
+ return null;
+ }
+
+ var runtime = MonoRuntimeInfo.FromCurrentRuntime ();
+ if (runtime == null) {
+ return null;
+ }
+
+ string monoPath = Path.Combine (runtime.Prefix, "bin", "mono");
+
+ List<string> updatedArguments = arguments.ToList ();
+ updatedArguments.Insert (0, "\"" + filePath + "\"");
+
+ return new ModifiedCommandLineArguments {
+ FilePath = monoPath,
+ Arguments = updatedArguments
+ };
+ }
+
+ sealed class ModifiedCommandLineArguments
+ {
+ public string FilePath { get; set; }
+ public List<string> Arguments { get; set; }
+ }
+ }
+}
diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/PackageManagementCredentialService.cs b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/PackageManagementCredentialService.cs
index 57c9b30abe..18b4936515 100644
--- a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/PackageManagementCredentialService.cs
+++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/PackageManagementCredentialService.cs
@@ -77,7 +77,7 @@ namespace MonoDevelop.PackageManagement
static IEnumerable<ICredentialProvider> GetPluginsCredentialProviders ()
{
var builder = new SecurePluginCredentialProviderBuilder (
- PluginManager.Instance,
+ PackageManagementServices.PluginManager,
canShowDialog: false,
logger: NuGet.Common.NullLogger.Instance
);
diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/PackageManagementServices.cs b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/PackageManagementServices.cs
index d095f7f9ae..72cfb0e590 100644
--- a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/PackageManagementServices.cs
+++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/PackageManagementServices.cs
@@ -28,7 +28,10 @@
using System;
using System.IO;
-
+using NuGet.Common;
+using NuGet.Configuration;
+using NuGet.Protocol.Plugins;
+
namespace MonoDevelop.PackageManagement
{
public static class PackageManagementServices
@@ -47,6 +50,7 @@ namespace MonoDevelop.PackageManagement
//static readonly AnalyzerPackageMonitor analyzerPackageMonitor;
static readonly MonoDevelopHttpUserAgent userAgent = new MonoDevelopHttpUserAgent ();
static readonly NuGetConfigFileChangedMonitor nuGetConfigFileChangedMonitor = new NuGetConfigFileChangedMonitor ();
+ static readonly PluginManager pluginManager;
static PackageManagementServices()
{
@@ -65,6 +69,8 @@ namespace MonoDevelop.PackageManagement
workspace = new PackageManagementWorkspace ();
+ pluginManager = CreatePluginManager ();
+
credentialService = new PackageManagementCredentialService ();
credentialService.Initialize ();
@@ -76,6 +82,23 @@ namespace MonoDevelop.PackageManagement
MonoDevelop.Refactoring.PackageInstaller.PackageInstallerServiceFactory.PackageServices = new MonoDevelop.PackageManagement.Refactoring.NuGetPackageServicesProxy ();
}
+ static PluginManager CreatePluginManager ()
+ {
+ return new PluginManager (
+ EnvironmentVariableWrapper.Instance,
+ new Lazy<IPluginDiscoverer> (InitializeDiscoverer),
+ (TimeSpan idleTimeout) => new MonoDevelopPluginFactory (idleTimeout),
+ new Lazy<string> (() => SettingsUtility.GetPluginsCacheFolder ()));
+ }
+
+ static PluginDiscoverer InitializeDiscoverer ()
+ {
+ var verifier = EmbeddedSignatureVerifier.Create ();
+
+ string pluginPaths = EnvironmentVariableWrapper.Instance.GetEnvironmentVariable ("NUGET_PLUGIN_PATHS");
+ return new PluginDiscoverer (pluginPaths, verifier);
+ }
+
internal static void InitializeCredentialService ()
{
credentialService.Initialize ();
@@ -116,5 +139,9 @@ namespace MonoDevelop.PackageManagement
internal static ProjectTargetFrameworkMonitor ProjectTargetFrameworkMonitor {
get { return projectTargetFrameworkMonitor; }
}
+
+ internal static IPluginManager PluginManager {
+ get { return pluginManager; }
+ }
}
}