Skip to content

Commit 3d0c529

Browse files
Updates structurizr-java to v3.0.0 - adds support for remote workspace branches.
1 parent cfae3e1 commit 3d0c529

File tree

11 files changed

+65
-31
lines changed

11 files changed

+65
-31
lines changed

build.gradle

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ targetCompatibility = '17'
1313

1414
repositories {
1515
mavenCentral()
16-
// mavenLocal()
1716
}
1817

1918
testing {
@@ -47,14 +46,16 @@ ext {
4746
}
4847

4948
dependencies {
49+
def structurizrVersion = '3.0.0'
50+
5051
implementation 'org.springframework.boot:spring-boot-starter-web'
5152
implementation 'org.apache.tomcat.embed:tomcat-embed-jasper:10.1.24'
5253
implementation 'jakarta.servlet.jsp.jstl:jakarta.servlet.jsp.jstl-api:3.0.0'
5354
implementation 'org.glassfish.web:jakarta.servlet.jsp.jstl:3.0.1'
5455

55-
implementation 'com.structurizr:structurizr-dsl:2.2.0'
56-
implementation 'com.structurizr:structurizr-autolayout:2.2.0'
57-
implementation 'com.structurizr:structurizr-inspection:2.2.0'
56+
implementation "com.structurizr:structurizr-dsl:${structurizrVersion}"
57+
implementation "com.structurizr:structurizr-autolayout:${structurizrVersion}"
58+
implementation "com.structurizr:structurizr-inspection:${structurizrVersion}"
5859

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

docs/workspace.dsl

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,38 +20,35 @@ workspace "Structurizr Lite" {
2020
source "${STRUCTURIZR_LITE_HOME}/src/main/java"
2121
strategy {
2222
technology "Java Component"
23-
matcher nameSuffix "Component"
24-
supportingTypes inpackage
23+
matcher name-suffix "Component"
24+
supportingTypes in-package
25+
url prefix-src "https://github.com/structurizr/lite/blob/main/src/main/java"
26+
forEach {
27+
-> data "Reads from and writes to"
28+
tag "Java Component"
29+
}
2530
}
2631
strategy {
2732
technology "Spring MVC Controller"
2833
matcher annotation "org.springframework.stereotype.Controller"
29-
filter excludeRegex ".*AbstractController|.*.Http[0-9]*Controller"
34+
filter exclude fqn-regex ".*AbstractController|.*.Http[0-9]*Controller"
35+
url prefix-src "https://github.com/structurizr/lite/blob/main/src/main/java"
36+
forEach {
37+
-> ui "Renders HTML page in"
38+
}
3039
}
3140
strategy {
3241
technology "Spring MVC REST Controller"
3342
matcher annotation "org.springframework.web.bind.annotation.RestController"
34-
filter excludeRegex ".*HealthCheckController"
43+
filter exclude fqn-regex ".*HealthCheckController"
44+
description first-sentence
45+
url prefix-src "https://github.com/structurizr/lite/blob/main/src/main/java"
46+
forEach {
47+
ui -> this "Makes API calls using"
48+
tag "API Component"
49+
}
3550
}
3651
}
37-
38-
!script groovy {
39-
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") }
40-
}
41-
42-
!elements "element.parent==server && element.technology==Java Component" {
43-
-> data "Reads from and writes to"
44-
tag "Java Component"
45-
}
46-
47-
!elements "element.parent==server && element.technology==Spring MVC REST Controller" {
48-
ui -> this "Makes API calls using"
49-
tag "API Component"
50-
}
51-
52-
!elements "element.parent==server && element.technology==Spring MVC Controller" {
53-
-> ui "Renders HTML page in"
54-
}
5552
}
5653
}
5754
}

