internal /*for testing purposes*/ bool TryUpdateExistingProjectRuleSet(string solutionRuleSetPath, string projectRuleSetRootFolder, string currentRuleSet, out string existingRuleSetPath, out RuleSet existingRuleSet) { existingRuleSetPath = null; existingRuleSet = null; if (ShouldIgnoreConfigureRuleSetValue(currentRuleSet)) { return(false); } existingRuleSetPath = PathHelper.ResolveRelativePath(currentRuleSet, projectRuleSetRootFolder); if (!PathHelper.IsPathRootedUnderRoot(existingRuleSetPath, projectRuleSetRootFolder)) { // Not our file (i.e. absolute path to some other ruleset) existingRuleSetPath = null; return(false); } if (this.AlreadyUpdatedExistingRuleSetPaths.TryGetValue(existingRuleSetPath, out existingRuleSet)) { return(true); } existingRuleSet = this.ruleSetSerializer.LoadRuleSet(existingRuleSetPath); if (existingRuleSet == null) { existingRuleSetPath = null; return(false); } RuleSetHelper.UpdateExistingProjectRuleSet(existingRuleSet, solutionRuleSetPath); this.AlreadyUpdatedExistingRuleSetPaths.Add(existingRuleSetPath, existingRuleSet); return(true); }
/// <summary> /// Attempts to fix the conflicts by ensuring that the server ruleset is included with the expected Include Action /// </summary> /// <returns>Whether all conflicts were resolved</returns> private bool TryResolveIncludeConflicts(RuleSet baselineRuleSet, RuleSet targetRuleSet) { Debug.Assert(baselineRuleSet != null); Debug.Assert(targetRuleSet != null); Debug.Assert(!string.IsNullOrWhiteSpace(baselineRuleSet.FilePath)); Debug.Assert(!string.IsNullOrWhiteSpace(targetRuleSet.FilePath)); RuleSetHelper.UpdateExistingProjectRuleSet(targetRuleSet, baselineRuleSet.FilePath); RuleConflictInfo conflicts1stAttempt = this.FindConflictsCore(baselineRuleSet, targetRuleSet); return(!conflicts1stAttempt.HasConflicts); }
public void RuleSetHelper_UpdateExistingProjectRuleSet() { // Arrange const string existingProjectRuleSetPath = @"X:\MySolution\ProjectOne\proj1.ruleset"; const string existingInclude = @"..\SolutionRuleSets\sonarqube1.ruleset"; const string newSolutionRuleSetPath = @"X:\MySolution\SolutionRuleSets\sonarqube2.ruleset"; const string expectedInclude = @"..\SolutionRuleSets\sonarqube2.ruleset"; var existingProjectRuleSet = TestRuleSetHelper.CreateTestRuleSet(existingProjectRuleSetPath); existingProjectRuleSet.RuleSetIncludes.Add(new RuleSetInclude(existingInclude, RuleAction.Default)); var expectedRuleSet = TestRuleSetHelper.CreateTestRuleSet(existingProjectRuleSetPath); expectedRuleSet.RuleSetIncludes.Add(new RuleSetInclude(expectedInclude, RuleAction.Default)); // Act RuleSetHelper.UpdateExistingProjectRuleSet(existingProjectRuleSet, newSolutionRuleSetPath); // Assert RuleSetAssert.AreEqual(expectedRuleSet, existingProjectRuleSet, "Update should delete previous solution rulesets, and replace them with a new one provide"); }