Skip to content

Commit

Permalink
bump structurizr version 2.1.2 and fix removed or deprecated features
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskn committed May 10, 2024
1 parent 47028b7 commit 25205d2
Show file tree
Hide file tree
Showing 22 changed files with 259 additions and 123 deletions.
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ repositories {
mavenCentral()
}

val structurizrVersion = "1.29.0"
val structurizrExportVersion = "1.19.0"
val structurizrVersion = "2.1.2"
val structurizrExportVersion = "2.1.2"
val junitVersion = "5.10.2"
val assertJVersion = "3.25.3"
val detektVersion = "1.23.6"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.github.chriskn.structurizrextension.export.exporter.ComponentViewExpo
import com.github.chriskn.structurizrextension.export.exporter.ContainerViewExporter
import com.github.chriskn.structurizrextension.export.exporter.DeploymentViewExporter
import com.github.chriskn.structurizrextension.export.exporter.DynamicViewExporter
import com.github.chriskn.structurizrextension.export.exporter.LandscapeViewExporter
import com.github.chriskn.structurizrextension.export.writer.BoundaryWriter
import com.github.chriskn.structurizrextension.export.writer.ElementWriter
import com.github.chriskn.structurizrextension.export.writer.FooterWriter
Expand All @@ -23,6 +24,7 @@ import com.structurizr.view.DeploymentView
import com.structurizr.view.DynamicView
import com.structurizr.view.ModelView
import com.structurizr.view.RelationshipView
import com.structurizr.view.SystemLandscapeView

