Search in sources :

Example 1 with Module

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

the class DocumenterTest method writesSingleModuleDocumentation.

@Test
void writesSingleModuleDocumentation() throws IOException {
    Module module = // 
    documenter.getModules().getModuleByName("moduleB").orElseThrow(() -> new IllegalArgumentException());
    documenter.writeModuleAsPlantUml(module, // 
    Options.defaults().withColorSelector(// 
    it -> Optional.of("#ff0000")).withDefaultDisplayName(it -> it.getDisplayName().toUpperCase()));
    Options options = // 
    Options.defaults().withComponentFilter(component -> component.getRelationships().stream().anyMatch(it -> it.getTagsAsSet().contains(DependencyType.EVENT_LISTENER.toString())));
    documenter.writeModulesAsPlantUml(options);
}
Also used : Files(java.nio.file.Files) Application(com.acme.myproject.Application) IOException(java.io.IOException) Options(org.moduliths.docs.Documenter.Options) File(java.io.File) Test(org.junit.jupiter.api.Test) DependencyType(org.moduliths.model.Module.DependencyType) Module(org.moduliths.model.Module) Paths(java.nio.file.Paths) Assertions(org.assertj.core.api.Assertions) Optional(java.util.Optional) Comparator(java.util.Comparator) Path(java.nio.file.Path) Options(org.moduliths.docs.Documenter.Options) Module(org.moduliths.model.Module) Test(org.junit.jupiter.api.Test)

Example 2 with Module

use of org.moduliths.model.Module 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 3 with Module

use of org.moduliths.model.Module 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 4 with Module

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

the class Documenter method applyBackgroundColor.

private static Component applyBackgroundColor(Module module, Map<Module, Component> components, Options options, Styles styles) {
    Component component = components.get(module);
    Function<Module, Optional<String>> selector = options.getColorSelector();
    // Apply custom color if configured
    selector.apply(module).ifPresent(color -> {
        String tag = module.getName() + "-" + color;
        component.addTags(tag);
        // Add or update background color
        styles.getElements().stream().filter(it -> it.getTag().equals(tag)).findFirst().orElseGet(() -> styles.addElementStyle(tag)).background(color);
    });
    return component;
}
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) Component(com.structurizr.model.Component) Module(org.moduliths.model.Module)

Example 5 with Module

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

the class Asciidoctor method toOptionalLink.

private String toOptionalLink(JavaClass source, Optional<String> methodSignature) {
    Module module = modules.getModuleByType(source).orElse(null);
    String typeAndMethod = toCode(toTypeAndMethod(FormatableJavaClass.of(source).getAbbreviatedFullName(module), methodSignature));
    if (module == null || !source.getModifiers().contains(JavaModifier.PUBLIC) || !module.contains(source)) {
        return typeAndMethod;
    }
    String classPath = // 
    convertClassNameToResourcePath(source.getFullName()).replace('$', '.');
    return // 
    Optional.ofNullable(javaDocBase == PLACEHOLDER ? null : javaDocBase).map(// 
    it -> it.concat("/").concat(classPath).concat(".html")).map(// 
    it -> toLink(typeAndMethod, it)).orElseGet(() -> typeAndMethod);
}
Also used : JavaModifier(com.tngtech.archunit.core.domain.JavaModifier) ClassUtils(org.springframework.util.ClassUtils) JavaMethod(com.tngtech.archunit.core.domain.JavaMethod) EventType(org.moduliths.model.EventType) ModuleProperty(org.moduliths.docs.ConfigurationProperties.ModuleProperty) Collectors(java.util.stream.Collectors) CanvasOptions(org.moduliths.docs.Documenter.CanvasOptions) Module(org.moduliths.model.Module) Modules(org.moduliths.model.Modules) List(java.util.List) Matcher(java.util.regex.Matcher) Stream(java.util.stream.Stream) Groupings(org.moduliths.docs.Documenter.CanvasOptions.Groupings) ArchitecturallyEvidentType(org.moduliths.model.ArchitecturallyEvidentType) Optional(java.util.Optional) Source(org.moduliths.model.Source) SpringBean(org.moduliths.model.SpringBean) Nullable(org.springframework.lang.Nullable) JavaClass(com.tngtech.archunit.core.domain.JavaClass) Pattern(java.util.regex.Pattern) FormatableJavaClass(org.moduliths.model.FormatableJavaClass) Assert(org.springframework.util.Assert) StringUtils(org.springframework.util.StringUtils) Module(org.moduliths.model.Module)

Aggregations

Module (org.moduliths.model.Module)6 JavaClass (com.tngtech.archunit.core.domain.JavaClass)4 File (java.io.File)4 IOException (java.io.IOException)4 Files (java.nio.file.Files)4 Path (java.nio.file.Path)4 Paths (java.nio.file.Paths)4 Collectors (java.util.stream.Collectors)4 Stream (java.util.stream.Stream)4 Modules (org.moduliths.model.Modules)4 SpringBean (org.moduliths.model.SpringBean)4 Nullable (org.springframework.lang.Nullable)4 Assert (org.springframework.util.Assert)4 Workspace (com.structurizr.Workspace)3 Diagram (com.structurizr.io.Diagram)3 BasicPlantUMLWriter (com.structurizr.io.plantuml.BasicPlantUMLWriter)3 C4PlantUMLExporter (com.structurizr.io.plantuml.C4PlantUMLExporter)3 PlantUMLWriter (com.structurizr.io.plantuml.PlantUMLWriter)3 Component (com.structurizr.model.Component)3 Container (com.structurizr.model.Container)3