示例#1
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);
        }
示例#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);
        }
示例#3
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);
                    }
                }
            }
        }