GH-9 - Rename core, public abstractions from Module to ApplicationModule.
Remove obsolete @since tags and deprecations.
This commit is contained in:
@@ -61,10 +61,10 @@ import com.tngtech.archunit.thirdparty.com.google.common.base.Suppliers;
|
||||
* @author Oliver Drotbohm
|
||||
*/
|
||||
@EqualsAndHashCode(doNotUseGetters = true)
|
||||
public class Module {
|
||||
public class ApplicationModule {
|
||||
|
||||
private final @Getter JavaPackage basePackage;
|
||||
private final ModuleInformation information;
|
||||
private final ApplicationModuleInformation information;
|
||||
private final @Getter NamedInterfaces namedInterfaces;
|
||||
private final boolean useFullyQualifiedModuleNames;
|
||||
|
||||
@@ -72,10 +72,10 @@ public class Module {
|
||||
private final Supplier<Classes> entities;
|
||||
private final Supplier<List<EventType>> publishedEvents;
|
||||
|
||||
Module(JavaPackage basePackage, boolean useFullyQualifiedModuleNames) {
|
||||
ApplicationModule(JavaPackage basePackage, boolean useFullyQualifiedModuleNames) {
|
||||
|
||||
this.basePackage = basePackage;
|
||||
this.information = ModuleInformation.of(basePackage);
|
||||
this.information = ApplicationModuleInformation.of(basePackage);
|
||||
this.namedInterfaces = NamedInterfaces.discoverNamedInterfaces(basePackage);
|
||||
this.useFullyQualifiedModuleNames = useFullyQualifiedModuleNames;
|
||||
|
||||
@@ -92,7 +92,7 @@ public class Module {
|
||||
return information.getDisplayName();
|
||||
}
|
||||
|
||||
public List<Module> getDependencies(Modules modules, DependencyType... type) {
|
||||
public List<ApplicationModule> getDependencies(ApplicationModules modules, DependencyType... type) {
|
||||
|
||||
return getAllModuleDependencies(modules) //
|
||||
.filter(it -> type.length == 0 ? true : Arrays.stream(type).anyMatch(it::hasType)) //
|
||||
@@ -108,7 +108,7 @@ public class Module {
|
||||
* @param modules must not be {@literal null}.
|
||||
* @return
|
||||
*/
|
||||
public List<JavaClass> getEventsListenedTo(Modules modules) {
|
||||
public List<JavaClass> getEventsListenedTo(ApplicationModules modules) {
|
||||
|
||||
Assert.notNull(modules, "Modules must not be null!");
|
||||
|
||||
@@ -143,35 +143,20 @@ public class Module {
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all types that are considered aggregate roots.
|
||||
*
|
||||
* @param modules must not be {@literal null}.
|
||||
* @return
|
||||
* @deprecated since 1.3, use {@link #getAggregateRoots()} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public List<JavaClass> getAggregateRoots(Modules modules) {
|
||||
|
||||
Assert.notNull(modules, "Modules must not be null!");
|
||||
|
||||
return getAggregateRoots();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all modules that contain types which the types of the current module depend on.
|
||||
*
|
||||
* @param modules must not be {@literal null}.
|
||||
* @return
|
||||
*/
|
||||
public Stream<Module> getBootstrapDependencies(Modules modules) {
|
||||
public Stream<ApplicationModule> getBootstrapDependencies(ApplicationModules modules) {
|
||||
|
||||
Assert.notNull(modules, "Modules must not be null!");
|
||||
|
||||
return getBootstrapDependencies(modules, DependencyDepth.IMMEDIATE);
|
||||
}
|
||||
|
||||
public Stream<Module> getBootstrapDependencies(Modules modules, DependencyDepth depth) {
|
||||
public Stream<ApplicationModule> getBootstrapDependencies(ApplicationModules modules, DependencyDepth depth) {
|
||||
|
||||
Assert.notNull(modules, "Modules must not be null!");
|
||||
Assert.notNull(depth, "Dependency depth must not be null!");
|
||||
@@ -186,15 +171,15 @@ public class Module {
|
||||
* @param depth must not be {@literal null}.
|
||||
* @return
|
||||
*/
|
||||
public Stream<JavaPackage> getBasePackages(Modules modules, DependencyDepth depth) {
|
||||
public Stream<JavaPackage> getBasePackages(ApplicationModules modules, DependencyDepth depth) {
|
||||
|
||||
Assert.notNull(modules, "Modules must not be null!");
|
||||
Assert.notNull(depth, "Dependency depth must not be null!");
|
||||
|
||||
Stream<Module> dependencies = streamDependencies(modules, depth);
|
||||
Stream<ApplicationModule> dependencies = streamDependencies(modules, depth);
|
||||
|
||||
return Stream.concat(Stream.of(this), dependencies) //
|
||||
.map(Module::getBasePackage);
|
||||
.map(ApplicationModule::getBasePackage);
|
||||
}
|
||||
|
||||
public List<SpringBean> getSpringBeans() {
|
||||
@@ -212,7 +197,7 @@ public class Module {
|
||||
}
|
||||
|
||||
public boolean contains(@Nullable Class<?> type) {
|
||||
return type != null && getType(type.getName()).isPresent();
|
||||
return (type != null) && getType(type.getName()).isPresent();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -220,7 +205,6 @@ public class Module {
|
||||
*
|
||||
* @param candidate must not be {@literal null} or empty.
|
||||
* @return will never be {@literal null}.
|
||||
* @since 1.1
|
||||
*/
|
||||
public Optional<JavaClass> getType(String candidate) {
|
||||
|
||||
@@ -245,11 +229,11 @@ public class Module {
|
||||
return namedInterfaces.stream().anyMatch(it -> it.contains(type));
|
||||
}
|
||||
|
||||
public void verifyDependencies(Modules modules) {
|
||||
public void verifyDependencies(ApplicationModules modules) {
|
||||
detectDependencies(modules).throwIfPresent();
|
||||
}
|
||||
|
||||
public Violations detectDependencies(Modules modules) {
|
||||
public Violations detectDependencies(ApplicationModules modules) {
|
||||
|
||||
return getAllModuleDependencies(modules) //
|
||||
.map(it -> it.isValidDependencyWithin(modules)) //
|
||||
@@ -265,7 +249,7 @@ public class Module {
|
||||
return toString(null);
|
||||
}
|
||||
|
||||
public String toString(@Nullable Modules modules) {
|
||||
public String toString(@Nullable ApplicationModules modules) {
|
||||
|
||||
StringBuilder builder = new StringBuilder("## ").append(getDisplayName()).append(" ##\n");
|
||||
builder.append("> Logical name: ").append(getName()).append('\n');
|
||||
@@ -282,11 +266,11 @@ public class Module {
|
||||
|
||||
if (modules != null) {
|
||||
|
||||
List<Module> dependencies = getBootstrapDependencies(modules).collect(Collectors.toList());
|
||||
List<ApplicationModule> dependencies = getBootstrapDependencies(modules).collect(Collectors.toList());
|
||||
|
||||
builder.append("> Direct module dependencies: ");
|
||||
builder.append(dependencies.isEmpty() ? "none"
|
||||
: dependencies.stream().map(Module::getName).collect(Collectors.joining(", ")));
|
||||
: dependencies.stream().map(ApplicationModule::getName).collect(Collectors.joining(", ")));
|
||||
builder.append('\n');
|
||||
}
|
||||
|
||||
@@ -309,12 +293,12 @@ public class Module {
|
||||
|
||||
/**
|
||||
* Returns all allowed module dependencies, either explicitly declared or defined as shared on the given
|
||||
* {@link Modules} instance.
|
||||
* {@link ApplicationModules} instance.
|
||||
*
|
||||
* @param modules must not be {@literal null}.
|
||||
* @return
|
||||
*/
|
||||
List<Module> getAllowedDependencies(Modules modules) {
|
||||
List<ApplicationModule> getAllowedDependencies(ApplicationModules modules) {
|
||||
|
||||
Assert.notNull(modules, "Modules must not be null!");
|
||||
|
||||
@@ -324,7 +308,7 @@ public class Module {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
Stream<Module> explicitlyDeclaredModules = allowedDependencyNames.stream() //
|
||||
Stream<ApplicationModule> explicitlyDeclaredModules = allowedDependencyNames.stream() //
|
||||
.map(modules::getModuleByName) //
|
||||
.flatMap(it -> it.map(Stream::of).orElse(Stream.empty()));
|
||||
|
||||
@@ -338,7 +322,6 @@ public class Module {
|
||||
*
|
||||
* @param candidate must not be {@literal null} or empty.
|
||||
* @return
|
||||
* @since 1.1
|
||||
*/
|
||||
boolean contains(String candidate) {
|
||||
|
||||
@@ -373,13 +356,13 @@ public class Module {
|
||||
Stream.of(type));
|
||||
}
|
||||
|
||||
private Stream<ModuleDependency> getAllModuleDependencies(Modules modules) {
|
||||
private Stream<ModuleDependency> getAllModuleDependencies(ApplicationModules modules) {
|
||||
|
||||
return basePackage.stream() //
|
||||
.flatMap(it -> getModuleDependenciesOf(it, modules));
|
||||
}
|
||||
|
||||
private Stream<Module> streamDependencies(Modules modules, DependencyDepth depth) {
|
||||
private Stream<ApplicationModule> streamDependencies(ApplicationModules modules, DependencyDepth depth) {
|
||||
|
||||
switch (depth) {
|
||||
|
||||
@@ -395,7 +378,7 @@ public class Module {
|
||||
}
|
||||
}
|
||||
|
||||
private Stream<Module> getDirectModuleDependencies(Modules modules) {
|
||||
private Stream<ApplicationModule> getDirectModuleDependencies(ApplicationModules modules) {
|
||||
|
||||
return getSpringBeansInternal().stream() //
|
||||
.flatMap(it -> ModuleDependency.fromType(it)) //
|
||||
@@ -405,7 +388,7 @@ public class Module {
|
||||
.flatMap(it -> it.map(Stream::of).orElseGet(Stream::empty));
|
||||
}
|
||||
|
||||
private Stream<ModuleDependency> getModuleDependenciesOf(JavaClass type, Modules modules) {
|
||||
private Stream<ModuleDependency> getModuleDependenciesOf(JavaClass type, ApplicationModules modules) {
|
||||
|
||||
Stream<ModuleDependency> injections = ModuleDependency.fromType(type) //
|
||||
.filter(it -> isDependencyToOtherModule(it.getTarget(), modules)); //
|
||||
@@ -417,7 +400,7 @@ public class Module {
|
||||
return Stream.concat(injections, directDependencies).distinct();
|
||||
}
|
||||
|
||||
private boolean isDependencyToOtherModule(JavaClass dependency, Modules modules) {
|
||||
private boolean isDependencyToOtherModule(JavaClass dependency, ApplicationModules modules) {
|
||||
return modules.contains(dependency) && !contains(dependency);
|
||||
}
|
||||
|
||||
@@ -483,18 +466,18 @@ public class Module {
|
||||
return this.type.equals(type);
|
||||
}
|
||||
|
||||
Violations isValidDependencyWithin(Modules modules) {
|
||||
Violations isValidDependencyWithin(ApplicationModules modules) {
|
||||
|
||||
Module originModule = getExistingModuleOf(origin, modules);
|
||||
Module targetModule = getExistingModuleOf(target, modules);
|
||||
ApplicationModule originModule = getExistingModuleOf(origin, modules);
|
||||
ApplicationModule targetModule = getExistingModuleOf(target, modules);
|
||||
|
||||
List<Module> allowedTargets = originModule.getAllowedDependencies(modules);
|
||||
List<ApplicationModule> allowedTargets = originModule.getAllowedDependencies(modules);
|
||||
Violations violations = Violations.NONE;
|
||||
|
||||
if (!allowedTargets.isEmpty() && !allowedTargets.contains(targetModule)) {
|
||||
|
||||
String allowedTargetsString = allowedTargets.stream() //
|
||||
.map(Module::getName) //
|
||||
.map(ApplicationModule::getName) //
|
||||
.collect(Collectors.joining(", "));
|
||||
|
||||
String message = String.format("Module '%s' depends on module '%s' via %s -> %s. Allowed target modules: %s.",
|
||||
@@ -514,9 +497,9 @@ public class Module {
|
||||
return violations;
|
||||
}
|
||||
|
||||
Module getExistingModuleOf(JavaClass javaClass, Modules modules) {
|
||||
ApplicationModule getExistingModuleOf(JavaClass javaClass, ApplicationModules modules) {
|
||||
|
||||
Optional<Module> module = modules.getModuleByType(javaClass);
|
||||
Optional<ApplicationModule> module = modules.getModuleByType(javaClass);
|
||||
|
||||
return module.orElseThrow(() -> new IllegalStateException(
|
||||
String.format("Origin/Target of a %s should always be within a module, but %s is not",
|
||||
@@ -550,7 +533,7 @@ public class Module {
|
||||
Set<JavaConstructor> constructors = source.getConstructors();
|
||||
|
||||
return constructors.stream() //
|
||||
.filter(it -> constructors.size() == 1 || isInjectionPoint(it)) //
|
||||
.filter(it -> (constructors.size() == 1) || isInjectionPoint(it)) //
|
||||
.flatMap(it -> it.getRawParameterTypes().stream() //
|
||||
.map(parameter -> new InjectionModuleDependency(source, parameter, it)));
|
||||
}
|
||||
@@ -673,13 +656,13 @@ public class Module {
|
||||
* @see org.springframework.modulith.model.Module.ModuleDependency#isValidDependencyWithin(org.springframework.modulith.model.Modules)
|
||||
*/
|
||||
@Override
|
||||
Violations isValidDependencyWithin(Modules modules) {
|
||||
Violations isValidDependencyWithin(ApplicationModules modules) {
|
||||
|
||||
Violations violations = super.isValidDependencyWithin(modules);
|
||||
|
||||
if (JavaField.class.isInstance(member) && !isConfigurationClass) {
|
||||
|
||||
Module module = getExistingModuleOf(member.getOwner(), modules);
|
||||
ApplicationModule module = getExistingModuleOf(member.getOwner(), modules);
|
||||
|
||||
violations = violations.and(new IllegalStateException(
|
||||
String.format("Module %s uses field injection in %s. Prefer constructor injection instead!",
|
||||
@@ -18,17 +18,17 @@ package org.springframework.modulith.model;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.springframework.modulith.Module;
|
||||
import org.springframework.modulith.ApplicationModule;
|
||||
import org.springframework.modulith.model.Types.JMoleculesTypes;
|
||||
|
||||
/**
|
||||
* Default implementations of {@link ModuleDetectionStrategy}.
|
||||
* Default implementations of {@link ApplicationModuleDetectionStrategy}.
|
||||
*
|
||||
* @author Oliver Drotbohm
|
||||
* @see ModuleDetectionStrategy#directSubPackage()
|
||||
* @see ModuleDetectionStrategy#explictlyAnnotated()
|
||||
* @see ApplicationModuleDetectionStrategy#directSubPackage()
|
||||
* @see ApplicationModuleDetectionStrategy#explictlyAnnotated()
|
||||
*/
|
||||
enum ModuleDetectionStrategies implements ModuleDetectionStrategy {
|
||||
enum ApplicationModuleDetectionStrategies implements ApplicationModuleDetectionStrategy {
|
||||
|
||||
DIRECT_SUB_PACKAGES {
|
||||
|
||||
@@ -52,7 +52,7 @@ enum ModuleDetectionStrategies implements ModuleDetectionStrategy {
|
||||
@Override
|
||||
public Stream<JavaPackage> getModuleBasePackages(JavaPackage basePackage) {
|
||||
|
||||
return Stream.of(Module.class, JMoleculesTypes.getModuleAnnotationTypeIfPresent())
|
||||
return Stream.of(ApplicationModule.class, JMoleculesTypes.getModuleAnnotationTypeIfPresent())
|
||||
.filter(Objects::nonNull)
|
||||
.flatMap(basePackage::getSubPackagesAnnotatedWith);
|
||||
}
|
||||
@@ -17,14 +17,14 @@ package org.springframework.modulith.model;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.springframework.modulith.Module;
|
||||
import org.springframework.modulith.ApplicationModule;
|
||||
|
||||
/**
|
||||
* Strategy interface to customize which packages are considered module base packages.
|
||||
*
|
||||
* @author Oliver Drotbohm
|
||||
*/
|
||||
public interface ModuleDetectionStrategy {
|
||||
public interface ApplicationModuleDetectionStrategy {
|
||||
|
||||
/**
|
||||
* Given the {@link JavaPackage} that Moduliths was initialized with, return the base packages for all modules in the
|
||||
@@ -36,22 +36,22 @@ public interface ModuleDetectionStrategy {
|
||||
Stream<JavaPackage> getModuleBasePackages(JavaPackage basePackage);
|
||||
|
||||
/**
|
||||
* A {@link ModuleDetectionStrategy} that considers all direct sub-packages of the Moduliths base package to be module
|
||||
* A {@link ApplicationModuleDetectionStrategy} that considers all direct sub-packages of the Moduliths base package to be module
|
||||
* base packages.
|
||||
*
|
||||
* @return will never be {@literal null}.
|
||||
*/
|
||||
static ModuleDetectionStrategy directSubPackage() {
|
||||
return ModuleDetectionStrategies.DIRECT_SUB_PACKAGES;
|
||||
static ApplicationModuleDetectionStrategy directSubPackage() {
|
||||
return ApplicationModuleDetectionStrategies.DIRECT_SUB_PACKAGES;
|
||||
}
|
||||
|
||||
/**
|
||||
* A {@link ModuleDetectionStrategy} that considers packages explicitly annotated with {@link Module} module base
|
||||
* A {@link ApplicationModuleDetectionStrategy} that considers packages explicitly annotated with {@link ApplicationModule} module base
|
||||
* packages.
|
||||
*
|
||||
* @return will never be {@literal null}.
|
||||
*/
|
||||
static ModuleDetectionStrategy explictlyAnnotated() {
|
||||
return ModuleDetectionStrategies.EXPLICITLY_ANNOTATED;
|
||||
static ApplicationModuleDetectionStrategy explictlyAnnotated() {
|
||||
return ApplicationModuleDetectionStrategies.EXPLICITLY_ANNOTATED;
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,7 @@ import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.springframework.modulith.Module;
|
||||
import org.springframework.modulith.ApplicationModule;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -35,11 +35,11 @@ import org.springframework.util.StringUtils;
|
||||
*
|
||||
* @author Oliver Drotbohm
|
||||
*/
|
||||
interface ModuleInformation {
|
||||
interface ApplicationModuleInformation {
|
||||
|
||||
public static ModuleInformation of(JavaPackage javaPackage) {
|
||||
public static ApplicationModuleInformation of(JavaPackage javaPackage) {
|
||||
|
||||
if (ClassUtils.isPresent("org.jmolecules.ddd.annotation.Module", ModuleInformation.class.getClassLoader())
|
||||
if (ClassUtils.isPresent("org.jmolecules.ddd.annotation.Module", ApplicationModuleInformation.class.getClassLoader())
|
||||
&& MoleculesModule.supports(javaPackage)) {
|
||||
return new MoleculesModule(javaPackage);
|
||||
}
|
||||
@@ -52,7 +52,7 @@ interface ModuleInformation {
|
||||
List<String> getAllowedDependencies();
|
||||
|
||||
@RequiredArgsConstructor(access = AccessLevel.PROTECTED)
|
||||
static abstract class AbstractModuleInformation implements ModuleInformation {
|
||||
static abstract class AbstractModuleInformation implements ApplicationModuleInformation {
|
||||
|
||||
private final JavaPackage javaPackage;
|
||||
|
||||
@@ -109,17 +109,17 @@ interface ModuleInformation {
|
||||
|
||||
static class ModulithsModule extends AbstractModuleInformation {
|
||||
|
||||
private final Optional<Module> annotation;
|
||||
private final Optional<ApplicationModule> annotation;
|
||||
|
||||
public static boolean supports(JavaPackage javaPackage) {
|
||||
return javaPackage.getAnnotation(Module.class).isPresent();
|
||||
return javaPackage.getAnnotation(ApplicationModule.class).isPresent();
|
||||
}
|
||||
|
||||
public ModulithsModule(JavaPackage javaPackage) {
|
||||
|
||||
super(javaPackage);
|
||||
|
||||
this.annotation = javaPackage.getAnnotation(Module.class);
|
||||
this.annotation = javaPackage.getAnnotation(ApplicationModule.class);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -130,7 +130,7 @@ interface ModuleInformation {
|
||||
public String getDisplayName() {
|
||||
|
||||
return annotation //
|
||||
.map(Module::displayName) //
|
||||
.map(ApplicationModule::displayName) //
|
||||
.filter(StringUtils::hasText) //
|
||||
.orElseGet(super::getDisplayName);
|
||||
}
|
||||
@@ -51,16 +51,16 @@ import com.tngtech.archunit.library.dependencies.SlicesRuleDefinition;
|
||||
* @author Peter Gafert
|
||||
*/
|
||||
@AllArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class Modules implements Iterable<Module> {
|
||||
public class ApplicationModules implements Iterable<ApplicationModule> {
|
||||
|
||||
private static final Map<CacheKey, Modules> CACHE = new HashMap<>();
|
||||
private static final Map<CacheKey, ApplicationModules> CACHE = new HashMap<>();
|
||||
|
||||
private static final ModuleDetectionStrategy DETECTION_STRATEGY;
|
||||
private static final ApplicationModuleDetectionStrategy DETECTION_STRATEGY;
|
||||
|
||||
static {
|
||||
|
||||
List<ModuleDetectionStrategy> loadFactories = SpringFactoriesLoader.loadFactories(ModuleDetectionStrategy.class,
|
||||
Modules.class.getClassLoader());
|
||||
List<ApplicationModuleDetectionStrategy> loadFactories = SpringFactoriesLoader.loadFactories(ApplicationModuleDetectionStrategy.class,
|
||||
ApplicationModules.class.getClassLoader());
|
||||
|
||||
if (loadFactories.size() > 1) {
|
||||
|
||||
@@ -69,18 +69,18 @@ public class Modules implements Iterable<Module> {
|
||||
loadFactories));
|
||||
}
|
||||
|
||||
DETECTION_STRATEGY = loadFactories.isEmpty() ? ModuleDetectionStrategies.DIRECT_SUB_PACKAGES : loadFactories.get(0);
|
||||
DETECTION_STRATEGY = loadFactories.isEmpty() ? ApplicationModuleDetectionStrategies.DIRECT_SUB_PACKAGES : loadFactories.get(0);
|
||||
}
|
||||
|
||||
private final ModulithMetadata metadata;
|
||||
private final Map<String, Module> modules;
|
||||
private final Map<String, ApplicationModule> modules;
|
||||
private final JavaClasses allClasses;
|
||||
private final List<JavaPackage> rootPackages;
|
||||
private final @With(AccessLevel.PRIVATE) @Getter Set<Module> sharedModules;
|
||||
private final @With(AccessLevel.PRIVATE) @Getter Set<ApplicationModule> sharedModules;
|
||||
|
||||
private boolean verified;
|
||||
|
||||
private Modules(ModulithMetadata metadata, Collection<String> packages, DescribedPredicate<JavaClass> ignored,
|
||||
private ApplicationModules(ModulithMetadata metadata, Collection<String> packages, DescribedPredicate<JavaClass> ignored,
|
||||
boolean useFullyQualifiedModuleNames) {
|
||||
|
||||
this.metadata = metadata;
|
||||
@@ -94,8 +94,8 @@ public class Modules implements Iterable<Module> {
|
||||
this.modules = packages.stream() //
|
||||
.map(it -> JavaPackage.of(classes, it))
|
||||
.flatMap(DETECTION_STRATEGY::getModuleBasePackages) //
|
||||
.map(it -> new Module(it, useFullyQualifiedModuleNames)) //
|
||||
.collect(toMap(Module::getName, Function.identity()));
|
||||
.map(it -> new ApplicationModule(it, useFullyQualifiedModuleNames)) //
|
||||
.collect(toMap(ApplicationModule::getName, Function.identity()));
|
||||
|
||||
this.rootPackages = packages.stream() //
|
||||
.map(it -> JavaPackage.of(classes, it).toSingle()) //
|
||||
@@ -105,18 +105,18 @@ public class Modules implements Iterable<Module> {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link Modules} relative to the given modulith type. Will inspect the {@link Modulith} annotation on
|
||||
* Creates a new {@link ApplicationModules} relative to the given modulith type. Will inspect the {@link Modulith} annotation on
|
||||
* the class given for advanced customizations of the module setup.
|
||||
*
|
||||
* @param modulithType must not be {@literal null}.
|
||||
* @return
|
||||
*/
|
||||
public static Modules of(Class<?> modulithType) {
|
||||
public static ApplicationModules of(Class<?> modulithType) {
|
||||
return of(modulithType, alwaysFalse());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link Modules} relative to the given modulith type, a {@link ModuleDetectionStrategy} and a
|
||||
* Creates a new {@link ApplicationModules} relative to the given modulith type, a {@link ApplicationModuleDetectionStrategy} and a
|
||||
* {@link DescribedPredicate} which types and packages to ignore. Will inspect the {@link Modulith} and
|
||||
* {@link Modulithic} annotations on the class given for advanced customizations of the module setup.
|
||||
*
|
||||
@@ -125,7 +125,7 @@ public class Modules implements Iterable<Module> {
|
||||
* @param ignored must not be {@literal null}.
|
||||
* @return
|
||||
*/
|
||||
public static Modules of(Class<?> modulithType, DescribedPredicate<JavaClass> ignored) {
|
||||
public static ApplicationModules of(Class<?> modulithType, DescribedPredicate<JavaClass> ignored) {
|
||||
|
||||
CacheKey key = TypeKey.of(modulithType, ignored);
|
||||
|
||||
@@ -139,25 +139,23 @@ public class Modules implements Iterable<Module> {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link Modules} instance for the given package name.
|
||||
* Creates a new {@link ApplicationModules} instance for the given package name.
|
||||
*
|
||||
* @param javaPackage must not be {@literal null} or empty.
|
||||
* @return will never be {@literal null}.
|
||||
* @since 1.1
|
||||
*/
|
||||
public static Modules of(String javaPackage) {
|
||||
public static ApplicationModules of(String javaPackage) {
|
||||
return of(javaPackage, alwaysFalse());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link Modules} instance for the given package name and ignored classes.
|
||||
* Creates a new {@link ApplicationModules} instance for the given package name and ignored classes.
|
||||
*
|
||||
* @param javaPackage must not be {@literal null} or empty.
|
||||
* @param ignored must not be {@literal null}.
|
||||
* @return will never be {@literal null}.
|
||||
* @since 1.1
|
||||
*/
|
||||
public static Modules of(String javaPackage, DescribedPredicate<JavaClass> ignored) {
|
||||
public static ApplicationModules of(String javaPackage, DescribedPredicate<JavaClass> ignored) {
|
||||
|
||||
CacheKey key = PackageKey.of(javaPackage, ignored);
|
||||
|
||||
@@ -171,12 +169,12 @@ public class Modules implements Iterable<Module> {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link Modules} instance for the given {@link CacheKey}.
|
||||
* Creates a new {@link ApplicationModules} instance for the given {@link CacheKey}.
|
||||
*
|
||||
* @param key must not be {@literal null}.
|
||||
* @return will never be {@literal null}.
|
||||
*/
|
||||
private static Modules of(CacheKey key) {
|
||||
private static ApplicationModules of(CacheKey key) {
|
||||
|
||||
Assert.notNull(key, "Cache key must not be null!");
|
||||
|
||||
@@ -186,10 +184,10 @@ public class Modules implements Iterable<Module> {
|
||||
basePackages.add(key.getBasePackage());
|
||||
basePackages.addAll(metadata.getAdditionalPackages());
|
||||
|
||||
Modules modules = new Modules(metadata, basePackages, key.getIgnored(),
|
||||
ApplicationModules modules = new ApplicationModules(metadata, basePackages, key.getIgnored(),
|
||||
metadata.useFullyQualifiedModuleNames());
|
||||
|
||||
Set<Module> sharedModules = metadata.getSharedModuleNames() //
|
||||
Set<ApplicationModule> sharedModules = metadata.getSharedModuleNames() //
|
||||
.map(modules::getRequiredModule) //
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
@@ -201,24 +199,7 @@ public class Modules implements Iterable<Module> {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
* @deprecated since 1.1, as a {@link Modules} instance doesn't have to be created from a class in the first place.
|
||||
* For generic use, use {@link #getModulithSource()} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public Class<?> getModulithType() {
|
||||
|
||||
Object source = getModulithSource();
|
||||
|
||||
if (!Class.class.isInstance(source)) {
|
||||
throw new IllegalStateException(String.format("Moduliths not created from a type but %s!", source));
|
||||
}
|
||||
|
||||
return (Class<?>) source;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the given {@link JavaClass} is contained within the {@link Modules}.
|
||||
* Returns whether the given {@link JavaClass} is contained within the {@link ApplicationModules}.
|
||||
*
|
||||
* @param type must not be {@literal null}.
|
||||
* @return
|
||||
@@ -246,12 +227,12 @@ public class Modules implements Iterable<Module> {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the {@link Module} with the given name.
|
||||
* Returns the {@link ApplicationModule} with the given name.
|
||||
*
|
||||
* @param name must not be {@literal null} or empty.
|
||||
* @return
|
||||
*/
|
||||
public Optional<Module> getModuleByName(String name) {
|
||||
public Optional<ApplicationModule> getModuleByName(String name) {
|
||||
|
||||
Assert.hasText(name, "Module name must not be null or empty!");
|
||||
|
||||
@@ -264,7 +245,7 @@ public class Modules implements Iterable<Module> {
|
||||
* @param type must not be {@literal null}.
|
||||
* @return
|
||||
*/
|
||||
public Optional<Module> getModuleByType(JavaClass type) {
|
||||
public Optional<ApplicationModule> getModuleByType(JavaClass type) {
|
||||
|
||||
Assert.notNull(type, "Type must not be null!");
|
||||
|
||||
@@ -274,13 +255,12 @@ public class Modules implements Iterable<Module> {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the {@link Module} containing the type with the given simple or fully-qualified name.
|
||||
* Returns the {@link ApplicationModule} containing the type with the given simple or fully-qualified name.
|
||||
*
|
||||
* @param candidate must not be {@literal null} or empty.
|
||||
* @return will never be {@literal null}.
|
||||
* @since 1.1
|
||||
*/
|
||||
public Optional<Module> getModuleByType(String candidate) {
|
||||
public Optional<ApplicationModule> getModuleByType(String candidate) {
|
||||
|
||||
Assert.hasText(candidate, "Candidate must not be null or empty!");
|
||||
|
||||
@@ -289,7 +269,7 @@ public class Modules implements Iterable<Module> {
|
||||
.findFirst();
|
||||
}
|
||||
|
||||
public Optional<Module> getModuleForPackage(String name) {
|
||||
public Optional<ApplicationModule> getModuleForPackage(String name) {
|
||||
|
||||
return modules.values().stream() //
|
||||
.filter(it -> name.startsWith(it.getBasePackage().getName())) //
|
||||
@@ -342,11 +322,11 @@ public class Modules implements Iterable<Module> {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all {@link Module}s.
|
||||
* Returns all {@link ApplicationModule}s.
|
||||
*
|
||||
* @return will never be {@literal null}.
|
||||
*/
|
||||
public Stream<Module> stream() {
|
||||
public Stream<ApplicationModule> stream() {
|
||||
return modules.values().stream();
|
||||
}
|
||||
|
||||
@@ -364,7 +344,7 @@ public class Modules implements Iterable<Module> {
|
||||
* @see java.lang.Iterable#iterator()
|
||||
*/
|
||||
@Override
|
||||
public Iterator<Module> iterator() {
|
||||
public Iterator<ApplicationModule> iterator() {
|
||||
return modules.values().iterator();
|
||||
}
|
||||
|
||||
@@ -374,9 +354,9 @@ public class Modules implements Iterable<Module> {
|
||||
* @param moduleName must not be {@literal null}.
|
||||
* @return
|
||||
*/
|
||||
private Module getRequiredModule(String moduleName) {
|
||||
private ApplicationModule getRequiredModule(String moduleName) {
|
||||
|
||||
Module module = modules.get(moduleName);
|
||||
ApplicationModule module = modules.get(moduleName);
|
||||
|
||||
if (module == null) {
|
||||
throw new IllegalArgumentException(String.format("Module %s does not exist!", moduleName));
|
||||
@@ -66,7 +66,6 @@ class DefaultModulithMetadata implements ModulithMetadata {
|
||||
*
|
||||
* @param javaPackage must not be {@literal null} or empty.
|
||||
* @return will never be {@literal null}.
|
||||
* @since 1.1
|
||||
*/
|
||||
public static ModulithMetadata of(String javaPackage) {
|
||||
|
||||
|
||||
@@ -31,7 +31,6 @@ import com.tngtech.archunit.core.domain.JavaModifier;
|
||||
* A type that represents an event in a system.
|
||||
*
|
||||
* @author Oliver Drotbohm
|
||||
* @since 1.1
|
||||
*/
|
||||
@Value
|
||||
public class EventType {
|
||||
|
||||
@@ -76,7 +76,7 @@ public class FormatableJavaClass {
|
||||
return abbreviatedName.get();
|
||||
}
|
||||
|
||||
public String getAbbreviatedFullName(@Nullable Module module) {
|
||||
public String getAbbreviatedFullName(@Nullable ApplicationModule module) {
|
||||
|
||||
if (module == null) {
|
||||
return getAbbreviatedFullName();
|
||||
|
||||
@@ -25,7 +25,6 @@ import com.tngtech.archunit.core.domain.JavaCodeUnit;
|
||||
* A {@link Source} backed by an ArchUnit {@link JavaAccess}.
|
||||
*
|
||||
* @author Oliver Drotbohm
|
||||
* @since 1.1
|
||||
*/
|
||||
class JavaAccessSource implements Source {
|
||||
|
||||
@@ -56,7 +55,7 @@ class JavaAccessSource implements Source {
|
||||
* @see org.springframework.modulith.model.Source#toString(org.springframework.modulith.model.Module)
|
||||
*/
|
||||
@Override
|
||||
public String toString(Module module) {
|
||||
public String toString(ApplicationModule module) {
|
||||
|
||||
boolean noParameters = method.getRawParameterTypes().isEmpty();
|
||||
|
||||
|
||||
@@ -55,7 +55,6 @@ interface ModulithMetadata {
|
||||
*
|
||||
* @param javaPackage must not be {@literal null} or empty.
|
||||
* @return will never be {@literal null}.
|
||||
* @since 1.1
|
||||
*/
|
||||
public static ModulithMetadata of(String javaPackage) {
|
||||
return DefaultModulithMetadata.of(javaPackage);
|
||||
@@ -65,7 +64,6 @@ interface ModulithMetadata {
|
||||
* Returns the source of the Moduliths setup. Either a type or a package.
|
||||
*
|
||||
* @return will never be {@literal null}.
|
||||
* @since 1.1
|
||||
*/
|
||||
Object getModulithSource();
|
||||
|
||||
|
||||
@@ -19,7 +19,6 @@ package org.springframework.modulith.model;
|
||||
* A {@link Source} of some type, bean definition etc. Essentially describes the origin of that bean, event etc.
|
||||
*
|
||||
* @author Oliver Drotbohm
|
||||
* @since 1.1
|
||||
*/
|
||||
public interface Source {
|
||||
|
||||
@@ -29,5 +28,5 @@ public interface Source {
|
||||
* @param module must not be {@literal null}.
|
||||
* @return
|
||||
*/
|
||||
String toString(Module module);
|
||||
String toString(ApplicationModule module);
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ import com.tngtech.archunit.core.domain.JavaClass;
|
||||
public class SpringBean {
|
||||
|
||||
private final @Getter JavaClass type;
|
||||
private final Module module;
|
||||
private final ApplicationModule module;
|
||||
|
||||
/**
|
||||
* Returns the fully-qualified name of the Spring bean type.
|
||||
|
||||
@@ -21,7 +21,7 @@ import java.util.stream.Stream;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.modulith.model.Module.ModuleDependency;
|
||||
import org.springframework.modulith.model.ApplicationModule.ModuleDependency;
|
||||
|
||||
import com.tngtech.archunit.core.domain.JavaClass;
|
||||
import com.tngtech.archunit.core.importer.ClassFileImporter;
|
||||
|
||||
@@ -24,7 +24,7 @@ import com.tngtech.archunit.core.importer.ClassFileImporter;
|
||||
import com.tngtech.archunit.core.importer.ImportOption;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link ModuleDetectionStrategy}.
|
||||
* Unit tests for {@link ApplicationModuleDetectionStrategy}.
|
||||
*
|
||||
* @author Oliver Drotbohm
|
||||
*/
|
||||
@@ -33,15 +33,15 @@ class ModuleDetectionStrategyUnitTest {
|
||||
@Test
|
||||
void usesExplicitlyAnnotatedConstant() {
|
||||
|
||||
assertThat(ModuleDetectionStrategy.explictlyAnnotated())
|
||||
.isEqualTo(ModuleDetectionStrategies.EXPLICITLY_ANNOTATED);
|
||||
assertThat(ApplicationModuleDetectionStrategy.explictlyAnnotated())
|
||||
.isEqualTo(ApplicationModuleDetectionStrategies.EXPLICITLY_ANNOTATED);
|
||||
}
|
||||
|
||||
@Test
|
||||
void usesDirectSubPackages() {
|
||||
|
||||
assertThat(ModuleDetectionStrategy.directSubPackage())
|
||||
.isEqualTo(ModuleDetectionStrategies.DIRECT_SUB_PACKAGES);
|
||||
assertThat(ApplicationModuleDetectionStrategy.directSubPackage())
|
||||
.isEqualTo(ApplicationModuleDetectionStrategies.DIRECT_SUB_PACKAGES);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -53,7 +53,7 @@ class ModuleDetectionStrategyUnitTest {
|
||||
|
||||
JavaPackage javaPackage = JavaPackage.of(Classes.of(classes), "jmolecules");
|
||||
|
||||
assertThat(ModuleDetectionStrategy.explictlyAnnotated().getModuleBasePackages(javaPackage))
|
||||
assertThat(ApplicationModuleDetectionStrategy.explictlyAnnotated().getModuleBasePackages(javaPackage))
|
||||
.containsExactly(javaPackage);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ import com.tngtech.archunit.core.domain.JavaClasses;
|
||||
import com.tngtech.archunit.core.importer.ClassFileImporter;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link Module}.
|
||||
* Unit tests for {@link ApplicationModule}.
|
||||
*
|
||||
* @author Oliver Drotbohm
|
||||
*/
|
||||
@@ -43,7 +43,7 @@ class ModuleUnitTest {
|
||||
JavaClasses classes = importer.importPackages("com.acme.withatbean"); //
|
||||
JavaPackage javaPackage = JavaPackage.of(Classes.of(classes), "");
|
||||
|
||||
Module module = new Module(javaPackage, false);
|
||||
ApplicationModule module = new ApplicationModule(javaPackage, false);
|
||||
|
||||
@Test
|
||||
public void considersExternalSpringBeans() {
|
||||
|
||||
@@ -36,10 +36,10 @@ import com.tngtech.archunit.thirdparty.com.google.common.base.Suppliers;
|
||||
class TestUtils {
|
||||
|
||||
private static Supplier<JavaClasses> imported = Suppliers.memoize(() -> new ClassFileImporter() //
|
||||
.importPackagesOf(Modules.class, Repository.class, AggregateRoot.class));
|
||||
.importPackagesOf(ApplicationModules.class, Repository.class, AggregateRoot.class));
|
||||
|
||||
private static DescribedPredicate<JavaClass> IS_MODULE_TYPE = JavaClass.Predicates
|
||||
.resideInAPackage(Modules.class.getPackage().getName());
|
||||
.resideInAPackage(ApplicationModules.class.getPackage().getName());
|
||||
|
||||
private static Supplier<Classes> classes = Suppliers.memoize(() -> Classes.of(imported.get()).that(IS_MODULE_TYPE));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user