Skip to content

Commit a185ea6

Browse files
"url prefix" -> "url prefix-src"
1 parent 3872cfe commit a185ea6

File tree

6 files changed

+24
-15
lines changed

6 files changed

+24
-15
lines changed

structurizr-component/src/main/java/com/structurizr/component/url/DefaultUrlStrategy.java

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

33
import com.structurizr.component.Type;
44

5+
/**
6+
* Generates a null URL.
7+
*/
58
public class DefaultUrlStrategy implements UrlStrategy {
69

710
@Override

structurizr-component/src/main/java/com/structurizr/component/url/PrefixUrlStrategy.java renamed to structurizr-component/src/main/java/com/structurizr/component/url/PrefixSourceUrlStrategy.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33
import com.structurizr.component.Type;
44
import com.structurizr.util.StringUtils;
55

6-
public class PrefixUrlStrategy implements UrlStrategy {
6+
/**
7+
* Adds a given prefix to the component source location.
8+
*/
9+
public class PrefixSourceUrlStrategy implements UrlStrategy {
710

811
private final String prefix;
912

10-
public PrefixUrlStrategy(String prefix) {
13+
public PrefixSourceUrlStrategy(String prefix) {
1114
if (StringUtils.isNullOrEmpty(prefix)) {
1215
throw new IllegalArgumentException("A prefix must be supplied");
1316
}

structurizr-component/src/main/java/com/structurizr/component/url/UrlStrategy.java

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

33
import com.structurizr.component.Type;
44

5+
/**
6+
* Provides a way customise how component URLs are generated.
7+
*/
58
public interface UrlStrategy {
69

710
String urlOf(Type type);

structurizr-dsl/src/main/java/com/structurizr/dsl/ComponentFinderStrategyParser.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import com.structurizr.component.naming.TypeNamingStrategy;
1010
import com.structurizr.component.naming.FullyQualifiedNamingStrategy;
1111
import com.structurizr.component.supporting.*;
12-
import com.structurizr.component.url.PrefixUrlStrategy;
12+
import com.structurizr.component.url.PrefixSourceUrlStrategy;
1313

1414
import java.io.File;
1515
import java.util.List;
@@ -52,9 +52,9 @@ final class ComponentFinderStrategyParser extends AbstractParser {
5252
private static final String DESCRIPTION_GRAMMAR = "description <" + String.join("|", List.of(DESCRIPTION_FIRST_SENTENCE, DESCRIPTION_TRUNCATED)) + ">";
5353
private static final String DESCRIPTION_TRUNCATED_GRAMMAR = "description truncated <maxLength>";
5454

55-
private static final String URL_PREFIX = "prefix";
56-
private static final String URL_GRAMMAR = "url <" + String.join("|", List.of(URL_PREFIX)) + ">";
57-
private static final String URL_PREFIX_GRAMMAR = "url prefix <prefix>";
55+
private static final String URL_PREFIX_SRC = "prefix-src";
56+
private static final String URL_GRAMMAR = "url <" + String.join("|", List.of(URL_PREFIX_SRC)) + ">";
57+
private static final String URL_PREFIX_SRC_GRAMMAR = "url prefix-src <prefix>";
5858

5959
void parseTechnology(ComponentFinderStrategyDslContext context, Tokens tokens) {
6060
if (tokens.size() != 2) {
@@ -248,13 +248,13 @@ void parseUrl(ComponentFinderStrategyDslContext context, Tokens tokens, File dsl
248248

249249
String type = tokens.get(1).toLowerCase();
250250
switch (type) {
251-
case URL_PREFIX:
251+
case URL_PREFIX_SRC:
252252
if (tokens.size() < 3) {
253-
throw new RuntimeException("Too few tokens, expected: " + URL_PREFIX_GRAMMAR);
253+
throw new RuntimeException("Too few tokens, expected: " + URL_PREFIX_SRC_GRAMMAR);
254254
}
255255

256256
String prefix = tokens.get(2);
257-
context.getComponentFinderStrategyBuilder().withUrl(new PrefixUrlStrategy(prefix));
257+
context.getComponentFinderStrategyBuilder().withUrl(new PrefixSourceUrlStrategy(prefix));
258258
break;
259259
default:
260260
throw new IllegalArgumentException("Unknown URL strategy: " + type);

structurizr-dsl/src/test/java/com/structurizr/dsl/ComponentFinderStrategyParserTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -283,23 +283,23 @@ void test_parseUrl_ThrowsAnException_WhenNoTypeIsSpecified() {
283283
parser.parseUrl(context, tokens("url"), null);
284284
fail();
285285
} catch (Exception e) {
286-
assertEquals("Too few tokens, expected: url <prefix>", e.getMessage());
286+
assertEquals("Too few tokens, expected: url <prefix-src>", e.getMessage());
287287
}
288288
}
289289

290290
@Test
291291
void test_parseUrl_Prefix_ThrowsAnException_WhenNoPrefixIsSpecified() {
292292
try {
293-
parser.parseUrl(context, tokens("url", "prefix"), null);
293+
parser.parseUrl(context, tokens("url", "prefix-src"), null);
294294
fail();
295295
} catch (Exception e) {
296-
assertEquals("Too few tokens, expected: url prefix <prefix>", e.getMessage());
296+
assertEquals("Too few tokens, expected: url prefix-src <prefix>", e.getMessage());
297297
}
298298
}
299299

300300
@Test
301301
void test_parseUrl_Prefix() {
302-
parser.parseUrl(context, tokens("url", "prefix", "https://example.com"), null);
302+
parser.parseUrl(context, tokens("url", "prefix-src", "https://example.com"), null);
303303
assertEquals("ComponentFinderStrategyBuilder{technology=null, typeMatcher=null, typeFilter=null, supportingTypesStrategy=null, namingStrategy=null, descriptionStrategy=null, urlStrategy=PrefixUrlStrategy{prefix='https://example.com/'}, componentVisitor=null}", context.getComponentFinderStrategyBuilder().toString());
304304
}
305305

structurizr-dsl/src/test/resources/dsl/spring-petclinic/workspace.dsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ workspace "Spring PetClinic" "A C4 model of the Spring PetClinic sample app (htt
2626
technology "Spring MVC Controller"
2727
matcher annotation "org.springframework.stereotype.Controller"
2828
filter exclude fqn-regex ".*.CrashController"
29-
url prefix "https://github.com/spring-projects/spring-petclinic/blob/main/src/main/java"
29+
url prefix-src "https://github.com/spring-projects/spring-petclinic/blob/main/src/main/java"
3030
forEach {
3131
clinicEmployee -> this "Uses"
3232
tag "Spring MVC Controller"
@@ -36,7 +36,7 @@ workspace "Spring PetClinic" "A C4 model of the Spring PetClinic sample app (htt
3636
technology "Spring Data Repository"
3737
matcher implements "org.springframework.data.repository.Repository"
3838
description first-sentence
39-
url prefix "https://github.com/spring-projects/spring-petclinic/blob/main/src/main/java"
39+
url prefix-src "https://github.com/spring-projects/spring-petclinic/blob/main/src/main/java"
4040
forEach {
4141
-> relationalDatabaseSchema "Reads from and writes to"
4242
tag "Spring Data Repository"

0 commit comments

Comments
 (0)