Skip to content

Commit fbd2c2e

Browse files
committed
GH-182 - Use dedicated SliceAssignment to verify modularity.
The previous modularity verification arrangement assumed the default module detection strategy to be used. To properly support alternative implementations during the verification we now use a dedicated SliceAssignment implementation that assigns types to slices identified by the module they are located in.
1 parent d9f298c commit fbd2c2e

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

spring-modulith-core/src/main/java/org/springframework/modulith/core/ApplicationModules.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
import com.tngtech.archunit.core.importer.ImportOption;
4949
import com.tngtech.archunit.lang.EvaluationResult;
5050
import com.tngtech.archunit.lang.FailureReport;
51+
import com.tngtech.archunit.library.dependencies.SliceAssignment;
52+
import com.tngtech.archunit.library.dependencies.SliceIdentifier;
5153
import com.tngtech.archunit.library.dependencies.SlicesRuleDefinition;
5254

5355
/**
@@ -455,7 +457,7 @@ private ApplicationModules withSharedModules(Set<ApplicationModule> sharedModule
455457
private FailureReport assertNoCyclesFor(JavaPackage rootPackage) {
456458

457459
var result = SlicesRuleDefinition.slices() //
458-
.matching(rootPackage.getName().concat(".(*)..")) //
460+
.assignedFrom(new ApplicationModulesSliceAssignment())
459461
.should().beFreeOfCycles() //
460462
.evaluate(allClasses.that(resideInAPackage(rootPackage.getName().concat(".."))));
461463

@@ -728,4 +730,29 @@ private static List<String> topologicallySortModules(ApplicationModules modules)
728730
}
729731
}
730732
}
733+
734+
private class ApplicationModulesSliceAssignment implements SliceAssignment {
735+
736+
/*
737+
* (non-Javadoc)
738+
* @see com.tngtech.archunit.library.dependencies.SliceAssignment#getIdentifierOf(com.tngtech.archunit.core.domain.JavaClass)
739+
*/
740+
@Override
741+
public SliceIdentifier getIdentifierOf(JavaClass javaClass) {
742+
743+
return getModuleByType(javaClass)
744+
.map(ApplicationModule::getName)
745+
.map(SliceIdentifier::of)
746+
.orElse(SliceIdentifier.ignore());
747+
}
748+
749+
/*
750+
* (non-Javadoc)
751+
* @see com.tngtech.archunit.base.HasDescription#getDescription()
752+
*/
753+
@Override
754+
public String getDescription() {
755+
return "Appliction module slices " + ApplicationModules.this.modules.keySet();
756+
}
757+
}
731758
}

0 commit comments

Comments
 (0)