Search in sources :

Example 1 with Modules

use of org.moduliths.model.Modules in project moduliths by moduliths.

the class Documenter method addComponentsToView.

private void addComponentsToView(Supplier<Stream<Module>> modules, ComponentView view, Options options, Consumer<ComponentView> afterCleanup) {
    Styles styles = view.getViewSet().getConfiguration().getStyles();
    Map<Module, Component> components = getComponents(options);
    // 
    modules.get().distinct().filter(// 
    options.getExclusions().negate()).map(// 
    it -> applyBackgroundColor(it, components, options, styles)).filter(// 
    options.getComponentFilter()).forEach(view::add);
    // view.getViewSet().getConfiguration().getStyles().findElementStyle(element).getBackground()
    // Remove filtered dependency types
    // 
    DependencyType.allBut(options.getDependencyTypes()).map(// 
    Object::toString).forEach(it -> view.removeRelationshipsWithTag(it));
    afterCleanup.accept(view);
    // Filter outgoing relationships of target-only modules
    // 
    modules.get().filter(options.getTargetOnly()).forEach(module -> {
        Component component = components.get(module);
        // 
        view.getRelationships().stream().map(// 
        RelationshipView::getRelationship).filter(// 
        it -> it.getSource().equals(component)).forEach(it -> view.remove(it));
    });
    // … as well as all elements left without a relationship
    if (options.hideElementsWithoutRelationships()) {
        view.removeElementsWithNoRelationships();
    }
    afterCleanup.accept(view);
    // Remove default relationships if more qualified ones exist
    // 
    view.getRelationships().stream().map(// 
    RelationshipView::getRelationship).collect(// 
    Collectors.groupingBy(Connection::of)).values().stream().forEach(it -> potentiallyRemoveDefaultRelationship(view, it));
}
Also used : RequiredArgsConstructor(lombok.RequiredArgsConstructor) Diagram(com.structurizr.io.Diagram) C4PlantUMLExporter(com.structurizr.io.plantuml.C4PlantUMLExporter) BasicPlantUMLWriter(com.structurizr.io.plantuml.BasicPlantUMLWriter) SpringBean(org.moduliths.model.SpringBean) JavaClass(com.tngtech.archunit.core.domain.JavaClass) Path(java.nio.file.Path) With(lombok.With) Predicate(java.util.function.Predicate) SoftwareSystem(com.structurizr.model.SoftwareSystem) RelationshipView(com.structurizr.view.RelationshipView) Asciidoctor(org.moduliths.docs.Asciidoctor) Collectors(java.util.stream.Collectors) DependencyDepth(org.moduliths.model.Module.DependencyDepth) Shape(com.structurizr.view.Shape) Tags(com.structurizr.model.Tags) Stream(java.util.stream.Stream) Relationship(com.structurizr.model.Relationship) Writer(java.io.Writer) Entry(java.util.Map.Entry) Styles(com.structurizr.view.Styles) java.util(java.util) Getter(lombok.Getter) Function(java.util.function.Function) Supplier(java.util.function.Supplier) Component(com.structurizr.model.Component) Value(lombok.Value) Modules(org.moduliths.model.Modules) AccessLevel(lombok.AccessLevel) BiConsumer(java.util.function.BiConsumer) View(com.structurizr.view.View) Nullable(org.springframework.lang.Nullable) Model(com.structurizr.model.Model) Container(com.structurizr.model.Container) ComponentView(com.structurizr.view.ComponentView) Files(java.nio.file.Files) StringWriter(java.io.StringWriter) FileWriter(java.io.FileWriter) MultiValueMap(org.springframework.util.MultiValueMap) IOException(java.io.IOException) File(java.io.File) Workspace(com.structurizr.Workspace) Consumer(java.util.function.Consumer) DependencyType(org.moduliths.model.Module.DependencyType) Module(org.moduliths.model.Module) Paths(java.nio.file.Paths) PlantUMLWriter(com.structurizr.io.plantuml.PlantUMLWriter) AllArgsConstructor(lombok.AllArgsConstructor) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) Element(com.structurizr.model.Element) Assert(org.springframework.util.Assert) RelationshipView(com.structurizr.view.RelationshipView) Module(org.moduliths.model.Module) Component(com.structurizr.model.Component) Styles(com.structurizr.view.Styles)

Example 2 with Modules

use of org.moduliths.model.Modules in project moduliths by moduliths.

the class Documenter method addDependencies.

