Beispiel #1
0
        /// <summary>
        /// Runs OSLEBot on a set of files. The set of files specified in response file is cross-joined with data in configuration file
        /// to produce an input configuration for OSLEBot engine.
        /// </summary>
        /// <param name="responseFilePath">A list of references to LCX files for OSLEBot processing. Includes additional metadata about project and locgroup.</param>
        /// <param name="cerberusConfigPath">A Cerberus configuration database which defines the checks that are to be applied by OSLEBot.</param>
        /// <param name="cerberusOutputPath">A path to be used by Cerberus to create merged output.</param>
        public OSLEBotResult Run(string responseFilePath, string cerberusConfigPath, string cerberusOutputPath, string oslebotEngineLogPath)
        {
            OSLEBotResult result = OSLEBotResult.Success;

            if (responseFilePath == null)
            {
                throw new ArgumentNullException("responseFilePath");
            }
            if (cerberusConfigPath == null)
            {
                throw new ArgumentNullException("cerberusConfigPath");
            }
            if (cerberusOutputPath == null)
            {
                throw new ArgumentNullException("ceberusOutputPath");
            }
            if (oslebotEngineLogPath == null)
            {
                throw new ArgumentNullException("oslebotEngineLogPath");
            }

            IList <InputFileItem> fileList = null;

            try
            {
                fileList = LoadResponseFile(responseFilePath);
            }
            catch (Exception e)
            {
                throw;
            }
            var readOnlyDB = new CheckConfiguration();

            LoadDataFromDatabase(readOnlyDB, cerberusConfigPath);

            //initialize configuration helper. WARNING: thread unsafe if multiple configurations are ever to be used.
            ConfigurationHelper.Initialize(readOnlyDB);

            var checkConfigs = ReadCheckConfigsFromDatabase(readOnlyDB);

            var inputCfg = CreateConfig(fileList, checkConfigs, cerberusOutputPath, oslebotEngineLogPath);

            try
            {
                if (inputCfg.DataSourcePkgs == null || inputCfg.DataSourcePkgs.Count == 0)
                {
                    //Skip the execution when there is 0 file matches for the specified {language, project} pair.
                }

                var engine    = new OSLEBotEngine(inputCfg);
                var engineRan = engine.StartRun();
                if (engineRan)
                {
                    LoggerSAP.Trace("Cerberus is waiting for engine activity to complete...");
                    engine.WaitForJobFinish(); //Wait for complete stop of activity.
                    engine.Cleanup();
                }
                if (engine.EngineLoggedErrors)
                {
                    LoggerSAP.Error("Engine reported some execution errors.");
                    result = OSLEBotResult.HandledExceptions;
                }
            }
            // catch and log any exception that was not handled by OSLEBot engine
            catch (Exception e)
            {
                LoggerSAP.Error("OSLEBot engine failed with the following exception:\n{0}", e.GetExceptionDetails(true));
                result = OSLEBotResult.HandledExceptions;
            }

            return(result);
        }