public static async Task <ProjectCacheService> FromDescriptorAsync( ProjectCacheDescriptor pluginDescriptor, BuildManager buildManager, ILoggingService loggingService, CancellationToken cancellationToken) { var plugin = await Task.Run(() => GetPluginInstance(pluginDescriptor), cancellationToken) .ConfigureAwait(false); // TODO: Detect and use the highest verbosity from all the user defined loggers. That's tricky because right now we can't query loggers about // their verbosity levels. var loggerFactory = new Func <PluginLoggerBase>(() => new LoggingServiceToPluginLoggerAdapter(LoggerVerbosity.Normal, loggingService)); var service = new ProjectCacheService(plugin, buildManager, loggerFactory, pluginDescriptor, cancellationToken); // TODO: remove the if after we change VS to set the cache descriptor via build parameters and always call BeginBuildAsync in FromDescriptorAsync. // When running under VS we can't initialize the plugin until we evaluate a project (any project) and extract // further information (set by VS) from it required by the plugin. if (!pluginDescriptor.VsWorkaround) { await service.BeginBuildAsync(); } return(service); }
private static async Task InitializePlugin( ProjectCacheDescriptor pluginDescriptor, CancellationToken cancellationToken, Func <PluginLoggerBase> loggerFactory, ProjectCachePluginBase plugin ) { var logger = loggerFactory(); try { await plugin.BeginBuildAsync( new CacheContext( pluginDescriptor.PluginSettings, new DefaultMSBuildFileSystem(), pluginDescriptor.ProjectGraph, pluginDescriptor.EntryPoints), // TODO: Detect verbosity from logging service. logger, cancellationToken); } catch (Exception e) { HandlePluginException(e, nameof(ProjectCachePluginBase.BeginBuildAsync)); } if (logger.HasLoggedErrors) { ProjectCacheException.ThrowForErrorLoggedInsideTheProjectCache("ProjectCacheInitializationFailed"); } }
private ProjectCacheService( ProjectCachePluginBase projectCachePlugin, BuildManager buildManager, Func <PluginLoggerBase> loggerFactory, ProjectCacheDescriptor projectCacheDescriptor, CancellationToken cancellationToken ) { _projectCachePlugin = projectCachePlugin; _buildManager = buildManager; _loggerFactory = loggerFactory; _projectCacheDescriptor = projectCacheDescriptor; _cancellationToken = cancellationToken; }
private ProjectCacheService( ProjectCachePluginBase projectCachePlugin, BuildManager buildManager, ILoggingService loggingService, ProjectCacheDescriptor projectCacheDescriptor, CancellationToken cancellationToken ) { _projectCachePlugin = projectCachePlugin; _buildManager = buildManager; _loggingService = loggingService; _projectCacheDescriptor = projectCacheDescriptor; _cancellationToken = cancellationToken; }
private static ProjectCachePluginBase GetPluginInstance(ProjectCacheDescriptor pluginDescriptor) { if (pluginDescriptor.PluginInstance != null) { return(pluginDescriptor.PluginInstance); } if (pluginDescriptor.PluginAssemblyPath != null) { return(GetPluginInstanceFromType(GetTypeFromAssemblyPath(pluginDescriptor.PluginAssemblyPath))); } ErrorUtilities.ThrowInternalErrorUnreachable(); return(null !); }
public static async Task <ProjectCacheService> FromDescriptorAsync( ProjectCacheDescriptor pluginDescriptor, BuildManager buildManager, ILoggingService loggingService, CancellationToken cancellationToken) { var plugin = await Task.Run(() => GetPluginInstance(pluginDescriptor), cancellationToken) .ConfigureAwait(false); var service = new ProjectCacheService(plugin, buildManager, loggingService, pluginDescriptor, cancellationToken); // TODO: remove the if after we change VS to set the cache descriptor via build parameters and always call BeginBuildAsync in FromDescriptorAsync. // When running under VS we can't initialize the plugin until we evaluate a project (any project) and extract // further information (set by VS) from it required by the plugin. if (!pluginDescriptor.VsWorkaround) { await service.BeginBuildAsync(); } return(service); }
// TODO: remove vsWorkaroundOverrideDescriptor after we change VS to set the cache descriptor via build parameters. private async Task BeginBuildAsync(ProjectCacheDescriptor?vsWorkaroundOverrideDescriptor = null) { BuildEventContext buildEventContext = BuildEventContext.Invalid; BuildEventFileInfo buildEventFileInfo = BuildEventFileInfo.Empty; var pluginLogger = new LoggingServiceToPluginLoggerAdapter( _loggingService, buildEventContext, buildEventFileInfo); ProjectCacheDescriptor projectDescriptor = vsWorkaroundOverrideDescriptor ?? _projectCacheDescriptor; try { SetState(ProjectCacheServiceState.BeginBuildStarted); _loggingService.LogComment(buildEventContext, MessageImportance.Low, "ProjectCacheBeginBuild"); MSBuildEventSource.Log.ProjectCacheBeginBuildStart(_projectCachePluginTypeName); await _projectCachePlugin.BeginBuildAsync( new CacheContext( projectDescriptor.PluginSettings, new DefaultMSBuildFileSystem(), projectDescriptor.ProjectGraph, projectDescriptor.EntryPoints), pluginLogger, _cancellationToken); } catch (Exception e) { HandlePluginException(e, nameof(ProjectCachePluginBase.BeginBuildAsync)); } finally { MSBuildEventSource.Log.ProjectCacheBeginBuildStop(_projectCachePluginTypeName); SetState(ProjectCacheServiceState.BeginBuildFinished); } if (pluginLogger.HasLoggedErrors) { ProjectCacheException.ThrowForErrorLoggedInsideTheProjectCache("ProjectCacheInitializationFailed"); } }
private static (ProjectCachePluginBase PluginInstance, string PluginTypeName) GetPluginInstance(ProjectCacheDescriptor pluginDescriptor) { if (pluginDescriptor.PluginInstance != null) { return(pluginDescriptor.PluginInstance, pluginDescriptor.PluginInstance.GetType().Name); } if (pluginDescriptor.PluginAssemblyPath != null) { MSBuildEventSource.Log.ProjectCacheCreatePluginInstanceStart(pluginDescriptor.PluginAssemblyPath); Type pluginType = GetTypeFromAssemblyPath(pluginDescriptor.PluginAssemblyPath); ProjectCachePluginBase pluginInstance = GetPluginInstanceFromType(pluginType); MSBuildEventSource.Log.ProjectCacheCreatePluginInstanceStop(pluginDescriptor.PluginAssemblyPath, pluginType.Name); return(pluginInstance, pluginType.Name); } ErrorUtilities.ThrowInternalErrorUnreachable(); return(null !, null !); // Unreachable }