@@ -137,25 +137,11 @@ private Documenter(ApplicationModules modules, String outputFolder) {
137
137
this .properties = new ConfigurationProperties ();
138
138
}
139
139
140
- private Map <ApplicationModule , Component > getComponents (Options options ) {
141
-
142
- if (components == null ) {
143
-
144
- this .components = modules .stream () //
145
- .collect (Collectors .toMap (Function .identity (),
146
- it -> container .addComponent (options .getDefaultDisplayName ().apply (it ), "" , "Module" )));
147
-
148
- this .components .forEach ((key , value ) -> addDependencies (key , value , options ));
149
- }
150
-
151
- return components ;
152
- }
153
-
154
140
/**
155
141
* Customize the output folder to write the generated files to. Defaults to {@value #DEFAULT_LOCATION}.
156
142
*
157
143
* @param outputFolder must not be {@literal null} or empty.
158
- * @return
144
+ * @return the current instance, will never be {@literal null}.
159
145
* @see #DEFAULT_LOCATION
160
146
*/
161
147
public Documenter withOutputFolder (String outputFolder ) {
@@ -169,24 +155,49 @@ public Documenter withOutputFolder(String outputFolder) {
169
155
* <li>Individual component diagrams per module to include all upstream modules.</li>
170
156
* <li>The Module Canvas for each module.</li>
171
157
* </ul>
158
+ * using {@link DiagramOptions#defaults()} and {@link CanvasOptions#defaults()}.
172
159
*
173
- * @param options must not be {@literal null}, use {@link Options#defaults()} for default.
174
- * @param canvasOptions must not be {@literal null}, use {@link CanvasOptions#defaults()} for default.
175
160
* @return the current instance, will never be {@literal null}.
176
161
*/
177
- public Documenter writeDocumentation (Options options , CanvasOptions canvasOptions ) {
162
+ public Documenter writeDocumentation () {
163
+ return writeDocumentation (DiagramOptions .defaults (), CanvasOptions .defaults ());
164
+ }
165
+
166
+ /**
167
+ * Writes all available documentation:
168
+ * <ul>
169
+ * <li>The entire set of modules as overview component diagram.</li>
170
+ * <li>Individual component diagrams per module to include all upstream modules.</li>
171
+ * <li>The Module Canvas for each module.</li>
172
+ * </ul>
173
+ *
174
+ * @param options must not be {@literal null}.
175
+ * @param canvasOptions must not be {@literal null}.
176
+ * @return the current instance, will never be {@literal null}.
177
+ */
178
+ public Documenter writeDocumentation (DiagramOptions options , CanvasOptions canvasOptions ) {
178
179
179
180
return writeModulesAsPlantUml (options )
180
181
.writeIndividualModulesAsPlantUml (options ) //
181
182
.writeModuleCanvases (canvasOptions );
182
183
}
183
184
184
185
/**
185
- * Writes the PlantUML component diagram for all {@link ApplicationModules}.
186
+ * Writes the PlantUML component diagram for all {@link ApplicationModules} using {@link DiagramOptions#defaults()}.
187
+ *
188
+ * @return the current instance, will never be {@literal null}.
189
+ */
190
+ public Documenter writeModulesAsPlantUml () {
191
+ return writeModulesAsPlantUml (DiagramOptions .defaults ());
192
+ }
193
+
194
+ /**
195
+ * Writes the PlantUML component diagram for all {@link ApplicationModules} with the given {@link DiagramOptions}.
186
196
*
187
197
* @param options must not be {@literal null}.
198
+ * @return the current instance, will never be {@literal null}.
188
199
*/
189
- public Documenter writeModulesAsPlantUml (Options options ) {
200
+ public Documenter writeModulesAsPlantUml (DiagramOptions options ) {
190
201
191
202
Assert .notNull (options , "Options must not be null!" );
192
203
@@ -201,13 +212,19 @@ public Documenter writeModulesAsPlantUml(Options options) {
201
212
return this ;
202
213
}
203
214
215
+ public Documenter writeIndividualModulesAsPlantUml () {
216
+ return writeIndividualModulesAsPlantUml (DiagramOptions .defaults ());
217
+ }
218
+
204
219
/**
205
220
* Writes the component diagrams for all individual modules.
206
221
*
207
222
* @param options must not be {@literal null}.
208
223
* @return the current instance, will never be {@literal null}.
209
224
*/
210
- public Documenter writeIndividualModulesAsPlantUml (Options options ) {
225
+ public Documenter writeIndividualModulesAsPlantUml (DiagramOptions options ) {
226
+
227
+ Assert .notNull (options , "DiagramOptions must not be null!" );
211
228
212
229
modules .forEach (it -> writeModuleAsPlantUml (it , options ));
213
230
@@ -224,18 +241,18 @@ public Documenter writeModuleAsPlantUml(ApplicationModule module) {
224
241
225
242
Assert .notNull (module , "Module must not be null!" );
226
243
227
- return writeModuleAsPlantUml (module , Options .defaults ());
244
+ return writeModuleAsPlantUml (module , DiagramOptions .defaults ());
228
245
}
229
246
230
247
/**
231
248
* Writes the PlantUML component diagram for the given {@link ApplicationModule} with the given rendering
232
- * {@link Options }.
249
+ * {@link DiagramOptions }.
233
250
*
234
251
* @param module must not be {@literal null}.
235
252
* @param options must not be {@literal null}.
236
253
* @return the current instance, will never be {@literal null}.
237
254
*/
238
- public Documenter writeModuleAsPlantUml (ApplicationModule module , Options options ) {
255
+ public Documenter writeModuleAsPlantUml (ApplicationModule module , DiagramOptions options ) {
239
256
240
257
Assert .notNull (module , "Module must not be null!" );
241
258
Assert .notNull (options , "Options must not be null!" );
@@ -253,16 +270,24 @@ public Documenter writeModuleAsPlantUml(ApplicationModule module, Options option
253
270
}
254
271
255
272
/**
256
- * Writes all module canvases using {@link Options #defaults()}.
273
+ * Writes all module canvases using {@link DiagramOptions #defaults()}.
257
274
*
258
275
* @return the current instance, will never be {@literal null}.
259
276
*/
260
277
public Documenter writeModuleCanvases () {
261
278
return writeModuleCanvases (CanvasOptions .defaults ());
262
279
}
263
280
281
+ /**
282
+ * Writes all module canvases using the given {@link DiagramOptions}.
283
+ *
284
+ * @param options must not be {@literal null}.
285
+ * @return the current instance, will never be {@literal null}.
286
+ */
264
287
public Documenter writeModuleCanvases (CanvasOptions options ) {
265
288
289
+ Assert .notNull (options , "CanvasOptions must not be null!" );
290
+
266
291
modules .forEach (module -> {
267
292
268
293
String filename = String .format (options .getTargetFileName ().orElse ("module-%s.adoc" ), module .getName ());
@@ -280,15 +305,15 @@ public Documenter writeModuleCanvases(CanvasOptions options) {
280
305
return this ;
281
306
}
282
307
283
- public String toModuleCanvas (ApplicationModule module ) {
308
+ String toModuleCanvas (ApplicationModule module ) {
284
309
return toModuleCanvas (module , CanvasOptions .defaults ());
285
310
}
286
311
287
- public String toModuleCanvas (ApplicationModule module , String apiBase ) {
312
+ String toModuleCanvas (ApplicationModule module , String apiBase ) {
288
313
return toModuleCanvas (module , CanvasOptions .defaults ().withApiBase (apiBase ));
289
314
}
290
315
291
- public String toModuleCanvas (ApplicationModule module , CanvasOptions options ) {
316
+ String toModuleCanvas (ApplicationModule module , CanvasOptions options ) {
292
317
293
318
Asciidoctor asciidoctor = Asciidoctor .withJavadocBase (modules , options .getApiBase ());
294
319
Function <List <JavaClass >, String > mapper = asciidoctor ::typesToBulletPoints ;
@@ -314,11 +339,11 @@ private <T> String addTableRow(List<T> types, String header, Function<List<T>, S
314
339
return types .isEmpty () ? "" : writeTableRow (header , mapper .apply (types ));
315
340
}
316
341
317
- public String toPlantUml () {
318
- return createPlantUml (Options .defaults ());
342
+ String toPlantUml () {
343
+ return createPlantUml (DiagramOptions .defaults ());
319
344
}
320
345
321
- private void addDependencies (ApplicationModule module , Component component , Options options ) {
346
+ private void addDependencies (ApplicationModule module , Component component , DiagramOptions options ) {
322
347
323
348
DEPENDENCY_DESCRIPTIONS .entrySet ().stream ().forEach (entry -> {
324
349
@@ -339,7 +364,21 @@ private void addDependencies(ApplicationModule module, Component component, Opti
339
364
});
340
365
}
341
366
342
- private void addComponentsToView (ApplicationModule module , ComponentView view , Options options ) {
367
+ private Map <ApplicationModule , Component > getComponents (DiagramOptions options ) {
368
+
369
+ if (components == null ) {
370
+
371
+ this .components = modules .stream () //
372
+ .collect (Collectors .toMap (Function .identity (),
373
+ it -> container .addComponent (options .getDefaultDisplayName ().apply (it ), "" , "Module" )));
374
+
375
+ this .components .forEach ((key , value ) -> addDependencies (key , value , options ));
376
+ }
377
+
378
+ return components ;
379
+ }
380
+
381
+ private void addComponentsToView (ApplicationModule module , ComponentView view , DiagramOptions options ) {
343
382
344
383
Supplier <Stream <ApplicationModule >> bootstrapDependencies = () -> module .getBootstrapDependencies (modules ,
345
384
options .getDependencyDepth ());
@@ -352,7 +391,8 @@ private void addComponentsToView(ApplicationModule module, ComponentView view, O
352
391
addComponentsToView (dependencies , view , options , it -> it .add (getComponents (options ).get (module )));
353
392
}
354
393
355
- private void addComponentsToView (Supplier <Stream <ApplicationModule >> modules , ComponentView view , Options options ,
394
+ private void addComponentsToView (Supplier <Stream <ApplicationModule >> modules , ComponentView view ,
395
+ DiagramOptions options ,
356
396
Consumer <ComponentView > afterCleanup ) {
357
397
358
398
Styles styles = view .getViewSet ().getConfiguration ().getStyles ();
@@ -409,8 +449,9 @@ private void potentiallyRemoveDefaultRelationship(View view, Collection<Relation
409
449
.findFirst ().ifPresent (view ::remove );
410
450
}
411
451
412
- private static Component applyBackgroundColor (ApplicationModule module , Map <ApplicationModule , Component > components ,
413
- Options options ,
452
+ private static Component applyBackgroundColor (ApplicationModule module ,
453
+ Map <ApplicationModule , Component > components ,
454
+ DiagramOptions options ,
414
455
Styles styles ) {
415
456
416
457
Component component = components .get (module );
@@ -433,7 +474,7 @@ private static Component applyBackgroundColor(ApplicationModule module, Map<Appl
433
474
return component ;
434
475
}
435
476
436
- private Documenter writeViewAsPlantUml (ComponentView view , String filename , Options options ) {
477
+ private Documenter writeViewAsPlantUml (ComponentView view , String filename , DiagramOptions options ) {
437
478
438
479
Path file = recreateFile (filename );
439
480
@@ -448,7 +489,7 @@ private Documenter writeViewAsPlantUml(ComponentView view, String filename, Opti
448
489
}
449
490
}
450
491
451
- private String render (ComponentView view , Options options ) {
492
+ private String render (ComponentView view , DiagramOptions options ) {
452
493
453
494
switch (options .style ) {
454
495
@@ -470,7 +511,7 @@ private String render(ComponentView view, Options options) {
470
511
}
471
512
}
472
513
473
- private String createPlantUml (Options options ) {
514
+ private String createPlantUml (DiagramOptions options ) {
474
515
475
516
ComponentView componentView = createComponentView (options );
476
517
componentView .setTitle (modules .getSystemName ().orElse ("Modules" ));
@@ -480,11 +521,11 @@ private String createPlantUml(Options options) {
480
521
return render (componentView , options );
481
522
}
482
523
483
- private ComponentView createComponentView (Options options ) {
524
+ private ComponentView createComponentView (DiagramOptions options ) {
484
525
return createComponentView (options , null );
485
526
}
486
527
487
- private ComponentView createComponentView (Options options , @ Nullable ApplicationModule module ) {
528
+ private ComponentView createComponentView (DiagramOptions options , @ Nullable ApplicationModule module ) {
488
529
489
530
String prefix = module == null ? "modules-" : module .getName ();
490
531
@@ -533,7 +574,7 @@ public static Connection of(Relationship relationship) {
533
574
*/
534
575
@ Getter (AccessLevel .PRIVATE )
535
576
@ RequiredArgsConstructor (access = AccessLevel .PRIVATE )
536
- public static class Options {
577
+ public static class DiagramOptions {
537
578
538
579
private static final Set <DependencyType > ALL_TYPES = Arrays .stream (DependencyType .values ())
539
580
.collect (Collectors .toSet ());
@@ -551,7 +592,8 @@ public static class Options {
551
592
private final @ With Predicate <ApplicationModule > exclusions ;
552
593
553
594
/**
554
- * A {@link Predicate} to define which Structurizr {@link Component}s to be included in the diagram to be created.
595
+ * A {@link Predicate} to define which Structurizr {@link Component}s to be included in the diagram to be
596
+ * created.
555
597
*/
556
598
private final @ With Predicate <Component > componentFilter ;
557
599
@@ -574,8 +616,8 @@ public static class Options {
574
616
private final @ With Function <ApplicationModule , Optional <String >> colorSelector ;
575
617
576
618
/**
577
- * A callback to return a default display names for a given {@link ApplicationModule}. Default implementation just
578
- * forwards to {@link ApplicationModule#getDisplayName()}.
619
+ * A callback to return a default display names for a given {@link ApplicationModule}. Default implementation
620
+ * just forwards to {@link ApplicationModule#getDisplayName()}.
579
621
*/
580
622
private final @ With Function <ApplicationModule , String > defaultDisplayName ;
581
623
@@ -587,23 +629,24 @@ public static class Options {
587
629
/**
588
630
* Configuration setting to define whether modules that do not have a relationship to any other module shall be
589
631
* retained in the diagrams created. The default is {@value ElementsWithoutRelationships#HIDDEN}. See
590
- * {@link Options #withExclusions(Predicate)} for a more fine-grained way of defining which modules to exclude in
591
- * case you flip this to {@link ElementsWithoutRelationships#VISIBLE}.
632
+ * {@link DiagramOptions #withExclusions(Predicate)} for a more fine-grained way of defining which modules to
633
+ * exclude in case you flip this to {@link ElementsWithoutRelationships#VISIBLE}.
592
634
*
593
635
* @see #withExclusions(Predicate)
594
636
*/
595
637
private final @ With ElementsWithoutRelationships elementsWithoutRelationships ;
596
638
597
639
/**
598
- * Creates a new default {@link Options } instance configured to use all dependency types, list immediate
640
+ * Creates a new default {@link DiagramOptions } instance configured to use all dependency types, list immediate
599
641
* dependencies for individual module instances, not applying any kind of {@link ApplicationModule} or
600
642
* {@link Component} filters and default file names.
601
643
*
602
644
* @return will never be {@literal null}.
603
645
*/
604
- public static Options defaults () {
605
- return new Options (ALL_TYPES , DependencyDepth .IMMEDIATE , it -> false , it -> true , it -> false , null ,
606
- __ -> Optional .empty (), it -> it .getDisplayName (), DiagramStyle .C4 , ElementsWithoutRelationships .HIDDEN );
646
+ public static DiagramOptions defaults () {
647
+ return new DiagramOptions (ALL_TYPES , DependencyDepth .IMMEDIATE , it -> false , it -> true , it -> false , null ,
648
+ __ -> Optional .empty (), it -> it .getDisplayName (), DiagramStyle .C4 ,
649
+ ElementsWithoutRelationships .HIDDEN );
607
650
}
608
651
609
652
/**
@@ -612,13 +655,14 @@ public static Options defaults() {
612
655
* @param types must not be {@literal null}.
613
656
* @return
614
657
*/
615
- public Options withDependencyTypes (DependencyType ... types ) {
658
+ public DiagramOptions withDependencyTypes (DependencyType ... types ) {
616
659
617
660
Assert .notNull (types , "Dependency types must not be null!" );
618
661
619
662
Set <DependencyType > dependencyTypes = Arrays .stream (types ).collect (Collectors .toSet ());
620
663
621
- return new Options (dependencyTypes , dependencyDepth , exclusions , componentFilter , targetOnly , targetFileName ,
664
+ return new DiagramOptions (dependencyTypes , dependencyDepth , exclusions , componentFilter , targetOnly ,
665
+ targetFileName ,
622
666
colorSelector , defaultDisplayName , style , elementsWithoutRelationships );
623
667
}
624
668
@@ -657,11 +701,11 @@ public enum DiagramStyle {
657
701
/**
658
702
* Configuration setting to define whether modules that do not have a relationship to any other module shall be
659
703
* retained in the diagrams created. The default is {@value ElementsWithoutRelationships#HIDDEN}. See
660
- * {@link Options #withExclusions(Predicate)} for a more fine-grained way of defining which modules to exclude in
661
- * case you flip this to {@link ElementsWithoutRelationships#VISIBLE}.
704
+ * {@link DiagramOptions #withExclusions(Predicate)} for a more fine-grained way of defining which modules to
705
+ * exclude in case you flip this to {@link ElementsWithoutRelationships#VISIBLE}.
662
706
*
663
707
* @author Oliver Drotbohm
664
- * @see Options #withExclusions(Predicate)
708
+ * @see DiagramOptions #withExclusions(Predicate)
665
709
*/
666
710
public enum ElementsWithoutRelationships {
667
711
HIDDEN , VISIBLE ;
0 commit comments