public void Execute() { var queue = new Queue <IProject>(); var extractor = new ProjectDataExtractor(); foreach (var project in _projects.AllProjects.Where(pn => pn.Version.IsSnapshot)) // first, deal with explicit version { project.Version = _version.IsDefined ? project.Version.SwitchSnapshotToRelease(_version) : project.Version.SwitchSnapshotToRelease(_build, _postfix); foreach (var dependentProject in _projects.AllProjects) { dependentProject.Operations().PropagateVersionToUsages(project); if (!dependentProject.Version.IsDefined && dependentProject.Operations().HasProjectAsParent(project)) { queue.Enqueue(dependentProject); } } } while (queue.Count != 0) // handle queue of projects with inherited version, no need to switch, it is done already, only propagate { var project = queue.Dequeue(); var projectReference = extractor.Extract(project); foreach (var dependentProject in _projects.AllProjects) { dependentProject.Operations().PropagateVersionToUsages(projectReference); if (!dependentProject.Version.IsDefined && dependentProject.Operations().HasProjectAsParent(projectReference)) { queue.Enqueue(dependentProject); } } } }
public IEnumerable <IProjectValidationProblem> Validate(IExecutionContext context, IProject project) { foreach (var module in project.Operations().AllModules) { var extractor = new ProjectDataExtractor(); IProject moduleProject; if (context.TryGetModule(project, module.Path, out moduleProject)) { if (extractor.Extract(project).Version.IsSnapshot&& !extractor.Extract(moduleProject).Version.IsSnapshot) { yield return(new ValidationProblem("modulereleasesnapshot") { ProjectReference = project, Severity = ProblemSeverity.ProjectWarning, Description = string.Format("try to build module in release during snapshot build: {0}", module.Path) }); } } else { yield return(new ValidationProblem("modulemissing") { ProjectReference = project, Severity = ProblemSeverity.ProjectWarning, Description = string.Format("module {0} not found", module.Path) }); } // REVIEW: move to tree integrity // 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; // } } }
public bool TryGetProject(IProjectReference reference, out IProject project, bool strictVersion = true) { var operation = reference.ReferenceOperations(); project = AllProjects. SingleOrDefault(p => { var r = _extractor.Extract(p); return(operation.ReferenceEqualTo(r, strictVersion)); }); return(project != null); }
public void ExecuteFor(IProject targetProject, int?position = null, int?stopAtPosition = null) { // var selected = _views.AllViews.Where(v => v.Checked).Select(v => v.ProjectNode); var searchOptions = new SearchOptions { LookForDependent = true, LookForParents = true, LookForPlugin = true, OnlyDirectUsages = true, StrictVersion = false }; var selector = new DependencySelector(_projects, searchOptions); var extractor = new ProjectDataExtractor(); var queue = new Queue <IProject>(); queue.Enqueue(targetProject); while (queue.Count != 0) { var project = queue.Dequeue(); if (project.Version.IsRelease) // explicit release { project.Version = project.Version.Operations().ToSnapshotWithVersionIncrement(position, stopAtPosition); } else if (project.Version.IsSnapshot) // explicit snapshot, just propogate { } else if (!project.Version.IsDefined && project.Parent != null && project.Parent.Version.IsRelease) // inherited from release { project.Version = project.Parent.Version.Operations().ToSnapshotWithVersionIncrement(position, stopAtPosition); // make it explicit } else if (!project.Version.IsDefined && project.Parent != null && project.Parent.Version.IsSnapshot) // inherited from snapshot, just propogate { } else { throw new InvalidOperationException($"why project {project} in queue"); } var reference = extractor.Extract(project); foreach (var dependentProject in selector.SelectUsages(reference)) { dependentProject.Operations().PropagateVersionToUsages(reference); if (dependentProject.Operations().HasProjectAsParent(reference)) { queue.Enqueue(dependentProject); } } } }
public IEnumerable <IProjectValidationProblem> Validate(IExecutionContext context, IProject project) { var extractor = new ProjectDataExtractor(); var extracted = extractor.Extract(project); var operation = extracted.ReferenceOperations(); var potencial = context.AllProjects .Where(p => p != project) .Select(extractor.Extract) .Where(pe => operation.ReferenceEqualTo(pe)); var external = context.AllExternalModules .Where(ex => operation.ReferenceEqualTo(ex)); return(potencial .Concat(external) .Select(failed => new ValidationProblem("duplication") { ProjectReference = project, Severity = ProblemSeverity.ProjectFatal, Description = string.Format("duplication {0}", failed) })); }
// REVIEW need logical refactoring private IProjectValidationProblem ValidateInternal(IExecutionContext context, IProject project) { var parentReference = project.Parent; if (parentReference == null) { return(null); } var extractor = new ProjectDataExtractor(); IProject parentByPath; if (context.TryGetParentByPath(project, out parentByPath)) { var resolved = extractor.Extract(parentByPath); if (project.Operations().HasProjectAsParent(resolved)) { return(null); } if (project.Operations().HasProjectAsParent(resolved, false)) { return(new ValidationProblem("actualparentversion") // TODO: fixable { ProjectReference = project, Severity = ProblemSeverity.ProjectWarning, Description = string.Format("parent reference version {0} is different from actual parent {1}.", project.Parent, resolved) }); } } var validation = new ReferenceValidator(context); var result = validation.ValidateReference(project, parentReference, "parent"); if (result != null) { return(result); } // previosly found exact match, but it includes including external modules, should be ignored if (string.IsNullOrEmpty(parentReference.RelativePath) && context.IsExternalModule(parentReference)) { return(null); } // exact match found, but path is wrong return(new ValidationProblem("parentpath") // TODO: fixable { ProjectReference = project, Severity = ProblemSeverity.ProjectWarning, Description = string.Format("incorrect relative path ({1}) to parent {0}", project.Parent, project.Parent.RelativePath) }); // var parentProject = _repository.SelectProjectNodes(parent, true).Single(); // string resolvedPathToParent = PathOperations.GetRelativePath(_projectNode.FullPath, parentProject.FullPath); // resolvedPathToParent = PathOperations.Normalize(resolvedPathToParent); // if (!string.Equals(_projectNode.RelativeParentPath, resolvedPathToParent, StringComparison.OrdinalIgnoreCase)) // { // error.Details = string.Format("Parent path '{0}' does not point to {1}, should be {2}", // _projectNode.RelativeParentPath, parentProject, resolvedPathToParent); // error.AddFix(new RelativePathFix(project, resolvedPathToParent)); // _validationOutput.AddError(error); }
public void EmptyVersionTest() { var resolved = _extractor.Extract(Project.Object); Assert.That(resolved.Version.IsDefined, Is.False); }