Пример #1
0
        private void ValidateModules()
        {
            foreach (Project project in _repository.AllProjects)
            {
                string baseDir = Path.GetDirectoryName(project.FullPath);
                if (baseDir == null)
                {
                    continue;
                }
                foreach (var module in project.AllModules)
                {
                    string moduleFolderPath = Path.Combine(baseDir, module.Path);
                    if (!Directory.Exists(moduleFolderPath))
                    {
                        string details = string.Format("Project contains a module '{0}' but corresponding folder doesn't exist.", module.Path);
                        ValidationErrors.Add(new ValidationError(project, "Module folder doesn't exists", details, ErrorLevel.Error));
                        continue;
                    }

                    string moduleProjectPath = Path.GetFullPath(Path.Combine(moduleFolderPath, ProjectsRepository.ProjectFilePattern));
                    if (!File.Exists(moduleProjectPath))
                    {
                        string details = string.Format("Project contains a module '{0}' but the folder doesn't contain a pom.xml.", module.Path);
                        ValidationErrors.Add(new ValidationError(project, "Module project doesn't exists", details, ErrorLevel.Error));
                        continue;
                    }

                    if (_repository.AllProjects.FirstOrDefault(p => PathOperations.ArePathesEqual(moduleProjectPath, p.FullPath)) == null)
                    {
                        string details = string.Format("Project contains a module '{0}', but corresponding project hasn't been loaded", module.Path);
                        var    fix     = new DelegatedFix
                        {
                            Title           = "Try to load the module",
                            DelegatedAction = () => _repository.LoadOneProject(moduleProjectPath)
                        };
                        var error = new ValidationError(project, "Module hasn't been loaded", details, ErrorLevel.Error);
                        error.AddFix(fix);
                        ValidationErrors.Add(error);
                        continue;
                    }
                }
            }
        }
Пример #2
0
        public ValidationResult Validate()
        {
            Project          project = _projectNode.Project;
            IParentReference parent  = project.Parent;

            if (parent == null)
            {
                return(ValidationResult.Good);
            }

            var error = new ValidationError(_projectNode.Project, "Project parent error", ErrorLevel.Warning);

            if (_externalModules.Contains(parent, true))
            {
                return(ValidationResult.Good);
            }

            if (_repository.ContainsProject(parent, true))
            {
                var    parentProject        = _repository.SelectProjectNodes(parent, true).Single();
                string resolvedPathToParent = PathOperations.GetRelativePath(_projectNode.FullPath, parentProject.FullPath);
                resolvedPathToParent = PathOperations.Normalize(resolvedPathToParent);

                if (!string.Equals(_projectNode.ParentPath, resolvedPathToParent, StringComparison.OrdinalIgnoreCase))
                {
                    error.Details = string.Format("Parent path '{0}' does not point to {1}, should be {2}",
                                                  _projectNode.ParentPath, parentProject, resolvedPathToParent);

                    error.AddFix(new RelativePathFix(project, resolvedPathToParent));
                    _validationOutput.AddError(error);
                }

                return(ValidationResult.Good);
            }

            var potencial = _repository.SelectProjectNodes(parent, false).ToArray();

            if (potencial.Length == 0)
            {
                error.Details = string.Format("Project {0} rererences unknown parent {1}.", _projectNode, parent);
                error.AddFix(new AddToExternalFix(_externalModules, parent));

                // REVIEW: try to resolve via parent path
            }
            else if (potencial.Length == 1)
            {
                error.Details = string.Format("Project {0} references does not match actual version {1}.", _projectNode.Project, parent);                 // TODO: better message
                error.AddFix(new VersionFix(_projectNode.Project, parent, potencial.Single().Version));
            }
            else
            {
                error.Details = string.Format("Project {0} references different plugin version {1}.", _projectNode.Project, parent);
                foreach (var candicate in potencial)
                {
                    error.AddFix(new VersionFix(_projectNode.Project, parent, candicate.Version));
                }
            }

            _validationOutput.AddError(error);
            return(ValidationResult.Good);
        }