log2uml

Java wrapper to PlantUml to draw diagrams directly from Java code

License

License

Categories

Categories

UML Business Logic Libraries Documents Processing
GroupId

GroupId

com.github.qbek
ArtifactId

ArtifactId

log2uml
Last Version

Last Version

0.2
Release Date

Release Date

Type

Type

jar
Description

Description

log2uml
Java wrapper to PlantUml to draw diagrams directly from Java code
Project URL

Project URL

https://github.com/qbek/log2uml
Source Code Management

Source Code Management

https://github.com/qbek/log2uml

Download log2uml

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.qbek/log2uml/ -->
<dependency>
    <groupId>com.github.qbek</groupId>
    <artifactId>log2uml</artifactId>
    <version>0.2</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.qbek/log2uml/
implementation 'com.github.qbek:log2uml:0.2'
// https://jarcasting.com/artifacts/com.github.qbek/log2uml/
implementation ("com.github.qbek:log2uml:0.2")
'com.github.qbek:log2uml:jar:0.2'
<dependency org="com.github.qbek" name="log2uml" rev="0.2">
  <artifact name="log2uml" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.qbek', module='log2uml', version='0.2')
)
libraryDependencies += "com.github.qbek" % "log2uml" % "0.2"
[com.github.qbek/log2uml "0.2"]

Dependencies

compile (1)

Group / Artifact Type Version
net.sourceforge.plantuml : plantuml jar 8057

test (3)

Group / Artifact Type Version
junit : junit jar 4.12
org.assertj : assertj-core jar 3.6.0
com.tngtech.jgiven : jgiven-junit jar 0.12.1

Project Modules

There are no modules declared in this project.

log2uml

Simple java wrapper for plantuml, allow to expressively create UML diagrams with java.

Getting started

Run examples

log2uml repository includes samples of all its features.

Compile it

mvn clean compile

and run it:

mvn exec:java

JAR file

To add log2uml as JAR to your project class path, first you have to generate it using following command:

mvn clean package

Maven dependency

You need to add following maven dependency to your pom.xml file:

<dependency>
    <groupId>com.github.qbek</groupId>
    <artifactId>log2uml</artifactId>
    <version>0.2</version>
</dependency>

Basic diagram

To create sequence diagram, just provide great title...

SequenceDiagram awesomeDiagram = SequenceDiagram.title("Awesome diagram");

...and you are ready to add elements to it...

awesomeDiagram.add(
    DefineMessage
        .from("John")
        .to("Diagram")
        .text("You are so awesome!")
        .type(MessageType.REQUEST),

    DefineMessage
        .from("Diagram")
        .to("John")
        .text("I know")
        .type(MessageType.RESPONSE)
);

...and finally you can save it to PNG file.

awesomeDiagram.save("awesome_diagram");

And this is result:

Awesome diagram example

https://github.com/qbek/log2uml/blob/docs/doc/awesome_diagram.png?raw=true

Sequence Diagram elements

Participants

You can declare many types of participants. They will be rendered in declaration order from left to right

SequenceDiagram example = SequenceDiagram.title("Declaring participants");

example.declare(
    DefineParticipant.name("actor").type(ParticipantType.ACTOR),
    DefineParticipant.name("boundary").type(ParticipantType.BOUNDARY),
    DefineParticipant.name("control").type(ParticipantType.CONTROL),
    DefineParticipant.name("database").type(ParticipantType.DATABASE),
    DefineParticipant.name("entity").type(ParticipantType.ENTITY),
    DefineParticipant.name("participant").type(ParticipantType.PARTICIPANT)
);

example.add(
  DefineMessage.from("actor").to("boundary").text("Hi!").type(MessageType.REQUEST)
);

As result you will get:

Declaring participants example

Messages

The most important element of each sequence diagram is a massage. Lets add some!

SequenceDiagram messages = SequenceDiagram.title("Messages");

messages.add(
    DefineMessage
        .from("Mighty Requestor")
        .to("Random Bob")
        .text("I'm requesting hi!")
        .type(MessageType.REQUEST),
    DefineMessage
        .from("Random Bob")
        .to("Mighty Requestor")
        .text("I'm responding with hi!")
        .type(MessageType.RESPONSE)
);

Result:

Message example

Message groups

You can also define message group:

SequenceDiagram group_example = SequenceDiagram.title("Message group");

group_example.add(
    DefineMessage
        .from("Bob")
        .to("Alice")
        .text("Hi!")
        .type(MessageType.REQUEST)
);

MessageGroup msgGroup = DefineMessageGroup
                            .name("Small talk")
                            .type(MessageGroupType.GROUP);

msgGroup.add(
    DefineMessage
        .from("Alice")
        .to("Bob")
        .text("Hi! How are you?")
        .type(MessageType.REQUEST),


    DefineMessage
        .from("Bob")
        .to("Alice")
        .text("I'm o'right!")
        .type(MessageType.RESPONSE)
);

group_example.add(msgGroup);

Generic group example

There are more types of groups ready to use:

  • OPT
  • LOOP
  • PARALLEL
  • BREAK
  • CRITICAL
  • ALTERNATIVE, ELSE

Simple example:

MessageGroup loopBreak = DefineMessageGroup
                                 .name("Repeat 100 times")
                                 .type(MessageGroupType.LOOP);

loopBreak.add(
        DefineMessage
                .from("Client")
                .to("Server")
                .text("request something fency")
                .type(MessageType.REQUEST),

        DefineMessageGroup
                .name("404 response")
                .type(MessageGroupType.BREAK)
                .add(
                        DefineMessage
                                .from("Client")
                                .to("LogServer")
                                .text("post logs")
                                .type(MessageType.REQUEST),
                        DefineMessage
                                .from("LogServer")
                                .to("Client")
                                .text("Roger!")
                                .type(MessageType.RESPONSE)
                )
);

MessageGroup altElse =
        DefineMessageGroup
                .name("Server up")
                .type(MessageGroupType.ALTERNATIVE)
                .add(DefineMessage
                             .from("Server")
                             .to("Client")
                             .text("Unicorn!!!")
                             .type(MessageType.RESPONSE),
                        DefineMessageGroup
                                .name("Server down")
                                .type(MessageGroupType.ELSE)
                                .add(DefineMessage
                                             .from("Server")
                                             .to("Client")
                                             .text("404")
                                             .type(MessageType.RESPONSE)
                                ),
                        DefineMessageGroup
                                .name("Server error")
                                .type(MessageGroupType.ELSE)
                                .add(DefineMessage
                                             .from("Server")
                                             .to("Client")
                                             .text("500")
                                             .type(MessageType.RESPONSE)
                                )
                );

SequenceDiagram group_types = SequenceDiagram.title("Message group types");
group_types.add(loopBreak);
group_types.add(
        DefineMessage
                .from("Client")
                .to("Server")
                .text("Give me a Unicorn!")
                .type(MessageType.REQUEST)
);

group_types.add(altElse);

Message group types example

Notes

You can add some note to

SequenceDiagram notes = SequenceDiagram.title("Notes");

notes.add(
        DefineMessage
                .from("Jeffrey")
                .to("Dad")
                .text("Daaaad, can I eat chocolate cake?")
                .type(MessageType.REQUEST),

        DefineNote
                .text("Typical morning request")
                .position(NotePosition.LEFT),

        DefineMessage
                .from("Dad")
                .to("Jeffrey")
                .text("Ask mother")
                .type(MessageType.RESPONSE),

        DefineNote
                .text("Defensive move")
                .position(NotePosition.RIGHT)
);

Message notes example

Versions

Version
0.2