Class FreezingArchRule
- java.lang.Object
-
- com.tngtech.archunit.library.freeze.FreezingArchRule
-
- All Implemented Interfaces:
HasDescription
,CanOverrideDescription<ArchRule>
,ArchRule
,CanBeEvaluated
@PublicAPI(usage=ACCESS) public final class FreezingArchRule extends java.lang.Object implements ArchRule
A decorator around an existingArchRule
that "freezes" the state of all violations on the first call instead of failing the test. This means in particular that the first run of aFreezingArchRule
will always pass. Consecutive calls will only fail if "unknown" violations are introduced (read below for further explanations when a violation is "unknown"). Once resolved, initially "known" violations will fail again if they were re-introduced.
You might consider using this class when introducing a newArchRule
to an existing project that causes too many violations to solve at the current time. A typical example is a huge legacy project where a new rule might cause thousands of violations. Even if it is impossible to fix all those violations at the moment, it is typically a good idea to a) make sure no further violations are introduced and b) incrementally fix those violations over time one by one.
FreezingArchRule
uses two concepts to support this use case:-
a
ViolationStore
to store the result of the current evaluation and retrieve the result of the previous evaluation of this rule.
The defaultViolationStore
stores violations in plain text files within the path specified byfreeze.store.default.path
of "archunit.properties" (default:archunit_store
)
A custom implementation can be provided in two ways. Either programmatically viapersistIn(ViolationStore)
, or by specifying the fully qualified class name within "archunit.properties", e.g.freeze.store=com.fully.qualified.MyViolationStore
-
a
ViolationLineMatcher
to decide which violations are "known", i.e. have already been present in the previous evaluation.
The defaultViolationLineMatcher
compares violations ignoring the line number of their source code location.
A custom implementation can be configured in two ways. Again either programmatically viaassociateViolationLinesVia(ViolationLineMatcher)
, or within "archunit.properties", e.g.freeze.lineMatcher=com.fully.qualified.MyViolationLineMatcher
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.tngtech.archunit.lang.ArchRule
ArchRule.Assertions, ArchRule.Factory, ArchRule.Transformation
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description FreezingArchRule
as(java.lang.String newDescription)
Allows to adjust the description of this object.FreezingArchRule
associateViolationLinesVia(ViolationLineMatcher matcher)
Allows to reconfigure how thisFreezingArchRule
will decide if an occurring violation is known or not.FreezingArchRule
because(java.lang.String reason)
void
check(JavaClasses classes)
EvaluationResult
evaluate(JavaClasses classes)
static FreezingArchRule
freeze(ArchRule rule)
java.lang.String
getDescription()
FreezingArchRule
persistIn(ViolationStore store)
Allows to reconfigure theViolationStore
to use.java.lang.String
toString()
-
-
-
Method Detail
-
check
@PublicAPI(usage=ACCESS) public void check(JavaClasses classes)
-
because
@PublicAPI(usage=ACCESS) public FreezingArchRule because(java.lang.String reason)
-
as
@PublicAPI(usage=ACCESS) public FreezingArchRule as(java.lang.String newDescription)
Description copied from interface:CanOverrideDescription
Allows to adjust the description of this object. Note that this method will not modify the current object, but instead return a new object with adjusted description.- Specified by:
as
in interfaceCanOverrideDescription<ArchRule>
- Parameters:
newDescription
- The description the result of this method will hold- Returns:
- A new equivalent object with adjusted description
-
evaluate
@PublicAPI(usage=ACCESS) public EvaluationResult evaluate(JavaClasses classes)
- Specified by:
evaluate
in interfaceCanBeEvaluated
-
getDescription
@PublicAPI(usage=ACCESS) public java.lang.String getDescription()
- Specified by:
getDescription
in interfaceHasDescription
-
persistIn
@PublicAPI(usage=ACCESS) public FreezingArchRule persistIn(ViolationStore store)
Allows to reconfigure theViolationStore
to use. TheViolationStore
will be used to store the initial state of aFreezingArchRule
and update this state on further evaluation of this rule.- Parameters:
store
- TheViolationStore
to use- Returns:
- An adjusted
FreezingArchRule
which will store violations in the passedViolationStore
- See Also:
FreezingArchRule
-
associateViolationLinesVia
@PublicAPI(usage=ACCESS) public FreezingArchRule associateViolationLinesVia(ViolationLineMatcher matcher)
Allows to reconfigure how thisFreezingArchRule
will decide if an occurring violation is known or not.- Parameters:
matcher
- AViolationLineMatcher
that decides which lines of a violation description are known and which are unknown and should cause a failure of this rule- Returns:
- An adjusted
FreezingArchRule
which will compare occurring violations to stored ones with the givenViolationLineMatcher
- See Also:
FreezingArchRule
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
freeze
@PublicAPI(usage=ACCESS) public static FreezingArchRule freeze(ArchRule rule)
- Parameters:
rule
- AnArchRule
that should be "frozen" on the first call, i.e. all occurring violations will be stored for comparison on consecutive calls.- Returns:
- A
FreezingArchRule
wrapping the original rule - See Also:
FreezingArchRule
-
-