Skip to content

Commit 98371df

Browse files
Initial POC re: archetypes.
1 parent 1d6cda2 commit 98371df

15 files changed

+525
-14
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ signing.secretKeyRingFile=/some/path
55
ossrhUsername=username
66
ossrhPassword=password
77

8-
version=3.2.1
8+
version=4.0.0
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package com.structurizr.dsl;
2+
3+
import com.structurizr.util.StringUtils;
4+
import com.structurizr.util.TagUtils;
5+
6+
import java.util.LinkedHashSet;
7+
import java.util.Set;
8+
9+
final class Archetype {
10+
11+
private final String name;
12+
private final String type;
13+
private String description;
14+
private String technology;
15+
private final Set<String> tags = new LinkedHashSet<>();
16+
17+
Archetype(String name, String type) {
18+
if (StringUtils.isNullOrEmpty(name)) {
19+
name = type;
20+
}
21+
22+
this.name = name.toLowerCase();
23+
this.type = type;
24+
}
25+
26+
String getName() {
27+
return name;
28+
}
29+
30+
String getType() {
31+
return type;
32+
}
33+
34+
String getDescription() {
35+
return description;
36+
}
37+
38+
void setDescription(String description) {
39+
this.description = description;
40+
}
41+
42+
String getTechnology() {
43+
return technology;
44+
}
45+
46+
void setTechnology(String technology) {
47+
this.technology = technology;
48+
}
49+
50+
void addTags(String... tags) {
51+
if (tags == null) {
52+
return;
53+
}
54+
55+
for (String tag : tags) {
56+
if (tag != null) {
57+
this.tags.add(tag.trim());
58+
}
59+
}
60+
}
61+
62+
Set<String> getTags() {
63+
return new LinkedHashSet<>(tags);
64+
}
65+
66+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.structurizr.dsl;
2+
3+
abstract class ArchetypeDslContext extends DslContext {
4+
5+
private final Archetype archetype;
6+
7+
ArchetypeDslContext(Archetype archetype) {
8+
this.archetype = archetype;
9+
}
10+
11+
Archetype getArchetype() {
12+
return archetype;
13+
}
14+
15+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package com.structurizr.dsl;
2+
3+
final class ArchetypeParser extends AbstractParser {
4+
5+
private final static int NAME_INDEX = 1;
6+
private final static int VALUE_INDEX = 1;
7+
8+
void parseTag(ArchetypeDslContext context, Tokens tokens) {
9+
// tag <tag>
10+
if (tokens.hasMoreThan(VALUE_INDEX)) {
11+
throw new RuntimeException("Too many tokens, expected: tag <tag>");
12+
}
13+
14+
if (!tokens.includes(NAME_INDEX)) {
15+
throw new RuntimeException("Expected: tag <tag>");
16+
}
17+
18+
String tag = tokens.get(VALUE_INDEX);
19+
context.getArchetype().addTags(tag);
20+
}
21+
22+
void parseTags(ArchetypeDslContext context, Tokens tokens) {
23+
// tags <tags> [tags]
24+
if (!tokens.includes(NAME_INDEX)) {
25+
throw new RuntimeException("Expected: tags <tags> [tags]");
26+
}
27+
28+
for (int i = NAME_INDEX; i < tokens.size(); i++) {
29+
String tags = tokens.get(i);
30+
context.getArchetype().addTags(tags.split(","));
31+
}
32+
}
33+
34+
void parseDescription(ArchetypeDslContext context, Tokens tokens) {
35+
// description <description>
36+
if (tokens.hasMoreThan(VALUE_INDEX)) {
37+
throw new RuntimeException("Too many tokens, expected: description <description>");
38+
}
39+
40+
if (!tokens.includes(NAME_INDEX)) {
41+
throw new RuntimeException("Expected: description <description>");
42+
}
43+
44+
String description = tokens.get(VALUE_INDEX);
45+
context.getArchetype().setDescription(description);
46+
}
47+
48+
void parseTechnology(ArchetypeDslContext context, Tokens tokens) {
49+
// technology <technology>
50+
if (tokens.hasMoreThan(VALUE_INDEX)) {
51+
throw new RuntimeException("Too many tokens, expected: technology <technology>");
52+
}
53+
54+
if (!tokens.includes(NAME_INDEX)) {
55+
throw new RuntimeException("Expected: technology <technology>");
56+
}
57+
58+
String technology = tokens.get(VALUE_INDEX);
59+
context.getArchetype().setTechnology(technology);
60+
}
61+
62+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.structurizr.dsl;
2+
3+
final class ArchetypesDslContext extends DslContext {
4+
5+
ArchetypesDslContext() {
6+
}
7+
8+
@Override
9+
protected String[] getPermittedTokens() {
10+
return new String[] {
11+
};
12+
}
13+
14+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.structurizr.dsl;
2+
3+
final class ComponentArchetypeDslContext extends ArchetypeDslContext {
4+
5+
ComponentArchetypeDslContext(Archetype archetype) {
6+
super(archetype);
7+
}
8+
9+
@Override
10+
protected String[] getPermittedTokens() {
11+
return new String[] {
12+
StructurizrDslTokens.DESCRIPTION_TOKEN,
13+
StructurizrDslTokens.TECHNOLOGY_TOKEN,
14+
StructurizrDslTokens.TAG_TOKEN,
15+
StructurizrDslTokens.TAGS_TOKEN,
16+
};
17+
}
18+
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.structurizr.dsl;
2+
3+
final class ContainerArchetypeDslContext extends ArchetypeDslContext {
4+
5+
ContainerArchetypeDslContext(Archetype archetype) {
6+
super(archetype);
7+
}
8+
9+
@Override
10+
protected String[] getPermittedTokens() {
11+
return new String[] {
12+
StructurizrDslTokens.DESCRIPTION_TOKEN,
13+
StructurizrDslTokens.TECHNOLOGY_TOKEN,
14+
StructurizrDslTokens.TAG_TOKEN,
15+
StructurizrDslTokens.TAGS_TOKEN,
16+
};
17+
}
18+
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.structurizr.dsl;
2+
3+
final class DeploymentNodeArchetypeDslContext extends ArchetypeDslContext {
4+
5+
DeploymentNodeArchetypeDslContext(Archetype archetype) {
6+
super(archetype);
7+
}
8+
9+
@Override
10+
protected String[] getPermittedTokens() {
11+
return new String[] {
12+
StructurizrDslTokens.DESCRIPTION_TOKEN,
13+
StructurizrDslTokens.TECHNOLOGY_TOKEN,
14+
StructurizrDslTokens.TAG_TOKEN,
15+
StructurizrDslTokens.TAGS_TOKEN,
16+
};
17+
}
18+
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.structurizr.dsl;
2+
3+
final class InfrastructureNodeArchetypeDslContext extends ArchetypeDslContext {
4+
5+
InfrastructureNodeArchetypeDslContext(Archetype archetype) {
6+
super(archetype);
7+
}
8+
9+
@Override
10+
protected String[] getPermittedTokens() {
11+
return new String[] {
12+
StructurizrDslTokens.DESCRIPTION_TOKEN,
13+
StructurizrDslTokens.TECHNOLOGY_TOKEN,
14+
StructurizrDslTokens.TAG_TOKEN,
15+
StructurizrDslTokens.TAGS_TOKEN,
16+
};
17+
}
18+
19+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.structurizr.dsl;
2+
3+
final class PersonArchetypeDslContext extends ArchetypeDslContext {
4+
5+
PersonArchetypeDslContext(Archetype archetype) {
6+
super(archetype);
7+
}
8+
9+
@Override
10+
protected String[] getPermittedTokens() {
11+
return new String[] {
12+
StructurizrDslTokens.DESCRIPTION_TOKEN,
13+
StructurizrDslTokens.TAG_TOKEN,
14+
StructurizrDslTokens.TAGS_TOKEN,
15+
};
16+
}
17+
18+
}

0 commit comments

Comments
 (0)