Skip to content

Commit

Permalink
Updates structurizr-java to v3.0.0 - adds support for remote workspac…
Browse files Browse the repository at this point in the history
…e branches.
  • Loading branch information
simonbrowndotje committed Sep 19, 2024
1 parent cfae3e1 commit 3d0c529
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 31 deletions.
9 changes: 5 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ targetCompatibility = '17'

repositories {
mavenCentral()
// mavenLocal()
}

testing {
Expand Down Expand Up @@ -47,14 +46,16 @@ ext {
}

dependencies {
def structurizrVersion = '3.0.0'

implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.apache.tomcat.embed:tomcat-embed-jasper:10.1.24'
implementation 'jakarta.servlet.jsp.jstl:jakarta.servlet.jsp.jstl-api:3.0.0'
implementation 'org.glassfish.web:jakarta.servlet.jsp.jstl:3.0.1'

implementation 'com.structurizr:structurizr-dsl:2.2.0'
implementation 'com.structurizr:structurizr-autolayout:2.2.0'
implementation 'com.structurizr:structurizr-inspection:2.2.0'
implementation "com.structurizr:structurizr-dsl:${structurizrVersion}"
implementation "com.structurizr:structurizr-autolayout:${structurizrVersion}"
implementation "com.structurizr:structurizr-inspection:${structurizrVersion}"

implementation 'org.apache.httpcomponents.client5:httpclient5:5.2.3'

Expand Down
41 changes: 19 additions & 22 deletions docs/workspace.dsl
Original file line number Diff line number Diff line change
Expand Up @@ -20,38 +20,35 @@ workspace "Structurizr Lite" {
source "${STRUCTURIZR_LITE_HOME}/src/main/java"
strategy {
technology "Java Component"
matcher nameSuffix "Component"
supportingTypes inpackage
matcher name-suffix "Component"
supportingTypes in-package
url prefix-src "https://github.com/structurizr/lite/blob/main/src/main/java"
forEach {
-> data "Reads from and writes to"
tag "Java Component"
}
}
strategy {
technology "Spring MVC Controller"
matcher annotation "org.springframework.stereotype.Controller"
filter excludeRegex ".*AbstractController|.*.Http[0-9]*Controller"
filter exclude fqn-regex ".*AbstractController|.*.Http[0-9]*Controller"
url prefix-src "https://github.com/structurizr/lite/blob/main/src/main/java"
forEach {
-> ui "Renders HTML page in"
}
}
strategy {
technology "Spring MVC REST Controller"
matcher annotation "org.springframework.web.bind.annotation.RestController"
filter excludeRegex ".*HealthCheckController"
filter exclude fqn-regex ".*HealthCheckController"
description first-sentence
url prefix-src "https://github.com/structurizr/lite/blob/main/src/main/java"
forEach {
ui -> this "Makes API calls using"
tag "API Component"
}
}
}

!script groovy {
element.components.each { it.url = it.properties["component.src"].replace(context.getDslParser().getConstant("STRUCTURIZR_LITE_HOME") + "/src/main/java", "https://github.com/structurizr/lite/blob/main/src/main/java") }
}

!elements "element.parent==server && element.technology==Java Component" {
-> data "Reads from and writes to"
tag "Java Component"
}

!elements "element.parent==server && element.technology==Spring MVC REST Controller" {
ui -> this "Makes API calls using"
tag "API Component"
}

!elements "element.parent==server && element.technology==Spring MVC Controller" {
-> ui "Renders HTML page in"
}
}
}
}
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/com/structurizr/lite/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ public class Configuration {
private static final String AUTO_REFRESH_INTERVAL_PROPERTY = "structurizr.autoRefreshInterval";
private static final String DEFAULT_AUTO_REFRESH_INTERVAL_IN_MILLISECONDS = "0";

private static final String REMOTE_WORKSPACE_API_URL_PROPERTY = "structurizr.remote.apiUrl";
private static final String REMOTE_WORKSPACE_API_KEY_PROPERTY = "structurizr.remote.apiKey";
private static final String REMOTE_WORKSPACE_API_SECRET_PROPERTY = "structurizr.remote.apiSecret";
private static final String REMOTE_WORKSPACE_PASSPHRASE_PROPERTY = "structurizr.remote.passphrase";
private static final String REMOTE_WORKSPACE_ID_PROPERTY = "structurizr.remote.workspaceId";
private static final String REMOTE_WORKSPACE_BRANCH_PROPERTY = "structurizr.remote.branch";
private static final String SINGLE_WORKSPACE = "1";

private File dataDirectory;
Expand Down Expand Up @@ -147,8 +149,12 @@ public long getRemoteWorkspaceId() {
return Long.parseLong(getConfigurationParameter(REMOTE_WORKSPACE_ID_PROPERTY, "0"));
}

public String getRemoteBranch() {
return getConfigurationParameter(REMOTE_WORKSPACE_BRANCH_PROPERTY, "");
}

public String getRemoteApiUrl() {
return getConfigurationParameter("structurizr.remote.apiUrl", STRUCTURIZR_CLOUD_SERVICE_API_URL);
return getConfigurationParameter(REMOTE_WORKSPACE_API_URL_PROPERTY, STRUCTURIZR_CLOUD_SERVICE_API_URL);
}

public String getRemoteApiKey() {
Expand Down
16 changes: 14 additions & 2 deletions src/main/java/com/structurizr/lite/StructurizrLite.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,12 @@ private static void start() {
long workspaceId = Configuration.getInstance().getRemoteWorkspaceId();
if (workspaceId > 0) {
log.info("");
log.info("Pulling workspace from " + Configuration.getInstance().getRemoteApiUrl() + " with ID " + workspaceId);

String branch = "";
if (!StringUtils.isNullOrEmpty(Configuration.getInstance().getRemoteBranch())) {
branch = " (branch=" + Configuration.getInstance().getRemoteBranch() + ")";
}
log.info("Pulling workspace from " + Configuration.getInstance().getRemoteApiUrl() + branch + " with ID " + workspaceId);

Workspace workspace = createWorkspaceApiClient().getWorkspace(workspaceId);

Expand Down Expand Up @@ -213,7 +218,12 @@ public void stop() {
long workspaceId = Configuration.getInstance().getRemoteWorkspaceId();
if (workspaceId > 0) {
log.info("");
log.info("Pushing workspace to " + Configuration.getInstance().getRemoteApiUrl() + " with ID " + workspaceId);

String branch = "";
if (!StringUtils.isNullOrEmpty(Configuration.getInstance().getRemoteBranch())) {
branch = " (branch=" + Configuration.getInstance().getRemoteBranch() + ")";
}
log.info("Pushing workspace to " + Configuration.getInstance().getRemoteApiUrl() + branch + " with ID " + workspaceId);

Workspace workspace = WorkspaceUtils.loadWorkspaceFromJson(new File(Configuration.getInstance().getDataDirectory(), Configuration.getInstance().getWorkspaceFilename() + ".json"));
createWorkspaceApiClient().putWorkspace(workspaceId, workspace);
Expand All @@ -232,10 +242,12 @@ private static WorkspaceApiClient createWorkspaceApiClient() {
String apiKey = Configuration.getInstance().getRemoteApiKey();
String apiSecret = Configuration.getInstance().getRemoteApiSecret();
String passphrase = Configuration.getInstance().getRemotePassphrase();
String branch = Configuration.getInstance().getRemoteBranch();

WorkspaceApiClient client = new WorkspaceApiClient(apiUrl, apiKey, apiSecret);
client.setAgent("structurizr-lite/" + new Version().getBuildNumber());
client.setUser(System.getenv(STRUCTURIZR_USERNAME));
client.setBranch(branch);
if (!StringUtils.isNullOrEmpty(passphrase)) {
client.setEncryptionStrategy(new AesEncryptionStrategy(passphrase));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

import java.util.List;

/**
* Provides workspace search facilities using Apache Lucene.
*/
public interface SearchComponent {

void index(Workspace workspace);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

import java.util.List;

/**
* Provides access to workspace data stored on the file system.
*/
public interface WorkspaceComponent {

void start() throws Exception;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/structurizr/lite/web/ApiController.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import java.util.Base64;

/**
* A simple implementation of the Structurizr web API, consisting of two operations to
* get and put JSON workspace definitions:
* An implementation of the Structurizr web API, consisting of two operations to
* get and put JSON workspace definitions.
*
* - GET /api/workspace/{id}
* - PUT /api/workspace/{id}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
import java.nio.charset.StandardCharsets;
import java.util.Base64;

/**
* Provides access to architecture decision records (ADRs) defined within a workspace.
*/
@Controller
public class DecisionsController extends AbstractController {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@

import jakarta.servlet.http.HttpServletResponse;

/**
* Provides access to the diagrams defined within a workspace.
*/
@Controller
public class DiagramsController extends AbstractController {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
import java.nio.charset.StandardCharsets;
import java.util.Base64;

/**
* Provides access to Markdown/AsciiDoc documentation defined within a workspace.
*/
@Controller
public class DocumentationController extends AbstractController {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
import java.nio.file.Files;
import java.util.Arrays;

/**
* Provides server-side automatic layout facilities for diagrams.
*/
@RestController
public class GraphvizController {

Expand Down

0 comments on commit 3d0c529

Please sign in to comment.