<commit_before>﻿using System.Collections.Generic;
using System.IO;
using System.Text;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;

namespace Moq.Proxy
{
    /// <summary>
    /// Task that generates the proxies.
    /// </summary>
    public class GenerateProxies : ToolTask
    {
        List<ITaskItem> proxies = new List<ITaskItem>();

        /// <summary>
        /// The extension of the generated proxy files.
        /// </summary>
        public string FileExtension { get; set; }

        /// <summary>
        /// Name of the target language, which must be one known to Rosly. 
        /// <see cref="Microsoft.CodeAnalysis.LanguageNames"/>.
        /// </summary>
        [Required]
        public string LanguageName { get; set; }

        /// <summary>
        /// The target directory where generated proxies should be written to.
        /// </summary>
        [Required]
        public string OutputPath { get; set; }

        /// <summary>
        /// Optional working directory to run the tool from.
        /// </summary>
        public string WorkingDirectory { get; set; }

        /// <summary>
        /// Assembly references for the code generation.
        /// </summary>
        public ITaskItem[] References { get; set; }

        /// <summary>
        /// Source files to inspect to discover types that need proxies, denoted 
        /// by invocations to methods that are annotated with <c>Moq.Proxy.ProxyGeneratorAttribute</c>.
        /// </summary>
        public ITaskItem[] Sources { get; set; }

        /// <summary>
        /// Additional interfaces (by full type name) that should be implemented by generated 
        /// proxies.
        /// </summary>
        public ITaskItem[] AdditionalInterfaces { get; set; }

        /// <summary>
        /// Additional types (by full type name) that should be proxied.
        /// </summary>
        public ITaskItem[] AdditionalProxies { get; set; }

        [Output]
        public ITaskItem[] Proxies => proxies.ToArray();

        protected override string ToolName => "pgen.exe";

        // NOTE: this allows the Mono or .NETCore targets to override 'pgen.exe' by setting ToolExe differently 
        // (i.e. 'mono pgen.exe' or 'dotnet pgen.dll').
        protected override string GenerateFullPathToTool() => Path.Combine(ToolPath, ToolExe ?? ToolName);

        protected override string GetWorkingDirectory() => WorkingDirectory ?? ToolPath;

        protected override void LogEventsFromTextOutput(string singleLine, MessageImportance messageImportance)
        {
            // The pgen tool writes to standard output the proxy files it writes out.
            if (File.Exists(singleLine))
                proxies.Add(new TaskItem(singleLine));

            base.LogEventsFromTextOutput(singleLine, messageImportance);
        }

        protected override void LogToolCommand(string message)<commit_msg>Render pgen output as MSBuild messages<commit_after>﻿using System.Collections.Generic;
using System.IO;
using System.Text;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;

namespace Moq.Proxy
{
    /// <summary>
    /// Task that generates the proxies.
    /// </summary>
    public class GenerateProxies : ToolTask
    {
        List<ITaskItem> proxies = new List<ITaskItem>();

        /// <summary>
        /// The extension of the generated proxy files.
        /// </summary>
        public string FileExtension { get; set; }

        /// <summary>
        /// Name of the target language, which must be one known to Rosly. 
        /// <see cref="Microsoft.CodeAnalysis.LanguageNames"/>.
        /// </summary>
        [Required]
        public string LanguageName { get; set; }

        /// <summary>
        /// The target directory where generated proxies should be written to.
        /// </summary>
        [Required]
        public string OutputPath { get; set; }

        /// <summary>
        /// Optional working directory to run the tool from.
        /// </summary>
        public string WorkingDirectory { get; set; }

        /// <summary>
        /// Assembly references for the code generation.
        /// </summary>
        public ITaskItem[] References { get; set; }

        /// <summary>
        /// Source files to inspect to discover types that need proxies, denoted 
        /// by invocations to methods that are annotated with <c>Moq.Proxy.ProxyGeneratorAttribute</c>.
        /// </summary>
        public ITaskItem[] Sources { get; set; }

        /// <summary>
        /// Additional interfaces (by full type name) that should be implemented by generated 
        /// proxies.
        /// </summary>
        public ITaskItem[] AdditionalInterfaces { get; set; }

        /// <summary>
        /// Additional types (by full type name) that should be proxied.
        /// </summary>
        public ITaskItem[] AdditionalProxies { get; set; }

        [Output]
        public ITaskItem[] Proxies => proxies.ToArray();

        protected override string ToolName => "pgen.exe";

        // NOTE: this allows the Mono or .NETCore targets to override 'pgen.exe' by setting ToolExe differently 
        // (i.e. 'mono pgen.exe' or 'dotnet pgen.dll').
        protected override string GenerateFullPathToTool() => Path.Combine(ToolPath, ToolExe ?? ToolName);

        protected override string GetWorkingDirectory() => WorkingDirectory ?? ToolPath;

        protected override void LogEventsFromTextOutput(string singleLine, MessageImportance messageImportance)
        {
            // The pgen tool writes to standard output the proxy files it writes out.
            if (File.Exists(singleLine))
                proxies.Add(new TaskItem(singleLine));

            base.Log.LogMessageFromText(singleLine, messageImportance);
        }

        protected override void LogToolCommand(string message)
{'fraction_non_alphanumeric': 0.1089699863574352, 'fraction_numerical': 0.0, 'mean_word_length': 2.1213411389036723, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 57, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5622742', 'n_tokens_mistral': 1523, 'n_tokens_neox': 1443, 'n_words': 500}