Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logger support in run settings #1382

Merged
merged 15 commits into from
Jan 30, 2018
Next Next commit
Initial commit
  • Loading branch information
abhishkk committed Jan 18, 2018
commit 4835d8c1b401c2e4fdc47f93a8f72b46f12df404
11 changes: 6 additions & 5 deletions src/Microsoft.TestPlatform.Client/TestPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public IDiscoveryRequest CreateDiscoveryRequest(IRequestData requestData, Discov
this.AddExtensionAssembliesFromSource(discoveryCriteria.Sources);

// Initialize loggers
TestLoggerManager.Instance.InitializeLoggers(requestData);
//TestLoggerManager.Instance.InitializeLoggers(requestData);
}

var testHostManager = this.testHostProviderManager.GetTestHostManagerByRunConfiguration(discoveryCriteria.RunSettings);
Expand Down Expand Up @@ -132,15 +132,16 @@ public ITestRunRequest CreateTestRunRequest(IRequestData requestData, TestRunCri

var runConfiguration = XmlRunSettingsUtilities.GetRunConfigurationNode(testRunCriteria.TestRunSettings);

// Update and initialize loggers only when DesignMode is false
// Update extension assemblies from source when design mode is false.
if (runConfiguration.DesignMode == false)
{
this.AddExtensionAssembliesFromSource(testRunCriteria);

// Initialize loggers
TestLoggerManager.Instance.InitializeLoggers(requestData);
}

// Initialize loggers
var loggerManager = this.TestEngine.GetLoggerManager(requestData);
loggerManager.Initialize(testRunCriteria.TestRunSettings);

var testHostManager = this.testHostProviderManager.GetTestHostManagerByRunConfiguration(testRunCriteria.TestRunSettings);
ThrowExceptionIfTestHostManagerIsNull(testHostManager, testRunCriteria.TestRunSettings);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace Microsoft.VisualStudio.TestPlatform.Common.Logging
namespace Microsoft.VisualStudio.TestPlatform.Common.ExtensionFramework
{
using System.Collections.Generic;

using Microsoft.VisualStudio.TestPlatform.Common;
using Microsoft.VisualStudio.TestPlatform.Common.ExtensionFramework;
using Microsoft.VisualStudio.TestPlatform.Common.ExtensionFramework.Utilities;
using Microsoft.VisualStudio.TestPlatform.Common.Interfaces;
Expand Down Expand Up @@ -62,4 +62,43 @@ public static TestLoggerExtensionManager Create(IMessageLogger messageLogger)
return new TestLoggerExtensionManager(unfilteredTestExtensions, filteredTestExtensions, messageLogger);
}
}