@Suppress("TooManyFunctions")
class ExtendedC4PlantUMLExporter : AbstractDiagramExporter() {
Expand Down Expand Up @@ -62,6 +64,13 @@ class ExtendedC4PlantUMLExporter : AbstractDiagramExporter() {
elementWriter,
relationshipWriter
)
private val contextViewExporter = LandscapeViewExporter(
boundaryWriter,
footerWriter,
headerWriter,
elementWriter,
relationshipWriter
)

override fun writeHeader(view: ModelView, writer: IndentingWriter) {
headerWriter.writeHeader(view, writer)
Expand Down Expand Up @@ -91,6 +100,8 @@ class ExtendedC4PlantUMLExporter : AbstractDiagramExporter() {

override fun export(view: ComponentView): Diagram = componentViewExporter.exportComponentView(view)

override fun export(view: SystemLandscapeView): Diagram = contextViewExporter.exportLandscapeView(view)

override fun createDiagram(view: ModelView, definition: String): Diagram = createC4Diagram(view, definition)

override fun startEnterpriseBoundary(view: ModelView, enterpriseName: String, writer: IndentingWriter) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package com.github.chriskn.structurizrextension.export.exporter

import com.github.chriskn.structurizrextension.export.createC4Diagram
import com.github.chriskn.structurizrextension.export.writer.BoundaryWriter
import com.github.chriskn.structurizrextension.export.writer.ElementWriter
import com.github.chriskn.structurizrextension.export.writer.FooterWriter
import com.github.chriskn.structurizrextension.export.writer.HeaderWriter
import com.github.chriskn.structurizrextension.export.writer.RelationshipWriter
import com.github.chriskn.structurizrextension.model.c4Location
import com.structurizr.export.Diagram
import com.structurizr.export.IndentingWriter
import com.structurizr.model.Element
import com.structurizr.model.Location
import com.structurizr.model.Person
import com.structurizr.model.SoftwareSystem
import com.structurizr.view.ModelView
import com.structurizr.view.SystemLandscapeView
import com.structurizr.view.showEnterpriseBoundary

class LandscapeViewExporter(
private val boundaryWriter: BoundaryWriter,
private val footerWriter: FooterWriter,
private val headerWriter: HeaderWriter,
private val elementWriter: ElementWriter,
private val relationshipWriter: RelationshipWriter
) {

internal fun exportLandscapeView(view: SystemLandscapeView): Diagram {
val writer = IndentingWriter()
headerWriter.writeHeader(view, writer)

val sortedElements = view.elements.sortedBy { it.id }
val systemsInEnterprise = systemsInEnterprise(view)
for (systemInEnterprise in systemsInEnterprise) {
val showEnterpriseBoundary = view.showEnterpriseBoundary
if (showEnterpriseBoundary) {
val enterpriseName = view.elements.map { it.element }.first().model.enterprise.name
boundaryWriter.startEnterpriseBoundary(enterpriseName, writer, view)
}
for (elementView in sortedElements) {
if (elementView.element === systemInEnterprise) {
elementWriter.writeElement(view, elementView.element, writer)
}
}
if (showEnterpriseBoundary) {
boundaryWriter.endEnterpriseBoundary(writer, view)
} else {
writer.writeLine()
}
}

var elementsWritten = false

for (elementView in sortedElements) {
elementWriter.writeElement(view, elementView.element, writer)
elementsWritten = true
}
if (elementsWritten) {
writer.writeLine()
}

relationshipWriter.writeRelationships(view, writer)

footerWriter.writeFooter(view, writer)

return createC4Diagram(view, writer.toString())
}

private fun systemsInEnterprise(view: ModelView): List<Element> =
view.elements
.map { it.element }
.filter {
(it is SoftwareSystem && it.c4Location == Location.Internal) || (it is Person && it.c4Location == Location.Internal)
}
.toSet()
.sortedBy { it.id }
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.github.chriskn.structurizrextension.export.writer

import com.github.chriskn.structurizrextension.export.idOf
import com.github.chriskn.structurizrextension.model.c4Location
import com.github.chriskn.structurizrextension.model.c4Type
import com.github.chriskn.structurizrextension.model.icon
import com.github.chriskn.structurizrextension.model.link
import com.github.chriskn.structurizrextension.model.location
import com.github.chriskn.structurizrextension.plantuml.IconRegistry
import com.structurizr.export.IndentingWriter
import com.structurizr.model.Component
Expand Down Expand Up @@ -74,21 +74,21 @@ class ElementWriter(
}"${linkString(link)})"""

private fun SoftwareSystem.toMacro(id: String) =
"""System${this.c4Type?.c4Type ?: ""}${this.location.toPlantUmlString()}($id, "$name", "${description ?: ""}", "${
"""System${this.c4Type?.c4Type ?: ""}${this.c4Location.toPlantUmlString()}($id, "$name", "${description ?: ""}", "${
IconRegistry.iconFileNameFor(
icon
) ?: ""
}"${linkString(link)})"""

private fun Container.toMacro(id: String): String =
"""Container${this.c4Type?.c4Type ?: ""}${this.location.toPlantUmlString()}($id, "$name", "$technology", "${description ?: ""}", "${
"""Container${this.c4Type?.c4Type ?: ""}${this.c4Location.toPlantUmlString()}($id, "$name", "$technology", "${description ?: ""}", "${
IconRegistry.iconFileNameFor(
icon
) ?: ""
}"${linkString(link)})"""

private fun Person.toMacro(): String {
val externalMarker = this.location.toPlantUmlString()
val externalMarker = this.c4Location.toPlantUmlString()
return """Person$externalMarker(${idOf(this)}, "$name", "${description ?: ""}", "${
IconRegistry.iconFileNameFor(
icon
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ data class C4Properties(
"Number of rows should not exceed $MAX_ROW_SIZE or number of header rows"
}
// Not supported. Issue: https://github.com/plantuml-stdlib/C4-PlantUML/issues/355
require(values.all { it.size > 1 } && header?.size?.let { it > 1 } == true) {
"C4PlantUml does not support single row properties"
require(values.all { it.size > 1 } && (header == null || header.size > 1)) {
"C4PlantUml does not support single row properties or property header"
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package com.github.chriskn.structurizrextension.model

import com.structurizr.export.plantuml.C4PlantUMLExporter
import com.structurizr.model.Component
import com.structurizr.model.Container
import com.structurizr.model.SoftwareSystem

/**
* Determines the shape of an Element in the rendered diagrams.
*/
Expand All @@ -16,7 +21,64 @@ enum class C4Type(val c4Type: String) {

companion object {
fun fromC4Type(c4Type: String): C4Type {
return values().first { it.c4Type == c4Type }
return entries.first { it.c4Type == c4Type }
}
}
}

var SoftwareSystem.c4Type: C4Type?
/**
* Returns the [C4Type] of the SoftwareSystem.
*/
get() = if (this.properties.containsKey(C4PlantUMLExporter.C4PLANTUML_SPRITE)) {
C4Type.fromC4Type(this.properties.getValue(C4PlantUMLExporter.C4PLANTUML_SPRITE))
} else {
null
}

/**
* Sets the [C4Type] of the SoftwareSystem.
*/
set(value) {
if (value != null) {
this.addProperty(C4PlantUMLExporter.C4PLANTUML_SPRITE, value.c4Type)
}
}

var Container.c4Type: C4Type?
/**
* Returns the [C4Type] of the container.
*/
get() = if (this.properties.containsKey(C4PlantUMLExporter.C4PLANTUML_SPRITE)) {
C4Type.fromC4Type(this.properties.getValue(C4PlantUMLExporter.C4PLANTUML_SPRITE))
} else {
null
}

/**
* Sets the [C4Type] of the container.
*/
set(value) {
if (value != null) {
this.addProperty(C4PlantUMLExporter.C4PLANTUML_SPRITE, value.c4Type)
}
}

var Component.c4Type: C4Type?
/**
* Returns the [C4Type] of the component.
*/
get() = if (this.properties.containsKey(C4PlantUMLExporter.C4PLANTUML_SPRITE)) {
C4Type.fromC4Type(this.properties.getValue(C4PlantUMLExporter.C4PLANTUML_SPRITE))
} else {
null
}

/**
* Sets the [C4Type] of the component.
*/
set(value) {
if (value != null) {
this.addProperty(C4PlantUMLExporter.C4PLANTUML_SPRITE, value.c4Type)
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
package com.github.chriskn.structurizrextension.model

import com.structurizr.export.plantuml.C4PlantUMLExporter
import com.structurizr.model.Component
import com.structurizr.model.Container
import com.structurizr.model.Location
import com.structurizr.model.StaticStructureElement

const val LOCATION_PROPERTY = "c4location"

/**
* Adds a component to this container.
*
Expand Down Expand Up @@ -42,35 +38,3 @@ fun Container.component(
component.configure(icon, link, tags, properties, uses, usedBy)
return component
}

var Container.c4Type: C4Type?
/**
* Returns the [C4Type] of the container.
*/
get() = if (this.properties.containsKey(C4PlantUMLExporter.C4PLANTUML_SPRITE)) {
C4Type.fromC4Type(this.properties.getValue(C4PlantUMLExporter.C4PLANTUML_SPRITE))
} else {
null
}

/**
* Sets the [C4Type] of the container.
*/
set(value) {
if (value != null) {
this.addProperty(C4PlantUMLExporter.C4PLANTUML_SPRITE, value.c4Type)
}
}

var Container.location: Location
/**
* Returns the [Location] of the container.
*/
get() = Location.valueOf(this.properties.getValue(LOCATION_PROPERTY))

/**
* Sets the [Location] of the container.
*/
set(location) {
this.addProperty(LOCATION_PROPERTY, location.name)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.github.chriskn.structurizrextension.model

import com.structurizr.model.Container
import com.structurizr.model.Location
import com.structurizr.model.Person
import com.structurizr.model.SoftwareSystem

private const val LOCATION_PROPERTY = "c4location"

var SoftwareSystem.c4Location: Location
/**
* Returns the [Location] of the SoftwareSystem.
*/
get() = Location.valueOf(this.properties.getValue(LOCATION_PROPERTY))

/**
* Sets the [Location] of the SoftwareSystem.
*/
set(location) {
this.addProperty(LOCATION_PROPERTY, location.name)
}

var Container.c4Location: Location
/**
* Returns the [Location] of the container.
*/
get() = Location.valueOf(this.properties.getValue(LOCATION_PROPERTY))

/**
* Sets the [Location] of the container.
*/
set(location) {
this.addProperty(LOCATION_PROPERTY, location.name)
}

var Person.c4Location: Location
/**
* Returns the [Location] of the Component.
*/
get() = Location.valueOf(this.properties.getValue(LOCATION_PROPERTY))

/**
* Sets the [Location] of the Component.
*/
set(location) {
this.addProperty(LOCATION_PROPERTY, location.name)
}
Loading

0 comments on commit 25205d2

Please sign in to comment.