Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion ArchUnitNET/Fluent/ConditionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,11 @@ var conditionResult in conditionElementResultsList
}
}

var identifier = new StringIdentifier(analyzedObject.FullName);
// The full name and the simple assembly name, so that objects with the same full name in
// different assemblies can be told apart. FreezingArchRule relies on this form.
var identifier = new StringIdentifier(
analyzedObject.FullName + ", " + (analyzedObject.Assembly?.Name ?? "")
);
return new EvaluationResult(
analyzedObject,
identifier,
Expand Down
61 changes: 54 additions & 7 deletions ArchUnitNET/Fluent/Freeze/FreezingArchRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,15 @@ public IEnumerable<EvaluationResult> Evaluate(Architecture architecture)
}
else
{
var frozenViolations = _violationStore.GetFrozenViolations(_frozenRule).ToList();
var frozenViolations = new HashSet<string>(
_violationStore
.GetFrozenViolations(_frozenRule)
.Select(violation => violation.Identifier)
);
var stillUnresolvedViolations = new List<StringIdentifier>();
foreach (var evalResult in evalResults)
{
if (
frozenViolations.Contains(
evalResult.EvaluatedObjectIdentifier,
new StringIdentifierComparer()
) && !evalResult.Passed
)
if (!evalResult.Passed && IsFrozen(evalResult, frozenViolations))
{
evalResultsIgnoringFrozen.Add(MarkAsPassed(evalResult));
stillUnresolvedViolations.Add(evalResult.EvaluatedObjectIdentifier);
Expand Down Expand Up @@ -98,6 +97,54 @@ public static FreezingArchRule Freeze(IArchRule rule)
return new FreezingArchRule(rule, new JsonViolationStore());
}

/// <summary>
/// Decides whether a failing result is covered by the frozen violations.
/// </summary>
/// <remarks>
/// Rules frozen before assembly-aware identifiers contain only the full name of a type or
/// member. Such a legacy entry freezes every failing object with that full name, also if
/// there are several of them in different assemblies; the old identifiers could not tell
/// them apart either. The next write replaces the entry with the new identifiers of all
/// these objects, so each rule migrates on its first run.
///
/// Only results whose identifier is exactly the new form of their evaluated object take
/// part in this fallback; see <see cref="LegacyFullName"/>.
/// Custom rules may pair an analyzed object with an identifier of their own, whose earlier
/// form was not necessarily the full name.
///
/// Legacy entries need no marker: an identifier in the new form always contains
/// <c>", "</c> before the assembly name, while full names never do (Mono.Cecil and the
/// loader separate parameters and generic arguments with a bare <c>","</c>). So an entry
/// can only equal a full name if it was written in the legacy form. This also migrates
/// entries of custom stores.
/// </remarks>
private static bool IsFrozen(EvaluationResult result, HashSet<string> frozenViolations)
{
if (frozenViolations.Contains(result.EvaluatedObjectIdentifier.Identifier))
{
return true;
}

var fullName = LegacyFullName(result);
return fullName != null && frozenViolations.Contains(fullName);
}

/// <summary>
/// The identifier the result would have had in a legacy store: the full name of the
/// evaluated object, if the result identifies it in the new form <c>FullName, Assembly</c>
/// that the fluent rules use.
/// Otherwise <c>null</c>, and the result can only match a frozen entry exactly.
/// </summary>
private static string LegacyFullName(EvaluationResult result)
{
return
result.EvaluatedObject is ICanBeAnalyzed analyzedObject
&& result.EvaluatedObjectIdentifier.Identifier
== analyzedObject.FullName + ", " + (analyzedObject.Assembly?.Name ?? "")
? analyzedObject.FullName
: null;
}

private static EvaluationResult MarkAsPassed(EvaluationResult evaluationResult)
{
return new EvaluationResult(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
{
"ArchRuleDescription": "Types that are \"ArchUnitNETTests.Fluent.FreezeTests+Violation\" or \"ArchUnitNETTests.Fluent.FreezeTests+Violation2\" should not be private",
"Violations": [
"ArchUnitNETTests.Fluent.FreezeTests+Violation",
"ArchUnitNETTests.Fluent.FreezeTests+Violation2"
"ArchUnitNETTests.Fluent.FreezeTests+Violation, ArchUnitNETTests",
"ArchUnitNETTests.Fluent.FreezeTests+Violation2, ArchUnitNETTests"
]
},
{
"ArchRuleDescription": "Types that are \"ArchUnitNETTests.Fluent.FreezeTests+Violation\" should be protected",
"Violations": [
"ArchUnitNETTests.Fluent.FreezeTests+Violation"
"ArchUnitNETTests.Fluent.FreezeTests+Violation, ArchUnitNETTests"
]
},
{
Expand Down
8 changes: 4 additions & 4 deletions ArchUnitNETTests/ArchUnitNET/Storage/FrozenRules.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
{
"ArchRuleDescription": "Types that are \"ArchUnitNETTests.Fluent.FreezeTests+Violation\" or \"ArchUnitNETTests.Fluent.FreezeTests+Violation2\" should not be private",
"Violations": [
"ArchUnitNETTests.Fluent.FreezeTests+Violation",
"ArchUnitNETTests.Fluent.FreezeTests+Violation2"
"ArchUnitNETTests.Fluent.FreezeTests+Violation, ArchUnitNETTests",
"ArchUnitNETTests.Fluent.FreezeTests+Violation2, ArchUnitNETTests"
]
},
{
"ArchRuleDescription": "Types that are \"ArchUnitNETTests.Fluent.FreezeTests+Violation\" should be protected",
"Violations": [
"ArchUnitNETTests.Fluent.FreezeTests+Violation"
"ArchUnitNETTests.Fluent.FreezeTests+Violation, ArchUnitNETTests"
]
},
{
"ArchRuleDescription": "Types that are \"ArchUnitNETTests.Fluent.FreezeTests+Violation\" or \"ArchUnitNETTests.Fluent.FreezeTests+Violation2\" should be public",
"Violations": [
"ArchUnitNETTests.Fluent.FreezeTests+Violation"
"ArchUnitNETTests.Fluent.FreezeTests+Violation, ArchUnitNETTests"
]
},
{
Expand Down
8 changes: 4 additions & 4 deletions ArchUnitNETTests/ArchUnitNET/Storage/FrozenRules.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<FrozenRules>
<FrozenRule ArchRule="Types that are &quot;ArchUnitNETTests.Fluent.FreezeTests+Violation&quot; or &quot;ArchUnitNETTests.Fluent.FreezeTests+Violation2&quot; should be public">
<Violation>ArchUnitNETTests.Fluent.FreezeTests+Violation</Violation>
<Violation>ArchUnitNETTests.Fluent.FreezeTests+Violation, ArchUnitNETTests</Violation>
</FrozenRule>
<FrozenRule ArchRule="Slices matching &quot;SlicesTestAssembly.MultipleSubnamespaces.(*)..&quot; should not depend on each other" />
<FrozenRule ArchRule="Types that are &quot;ArchUnitNETTests.Fluent.FreezeTests+Violation&quot; or &quot;ArchUnitNETTests.Fluent.FreezeTests+Violation2&quot; should not be private">
<Violation>ArchUnitNETTests.Fluent.FreezeTests+Violation</Violation>
<Violation>ArchUnitNETTests.Fluent.FreezeTests+Violation2</Violation>
<Violation>ArchUnitNETTests.Fluent.FreezeTests+Violation, ArchUnitNETTests</Violation>
<Violation>ArchUnitNETTests.Fluent.FreezeTests+Violation2, ArchUnitNETTests</Violation>
</FrozenRule>
<FrozenRule ArchRule="Types that are &quot;ArchUnitNETTests.Fluent.FreezeTests+Violation&quot; should be protected">
<Violation>ArchUnitNETTests.Fluent.FreezeTests+Violation</Violation>
<Violation>ArchUnitNETTests.Fluent.FreezeTests+Violation, ArchUnitNETTests</Violation>
</FrozenRule>
<FrozenRule ArchRule="Slices matching &quot;SlicesTestAssembly.MultipleSubnamespaces.(**)&quot; should not depend on each other">
<Violation>Slice Slice3</Violation>
Expand Down
Loading