/// <summary>
/// Hold data about the Test logger.
/// </summary>
public class TestLoggerMetadata : ITestLoggerCapabilities
{
/// <summary>
/// Constructor for TestLoggerMetadata
/// </summary>
/// <param name="extension">
/// Uri identifying the logger.
/// </param>
/// <param name="friendlyName">
/// The friendly Name.
/// </param>
public TestLoggerMetadata(string extension, string friendlyName)
{
this.ExtensionUri = extension;
this.FriendlyName = friendlyName;
}

/// <summary>
/// Gets Uri identifying the logger.
/// </summary>
public string ExtensionUri
{
get;
private set;
}

/// <summary>
/// Gets Friendly Name identifying the logger.
/// </summary>
public string FriendlyName
{
get;
private set;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,7 @@ public interface ITestEngine
/// </summary>
/// <returns>ITestExtensionManager object that helps with extensibility</returns>
ITestExtensionManager GetExtensionManager();

ITestLoggerManager GetLoggerManager(IRequestData requestData);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doc please

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine
{
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;

/// <summary>
/// Orchestrates logger operations for this engine.
/// </summary>
public interface ITestLoggerManager
{
/// <summary>
/// Initialize loggers.
/// </summary>
void Initialize(string runSettings);
}
}
46 changes: 0 additions & 46 deletions src/Microsoft.TestPlatform.Common/Logging/TestLoggerMetadata.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace Microsoft.VisualStudio.TestPlatform.Common.Logging
Expand All @@ -10,7 +10,7 @@ namespace Microsoft.VisualStudio.TestPlatform.Common.Logging
using Microsoft.VisualStudio.TestPlatform.Utilities;

using ObjectModelCommonResources = Microsoft.VisualStudio.TestPlatform.ObjectModel.Resources.CommonResources;

/// <summary>
/// The test session message logger.
/// </summary>
Expand All @@ -34,7 +34,7 @@ protected TestSessionMessageLogger()
/// <summary>
/// Gets the instance of the singleton.
/// </summary>
internal static TestSessionMessageLogger Instance
public static TestSessionMessageLogger Instance
{
get
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace Microsoft.VisualStudio.TestPlatform.Common.Logging
namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client
{
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Linq;

using System.Xml;
using Microsoft.VisualStudio.TestPlatform.Common;
using Microsoft.VisualStudio.TestPlatform.Common.Exceptions;
using Microsoft.VisualStudio.TestPlatform.Common.ExtensionFramework;
using Microsoft.VisualStudio.TestPlatform.Common.Interfaces;
using Microsoft.VisualStudio.TestPlatform.Common.Logging;
using Microsoft.VisualStudio.TestPlatform.Common.Telemetry;
using Microsoft.VisualStudio.TestPlatform.Common.Utilities;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Utilities;

Expand All @@ -24,12 +28,11 @@ namespace Microsoft.VisualStudio.TestPlatform.Common.Logging
/// Responsible for managing logger extensions and broadcasting results
/// and error/warning/informational messages to them.
/// </summary>
internal class TestLoggerManager : ITestDiscoveryEventsRegistrar, ITestRunEventsRegistrar, IDisposable
internal class TestLoggerManager : ITestDiscoveryEventsRegistrar, ITestRunEventsRegistrar, ITestLoggerManager, IDisposable
{
#region Fields

private static readonly object Synclock = new object();
private static TestLoggerManager testLoggerManager;
protected List<LoggerInfo> loggersInfoList = new List<LoggerInfo>();

/// <summary>
Expand All @@ -54,10 +57,15 @@ internal class TestLoggerManager : ITestDiscoveryEventsRegistrar, ITestRunEvents
private ITestRunRequest runRequest = null;

/// <summary>
/// Gets an instance of the logger.
/// Message logger.
/// </summary>
private IMessageLogger messageLogger;

/// <summary>
/// Request data.
/// </summary>
private IRequestData requestData;

private TestLoggerExtensionManager testLoggerExtensionManager;
private IDiscoveryRequest discoveryRequest;

Expand All @@ -66,43 +74,19 @@ internal class TestLoggerManager : ITestDiscoveryEventsRegistrar, ITestRunEvents
#region Constructor

/// <summary>
/// Default constructor.
///
/// </summary>
protected TestLoggerManager(TestSessionMessageLogger sessionLogger, InternalTestLoggerEvents loggerEvents)
/// <param name="requestData">Request Data for Providing Common Services/Data for Discovery and Execution.</param>
/// <param name="messageLogger">Message Logger.</param>
/// <param name="loggerEvents">Logger events.</param>
public TestLoggerManager(IRequestData requestData, IMessageLogger messageLogger, InternalTestLoggerEvents loggerEvents)
{
this.messageLogger = sessionLogger;
this.requestData = requestData;
this.messageLogger = messageLogger;
this.testLoggerExtensionManager = null;
this.loggerEvents = loggerEvents;
}

/// <summary>
/// Gets the instance.
/// </summary>
public static TestLoggerManager Instance
{
get
{
if (testLoggerManager == null)
{
lock (Synclock)
{
if (testLoggerManager == null)
{
testLoggerManager = new TestLoggerManager(TestSessionMessageLogger.Instance,
new InternalTestLoggerEvents(TestSessionMessageLogger.Instance));
}
}
}

return testLoggerManager;
}

protected set
{
testLoggerManager = value;
}
}

#endregion

#region Properties
Expand Down Expand Up @@ -161,40 +145,60 @@ public void UpdateLoggerList(string argument, string loggerIdentifier, Dictionar
/// <summary>
/// Initializes all the loggers passed by user
/// </summary>
/// <param name="requestData">Request Data for Providing Common Services/Data for Discovery and Execution</param>
public void InitializeLoggers(IRequestData requestData)
public void Initialize(string runSettings)
{
foreach (var logger in this.loggersInfoList)
{
string loggerIdentifier = logger.loggerIdentifier;
Dictionary<string, string> parameters = logger.parameters;
//List<Logger> loggers = RunSett
var loggers = XmlRunSettingsUtilities.GetLoggerRunSettings(runSettings);

// First assume the logger is specified by URI. If that fails try with friendly name.
try
foreach (var logger in loggers.LoggerSettingsList ?? Enumerable.Empty<LoggerSettings>())
{
// reading using friendly name
// TODO: console might not work.
// TODO: enabled check for logger
if (TryGetUriFromFriendlyName(logger.FriendlyName, out var loggerUri))
{
this.AddLoggerByUri(loggerIdentifier, parameters);
}
catch (InvalidLoggerException)
{
string loggerUri;
if (testLoggerManager.TryGetUriFromFriendlyName(loggerIdentifier, out loggerUri))
{
this.AddLoggerByUri(loggerUri, parameters);
}
else
{
throw new InvalidLoggerException(
String.Format(
CultureInfo.CurrentUICulture,
CommonResources.LoggerNotFound,
logger.argument));
}
//var paramters = GetParametersFromConfigurationElement(logger.Configuration);
this.AddLoggerByUri(loggerUri, null);
}
}

//foreach (var logger in this.loggersInfoList)
//{
// string loggerIdentifier = logger.loggerIdentifier;
// Dictionary<string, string> parameters = logger.parameters;

// // First assume the logger is specified by URI. If that fails try with friendly name.
// try
// {
// this.AddLoggerByUri(loggerIdentifier, parameters);
// }
// catch (InvalidLoggerException)
// {
// string loggerUri;
// if (TryGetUriFromFriendlyName(loggerIdentifier, out loggerUri))
// {
// this.AddLoggerByUri(loggerUri, parameters);
// }
// else
// {
// throw new InvalidLoggerException(
// String.Format(
// CultureInfo.CurrentUICulture,
// CommonResources.LoggerNotFound,
// logger.argument));
// }
// }
//}

requestData.MetricsCollection.Add(TelemetryDataConstants.LoggerUsed, string.Join(",", this.initializedLoggers.ToArray()));
}

private Dictionary<string, string> GetParametersFromConfigurationElement(XmlElement configuration)
{
//LoggerNameValueConfigurationManager configuration = new LoggerNameValueConfigurationManager();
throw new NotImplementedException();
}

/// <summary>
/// Add and initialize the logger with the given parameters
/// </summary>
Expand Down Expand Up @@ -270,7 +274,7 @@ private void AddLoggerByUri(string argument, Dictionary<string, string> paramete
// Add the logger and if it is a non-existent logger, throw.
try
{
testLoggerManager.AddLogger(loggerUri, parameters);
AddLogger(loggerUri, parameters);
}
catch (InvalidOperationException e)
{
Expand Down
Loading