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

using YamlDotNet.Serialization;
using YamlDotNet.Serialization.NamingConventions;

namespace DevAudit.AuditLibrary
{
    public class DrupalApplication : Application
    {
        #region Overriden properties

        public override string ApplicationId { get { return "drupal8"; } }

        public override string ApplicationLabel { get { return "Drupal 8"; } }

        public override string PackageManagerId { get { return "drupal"; } }

        public override string PackageManagerLabel { get { return "Drupal"; } }

        public override OSSIndexHttpClient HttpClient { get; } = new OSSIndexHttpClient("1.1");
       
        public override Dictionary<string, string> RequiredDirectoryLocations { get; } = new Dictionary<string, string>()
        {
            { "CoreModulesDirectory", Path.Combine("core", "modules") },
            { "ContribModulesDirectory", "modules" },
            { "DefaultSiteDirectory", Path.Combine("sites", "default") },
        };

        public override Dictionary<string, string> RequiredFileLocations { get; } = new Dictionary<string, string>()
        {
            { "CorePackagesFile", Path.Combine("core", "composer.json") }
        };

        #endregion

        #region Public properties

        public DirectoryInfo CoreModulesDirectory
        {
            get
            {
                return (DirectoryInfo) this.ApplicationFileSystemMap["CoreModulesDirectory"];
            }
        }

        public DirectoryInfo ContribModulesDirectory
        {
            get
            {
                return (DirectoryInfo)this.ApplicationFileSystemMap["ContribModulesDirectory"];
            }
        }

        public DirectoryInfo SitesAllModulesDirectory
        {
            get
            {
                return this.RootDirectory.GetDirectories(Path.Combine("sites", "all", "modules")).FirstOrDefault();
            }
        }

        public FileInfo CorePackagesFile
        {
            get
            {
                return (FileInfo) this.ApplicationFileSystemMap["CorePackagesFile"];
            }
        }

        #endregion

        #region Overriden methods

        public override Dictionary<string, IEnumerable<OSSIndexQueryObject>> GetModules()
        {
            Dictionary<string, IEnumerable<OSSIndexQueryObject>> modules = new Dictionary<string, IEnumerable<OSSIndexQueryObject>>();            
            List<FileSystemInfo> core_module_files = this.CoreModulesDirectory.GetFileSystemInfos("*.info.yml", SearchOption.AllDirectories)
                .Where(f => !f.Name.Contains("_test") && !f.Name.Contains("test_")).ToList();
            List<FileSystemInfo> contrib_module_files = this.ContribModulesDirectory.GetFileSystemInfos("*.info.yml", SearchOption.AllDirectories)
                .Where(f => !f.Name.Contains("_test") && !f.Name.Contains("test_")).ToList();
            List<OSSIndexQueryObject> core_modules = new List<OSSIndexQueryObject>(core_module_files.Count + 1);
            List<OSSIndexQueryObject> contrib_modules = new List<OSSIndexQueryObject>(contrib_module_files.Count);
            List<OSSIndexQueryObject> all_modules = new List<OSSIndexQueryObject>(core_module_files.Count + 1);
            core_modules.Add(new OSSIndexQueryObject("drupal", "drupal_core", "8.x"));
            Deserializer yaml_deserializer = new Deserializer(namingConvention: new CamelCaseNamingConvention(), ignoreUnmatched: true);
            foreach (FileInfo f in core_module_files)
            {
                using (FileStream fs = f.OpenRead())<commit_msg>Check for sites_all directory first.<commit_after>﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using YamlDotNet.Serialization;
using YamlDotNet.Serialization.NamingConventions;

namespace DevAudit.AuditLibrary
{
    public class DrupalApplication : Application
    {
        #region Overriden properties

        public override string ApplicationId { get { return "drupal8"; } }

        public override string ApplicationLabel { get { return "Drupal 8"; } }

        public override string PackageManagerId { get { return "drupal"; } }

        public override string PackageManagerLabel { get { return "Drupal"; } }

        public override OSSIndexHttpClient HttpClient { get; } = new OSSIndexHttpClient("1.1");
       
        public override Dictionary<string, string> RequiredDirectoryLocations { get; } = new Dictionary<string, string>()
        {
            { "CoreModulesDirectory", Path.Combine("core", "modules") },
            { "ContribModulesDirectory", "modules" },
            { "DefaultSiteDirectory", Path.Combine("sites", "default") },
        };

        public override Dictionary<string, string> RequiredFileLocations { get; } = new Dictionary<string, string>()
        {
            { "CorePackagesFile", Path.Combine("core", "composer.json") }
        };

        #endregion

        #region Public properties

        public DirectoryInfo CoreModulesDirectory
        {
            get
            {
                return (DirectoryInfo) this.ApplicationFileSystemMap["CoreModulesDirectory"];
            }
        }

        public DirectoryInfo ContribModulesDirectory
        {
            get
            {
                return (DirectoryInfo)this.ApplicationFileSystemMap["ContribModulesDirectory"];
            }
        }

        public DirectoryInfo SitesAllModulesDirectory
        {
            get
            {
                DirectoryInfo sites_all;
                if ((sites_all = this.RootDirectory.GetDirectories(Path.Combine("sites", "all")).FirstOrDefault()) != null)
                {
                    return sites_all.GetDirectories(Path.Combine("modules")).FirstOrDefault();
                }
                else return null;
            }
        }

        public FileInfo CorePackagesFile
        {
            get
            {
                return (FileInfo) this.ApplicationFileSystemMap["CorePackagesFile"];
            }
        }

        #endregion

        #region Overriden methods

        public override Dictionary<string, IEnumerable<OSSIndexQueryObject>> GetModules()
        {
            Dictionary<string, IEnumerable<OSSIndexQueryObject>> modules = new Dictionary<string, IEnumerable<OSSIndexQueryObject>>();            
            List<FileSystemInfo> core_module_files = this.CoreModulesDirectory.GetFileSystemInfos("*.info.yml", SearchOption.AllDirectories)
                .Where(f => !f.Name.Contains("_test") && !f.Name.Contains("test_")).ToList();
            List<FileSystemInfo> contrib_module_files = this.ContribModulesDirectory.GetFileSystemInfos("*.info.yml", SearchOption.AllDirectories)
                .Where(f => !f.Name.Contains("_test") && !f.Name.Contains("test_")).ToList();
            List<OSSIndexQueryObject> core_modules = new List<OSSIndexQueryObject>(core_module_files.Count + 1);
            List<OSSIndexQueryObject> contrib_modules = new List<OSSIndexQueryObject>(contrib_module_files.Count);
            List<OSSIndexQueryObject> all_modules = new List<OSSIndexQueryObject>(core_module_files.Count + 1);
            core_modules.Add(new OSSIndexQueryObject("drupal", "drupal_core", "8.x"));
            Deserializer yaml_deserializer = new Deserializer(namingConvention: new CamelCaseNamingConvention(), ignoreUnmatched: true);
            foreach (FileInfo f in core_module_files)
            {
                using (FileStream fs = f.OpenRead())
{'fraction_non_alphanumeric': 0.09912612495108908, 'fraction_numerical': 0.0018260075648884831, 'mean_word_length': 2.584852734922861, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 43, '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': '6716346', 'n_tokens_mistral': 1998, 'n_tokens_neox': 1934, 'n_words': 383}