<commit_before>﻿using System;
using System.IO;
using BenchmarkDotNet.Extensions;
using BenchmarkDotNet.Helpers;
using BenchmarkDotNet.Plugins.Loggers;
using BenchmarkDotNet.Plugins.Toolchains.Classic;
using BenchmarkDotNet.Tasks;

namespace BenchmarkDotNet.Plugins.Toolchains.Dnx
{
    internal class BenchmarkDnxGenerator : BenchmarkClassicGenerator
    {
        internal const string ProjectFileName = "project.json";

        public BenchmarkDnxGenerator(IBenchmarkLogger logger) : base(logger)
        {
        }

        protected override void GenerateProjectFile(string projectDir, Benchmark benchmark)
        {
            var template = ResourceHelper.LoadTemplate("BenchmarkProject.json");

            var content = SetPlatform(template, benchmark.Task.Configuration.Platform);
            content = SetDependency(content, benchmark.Target.Type);

    
            string fileName = Path.Combine(projectDir, ProjectFileName);

            File.WriteAllText(fileName, content);
        }

        protected override void GenerateProjectBuildFile(string projectDir)
        {
            // do nothing on purpose, we do not need bat file
        }

        private static string SetPlatform(string template, BenchmarkPlatform platform)
        {
            return template.Replace("$PLATFORM", platform.ToConfig()); // todo: verify name
        }

        private static string SetDependency(string template, Type benchmarkTarget)
        {
            var assemblyName = benchmarkTarget.Assembly.GetName();

            return template
                // todo: handle number.number.number-text format
                .Replace("$EXECUTINGASSEMBLYVERSION", assemblyName.Version.ToString()) 
                .Replace("$EXECUTINGASSEMBLY", assemblyName.Name);
        }
    }
}<commit_msg>road to DNX: handling "nuget-like" package versions that can contain text (assembly version contains only numbers)<commit_after>﻿using System;
using System.IO;
using BenchmarkDotNet.Extensions;
using BenchmarkDotNet.Helpers;
using BenchmarkDotNet.Plugins.Loggers;
using BenchmarkDotNet.Plugins.Toolchains.Classic;
using BenchmarkDotNet.Tasks;

namespace BenchmarkDotNet.Plugins.Toolchains.Dnx
{
    internal class BenchmarkDnxGenerator : BenchmarkClassicGenerator
    {
        internal const string ProjectFileName = "project.json";

        public BenchmarkDnxGenerator(IBenchmarkLogger logger) : base(logger)
        {
        }

        protected override void GenerateProjectFile(string projectDir, Benchmark benchmark)
        {
            var template = ResourceHelper.LoadTemplate("BenchmarkProject.json");

            var content = SetPlatform(template, benchmark.Task.Configuration.Platform);
            content = SetDependency(content, benchmark.Target.Type);
    
            var projectJsonFilePath = Path.Combine(projectDir, ProjectFileName);

            File.WriteAllText(projectJsonFilePath, content);
        }

        protected override void GenerateProjectBuildFile(string projectDir)
        {
            // do nothing on purpose, we do not need bat file
        }

        private static string SetPlatform(string template, BenchmarkPlatform platform)
        {
            return template.Replace("$PLATFORM", platform.ToConfig()); // todo: verify name
        }

        private static string SetDependency(string template, Type benchmarkTarget)
        {
            var assemblyName = benchmarkTarget.Assembly.GetName();

            var packageVersion =
                $"{assemblyName.Version.Major}.{assemblyName.Version.Minor}.{assemblyName.Version.Build}-*";

            return template
                .Replace("$EXECUTINGASSEMBLYVERSION", packageVersion) 
                .Replace("$EXECUTINGASSEMBLY", assemblyName.Name);
        }
    }
}
{'fraction_non_alphanumeric': 0.07967178401270514, 'fraction_numerical': 0.0, 'mean_word_length': 2.8482688391038695, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4626191', 'n_tokens_mistral': 974, 'n_tokens_neox': 909, 'n_words': 214}