// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. using Microsoft.Testing.Platform.IPC; namespace Microsoft.Testing.Platform.Extensions.ArtifactPostProcessing; internal static class ArtifactPostProcessingHandshakeProperties { public static IReadOnlyDictionary? Create(IEnumerable processors) { string kinds = string.Join( ";", processors.Where(SupportsTestModuleMerging) .SelectMany(processor => processor.SupportedKinds) .Where(kind => !RoslynString.IsNullOrWhiteSpace(kind)) .Distinct(StringComparer.Ordinal) .OrderBy(kind => kind, StringComparer.Ordinal)); string extensions = string.Join( ";", processors.Where(SupportsTestModuleMerging) .SelectMany(processor => processor.SupportedFileExtensionsFallback) .Where(extension => !RoslynString.IsNullOrWhiteSpace(extension)) .Select(extension => extension.ToLowerInvariant()) .Distinct(StringComparer.Ordinal) .OrderBy(extension => extension, StringComparer.Ordinal)); string truncatedRunKinds = string.Join( ";", processors.Where(processor => SupportsTestModuleMerging(processor) && processor.SupportsTruncatedRuns) .SelectMany(processor => processor.SupportedKinds) .Where(kind => !RoslynString.IsNullOrWhiteSpace(kind)) .Distinct(StringComparer.Ordinal) .OrderBy(kind => kind, StringComparer.Ordinal)); string truncatedRunExtensions = string.Join( ";", processors.Where(processor => SupportsTestModuleMerging(processor) && processor.SupportsTruncatedRuns) .SelectMany(processor => processor.SupportedFileExtensionsFallback) .Where(extension => !RoslynString.IsNullOrWhiteSpace(extension)) .Select(extension => extension.ToLowerInvariant()) .Distinct(StringComparer.Ordinal) .OrderBy(extension => extension, StringComparer.Ordinal)); string requiredKinds = string.Join( ";", processors.OfType() .Where(SupportsTestModuleMerging) .SelectMany(processor => processor.SupportedKinds) .Where(kind => !RoslynString.IsNullOrWhiteSpace(kind)) .Distinct(StringComparer.Ordinal) .OrderBy(kind => kind, StringComparer.Ordinal)); if (kinds.Length == 0 && extensions.Length == 0) { return null; } var properties = new Dictionary(); if (kinds.Length > 0) { properties[HandshakeMessagePropertyNames.SupportedPostProcessorKinds] = kinds; } if (extensions.Length > 0) { properties[HandshakeMessagePropertyNames.SupportedPostProcessorExtensionsLegacy] = extensions; } if (truncatedRunKinds.Length > 0) { properties[HandshakeMessagePropertyNames.SupportedTruncatedRunPostProcessorKinds] = truncatedRunKinds; } if (truncatedRunExtensions.Length > 0) { properties[HandshakeMessagePropertyNames.SupportedTruncatedRunPostProcessorExtensionsLegacy] = truncatedRunExtensions; } if (requiredKinds.Length > 0) { properties[HandshakeMessagePropertyNames.RequiredPostProcessorKinds] = requiredKinds; } return properties; } private static bool SupportsTestModuleMerging(IArtifactPostProcessor processor) => processor.SupportedModes.Contains(ArtifactPostProcessingMode.TestModules); }