449
449
< div id ="header ">
450
450
< h1 > ArchUnit User Guide</ h1 >
451
451
< div class ="details ">
452
- < span id ="revnumber "> version 0.18 .0</ span >
452
+ < span id ="revnumber "> version 0.19 .0</ span >
453
453
</ div >
454
454
< div id ="toc " class ="toc2 ">
455
455
< div id ="toctitle "> Table of Contents</ div >
@@ -530,6 +530,7 @@ <h1>ArchUnit User Guide</h1>
530
530
< li > < a href ="#_overriding_configuration "> 10.1. Overriding configuration</ a > </ li >
531
531
< li > < a href ="#_configuring_the_resolution_behavior "> 10.2. Configuring the Resolution Behavior</ a > </ li >
532
532
< li > < a href ="#_md5_sums_of_classes "> 10.3. MD5 Sums of Classes</ a > </ li >
533
+ < li > < a href ="#_custom_error_messages "> 10.4. Custom Error Messages</ a > </ li >
533
534
</ ul >
534
535
</ li >
535
536
</ ul >
@@ -615,7 +616,7 @@ <h3 id="_junit_4"><a class="anchor" href="#_junit_4"></a>2.1. JUnit 4</h3>
615
616
< pre class ="highlightjs highlight nowrap "> < code data-lang ="xml " class ="language-xml hljs "> <dependency>
616
617
<groupId>com.tngtech.archunit</groupId>
617
618
<artifactId>archunit-junit4</artifactId>
618
- <version>0.18 .0</version>
619
+ <version>0.19 .0</version>
619
620
<scope>test</scope>
620
621
</dependency></ code > </ pre >
621
622
</ div >
@@ -624,7 +625,7 @@ <h3 id="_junit_4"><a class="anchor" href="#_junit_4"></a>2.1. JUnit 4</h3>
624
625
< div class ="title "> build.gradle</ div >
625
626
< div class ="content ">
626
627
< pre class ="highlightjs highlight nowrap "> < code class ="language-none hljs "> dependencies {
627
- testImplementation 'com.tngtech.archunit:archunit-junit4:0.18 .0'
628
+ testImplementation 'com.tngtech.archunit:archunit-junit4:0.19 .0'
628
629
}</ code > </ pre >
629
630
</ div >
630
631
</ div >
@@ -645,7 +646,7 @@ <h3 id="_junit_5"><a class="anchor" href="#_junit_5"></a>2.2. JUnit 5</h3>
645
646
< pre class ="highlightjs highlight nowrap "> < code data-lang ="xml " class ="language-xml hljs "> <dependency>
646
647
<groupId>com.tngtech.archunit</groupId>
647
648
<artifactId>archunit-junit5</artifactId>
648
- <version>0.18 .0</version>
649
+ <version>0.19 .0</version>
649
650
<scope>test</scope>
650
651
</dependency></ code > </ pre >
651
652
</ div >
@@ -654,7 +655,7 @@ <h3 id="_junit_5"><a class="anchor" href="#_junit_5"></a>2.2. JUnit 5</h3>
654
655
< div class ="title "> build.gradle</ div >
655
656
< div class ="content ">
656
657
< pre class ="highlightjs highlight nowrap "> < code class ="language-none hljs "> dependencies {
657
- testImplementation 'com.tngtech.archunit:archunit-junit5:0.18 .0'
658
+ testImplementation 'com.tngtech.archunit:archunit-junit5:0.19 .0'
658
659
}</ code > </ pre >
659
660
</ div >
660
661
</ div >
@@ -671,7 +672,7 @@ <h3 id="_other_test_frameworks"><a class="anchor" href="#_other_test_frameworks"
671
672
< pre class ="highlightjs highlight nowrap "> < code data-lang ="xml " class ="language-xml hljs "> <dependency>
672
673
<groupId>com.tngtech.archunit</groupId>
673
674
<artifactId>archunit</artifactId>
674
- <version>0.18 .0</version>
675
+ <version>0.19 .0</version>
675
676
<scope>test</scope>
676
677
</dependency></ code > </ pre >
677
678
</ div >
@@ -680,7 +681,7 @@ <h3 id="_other_test_frameworks"><a class="anchor" href="#_other_test_frameworks"
680
681
< div class ="title "> build.gradle</ div >
681
682
< div class ="content ">
682
683
< pre class ="highlightjs highlight nowrap "> < code class ="language-none hljs "> dependencies {
683
- testImplementation 'com.tngtech.archunit:archunit:0.18 .0'
684
+ testImplementation 'com.tngtech.archunit:archunit:0.19 .0'
684
685
}</ code > </ pre >
685
686
</ div >
686
687
</ div >
@@ -2125,6 +2126,14 @@ <h4 id="_configuration"><a class="anchor" href="#_configuration"></a>8.5.2. Conf
2125
2126
< pre class ="highlightjs highlight nowrap "> < code class ="language-none hljs "> -Darchunit.freeze.store.default.allowStoreCreation=true</ code > </ pre >
2126
2127
</ div >
2127
2128
</ div >
2129
+ < div class ="paragraph ">
2130
+ < p > It is also possible to allow all violations to be "refrozen", i.e. the store will just be updated
2131
+ with the current state, and the reported result will be success. Thus, it is effectively the same behavior
2132
+ as if all rules would never have been frozen.
2133
+ This can e.g. make sense, because current violations are consciously accepted and should be added to the store,
2134
+ or because the format of some violations has changed. The respective property to allow refreezing
2135
+ all current violations is < code > freeze.refreeze=true</ code > , where the default is < code > false</ code > .</ p >
2136
+ </ div >
2128
2137
</ div >
2129
2138
< div class ="sect3 ">
2130
2139
< h4 id ="_extension "> < a class ="anchor " href ="#_extension "> </ a > 8.5.3. Extension</ h4 >
@@ -2525,7 +2534,7 @@ <h4 id="_controlling_the_import"><a class="anchor" href="#_controlling_the_impor
2525
2534
</ div >
2526
2535
< div class ="listingblock ">
2527
2536
< div class ="content ">
2528
- < pre class ="highlightjs highlight nowrap "> < code data-lang ="java " class ="language-java hljs "> @AnalyzeClasses(packages = {"com.myapp.subone", "com.myapp.subone "})</ code > </ pre >
2537
+ < pre class ="highlightjs highlight nowrap "> < code data-lang ="java " class ="language-java hljs "> @AnalyzeClasses(packages = {"com.myapp.subone", "com.myapp.subtwo "})</ code > </ pre >
2529
2538
</ div >
2530
2539
</ div >
2531
2540
< div class ="paragraph ">
@@ -2782,6 +2791,54 @@ <h3 id="_md5_sums_of_classes"><a class="anchor" href="#_md5_sums_of_classes"></a
2782
2791
</ div >
2783
2792
</ div >
2784
2793
</ div >
2794
+ < div class ="sect2 ">
2795
+ < h3 id ="_custom_error_messages "> < a class ="anchor " href ="#_custom_error_messages "> </ a > 10.4. Custom Error Messages</ h3 >
2796
+ < div class ="paragraph ">
2797
+ < p > You can configure a custom format to display the failures of a rule.</ p >
2798
+ </ div >
2799
+ < div class ="paragraph ">
2800
+ < p > First Supply a custom implementation of</ p >
2801
+ </ div >
2802
+ < div class ="listingblock ">
2803
+ < div class ="content ">
2804
+ < pre class ="highlightjs highlight nowrap "> < code data-lang ="java " class ="language-java hljs "> com.tngtech.archunit.lang.FailureDisplayFormat</ code > </ pre >
2805
+ </ div >
2806
+ </ div >
2807
+ < div class ="paragraph ">
2808
+ < p > Then configure it</ p >
2809
+ </ div >
2810
+ < div class ="listingblock ">
2811
+ < div class ="title "> archunit.properties</ div >
2812
+ < div class ="content ">
2813
+ < pre class ="highlightjs highlight nowrap "> < code class ="language-none hljs "> failureDisplayFormat=some.pkg.MyCustomFailureDisplayFormat</ code > </ pre >
2814
+ </ div >
2815
+ </ div >
2816
+ < div class ="paragraph ">
2817
+ < p > One example would be to shorten the fully qualified class names in failure messages:</ p >
2818
+ </ div >
2819
+ < div class ="listingblock ">
2820
+ < div class ="content ">
2821
+ < pre class ="highlightjs highlight nowrap "> < code data-lang ="java " class ="language-java hljs "> private static class SimpleClassNameFailureFormat implements FailureDisplayFormat {
2822
+ @Override
2823
+ public String formatFailure(HasDescription rule, FailureMessages failureMessages, Priority priority) {
2824
+ String failureDetails = failureMessages.stream()
2825
+ .map(message -> message.replaceAll("<(?:\\w+\\.)+([A-Z][^>]*)>", "<$1>"))
2826
+ .collect(joining(lineSeparator()));
2827
+
2828
+ return String.format("Architecture Violation [Priority: %s] - Rule '%s' was violated (%s):%n%s",
2829
+ priority.asString(), rule.getDescription(), failureMessages.getInformationAboutNumberOfViolations(), failureDetails);
2830
+ }
2831
+ }</ code > </ pre >
2832
+ </ div >
2833
+ </ div >
2834
+ < div class ="paragraph ">
2835
+ < p > Note that due to the free format how violation texts can be composed,
2836
+ in particular by custom predicates and conditions,
2837
+ there is at the moment no more sophisticated way than plain text parsing.
2838
+ Users can tailor this to their specific environments where they know
2839
+ which sorts of failure formats can appear in practice.</ p >
2840
+ </ div >
2841
+ </ div >
2785
2842
</ div >
2786
2843
</ div >
2787
2844
</ div >
0 commit comments