-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #12099: Add ArchUnit test to detect cycles in packages
- Loading branch information
1 parent
ba66ce2
commit c54f913
Showing
8 changed files
with
2,871 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2,776 changes: 2,776 additions & 0 deletions
2,776
config/archunit-store/7999d2d1-606c-4e14-a852-2cb0fa661f48
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# | ||
#Sat Sep 10 22:27:26 IST 2022 | ||
slices\ matching\ 'com.puppycrawl.tools.checkstyle.(**)'\ should\ be\ free\ of\ cycles=7999d2d1-606c-4e14-a852-2cb0fa661f48 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
src/test/java/com/puppycrawl/tools/checkstyle/internal/ArchUnitCyclesCheckTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/////////////////////////////////////////////////////////////////////////////////////////////// | ||
// checkstyle: Checks Java source code and other text files for adherence to a set of rules. | ||
// Copyright (C) 2001-2022 the original author or authors. | ||
// | ||
// This library is free software; you can redistribute it and/or | ||
// modify it under the terms of the GNU Lesser General Public | ||
// License as published by the Free Software Foundation; either | ||
// version 2.1 of the License, or (at your option) any later version. | ||
// | ||
// This library is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
// Lesser General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public | ||
// License along with this library; if not, write to the Free Software | ||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
/////////////////////////////////////////////////////////////////////////////////////////////// | ||
|
||
package com.puppycrawl.tools.checkstyle.internal; | ||
|
||
import static com.tngtech.archunit.library.dependencies.SlicesRuleDefinition.slices; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import com.tngtech.archunit.core.domain.JavaClasses; | ||
import com.tngtech.archunit.core.importer.ClassFileImporter; | ||
import com.tngtech.archunit.core.importer.ImportOption; | ||
import com.tngtech.archunit.lang.ArchRule; | ||
import com.tngtech.archunit.library.freeze.FreezingArchRule; | ||
|
||
public class ArchUnitCyclesCheckTest { | ||
|
||
/** | ||
* Tests that there are no | ||
* <a href="https://www.archunit.org/userguide/html/000_Index.html#_cycle_checks">cycles</a> | ||
* in the package dependencies. Currently the violations from this test are frozen using | ||
* <a href="https://www.archunit.org/userguide/html/000_Index.html#_freezing_arch_rules"> | ||
* FreezingArchRule</a>. | ||
* | ||
* <p>Whenever a new violation is introduced, the test will pass successfully but the frozen | ||
* violations will be updated. In that case, developers should check if the new violation is | ||
* expected or not. In both cases create a separate commit in the PR for discussing changes | ||
* in the violation store. | ||
* | ||
* <p>The frozen violations are present in {@code config/archunit-store} directory. | ||
*/ | ||
@Test | ||
public void testSlicesShouldBeFreeOfCycle() { | ||
final JavaClasses importedClasses = new ClassFileImporter() | ||
.withImportOption(ImportOption.Predefined.DO_NOT_INCLUDE_TESTS) | ||
.importPackages("com.puppycrawl.tools.checkstyle"); | ||
|
||
final ArchRule slicesShouldBeFreeOfCycle = FreezingArchRule.freeze( | ||
slices() | ||
.matching("com.puppycrawl.tools.checkstyle.(**)") | ||
.should().beFreeOfCycles()); | ||
|
||
slicesShouldBeFreeOfCycle.check(importedClasses); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# This will limit the maximum number of dependencies to report per cycle edge. | ||
# Note that ArchUnit will regardless always analyze all dependencies to detect cycles, | ||
# so this purely affects how many dependencies will be printed in the report. | ||
# Also note that this number will quickly affect the required heap since it scales with number. | ||
# of edges and number of cycles | ||
# default is 20 | ||
cycles.maxNumberOfDependenciesPerEdge=550 | ||
|
||
# This will limit the maximum number of cycles to detect and thus required CPU and heap. | ||
# default is 100 | ||
cycles.maxNumberToDetect=200 | ||
|
||
# The store will be updated with the current state, and the reported result will be success. | ||
# Just like freezing violation for the first time while creating the store. | ||
freeze.refreeze=true | ||
|
||
freeze.store.default.path=config/archunit-store |