Esempio n. 1
0
        protected override Dictionary <string, IEnumerable <Package> > GetModules()
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();
            var    M            = this.ModulePackages = new Dictionary <string, IEnumerable <Package> >();
            object modules_lock = new object();
            string core_version = this.Version;
            List <AuditFileInfo> core_module_files    = this.CoreModulesDirectory.GetFiles("*.info.yml")?.Where(f => !f.Name.Contains("_test") && !f.Name.Contains("test_")).Select(f => f as AuditFileInfo).ToList();
            List <AuditFileInfo> contrib_module_files = this.ContribModulesDirectory.GetFiles("*.info.yml")?.Where(f => !f.Name.Contains("_test") && !f.Name.Contains("test_")).Select(f => f as AuditFileInfo).ToList();
            List <Package>       all_modules          = new List <Package>(100);

            if (core_module_files != null && core_module_files.Count > 0)
            {
                List <Package> core_modules = new List <Package>(core_module_files.Count + 1);
                this.AuditEnvironment.Status("Reading Drupal 8 core module files from environment...", core_module_files.Count);
                Dictionary <AuditFileInfo, string> core_modules_files_text = this.CoreModulesDirectory.ReadFilesAsText(core_module_files);
                Parallel.ForEach(core_modules_files_text, new ParallelOptions()
                {
                    MaxDegreeOfParallelism = 20
                }, kv =>
                {
                    if (!string.IsNullOrEmpty(kv.Value))
                    {
                        Deserializer yaml_deserializer = new Deserializer(namingConvention: new CamelCaseNamingConvention(), ignoreUnmatched: true);
                        DrupalModuleInfo m             = yaml_deserializer.Deserialize <DrupalModuleInfo>(new System.IO.StringReader(kv.Value));
                        m.ShortName = kv.Key.Name.Split('.')[0];
                        lock (modules_lock)
                        {
                            core_modules.Add(new Package("drupal", m.ShortName, m.Version == "VERSION" ? core_version : m.Version, "", string.Empty));
                        }
                        this.AuditEnvironment.Debug("Added Drupal 8 core module {0}: {1}.", m.ShortName, m.Version);
                    }
                });
                M.Add("core", core_modules);
                core_modules.Add(new Package("drupal", "drupal_core", string.Empty));
                all_modules.AddRange(core_modules);
            }
            if (contrib_module_files != null && contrib_module_files.Count > 0)
            {
                List <Package> contrib_modules = new List <Package>(contrib_module_files.Count);
                this.AuditEnvironment.Info("Reading Drupal 8 contrib module files from environment...", core_module_files.Count);
                Dictionary <AuditFileInfo, string> contrib_modules_files_text = this.ContribModulesDirectory.ReadFilesAsText(contrib_module_files);
                Parallel.ForEach(contrib_modules_files_text, new ParallelOptions()
                {
                    MaxDegreeOfParallelism = 20
                }, kv =>
                {
                    if (!string.IsNullOrEmpty(kv.Value))
                    {
                        Deserializer yaml_deserializer = new Deserializer(namingConvention: new CamelCaseNamingConvention(), ignoreUnmatched: true);
                        DrupalModuleInfo m             = yaml_deserializer.Deserialize <DrupalModuleInfo>(new System.IO.StringReader(kv.Value));
                        m.ShortName = kv.Key.Name.Split('.')[0];
                        lock (modules_lock)
                        {
                            contrib_modules.Add(new Package(this.PackageManagerId, m.ShortName, m.Version));
                        }
                        this.AuditEnvironment.Debug("Added Drupal 8 contrib module {0}: {1}.", m.ShortName, m.Version);
                    }
                });
                if (contrib_modules.Count > 0)
                {
                    M.Add("contrib", contrib_modules);
                    all_modules.AddRange(contrib_modules);
                }
            }
            if (this.SitesAllModulesDirectory != null)
            {
                List <AuditFileInfo> sites_all_contrib_modules_files = this.SitesAllModulesDirectory.GetFiles("*.info.yml")?
                                                                       .Where(f => !f.Name.Contains("_test") && !f.Name.Contains("test_")).Select(f => f as AuditFileInfo).ToList();
                if (sites_all_contrib_modules_files != null && sites_all_contrib_modules_files.Count > 0)
                {
                    Dictionary <AuditFileInfo, string> sites_all_contrib_modules_files_text = this.SitesAllModulesDirectory.ReadFilesAsText(sites_all_contrib_modules_files);
                    List <Package> sites_all_contrib_modules = new List <Package>(sites_all_contrib_modules_files.Count + 1);
                    Parallel.ForEach(sites_all_contrib_modules_files_text, new ParallelOptions()
                    {
                        MaxDegreeOfParallelism = 20
                    }, kv =>
                    {
                        if (!string.IsNullOrEmpty(kv.Value))
                        {
                            Deserializer yaml_deserializer = new Deserializer(namingConvention: new CamelCaseNamingConvention(), ignoreUnmatched: true);
                            DrupalModuleInfo m             = yaml_deserializer.Deserialize <DrupalModuleInfo>(new System.IO.StringReader(kv.Value));
                            m.ShortName = kv.Key.Name.Split('.')[0];
                            lock (modules_lock)
                            {
                                sites_all_contrib_modules.Add(new Package("drupal", m.ShortName, m.Version, "", string.Empty));
                            }
                            this.AuditEnvironment.Debug("Added Drupal 8 contrib module {0}: {1}.", m.ShortName, m.Version);
                        }
                    });
                    if (sites_all_contrib_modules.Count > 0)
                    {
                        M.Add("sites_all_contrib", sites_all_contrib_modules);
                        all_modules.AddRange(sites_all_contrib_modules);
                    }
                }
            }
            M.Add("all", all_modules);
            this.ModulePackages           = M;
            this.ModulesInitialised       = true;
            this.PackageSourceInitialized = true; //Packages are read from modules
            sw.Stop();
            this.AuditEnvironment.Success("Got {0} total {1} modules in {2} ms.", ModulePackages["all"].Count(), this.ApplicationLabel, sw.ElapsedMilliseconds);
            return(this.ModulePackages);
        }
