Пример #1
0
        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 discern between user set loggers and msbuild's internally added loggers.
            var logger = new LoggingServiceToPluginLoggerAdapter(LoggerVerbosity.Normal, loggingService);

            await plugin.BeginBuildAsync(
                new CacheContext(
                    pluginDescriptor.PluginSettings,
                    new IFileSystemAdapter(FileSystems.Default),
                    pluginDescriptor.ProjectGraph,
                    pluginDescriptor.EntryPoints),
                // TODO: Detect verbosity from logging service.
                logger,
                cancellationToken);

            if (logger.HasLoggedErrors)
            {
                throw new Exception(
                          ResourceUtilities.FormatResourceStringIgnoreCodeAndKeyword("ProjectCacheInitializationFailed"));
            }

            return(new ProjectCacheService(plugin, buildManager, logger, pluginDescriptor, cancellationToken));
        }
Пример #2
0
 private ProjectCacheService(
     ProjectCachePluginBase projectCachePlugin,
     BuildManager buildManager,
     PluginLoggerBase logger,
     ProjectCacheDescriptor projectCacheDescriptor,
     CancellationToken cancellationToken)
 {
     _projectCachePlugin     = projectCachePlugin;
     _buildManager           = buildManager;
     _logger                 = logger;
     _projectCacheDescriptor = projectCacheDescriptor;
     _cancellationToken      = cancellationToken;
 }
Пример #3
0
        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 !);
        }
Пример #4
0
        private static ProjectCachePluginBase GetPluginInstance(ProjectCacheDescriptor pluginDescriptor)
        {
            if (pluginDescriptor.PluginInstance != null)
            {
                return(pluginDescriptor.PluginInstance);
            }
            if (pluginDescriptor.PluginAssemblyPath != null)
            {
                return(GetPluginInstanceFromType(GetTypeFromAssemblyPath(pluginDescriptor.PluginAssemblyPath)));
            }

            ErrorUtilities.ThrowInternalErrorUnreachable();

#pragma warning disable CS8603 // Possible null reference return.
            return(null);

#pragma warning restore CS8603 // Possible null reference return.
        }
Пример #5
0
        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 discern between user set loggers and msbuild's internally added loggers.
            var loggerFactory = new Func <PluginLoggerBase>(() => new LoggingServiceToPluginLoggerAdapter(LoggerVerbosity.Normal, loggingService));

            var logger = loggerFactory();

            try
            {
                await plugin.BeginBuildAsync(
                    new CacheContext(
                        pluginDescriptor.PluginSettings,
                        new IFileSystemAdapter(FileSystems.Default),
                        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");
            }

            return(new ProjectCacheService(plugin, buildManager, loggerFactory, pluginDescriptor, cancellationToken));
        }