From 6937300c7a99272d1e56d812a35c1b63357dc07b Mon Sep 17 00:00:00 2001 From: Jerome Haltom Date: Mon, 13 May 2024 18:09:01 -0500 Subject: [PATCH] Remove isolation code for netfx. Causes two loads of Java. --- .../JTRegTestManager.cs | 2 + .../JTRegTestManagerProxy.cs | 92 ------------------- .../JTRegTestAdapterTests.cs | 2 - .../JTRegExecutionContextProxy.cs | 16 +--- .../JTRegTestDiscoverer.cs | 4 +- .../JTRegTestExecutor.cs | 9 +- .../JTRegTestIsolationHost.cs | 74 --------------- 7 files changed, 7 insertions(+), 192 deletions(-) delete mode 100644 src/IKVM.JTReg.TestAdapter.Core/JTRegTestManagerProxy.cs delete mode 100644 src/IKVM.JTReg.TestAdapter/JTRegTestIsolationHost.cs diff --git a/src/IKVM.JTReg.TestAdapter.Core/JTRegTestManager.cs b/src/IKVM.JTReg.TestAdapter.Core/JTRegTestManager.cs index a7fb702acb..c27486a00f 100644 --- a/src/IKVM.JTReg.TestAdapter.Core/JTRegTestManager.cs +++ b/src/IKVM.JTReg.TestAdapter.Core/JTRegTestManager.cs @@ -18,6 +18,8 @@ namespace IKVM.JTReg.TestAdapter.Core public class JTRegTestManager { + public static readonly JTRegTestManager Instance = new(); + public const string URI = "executor://ikvmjtregtestadapter/v1"; internal static readonly string JTREG_LIB = Path.Combine(Path.GetDirectoryName(typeof(JTRegTestManager).Assembly.Location), "jtreg"); diff --git a/src/IKVM.JTReg.TestAdapter.Core/JTRegTestManagerProxy.cs b/src/IKVM.JTReg.TestAdapter.Core/JTRegTestManagerProxy.cs deleted file mode 100644 index ee007eb077..0000000000 --- a/src/IKVM.JTReg.TestAdapter.Core/JTRegTestManagerProxy.cs +++ /dev/null @@ -1,92 +0,0 @@ -using System; -using System.Collections.Generic; - -namespace IKVM.JTReg.TestAdapter.Core -{ - - /// - /// Proxy to a instance that can be marshalled by reference. - /// - public class JTRegTestManagerProxy : -#if NETFRAMEWORK - MarshalByRefObject -#else - object -#endif - { - - readonly JTRegTestManager real = new JTRegTestManager(); - - /// - /// Initiates a discovery of the tests of the given source. - /// - /// - /// - /// - public void DiscoverTests(string source, IJTRegDiscoveryContext context, CancellationTokenProxy cancellationTokenProxy) - { - var ctp = new CancellationTokenCancellationProxy(); - - try - { - cancellationTokenProxy.Register(ctp); - real.DiscoverTests(source, context, ctp.Token); - } - finally - { - cancellationTokenProxy.Unregister(ctp); - } - } - - /// - /// Initiates a run of the given sources, optionally with the specified tests. - /// - /// - /// - /// - public void RunTests(string source, IJTRegExecutionContext context, CancellationTokenProxy cancellationTokenProxy) - { - RunTests(source, null, context, cancellationTokenProxy); - } - - /// - /// Initiates a run of the given source, optionally with the specified tests. - /// - /// - /// - /// - /// - public void RunTests(string source, List tests, IJTRegExecutionContext context, CancellationTokenProxy cancellationTokenProxy) - { - if (source is null) - throw new ArgumentNullException(nameof(source)); - if (context is null) - throw new ArgumentNullException(nameof(context)); - if (cancellationTokenProxy is null) - throw new ArgumentNullException(nameof(cancellationTokenProxy)); - - var ctp = new CancellationTokenCancellationProxy(); - - try - { - cancellationTokenProxy.Register(ctp); - real.RunTests(source, tests, context, ctp.Token); - } - finally - { - cancellationTokenProxy.Unregister(ctp); - } - } - -#if NETFRAMEWORK - - public override object InitializeLifetimeService() - { - return null; - } - -#endif - - } - -} diff --git a/src/IKVM.JTReg.TestAdapter.Tests/JTRegTestAdapterTests.cs b/src/IKVM.JTReg.TestAdapter.Tests/JTRegTestAdapterTests.cs index 9285f08ece..38c4351f44 100644 --- a/src/IKVM.JTReg.TestAdapter.Tests/JTRegTestAdapterTests.cs +++ b/src/IKVM.JTReg.TestAdapter.Tests/JTRegTestAdapterTests.cs @@ -7,8 +7,6 @@ using IKVM.JTReg.TestAdapter.Core; -using javax.xml.bind; - using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; diff --git a/src/IKVM.JTReg.TestAdapter/JTRegExecutionContextProxy.cs b/src/IKVM.JTReg.TestAdapter/JTRegExecutionContextProxy.cs index 65429cab49..e95fba18b5 100644 --- a/src/IKVM.JTReg.TestAdapter/JTRegExecutionContextProxy.cs +++ b/src/IKVM.JTReg.TestAdapter/JTRegExecutionContextProxy.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; using IKVM.JTReg.TestAdapter.Core; @@ -13,11 +12,7 @@ namespace IKVM.JTReg.TestAdapter /// /// Proxies the interface to the Visual Studio test adapter. /// - class JTRegExecutionContextProxy : -#if NETFRAMEWORK - MarshalByRefObject, -#endif - IJTRegExecutionContext + class JTRegExecutionContextProxy : IJTRegExecutionContext { static readonly Dictionary properties = new Dictionary(StringComparer.OrdinalIgnoreCase); @@ -101,15 +96,6 @@ public void SendMessage(JTRegTestMessageLevel level, string message) frameworkHandle.SendMessage(JTRegProxyUtil.Convert(level), message); } -#if NETFRAMEWORK - - public override object InitializeLifetimeService() - { - return null; - } - -#endif - } } \ No newline at end of file diff --git a/src/IKVM.JTReg.TestAdapter/JTRegTestDiscoverer.cs b/src/IKVM.JTReg.TestAdapter/JTRegTestDiscoverer.cs index 83893ea461..9c42b5083e 100644 --- a/src/IKVM.JTReg.TestAdapter/JTRegTestDiscoverer.cs +++ b/src/IKVM.JTReg.TestAdapter/JTRegTestDiscoverer.cs @@ -27,9 +27,7 @@ public void DiscoverTests(IEnumerable sources, IDiscoveryContext discove try { - // setup isolation host for source - var proxy = JTRegTestIsolationHost.Instance.CreateManager(); - proxy.DiscoverTests(source, new JTRegDiscoveryContextProxy(discoveryContext, logger, discoverySink), new CancellationTokenProxy(CancellationToken.None)); + JTRegTestManager.Instance.DiscoverTests(source, new JTRegDiscoveryContextProxy(discoveryContext, logger, discoverySink), CancellationToken.None); } catch (Exception e) { diff --git a/src/IKVM.JTReg.TestAdapter/JTRegTestExecutor.cs b/src/IKVM.JTReg.TestAdapter/JTRegTestExecutor.cs index 673d5e9775..6559f4c982 100644 --- a/src/IKVM.JTReg.TestAdapter/JTRegTestExecutor.cs +++ b/src/IKVM.JTReg.TestAdapter/JTRegTestExecutor.cs @@ -28,15 +28,13 @@ public class JTRegTestExecutor : ITestExecutor public void RunTests(IEnumerable tests, IRunContext runContext, IFrameworkHandle frameworkHandle) { cts = new CancellationTokenSource(); - var ctp = new CancellationTokenProxy(cts.Token); foreach (var group in tests.GroupBy(i => i.Source)) { if (cts.Token.IsCancellationRequested) break; - var proxy = JTRegTestIsolationHost.Instance.CreateManager(); - proxy.RunTests(group.Key, JTRegProxyUtil.Convert(group).ToList(), new JTRegExecutionContextProxy(runContext, frameworkHandle), ctp); + JTRegTestManager.Instance.RunTests(group.Key, JTRegProxyUtil.Convert(group).ToList(), new JTRegExecutionContextProxy(runContext, frameworkHandle), cts.Token); } } @@ -49,15 +47,13 @@ public void RunTests(IEnumerable tests, IRunContext runContext, IFrame public void RunTests(IEnumerable sources, IRunContext runContext, IFrameworkHandle frameworkHandle) { cts = new CancellationTokenSource(); - var ctp = new CancellationTokenProxy(cts.Token); foreach (var source in sources) { if (cts.Token.IsCancellationRequested) break; - var proxy = JTRegTestIsolationHost.Instance.CreateManager(); - proxy.RunTests(source, new JTRegExecutionContextProxy(runContext, frameworkHandle), ctp); + JTRegTestManager.Instance.RunTests(source, null, new JTRegExecutionContextProxy(runContext, frameworkHandle), cts.Token); } } @@ -68,6 +64,7 @@ public void Cancel() { cts?.Cancel(); } + } } diff --git a/src/IKVM.JTReg.TestAdapter/JTRegTestIsolationHost.cs b/src/IKVM.JTReg.TestAdapter/JTRegTestIsolationHost.cs deleted file mode 100644 index 0aa1a0c748..0000000000 --- a/src/IKVM.JTReg.TestAdapter/JTRegTestIsolationHost.cs +++ /dev/null @@ -1,74 +0,0 @@ -using System; -using System.IO; - -using IKVM.JTReg.TestAdapter.Core; - -namespace IKVM.JTReg.TestAdapter -{ - - /// - /// Manages the isolation requirements for the services of the JTReg test adapter. - /// - class JTRegTestIsolationHost : IDisposable - { - - public static readonly JTRegTestIsolationHost Instance = new(); - -#if NETFRAMEWORK - AppDomain appdomain; -#endif - - /// - /// Initializes the static instance. - /// - public JTRegTestIsolationHost() - { -#if NETFRAMEWORK - var path = typeof(JTRegTestIsolationHost).Assembly.Location; - var conf = Path.ChangeExtension(path, ".dll.config"); - - var setup = new AppDomainSetup(); - setup.ApplicationBase = Path.GetDirectoryName(path); - setup.ConfigurationFile = conf; - appdomain = AppDomain.CreateDomain("JTRegTestAdapter", null, setup); -#endif - } - - /// - /// Creates a new for the given isolation host. - /// - /// - public JTRegTestManagerProxy CreateManager() - { -#if NETFRAMEWORK - return (JTRegTestManagerProxy)appdomain.CreateInstanceAndUnwrap(typeof(JTRegTestManagerProxy).Assembly.FullName, typeof(JTRegTestManagerProxy).FullName); -#else - return new JTRegTestManagerProxy(); -#endif - } - - /// - /// Disposes of the isolation host. - /// - public void Dispose() - { -#if NETFRAMEWORK - if (appdomain != null) - { - try - { - AppDomain.Unload(appdomain); - } - catch - { - // ignore any exceptions during unload - } - - appdomain = null; - } -#endif - } - - } - -}