src/main/java/com/structurizr/lite/Configuration.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@ public class Configuration {
2727
private static final String AUTO_REFRESH_INTERVAL_PROPERTY = "structurizr.autoRefreshInterval";
2828
private static final String DEFAULT_AUTO_REFRESH_INTERVAL_IN_MILLISECONDS = "0";
2929

30+
private static final String REMOTE_WORKSPACE_API_URL_PROPERTY = "structurizr.remote.apiUrl";
3031
private static final String REMOTE_WORKSPACE_API_KEY_PROPERTY = "structurizr.remote.apiKey";
3132
private static final String REMOTE_WORKSPACE_API_SECRET_PROPERTY = "structurizr.remote.apiSecret";
3233
private static final String REMOTE_WORKSPACE_PASSPHRASE_PROPERTY = "structurizr.remote.passphrase";
3334
private static final String REMOTE_WORKSPACE_ID_PROPERTY = "structurizr.remote.workspaceId";
35+
private static final String REMOTE_WORKSPACE_BRANCH_PROPERTY = "structurizr.remote.branch";
3436
private static final String SINGLE_WORKSPACE = "1";
3537

3638
private File dataDirectory;
@@ -147,8 +149,12 @@ public long getRemoteWorkspaceId() {
147149
return Long.parseLong(getConfigurationParameter(REMOTE_WORKSPACE_ID_PROPERTY, "0"));
148150
}
149151

152+
public String getRemoteBranch() {
153+
return getConfigurationParameter(REMOTE_WORKSPACE_BRANCH_PROPERTY, "");
154+
}
155+
150156
public String getRemoteApiUrl() {
151-
return getConfigurationParameter("structurizr.remote.apiUrl", STRUCTURIZR_CLOUD_SERVICE_API_URL);
157+
return getConfigurationParameter(REMOTE_WORKSPACE_API_URL_PROPERTY, STRUCTURIZR_CLOUD_SERVICE_API_URL);
152158
}
153159

154160
public String getRemoteApiKey() {

src/main/java/com/structurizr/lite/StructurizrLite.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,12 @@ private static void start() {
160160
long workspaceId = Configuration.getInstance().getRemoteWorkspaceId();
161161
if (workspaceId > 0) {
162162
log.info("");
163-
log.info("Pulling workspace from " + Configuration.getInstance().getRemoteApiUrl() + " with ID " + workspaceId);
163+
164+
String branch = "";
165+
if (!StringUtils.isNullOrEmpty(Configuration.getInstance().getRemoteBranch())) {
166+
branch = " (branch=" + Configuration.getInstance().getRemoteBranch() + ")";
167+
}
168+
log.info("Pulling workspace from " + Configuration.getInstance().getRemoteApiUrl() + branch + " with ID " + workspaceId);
164169

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

@@ -213,7 +218,12 @@ public void stop() {
213218
long workspaceId = Configuration.getInstance().getRemoteWorkspaceId();
214219
if (workspaceId > 0) {
215220
log.info("");
216-
log.info("Pushing workspace to " + Configuration.getInstance().getRemoteApiUrl() + " with ID " + workspaceId);
221+
222+
String branch = "";
223+
if (!StringUtils.isNullOrEmpty(Configuration.getInstance().getRemoteBranch())) {
224+
branch = " (branch=" + Configuration.getInstance().getRemoteBranch() + ")";
225+
}
226+
log.info("Pushing workspace to " + Configuration.getInstance().getRemoteApiUrl() + branch + " with ID " + workspaceId);
217227

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

236247
WorkspaceApiClient client = new WorkspaceApiClient(apiUrl, apiKey, apiSecret);
237248
client.setAgent("structurizr-lite/" + new Version().getBuildNumber());
238249
client.setUser(System.getenv(STRUCTURIZR_USERNAME));
250+
client.setBranch(branch);
239251
if (!StringUtils.isNullOrEmpty(passphrase)) {
240252
client.setEncryptionStrategy(new AesEncryptionStrategy(passphrase));
241253
}

src/main/java/com/structurizr/lite/component/search/SearchComponent.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
import java.util.List;
66

7+
/**
8+
* Provides workspace search facilities using Apache Lucene.
9+
*/
710
public interface SearchComponent {
811

912
void index(Workspace workspace);

src/main/java/com/structurizr/lite/component/workspace/WorkspaceComponent.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
import java.util.List;
88

9+
/**
10+
* Provides access to workspace data stored on the file system.
11+
*/
912
public interface WorkspaceComponent {
1013

1114
void start() throws Exception;

src/main/java/com/structurizr/lite/web/ApiController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
import java.util.Base64;
1818

1919
/**
20-
* A simple implementation of the Structurizr web API, consisting of two operations to
21-
* get and put JSON workspace definitions:
20+
* An implementation of the Structurizr web API, consisting of two operations to
21+
* get and put JSON workspace definitions.
2222
*
2323
* - GET /api/workspace/{id}
2424
* - PUT /api/workspace/{id}

src/main/java/com/structurizr/lite/web/DecisionsController.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
import java.nio.charset.StandardCharsets;
1212
import java.util.Base64;
1313

14+
/**
15+
* Provides access to architecture decision records (ADRs) defined within a workspace.
16+
*/
1417
@Controller
1518
public class DecisionsController extends AbstractController {
1619

src/main/java/com/structurizr/lite/web/DiagramsController.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818

1919
import jakarta.servlet.http.HttpServletResponse;
2020

21+
/**
22+
* Provides access to the diagrams defined within a workspace.
23+
*/
2124
@Controller
2225
public class DiagramsController extends AbstractController {
2326

src/main/java/com/structurizr/lite/web/DocumentationController.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
import java.nio.charset.StandardCharsets;
1212
import java.util.Base64;
1313

14+
/**
15+
* Provides access to Markdown/AsciiDoc documentation defined within a workspace.
16+
*/
1417
@Controller
1518
public class DocumentationController extends AbstractController {
1619

src/main/java/com/structurizr/lite/web/GraphvizController.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
import java.nio.file.Files;
1919
import java.util.Arrays;
2020

21+
/**
22+
* Provides server-side automatic layout facilities for diagrams.
23+
*/
2124
@RestController
2225
public class GraphvizController {
2326

0 commit comments

Comments
 (0)