コード例 #1
0
        private void ValidateExternalModules()
        {
            foreach (ExternalModule externalModule in _externalModules.Items)
            {
                if (!_repository.IsItUsed(externalModule))
                {
                    ValidationError error = new ValidationError(
                        externalModule,
                        "The external module is not used",
                        externalModule.ToString(), ErrorLevel.Info);

                    ExternalModule module = externalModule;
                    DelegatedFix   fix    = new DelegatedFix
                    {
                        ShouldBeConfirmed = true,
                        Title             = "Delete external module",
                        DelegatedAction   = () =>
                        {
                            _externalModules.Remove(module);
                            _externalModules.AllModules.Save();
                        }
                    };
                    error.AddFix(fix);
                    ValidationErrors.Add(error);
                }
            }
        }
コード例 #2
0
        public ValidationResult Validate()
        {
            foreach (IPlugin plugin in _projectNode
                     .Project.AllPlugins.Where(
                         p => p.HasSpecificVersion &&
                         !_repository.ContainsProject(p, true) &&
                         !_externalModules.Contains(p, true)))
            {
                var error = new ValidationError(
                    _projectNode.Project, "Project plugin error",
                    ErrorLevel.Warning);

                var potencial = _repository.SelectProjectNodes(plugin, false).ToArray();
                if (potencial.Length == 0)
                {
                    error.Details = string.Format("Project {0} uses undefined plugin {1}.", _projectNode.Project, plugin);
                    error.AddFix(new AddToExternalFix(_externalModules, plugin));
                }
                else if (potencial.Length == 1)
                {
                    error.Details = string.Format("Project {0} references different plugin version {1}.", _projectNode.Project, plugin);
                    error.AddFix(new VersionFix(_projectNode.Project, plugin, potencial.Single().Version));
                }
                else
                {
                    error.Details = string.Format("Project {0} references different plugin version {1}.", _projectNode.Project, plugin);
                    foreach (var candicate in potencial)
                    {
                        error.AddFix(new VersionFix(_projectNode.Project, plugin, candicate.Version));
                    }
                }

                _validationOutput.AddError(error);
            }
            return(ValidationResult.Good);
        }
コード例 #3
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;
                    }
                }
            }
        }
コード例 #4
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);
        }
コード例 #5
0
        private void ValidateDependencies()
        {
            foreach (ProjectNode projectNode in _repository.AllProjectNodes)
            {
                Project project = projectNode.Project;

                foreach (IDependency dependencyReference in project.AllDependencies)
                {
                    var error = new ValidationError(projectNode.Project, "Project dependency error", ErrorLevel.Error);
                    if (dependencyReference.HasSpecificVersion && _repository.ContainsProject(dependencyReference, true))                     // REVIEW: inhereited too
                    {
                        if (!projectNode.IsSnapshot && dependencyReference.IsSnapshot())
                        {
                            error.Details = string.Format("Release project {0} depends on SNAPSHOT project {1}.", project, dependencyReference);
                            error.AddFix(new SwitchToSnapshotFix(_repository, projectNode));
                            AddError(error);
                        }
                        continue;                         // found, nothing to validate
                    }
                    var potencial = _repository.SelectProjectNodes(dependencyReference, false).ToArray();
                    if (potencial.Length == 0)
                    {
                        if (!IsDependencyIgnored(dependencyReference))                         // TODO: should we ignore specific version???
                        {
                            error.Details = string.Format("Project {0} dependency {1} not resolved.", projectNode.Project, dependencyReference);
                            error.AddFix(new AddToExternalFix(_externalModules, dependencyReference));
                            ValidationErrors.Add(error);
                        }
                        continue;
                    }
                    if (potencial.Length > 1)
                    {
                        error.Details = string.Format("Project {0} dependency {1} not resolved. Multiple corresponding projects found.", projectNode.Project, dependencyReference);
                        foreach (var candicate in potencial)
                        {
                            error.AddFix(new VersionFix(projectNode.Project, dependencyReference, candicate.Version));
                        }
                        AddError(error);
                        continue;
                    }

                    var    dependencyProject     = potencial.Single();
                    string realDependencyVersion = dependencyProject.Version;

                    if (!dependencyReference.HasSpecificVersion)
                    {
                        error.Level   = ErrorLevel.Warning;
                        error.Details = string.Format("Project {0} depends on {1}:{2} has no version specified.",
                                                      projectNode.Project, dependencyReference.GroupId, dependencyReference.ArtifactId);
                        error.AddFix(new VersionFix(projectNode.Project, dependencyReference, realDependencyVersion));
                        AddError(error);
                        continue;
                    }

                    if (!string.IsNullOrEmpty(realDependencyVersion) && realDependencyVersion != dependencyReference.Version)
                    {
                        error.Details = string.Format("Project {0} depends on {1} but tree contains {2}.",
                                                      projectNode.Project, dependencyReference, dependencyProject);

                        error.AddFix(new VersionFix(projectNode.Project, dependencyReference, realDependencyVersion));
                        ValidationErrors.Add(error);
                    }
                }
            }
        }