Search in sources :

Example 1 with CallGraphModel

use of org.ndx.agile.architecture.sequence.generator.javaparser.adapter.CallGraphModel in project agile-architecture-documentation-system by Riduidel.

the class SequenceDiagramVisitorTest method can_read_a_model.

@Test
@Disabled
void can_read_a_model() {
    // Given all those elements
    Workspace workspace = new Workspace("test workspace", "test workspace");
    Model model = workspace.getModel();
    SoftwareSystem system = model.addSoftwareSystem("agile-architecture-documentation-system");
    Container sequenceGenerator = system.addContainer("sequence-generator", "generator", "Java/Maven");
    sequenceGenerator.addProperty(SequenceGenerator.GENERATES_WITH, StructurizrUtils.getCanonicalPath(sequenceGenerator));
    sequenceGenerator.addProperty(ModelElementKeys.JAVA_SOURCES, new File("src/main/java").toURI().toString());
    Component visitor = sequenceGenerator.addComponent(SequenceDiagramVisitor.class.getSimpleName(), "visitor building the sequence");
    visitor.addSupportingType(SequenceDiagramVisitor.class.getName());
    Component callGraphModel = sequenceGenerator.addComponent(CallGraphModel.class.getSimpleName(), "navigator accumulating data");
    callGraphModel.addSupportingType(CallGraphModel.class.getName());
    Component generator = sequenceGenerator.addComponent(SequenceDiagramGenerator.class.getSimpleName(), "Component producing the sequence diagram");
    generator.addSupportingType(SequenceDiagramGenerator.class.getName());
    // Let's build a sequence diagram visitor
    SequenceDiagramVisitor tested = new SequenceDiagramVisitor();
    tested.logger = Logger.getLogger(getClass().getName());
    tested.destination = new File("target/tests/" + getClass().getSimpleName());
    // Emulate the standard visit
    tested.startVisit(model);
    tested.startVisit(system);
    assertThat(tested.allContainers).hasSize(1);
    assertThat(tested.codeToComponents).hasSize(3);
    assertThat(tested.callGraphModel).isNull();
    // And finally, visit the container and parse source code
    tested.startVisit(sequenceGenerator);
    assertThat(tested.callGraphModel).isNotNull();
    // And visit components to see what happens
    assertThat(tested.startVisit(visitor)).isTrue();
    // And that something is generated
    tested.endVisit(visitor, new SimpleOutputBuilder(tested.destination));
    assertThat(tested.destination).isDirectoryContaining(file -> file.getName().equals(system.getName()));
}
Also used : Container(com.structurizr.model.Container) CallGraphModel(org.ndx.agile.architecture.sequence.generator.javaparser.adapter.CallGraphModel) SequenceDiagramGenerator(org.ndx.agile.architecture.sequence.generator.javaparser.generator.SequenceDiagramGenerator) CallGraphModel(org.ndx.agile.architecture.sequence.generator.javaparser.adapter.CallGraphModel) Model(com.structurizr.model.Model) SoftwareSystem(com.structurizr.model.SoftwareSystem) Component(com.structurizr.model.Component) File(java.io.File) Workspace(com.structurizr.Workspace) SimpleOutputBuilder(org.ndx.agile.architecture.base.utils.SimpleOutputBuilder) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 2 with CallGraphModel

use of org.ndx.agile.architecture.sequence.generator.javaparser.adapter.CallGraphModel in project agile-architecture-documentation-system by Riduidel.

the class SequenceDiagramVisitor method startVisit.

@Override
public boolean startVisit(Container container) {
    if (allowSequenceGeneration(container)) {
        if (container.getProperties().containsKey(ModelElementKeys.JAVA_SOURCES)) {
            ProjectRoot projectRoot = createProjectRootFor(container);
            Map<String, CompilationUnit> sources = parseAllSources(projectRoot);
            callGraphModel = new CallGraphModel(codeToComponents, sources);
            // Now we have all compilation units parsed, let's try to analyze that a little by, say,
            // mapping class names to their associated compilation units
            callGraphModel.analyzeCalls(getComponentsToScanFor(container).stream().flatMap(component -> component.getCode().stream()).map(code -> code.getType()).collect(Collectors.toList()));
            return true;
        } else {
            logger.log(Level.SEVERE, String.format("Unable to generate sequence diagrams since container %s has no associated sources", StructurizrUtils.getCanonicalPath(container)));
        }
    }
    // In any missing info case, return false
    return false;
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) SequenceGenerator(org.ndx.agile.architecture.sequence.generator.SequenceGenerator) ParseResult(com.github.javaparser.ParseResult) OutputBuilder(org.ndx.agile.architecture.base.OutputBuilder) ModelElementAdapter(org.ndx.agile.architecture.base.enhancers.ModelElementAdapter) Function(java.util.function.Function) Component(com.structurizr.model.Component) ConfigProperty(org.apache.deltaspike.core.api.config.ConfigProperty) ModelElementKeys(org.ndx.agile.architecture.base.enhancers.ModelElementKeys) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) Inject(javax.inject.Inject) CodeElement(com.structurizr.model.CodeElement) StructurizrUtils(org.ndx.agile.architecture.base.utils.StructurizrUtils) Map(java.util.Map) CompilationUnit(com.github.javaparser.ast.CompilationUnit) LinkedList(java.util.LinkedList) ProjectRoot(com.github.javaparser.utils.ProjectRoot) Method(java.lang.reflect.Method) Path(java.nio.file.Path) Model(com.structurizr.model.Model) SourceRoot(com.github.javaparser.utils.SourceRoot) Container(com.structurizr.model.Container) Collection(java.util.Collection) Set(java.util.Set) IOException(java.io.IOException) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) CallGraphModel(org.ndx.agile.architecture.sequence.generator.javaparser.adapter.CallGraphModel) File(java.io.File) List(java.util.List) Stream(java.util.stream.Stream) TreeMap(java.util.TreeMap) Modifier(java.lang.reflect.Modifier) CallGraphModel(org.ndx.agile.architecture.sequence.generator.javaparser.adapter.CallGraphModel) ProjectRoot(com.github.javaparser.utils.ProjectRoot)

Aggregations

Component (com.structurizr.model.Component)2 Container (com.structurizr.model.Container)2 Model (com.structurizr.model.Model)2 File (java.io.File)2 CallGraphModel (org.ndx.agile.architecture.sequence.generator.javaparser.adapter.CallGraphModel)2 ParseResult (com.github.javaparser.ParseResult)1 CompilationUnit (com.github.javaparser.ast.CompilationUnit)1 ProjectRoot (com.github.javaparser.utils.ProjectRoot)1 SourceRoot (com.github.javaparser.utils.SourceRoot)1 Workspace (com.structurizr.Workspace)1 CodeElement (com.structurizr.model.CodeElement)1 SoftwareSystem (com.structurizr.model.SoftwareSystem)1 IOException (java.io.IOException)1 Method (java.lang.reflect.Method)1 Modifier (java.lang.reflect.Modifier)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1