11# Scala2PlantUML
22
3- [ ![ Continuous Integration] ( https://github.com/BotTech/scala2plantuml/actions/workflows/ci.yml/badge.svg )] ( https://github.com/BotTech/scala2plantuml/actions/workflows/ci.yml )
4- ![ Scala2PlantUML Version] ( https://img.shields.io/maven-central/v/nz.co.bottech/scala2plantuml_2.13?label=Scala2PlantUML )
3+ [ ![ Build badge] ( https://img.shields.io/github/workflow/status/BotTech/scala2plantuml/Continuous%20Integration/main )] ( https://github.com/BotTech/scala2plantuml/actions/workflows/ci.yml )
4+ [ ![ Maven-Central badge] ( https://img.shields.io/maven-central/v/nz.co.bottech/scala2plantuml_2.13 )] ( https://search.maven.org/search?q=g:nz.co.bottech%20a:*scala2plantuml* )
5+ [ ![ Scala Steward badge] ( https://img.shields.io/badge/Scala_Steward-helping-blue.svg?style=flat&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAQCAMAAAARSr4IAAAAVFBMVEUAAACHjojlOy5NWlrKzcYRKjGFjIbp293YycuLa3pYY2LSqql4f3pCUFTgSjNodYRmcXUsPD/NTTbjRS+2jomhgnzNc223cGvZS0HaSD0XLjbaSjElhIr+AAAAAXRSTlMAQObYZgAAAHlJREFUCNdNyosOwyAIhWHAQS1Vt7a77/3fcxxdmv0xwmckutAR1nkm4ggbyEcg/wWmlGLDAA3oL50xi6fk5ffZ3E2E3QfZDCcCN2YtbEWZt+Drc6u6rlqv7Uk0LdKqqr5rk2UCRXOk0vmQKGfc94nOJyQjouF9H/wCc9gECEYfONoAAAAASUVORK5CYII= )] ( https://scala-steward.org )
56
67Scala2PlantUML generates [ PlantUML] diagrams from Scala code.
78
@@ -10,6 +11,40 @@ It comes as a standalone library, a CLI tool and an sbt plugin.
1011Scala2PlantUML consumes [ SemanticDB] files so you will need to know how to create those or simply follow the sbt setup
1112instructions below.
1213
14+ ## Example
15+
16+ ``` shell
17+ scala2plantuml \
18+ --url ' https://repo1.maven.org/maven2/nz/co/bottech/scala2plantuml-example_2.13/0.2.0/scala2plantuml-example_2.13-0.2.0.jar' \
19+ --project example \
20+ " nz/co/bottech/scala2plantuml/example/Main."
21+ ```
22+
23+ ``` text
24+ @startuml
25+ class A extends B {
26+ + {method} <init>
27+ + {method} b
28+ }
29+ A o-- C
30+ interface B {
31+ + {abstract} {method} b
32+ }
33+ B o-- C
34+ class C {
35+ + {method} <init>
36+ + {field} value
37+ }
38+ C o-- A
39+ class Main {
40+ + {static} {field} a
41+ }
42+ Main o-- A
43+ @enduml
44+ ```
45+
46+ ![ Example Class Diagram] ( http://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/BotTech/scala2plantuml/main/example/example.md )
47+
1348## sbt
1449
1550### Enable SemanticDB
@@ -36,9 +71,24 @@ For most use cases you should add Scala2PlantUML as a global plugin since your b
3671Create ` ~/.sbt/1.0/plugins/scala2PlantUML.sbt ` containing:
3772
3873``` text
39- addSbtPlugin("nz.co.bottech" % "sbt-scala2plantuml" % "0.1.12")
74+ addSbtPlugin("nz.co.bottech" % "sbt-scala2plantuml" % "0.2.0")
75+ ```
76+
77+ ### Generate the Diagram
78+
79+ Run the ` scala2PlantUML ` task from sbt:
80+
81+ ``` sbt
82+ scala2PlantUML " com/example/Foo#"
4083```
4184
85+ This accepts the following arguments:
86+ - ` --include `
87+ - ` --exclude `
88+ - ` --output `
89+
90+ Refer to the [ CLI Usage] ( #usage ) for the definition of these arguments.
91+
4292## CLI
4393
4494### Install
@@ -51,19 +101,23 @@ cs install --channel https://git.io/Jqv1i scala2plantuml
51101
52102### Usage
53103
104+ ``` shell
105+ scala2plantuml --help
106+ ```
107+
54108``` text
55- Scala2PlantUML version 0.1.12
109+ Scala2PlantUML version 0.2.0
56110Usage: scala2plantuml [options] symbol
57111
58112Scala2PlantUML generates PlantUML Class Diagrams from Scala SemanticDB files.
59113
60114 symbol The symbol to use as the starting point for generating the diagram.
61-
115+
62116 To get a symbol from a class name, convert the package name separate '.' to '/' and add a '#'
63117 suffix. For an object use a suffix of '.'.
64-
118+
65119 See https://scalameta.org/docs/semanticdb/specification.html#symbol-1 for the full syntax.
66-
120+
67121 Examples:
68122 'com/example/Foo#' (class com.example.Foo)
69123 'com/example/Foo.' (object com.example.Foo)
@@ -77,16 +131,16 @@ The pattern supports two wildcards:
771312) * (matches all characters except for '/')
78132
79133 -i, --include <pattern> Only include symbols that match the pattern.
80-
134+
81135 Default: '**'
82-
136+
83137 Example:
84138 --include 'com/example/**/model/*'
85139
86140 -e, --exclude <pattern> Excludes all symbols that match the pattern.
87-
141+
88142 Default: 'scala/**', 'java/**'
89-
143+
90144 Example:
91145 --exclude 'com/example/**/data/*'
92146
@@ -96,62 +150,73 @@ Each of these can be provided multiple times.
96150By default, the classpath that was used when executing Scala2PlantUML is also used.
97151
98152 -d, --dir <dir> Directories of the SemanticDB target roots containing META-INF/semanticdb/**/*.semanticdb files.
99-
153+
100154 Example:
101155 --dir 'my-project/target/scala-2.13/meta'
102156
103157 -j, --jar <jar> JAR containing META-INF/semanticdb/**/*.semanticdb files.
104-
158+
105159 Example:
106160 --jar 'foo.jar'
107161
108162 -u, --url <url> A URL to a JAR containing META-INF/semanticdb/**/*.semanticdb files.
109-
163+
110164 Example:
111165 --url 'https://repo1.maven.org/maven2/com/example/foo/foo_2.13/1.0.0/foo_2.13-1.0.0-semanticdb.jar'
112166
113167The --project and --source options specify where within the search locations the SemanticDB files can be found.
114168Each of these can be provided multiple times. The result will be all combinations of projects and source roots.
115169
116170 -p, --project <project> The name of the projects that have SemanticDB files.
117-
171+
118172 The project name will be used when looking for SemanticDB files such as:
119173 META-INF/semanticdb/<project>/<source>/*.semanticdb
120-
174+
121175 An empty project name will search in:
122176 META-INF/semanticdb/<source>/*.semanticdb
123-
177+
124178 Default: ''
125-
179+
126180 Example:
127181 --project my-project
128182
129183 -s, --source <source> The directory relative to the project where the source files were located.
130-
184+
131185 The source will be used when looking for SemanticDB files such as
132186 META-INF/semanticdb/<project>/<source>/*.semanticdb.
133-
187+
134188 Default: src/main/scala
135-
189+
136190 Example:
137191 --source 'source/scala'
138192
139- -o, --output <file> Write the output to the given file.
193+ -l, --max-level <level> The maximum number of levels that will be traversed when following symbol references.
194+
195+ This means that parent symbols that would be beyond the max level will not be shown.
196+
197+ A diagram with a max-level of 1 will only contain the initial symbol.
198+
199+ Default: Unlimited
200+
201+ Example:
202+ --max-level 3
140203
204+ -o, --output <file> Write the output to the given file.
205+
141206 Example:
142207 --output docs/diagrams/my-project.puml
143208
144209 -c, --colour <value> Enables coloured output.
145-
210+
146211 Default: true
147-
212+
148213 Example:
149214 --colour false
150215
151216 -v, --verbose Increases the log level.
152-
217+
153218 This can be provided twice for the most verbose logging.
154-
219+
155220 Example:
156221 -vv
157222
@@ -163,6 +228,18 @@ Each of these can be provided multiple times. The result will be all combination
163228
164229> 🚧 TODO: Document Library.
165230
231+ ## Limitations
232+
233+ - Only class diagrams are supported.
234+ - Only inheritance or aggregations are supported, compositions are shown as aggregations.
235+ - Aggregations are shown between types not between fields. There is a [ bug] [ namespaced field links ] in PlantUML which
236+ prevents us from being able to do this reliably.
237+ - There is no reliable way to determine the path to a SemanticDB file from any symbol.
238+ If Scala2PlantUML is unable to find your symbols then the following may help:
239+ - Only have a single top level type in each file.
240+ - Ensure that the file name matches the type name.
241+ - Nest any subclasses of a sealed class within the companion object of the sealed class.
242+
166243[ coursier ] : https://get-coursier.io/docs/cli-install
167244[ plantuml ] : https://plantuml.com/
168245[ semanticdb ] : https://scalameta.org/docs/semanticdb/guide.html
0 commit comments