private void addDependencies(Module module, Component component, Options options) {
    DEPENDENCY_DESCRIPTIONS.entrySet().stream().forEach(entry -> {
        // 
        module.getDependencies(modules, entry.getKey()).stream().map(// 
        it -> getComponents(options).get(it)).forEach(it -> {
            Relationship relationship = component.uses(it, entry.getValue());
            relationship.addTags(entry.getKey().toString());
        });
    });
    // 
    module.getBootstrapDependencies(modules).forEach(it -> {
        Relationship relationship = component.uses(getComponents(options).get(it), "uses");
        relationship.addTags(DependencyType.USES_COMPONENT.toString());
    });
}
Also used : RequiredArgsConstructor(lombok.RequiredArgsConstructor) Diagram(com.structurizr.io.Diagram) C4PlantUMLExporter(com.structurizr.io.plantuml.C4PlantUMLExporter) BasicPlantUMLWriter(com.structurizr.io.plantuml.BasicPlantUMLWriter) SpringBean(org.moduliths.model.SpringBean) JavaClass(com.tngtech.archunit.core.domain.JavaClass) Path(java.nio.file.Path) With(lombok.With) Predicate(java.util.function.Predicate) SoftwareSystem(com.structurizr.model.SoftwareSystem) RelationshipView(com.structurizr.view.RelationshipView) Asciidoctor(org.moduliths.docs.Asciidoctor) Collectors(java.util.stream.Collectors) DependencyDepth(org.moduliths.model.Module.DependencyDepth) Shape(com.structurizr.view.Shape) Tags(com.structurizr.model.Tags) Stream(java.util.stream.Stream) Relationship(com.structurizr.model.Relationship) Writer(java.io.Writer) Entry(java.util.Map.Entry) Styles(com.structurizr.view.Styles) java.util(java.util) Getter(lombok.Getter) Function(java.util.function.Function) Supplier(java.util.function.Supplier) Component(com.structurizr.model.Component) Value(lombok.Value) Modules(org.moduliths.model.Modules) AccessLevel(lombok.AccessLevel) BiConsumer(java.util.function.BiConsumer) View(com.structurizr.view.View) Nullable(org.springframework.lang.Nullable) Model(com.structurizr.model.Model) Container(com.structurizr.model.Container) ComponentView(com.structurizr.view.ComponentView) Files(java.nio.file.Files) StringWriter(java.io.StringWriter) FileWriter(java.io.FileWriter) MultiValueMap(org.springframework.util.MultiValueMap) IOException(java.io.IOException) File(java.io.File) Workspace(com.structurizr.Workspace) Consumer(java.util.function.Consumer) DependencyType(org.moduliths.model.Module.DependencyType) Module(org.moduliths.model.Module) Paths(java.nio.file.Paths) PlantUMLWriter(com.structurizr.io.plantuml.PlantUMLWriter) AllArgsConstructor(lombok.AllArgsConstructor) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) Element(com.structurizr.model.Element) Assert(org.springframework.util.Assert) Relationship(com.structurizr.model.Relationship)

Example 3 with Modules

use of org.moduliths.model.Modules in project moduliths by moduliths.

the class ModuleTracingBeanPostProcessor method postProcessAfterInitialization.

/*
	 * (non-Javadoc)
	 * @see org.springframework.beans.factory.config.BeanPostProcessor#postProcessAfterInitialization(java.lang.Object, java.lang.String)
	 */
@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
    Class<?> type = getBeanUserClass(bean, beanName);
    if (!runtime.isApplicationClass(type) || !type.isInstance(bean)) {
        return bean;
    }
    Modules modules = getModules();
    return modules.getModuleByType(type.getName()).map(DefaultObservedModule::new).map(it -> {
        ObservedModuleType moduleType = it.getObservedModuleType(type, modules);
        return // 
        moduleType != null ? // 
        addAdvisor(bean, getOrBuildAdvisor(it, moduleType)) : bean;
    }).orElse(bean);
}
Also used : ComposablePointcut(org.springframework.aop.support.ComposablePointcut) Pointcut(org.springframework.aop.Pointcut) RequiredArgsConstructor(lombok.RequiredArgsConstructor) DefaultPointcutAdvisor(org.springframework.aop.support.DefaultPointcutAdvisor) HashMap(java.util.HashMap) BeansException(org.springframework.beans.BeansException) BeanPostProcessor(org.springframework.beans.factory.config.BeanPostProcessor) Modules(org.moduliths.model.Modules) Map(java.util.Map) Tracer(org.springframework.cloud.sleuth.Tracer) Advice(org.aopalliance.aop.Advice) Method(java.lang.reflect.Method) StaticMethodMatcher(org.springframework.aop.support.StaticMethodMatcher) Advisor(org.springframework.aop.Advisor) MethodMatcher(org.springframework.aop.MethodMatcher) Modules(org.moduliths.model.Modules)

Example 4 with Modules

use of org.moduliths.model.Modules in project moduliths by moduliths.

the class FieldInjectedIntegrationTest method rejectsFieldInjection.

// #52
@Test
void rejectsFieldInjection() {
    Modules modules = execution.getModules();
    // 
    assertThat(execution.getModule().detectDependencies(modules)).hasMessageContaining(// 
    "field injection").hasMessageContaining(// offending field
    "WithFieldInjection.a");
}
Also used : Modules(org.moduliths.model.Modules) Test(org.junit.jupiter.api.Test) NonVerifyingModuleTest(com.acme.myproject.NonVerifyingModuleTest)

Aggregations

Modules (org.moduliths.model.Modules)4 RequiredArgsConstructor (lombok.RequiredArgsConstructor)3 Workspace (com.structurizr.Workspace)2 Diagram (com.structurizr.io.Diagram)2 BasicPlantUMLWriter (com.structurizr.io.plantuml.BasicPlantUMLWriter)2 C4PlantUMLExporter (com.structurizr.io.plantuml.C4PlantUMLExporter)2 PlantUMLWriter (com.structurizr.io.plantuml.PlantUMLWriter)2 Component (com.structurizr.model.Component)2 Container (com.structurizr.model.Container)2 Element (com.structurizr.model.Element)2 Model (com.structurizr.model.Model)2 Relationship (com.structurizr.model.Relationship)2 SoftwareSystem (com.structurizr.model.SoftwareSystem)2 Tags (com.structurizr.model.Tags)2 ComponentView (com.structurizr.view.ComponentView)2 RelationshipView (com.structurizr.view.RelationshipView)2 Shape (com.structurizr.view.Shape)2 Styles (com.structurizr.view.Styles)2 View (com.structurizr.view.View)2 JavaClass (com.tngtech.archunit.core.domain.JavaClass)2