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()));
}
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;
}
Aggregations