Esempio n. 2
0
        public override Dictionary <string, IEnumerable <OSSIndexQueryObject> > GetModules()
        {
            Dictionary <string, IEnumerable <OSSIndexQueryObject> > modules = new Dictionary <string, IEnumerable <OSSIndexQueryObject> >();
            List <FileInfo> core_module_files    = RecursiveFolderScan(this.CoreModulesDirectory, "*.info.yml").Where(f => !f.Name.Contains("_test") && !f.Name.Contains("test_")).ToList();
            List <FileInfo> contrib_module_files = RecursiveFolderScan(this.ContribModulesDirectory, "*.info.yml").Where(f => !f.Name.Contains("_test") && !f.Name.Contains("test_")).ToList();
            //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())
                {
                    using (StreamReader r = new StreamReader(f.OpenRead()))
                    {
                        DrupalModuleInfo m = yaml_deserializer.Deserialize <DrupalModuleInfo>(r);
                        m.ShortName = f.Name.Split('.')[0];
                        core_modules.Add(new OSSIndexQueryObject("drupal", m.ShortName, m.Version, "", m.Project));
                    }
                }
            }
            modules.Add("core", core_modules);
            all_modules.AddRange(core_modules);
            foreach (FileInfo f in contrib_module_files)
            {
                using (FileStream fs = f.OpenRead())
                {
                    using (StreamReader r = new StreamReader(f.OpenRead()))
                    {
                        DrupalModuleInfo m = yaml_deserializer.Deserialize <DrupalModuleInfo>(r);
                        m.ShortName = f.Name.Split('.')[0];
                        contrib_modules.Add(new OSSIndexQueryObject("drupal", m.ShortName, m.Version, "", m.Project));
                    }
                }
            }
            if (contrib_modules.Count > 0)
            {
                modules.Add("contrib", contrib_modules);
                all_modules.AddRange(contrib_modules);
            }
            if (this.SitesAllModulesDirectory != null)
            {
                //                List<FileSystemInfo> sites_all_contrib_modules_files = this.SitesAllModulesDirectory.GetFileSystemInfos("*.info.yml", SearchOption.AllDirectories)
                //                    .Where(f => !f.Name.Contains("_test") && !f.Name.Contains("test_")).ToList();
                List <FileInfo> sites_all_contrib_modules_files = RecursiveFolderScan(this.SitesAllModulesDirectory, "*.info.yml").Where(f => !f.Name.Contains("_test") && !f.Name.Contains("test_")).ToList();
                if (sites_all_contrib_modules_files.Count > 0)
                {
                    List <OSSIndexQueryObject> sites_all_contrib_modules = new List <OSSIndexQueryObject>(sites_all_contrib_modules_files.Count + 1);
                    foreach (FileInfo f in sites_all_contrib_modules_files)
                    {
                        using (FileStream fs = f.OpenRead())
                        {
                            using (StreamReader r = new StreamReader(f.OpenRead()))
                            {
                                DrupalModuleInfo m = yaml_deserializer.Deserialize <DrupalModuleInfo>(r);
                                m.ShortName = f.Name.Split('.')[0];
                                sites_all_contrib_modules.Add(new OSSIndexQueryObject("drupal", m.ShortName, m.Version, "", m.Project));
                            }
                        }
                    }
                    if (sites_all_contrib_modules.Count > 0)
                    {
                        modules.Add("sites_all_contrib", sites_all_contrib_modules);
                        all_modules.AddRange(sites_all_contrib_modules);
                    }
                }
            }
            modules.Add("all", all_modules);
            return(modules);
        }
        protected override Dictionary <string, IEnumerable <Package> > GetModules()
        {
            object modules_lock = new object();
            Dictionary <string, IEnumerable <Package> > modules = new Dictionary <string, IEnumerable <Package> >();
            List <AuditFileInfo>   core_module_files            = this.CoreModulesDirectory.GetFiles("*.info").Where(f => !f.Name.Contains("_test") && !f.Name.Contains("test_")).Select(f => f as AuditFileInfo).ToList();
            List <AuditFileInfo>   contrib_module_files         = this.ContribModulesDirectory.GetFiles("*.info")?.Where(f => !f.Name.Contains("_test") && !f.Name.Contains("test_")).Select(f => f as AuditFileInfo).ToList();
            List <Package>         core_modules    = new List <Package>(core_module_files.Count + 1);
            List <Package>         contrib_modules = contrib_module_files != null ? new List <Package>(contrib_module_files.Count) : new List <Package>(0);
            List <Package>         all_modules     = new List <Package>(core_module_files.Count + 1);
            IniParserConfiguration ini_parser_cfg  = new IniParserConfiguration();

            ini_parser_cfg.CommentString         = ";";
            ini_parser_cfg.AllowDuplicateKeys    = true;
            ini_parser_cfg.OverrideDuplicateKeys = true;
            this.AuditEnvironment.Status("Reading Drupal 7 core module files from environment...", core_module_files.Count);
            Dictionary <AuditFileInfo, string> core_modules_files_text = this.CoreModulesDirectory.ReadFilesAsText(core_module_files);

            Parallel.ForEach(core_modules_files_text, new ParallelOptions()
            {
                MaxDegreeOfParallelism = 20
            }, _kv =>
            {
                IniDataParser ini_parser = new IniDataParser(ini_parser_cfg);
                IniData data             = ini_parser.Parse(_kv.Value);
                foreach (KeyData d in data.Global)
                {
                    if (d.Value.First() == '"')
                    {
                        d.Value = d.Value.Remove(0, 1);
                    }
                    if (d.Value.Last() == '"')
                    {
                        d.Value = d.Value.Remove(d.Value.Length - 1, 1);
                    }
                }
                DrupalModuleInfo m = new DrupalModuleInfo
                {
                    Core        = data.Global["core"],
                    Name        = data.Global["name"],
                    Description = data.Global["description"],
                    Package     = data.Global["package"],
                    Version     = data.Global["version"],
                    Project     = data.Global["project"]
                };
                lock (modules_lock)
                {
                    core_modules.Add(new Package("drupal", m.Name, m.Version == "VERSION" ? m.Core : m.Version, "", string.Empty));
                }
            });
            core_modules.Add(new Package("drupal", "drupal_core", core_modules.First().Version));
            modules.Add("core", core_modules);
            all_modules.AddRange(core_modules);
            if (contrib_module_files != null)
            {
                this.AuditEnvironment.Status("Reading contrib module files from environment...", core_module_files.Count);
                Dictionary <AuditFileInfo, string> contrib_modules_files_text = this.ContribModulesDirectory.ReadFilesAsText(contrib_module_files);
                Parallel.ForEach(contrib_modules_files_text, new ParallelOptions()
                {
                    MaxDegreeOfParallelism = 20
                }, _kv =>
                {
                    IniDataParser ini_parser = new IniDataParser(ini_parser_cfg);
                    IniData data             = ini_parser.Parse(_kv.Value);
                    foreach (KeyData d in data.Global)
                    {
                        if (d.Value.First() == '"')
                        {
                            d.Value = d.Value.Remove(0, 1);
                        }
                        if (d.Value.Last() == '"')
                        {
                            d.Value = d.Value.Remove(d.Value.Length - 1, 1);
                        }
                    }
                    DrupalModuleInfo m = new DrupalModuleInfo
                    {
                        Core        = data.Global["core"],
                        Name        = data.Global["name"],
                        Description = data.Global["description"],
                        Package     = data.Global["package"],
                        Version     = data.Global["version"],
                        Project     = data.Global["project"]
                    };
                    lock (modules_lock)
                    {
                        contrib_modules.Add(new Package("drupal", m.Name, m.Version == "VERSION" ? m.Core : m.Version, "", string.Empty));
                    }
                });
            }
            if (contrib_modules.Count > 0)
            {
                modules.Add("contrib", contrib_modules);
                all_modules.AddRange(contrib_modules);
            }
            List <Package> sites_all_contrib_modules = null;

            if (this.SitesAllModulesDirectory != null)
            {
                List <AuditFileInfo> sites_all_contrib_modules_files = this.SitesAllModulesDirectory.GetFiles("*.info")?.Where(f => !f.Name.Contains("_test") && !f.Name.Contains("test_")).Select(f => f as AuditFileInfo).ToList();
                if (sites_all_contrib_modules_files != null && sites_all_contrib_modules_files.Count > 0)
                {
                    Dictionary <AuditFileInfo, string> sites_all_contrib_modules_files_text = this.SitesAllModulesDirectory.ReadFilesAsText(sites_all_contrib_modules_files);
                    sites_all_contrib_modules = new List <Package>(sites_all_contrib_modules_files.Count);
                    Parallel.ForEach(sites_all_contrib_modules_files_text, new ParallelOptions()
                    {
                        MaxDegreeOfParallelism = 20
                    }, _kv =>
                    {
                        IniDataParser ini_parser = new IniDataParser(ini_parser_cfg);
                        IniData data             = ini_parser.Parse(_kv.Value);
                        foreach (KeyData d in data.Global)
                        {
                            if (d.Value.First() == '"')
                            {
                                d.Value = d.Value.Remove(0, 1);
                            }
                            if (d.Value.Last() == '"')
                            {
                                d.Value = d.Value.Remove(d.Value.Length - 1, 1);
                            }
                        }
                        DrupalModuleInfo m = new DrupalModuleInfo
                        {
                            Core        = data.Global["core"],
                            Name        = data.Global["name"],
                            Description = data.Global["description"],
                            Package     = data.Global["package"],
                            Version     = data.Global["version"],
                        };
                        lock (modules_lock)
                        {
                            sites_all_contrib_modules.Add(new Package("drupal", m.Name, m.Version == "VERSION" ? m.Core : m.Version, "", string.Empty));
                        }
                    });
                }
            }
            if (sites_all_contrib_modules != null && sites_all_contrib_modules.Count > 0)
            {
                modules.Add("sites_all_contrib", sites_all_contrib_modules);
                all_modules.AddRange(sites_all_contrib_modules);
            }
            modules.Add("all", all_modules);
            this.ModulePackages           = modules;
            this.ModulesInitialised       = true;
            this.PackageSourceInitialized = true; //Packages are read from modules.
            return(this.ModulePackages);
        }