Esempio n. 1
0
        protected InstanceValidatorManagerBase(ClassTypeCache cache, LogCache logCache)
            : base(logCache)
        {
            _cache = cache;
            _instanceValidatorCache = new InstanceValidatorCache();
            for (var i = 0; i < _instanceValidatorCache.Count; i++)
            {
                _instanceValidatorCache[i].LogCreated += OnLogCreated;
            }

            // Build up a lookup table of type to validators to be able to apply that set of validators to
            // an instance of that type later on.
            _objectsToValidate      = new List <Object>();
            _typeToValidatorsLookup = new Dictionary <Type, List <AbstractInstanceValidator> >();

            for (var i = 0; i < _cache.Count; i++)
            {
                var cacheType = _cache[i];
                for (var j = 0; j < _instanceValidatorCache.Count; j++)
                {
                    var validator = _instanceValidatorCache[j];
                    if (!validator.AppliesTo(cacheType))
                    {
                        continue;
                    }

                    if (!_typeToValidatorsLookup.ContainsKey(cacheType))
                    {
                        _typeToValidatorsLookup.Add(cacheType, new List <AbstractInstanceValidator>());
                    }

                    _typeToValidatorsLookup[cacheType].Add(validator);
                }
            }
        }
Esempio n. 2
0
        public CrossSceneValidatorManager(LogCache logCache)
            : base(logCache)
        {
            _crossSceneValidatorCache = new CrossSceneValidatorCache();

            for (var i = 0; i < _crossSceneValidatorCache.Count; i++)
            {
                _crossSceneValidatorCache[i].LogCreated += logCache.OnLogCreated;
            }
        }
 public ProjectAssetValidatorManager(ClassTypeCache cache, LogCache logCache)
     : base(cache, logCache)
 {
     _continueSearchProgress = 0;
     _allPrefabGUIDs         = AssetDatabase.FindAssets(PrefabWildcardFilter);
     _projectValidatorCache  = new ProjectValidatorCache();
     for (var i = 0; i < _projectValidatorCache.Count; i++)
     {
         _projectValidatorCache[i].LogCreated += OnLogCreated;
     }
 }
        /// <summary>
        /// Runs validation against the project in <see cref="SceneValidationMode"/>
        /// <paramref name="validationMode"/> and writes the log file to a file with a custom name.
        /// </summary>
        /// <param name="validationMode">The <see cref="SceneValidationMode"/> the validation is run in.</param>
        /// <param name="fileOutputFormat">The <see cref="FileOutputFormat"/> the file will be written in, if any.</param>
        /// <param name="doValidateProjectAssets">True if project assets should be validated, false if not.</param>
        /// <param name="doValidateAcrossScenes">True if cross-scene validation should be performed.</param>
        /// <param name="fileName">A custom filename for the log results to be written to.</param>
        /// <returns></returns>
        public static Result RunValidation(
            SceneValidationMode validationMode,
            FileOutputFormat fileOutputFormat,
            bool doValidateProjectAssets,
            bool doValidateAcrossScenes,
            string fileName)
        {
            try
            {
                var logCache = new LogCache();
                var assetValidationRunner = new AssetValidatorRunner(logCache, validationMode);
                if (doValidateProjectAssets)
                {
                    assetValidationRunner.EnableProjectAssetValidation();
                }

                if (doValidateAcrossScenes)
                {
                    assetValidationRunner.EnableCrossSceneValidation();
                }

                assetValidationRunner.Run();

                var newFileName = string.IsNullOrEmpty(fileName)
                                        ? EditorConstants.DefaultLogFilename
                                        : fileName;

                LogFileWriter.WriteLogs(newFileName, fileOutputFormat, logCache);

                var result = new Result
                {
                    isSuccessful = logCache.All(x => x.logType != LogType.Error)
                };
                result.message = result.isSuccessful
                                        ? ValidationSuccessMessage
                                        : ValidationFailedMessage;

                return(result);
            }
            catch (Exception ex)
            {
                return(new Result
                {
                    isSuccessful = false,
                    message = string.Format(ValidationErrorFormat, ex)
                });
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Adds to an <see cref="LogCache"/> <paramref name="_logCache"/> logs for all of the
        /// validators that have been disabled for this run.
        /// </summary>
        /// <param name="_logCache"></param>
        internal void AddDisabledLogs(LogCache _logCache)
        {
            for (var i = 0; i < OverrideItems.Count; i++)
            {
                if (OverrideItems[i].enabled)
                {
                    continue;
                }

                _logCache.OnLogCreated(new ValidationLog
                {
                    source  = LogSource.None,
                    logType = LogType.Warning,
                    message = string.Format(
                        EditorConstants.ConfigValidatorDisabledWarning,
                        OverrideItems[i].type.Name,
                        AssetDatabase.GetAssetPath(this))
                });
            }
        }
        /// <summary>
        /// Constructor that accepts the <see cref="LogCache"/> <paramref name="logCache"/> that logs will be
        /// stored in and the <see cref="SceneValidationMode"/> <paramref name="validationMode"/> that scenes
        /// will be validated in (if any).
        /// </summary>
        /// <param name="logCache"></param>
        /// <param name="validationMode"></param>
        public AssetValidatorRunner(LogCache logCache, SceneValidationMode validationMode)
        {
            _scenePaths = ProjectTools.GetScenePaths(validationMode);

            _logCache = logCache;

            _cache = new ClassTypeCache();

            // Ensure any unit test types do not get picked up for validation.
            _cache.IgnoreType <MonoBehaviourTwo>();
            _cache.IgnoreAttribute <OnlyIncludeInTestsAttribute>();

            // Find all objects for validation
            _cache.AddTypeWithAttribute <MonoBehaviour, ValidateAttribute>();

            // Add all disabled logs for this run
            AssetValidatorOverrideConfig.FindOrCreate().AddDisabledLogs(logCache);

            _isRunning   = true;
            _runningTime = EditorApplication.timeSinceStartup;
        }
        private void OnEnable()
        {
            titleContent.text = EditorConstants.EditorWindowTitle;

            _logCache = new LogCache();

            _guiLayoutOptions = new[] { GUILayout.Height(30f), GUILayout.MinWidth(625f) };

            _groupByOptionsValues = (LogGroupingMode[])Enum.GetValues(typeof(LogGroupingMode));
            _groupByOptionsNames  = _groupByOptionsValues.Select(ReflectionTools.GetEnumString).ToArray();

            _fileOutputFormatOptions = (FileOutputFormat[])Enum.GetValues(typeof(FileOutputFormat));
            _outputFormatOptionNames = _fileOutputFormatOptions.Select(ReflectionTools.GetEnumString).ToArray();

            _sceneValidationModeOptions     = (SceneValidationMode[])Enum.GetValues(typeof(SceneValidationMode));
            _sceneValidationModeOptionNames = _sceneValidationModeOptions.Select(ReflectionTools.GetEnumString).ToArray();

            _validationLogTreeView = new ValidationLogTreeView(new TreeViewState());

            EditorSceneManager.sceneOpened += OnSceneLoaded;
        }
Esempio n. 8
0
 public ActiveSceneValidatorManager(ClassTypeCache cache, LogCache logCache)
     : base(cache, logCache)
 {
 }
Esempio n. 9
0
 protected ValidatorManagerBase(LogCache logCache)
 {
     _logCache = logCache;
 }