<commit_before>﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace BuildBoss
{
    internal static class Program
    {
        internal static int Main(string[] args)
        {
            string configFile;
            string basePath;
            List<string> solutionFilePaths;
            if (!ParseCommandLine(args, out configFile, out basePath, out solutionFilePaths))
            { 
                Usage();
                return 1;
            }

            if (configFile != null)
            {
                var config = JsonConvert.DeserializeObject<BuildBossConfig>(File.ReadAllText(configFile));
                foreach (var target in config.Targets)
                {
                    solutionFilePaths.Add(Path.IsPathRooted(target)
                        ? target
                        : Path.Combine(basePath, target));
                }
            }

            var allGood = true;
            foreach (var solutionFilePath in solutionFilePaths)
            {
                allGood &= ProcessSolution(solutionFilePath);
            }

            return allGood ? 0 : 1;
        }

        private static bool ProcessSolution(string solutionFilePath)
        {
            var solutionPath = Path.GetDirectoryName(solutionFilePath);
            var projectDataList = SolutionUtil.ParseProjects(solutionFilePath);
            var map = new Dictionary<ProjectKey, ProjectData>();
            foreach (var projectEntry in projectDataList)
            {
                if (projectEntry.IsFolder)
                {
                    continue;
                }

                var projectFilePath = Path.Combine(solutionPath, projectEntry.RelativeFilePath);
                var projectData = new ProjectData(projectFilePath);
                map.Add(projectData.Key, projectData);
            }

            var allGood = true;
            var count = 0;
            foreach (var projectData in map.Values.OrderBy(x => x.FileName))
            {
                allGood &= ProcessProject(solutionPath, projectData, map);
                count++;

                var element = projectData.ProjectUtil.FindSingleProperty("Configuration");
                if (element != null)
                {
                    element.Remove();
                    projectData.Document.Save(projectData.FilePath);
                }
            }

            var result = allGood ? "passed" : "FAILED";
            Console.WriteLine($"Processing {Path.GetFileName(solutionFilePath)} ... {result} ({count} projects processed)");
            return allGood;
        }

        private static bool ProcessProject(string solutionPath, ProjectData projectData, Dictionary<ProjectKey, ProjectData> map)
        {
            var util = new ProjectCheckerUtil(projectData, map);<commit_msg>Remove the cleanup phase<commit_after>﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace BuildBoss
{
    internal static class Program
    {
        internal static int Main(string[] args)
        {
            string configFile;
            string basePath;
            List<string> solutionFilePaths;
            if (!ParseCommandLine(args, out configFile, out basePath, out solutionFilePaths))
            { 
                Usage();
                return 1;
            }

            if (configFile != null)
            {
                var config = JsonConvert.DeserializeObject<BuildBossConfig>(File.ReadAllText(configFile));
                foreach (var target in config.Targets)
                {
                    solutionFilePaths.Add(Path.IsPathRooted(target)
                        ? target
                        : Path.Combine(basePath, target));
                }
            }

            var allGood = true;
            foreach (var solutionFilePath in solutionFilePaths)
            {
                allGood &= ProcessSolution(solutionFilePath);
            }

            return allGood ? 0 : 1;
        }

        private static bool ProcessSolution(string solutionFilePath)
        {
            var solutionPath = Path.GetDirectoryName(solutionFilePath);
            var projectDataList = SolutionUtil.ParseProjects(solutionFilePath);
            var map = new Dictionary<ProjectKey, ProjectData>();
            foreach (var projectEntry in projectDataList)
            {
                if (projectEntry.IsFolder)
                {
                    continue;
                }

                var projectFilePath = Path.Combine(solutionPath, projectEntry.RelativeFilePath);
                var projectData = new ProjectData(projectFilePath);
                map.Add(projectData.Key, projectData);
            }

            var allGood = true;
            var count = 0;
            foreach (var projectData in map.Values.OrderBy(x => x.FileName))
            {
                allGood &= ProcessProject(solutionPath, projectData, map);
                count++;
            }

            var result = allGood ? "passed" : "FAILED";
            Console.WriteLine($"Processing {Path.GetFileName(solutionFilePath)} ... {result} ({count} projects processed)");
            return allGood;
        }

        private static bool ProcessProject(string solutionPath, ProjectData projectData, Dictionary<ProjectKey, ProjectData> map)
        {
            var util = new ProjectCheckerUtil(projectData, map);
{'fraction_non_alphanumeric': 0.08014247551202137, 'fraction_numerical': 0.0014247551202137133, 'mean_word_length': 1.6832298136645962, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, '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': '3493061', 'n_tokens_mistral': 1344, 'n_tokens_neox': 1264, 'n_words': 314}