Skip to content

Commit

Permalink
Initial POC re: archetypes.
Browse files Browse the repository at this point in the history
  • Loading branch information
simonbrowndotje committed Dec 15, 2024
1 parent 1d6cda2 commit 98371df
Show file tree
Hide file tree
Showing 15 changed files with 525 additions and 14 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ signing.secretKeyRingFile=/some/path
ossrhUsername=username
ossrhPassword=password

version=3.2.1
version=4.0.0
66 changes: 66 additions & 0 deletions structurizr-dsl/src/main/java/com/structurizr/dsl/Archetype.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package com.structurizr.dsl;

import com.structurizr.util.StringUtils;
import com.structurizr.util.TagUtils;

import java.util.LinkedHashSet;
import java.util.Set;

final class Archetype {

private final String name;
private final String type;
private String description;
private String technology;
private final Set<String> tags = new LinkedHashSet<>();

Archetype(String name, String type) {
if (StringUtils.isNullOrEmpty(name)) {
name = type;
}

this.name = name.toLowerCase();
this.type = type;
}

String getName() {
return name;
}

String getType() {
return type;
}

String getDescription() {
return description;
}

void setDescription(String description) {
this.description = description;
}

String getTechnology() {
return technology;
}

void setTechnology(String technology) {
this.technology = technology;
}

void addTags(String... tags) {
if (tags == null) {
return;
}

for (String tag : tags) {
if (tag != null) {
this.tags.add(tag.trim());
}
}
}

Set<String> getTags() {
return new LinkedHashSet<>(tags);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.structurizr.dsl;

abstract class ArchetypeDslContext extends DslContext {

private final Archetype archetype;

ArchetypeDslContext(Archetype archetype) {
this.archetype = archetype;
}

Archetype getArchetype() {
return archetype;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package com.structurizr.dsl;

final class ArchetypeParser extends AbstractParser {

private final static int NAME_INDEX = 1;
private final static int VALUE_INDEX = 1;

void parseTag(ArchetypeDslContext context, Tokens tokens) {
// tag <tag>
if (tokens.hasMoreThan(VALUE_INDEX)) {
throw new RuntimeException("Too many tokens, expected: tag <tag>");
}

if (!tokens.includes(NAME_INDEX)) {
throw new RuntimeException("Expected: tag <tag>");
}

String tag = tokens.get(VALUE_INDEX);
context.getArchetype().addTags(tag);
}

void parseTags(ArchetypeDslContext context, Tokens tokens) {
// tags <tags> [tags]
if (!tokens.includes(NAME_INDEX)) {
throw new RuntimeException("Expected: tags <tags> [tags]");
}

for (int i = NAME_INDEX; i < tokens.size(); i++) {
String tags = tokens.get(i);
context.getArchetype().addTags(tags.split(","));
}
}

void parseDescription(ArchetypeDslContext context, Tokens tokens) {
// description <description>
if (tokens.hasMoreThan(VALUE_INDEX)) {
throw new RuntimeException("Too many tokens, expected: description <description>");
}

if (!tokens.includes(NAME_INDEX)) {
throw new RuntimeException("Expected: description <description>");
}

String description = tokens.get(VALUE_INDEX);
context.getArchetype().setDescription(description);
}

void parseTechnology(ArchetypeDslContext context, Tokens tokens) {
// technology <technology>
if (tokens.hasMoreThan(VALUE_INDEX)) {
throw new RuntimeException("Too many tokens, expected: technology <technology>");
}

if (!tokens.includes(NAME_INDEX)) {
throw new RuntimeException("Expected: technology <technology>");
}

String technology = tokens.get(VALUE_INDEX);
context.getArchetype().setTechnology(technology);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.structurizr.dsl;

final class ArchetypesDslContext extends DslContext {

ArchetypesDslContext() {
}

@Override
protected String[] getPermittedTokens() {
return new String[] {
};
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.structurizr.dsl;

final class ComponentArchetypeDslContext extends ArchetypeDslContext {

ComponentArchetypeDslContext(Archetype archetype) {
super(archetype);
}

@Override
protected String[] getPermittedTokens() {
return new String[] {
StructurizrDslTokens.DESCRIPTION_TOKEN,
StructurizrDslTokens.TECHNOLOGY_TOKEN,
StructurizrDslTokens.TAG_TOKEN,
StructurizrDslTokens.TAGS_TOKEN,
};
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.structurizr.dsl;

final class ContainerArchetypeDslContext extends ArchetypeDslContext {

ContainerArchetypeDslContext(Archetype archetype) {
super(archetype);
}

@Override
protected String[] getPermittedTokens() {
return new String[] {
StructurizrDslTokens.DESCRIPTION_TOKEN,
StructurizrDslTokens.TECHNOLOGY_TOKEN,
StructurizrDslTokens.TAG_TOKEN,
StructurizrDslTokens.TAGS_TOKEN,
};
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.structurizr.dsl;

final class DeploymentNodeArchetypeDslContext extends ArchetypeDslContext {

DeploymentNodeArchetypeDslContext(Archetype archetype) {
super(archetype);
}

@Override
protected String[] getPermittedTokens() {
return new String[] {
StructurizrDslTokens.DESCRIPTION_TOKEN,
StructurizrDslTokens.TECHNOLOGY_TOKEN,
StructurizrDslTokens.TAG_TOKEN,
StructurizrDslTokens.TAGS_TOKEN,
};
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.structurizr.dsl;

final class InfrastructureNodeArchetypeDslContext extends ArchetypeDslContext {

InfrastructureNodeArchetypeDslContext(Archetype archetype) {
super(archetype);
}

@Override
protected String[] getPermittedTokens() {
return new String[] {
StructurizrDslTokens.DESCRIPTION_TOKEN,
StructurizrDslTokens.TECHNOLOGY_TOKEN,
StructurizrDslTokens.TAG_TOKEN,
StructurizrDslTokens.TAGS_TOKEN,
};
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.structurizr.dsl;

final class PersonArchetypeDslContext extends ArchetypeDslContext {

PersonArchetypeDslContext(Archetype archetype) {
super(archetype);
}

@Override
protected String[] getPermittedTokens() {
return new String[] {
StructurizrDslTokens.DESCRIPTION_TOKEN,
StructurizrDslTokens.TAG_TOKEN,
StructurizrDslTokens.TAGS_TOKEN,
};
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.structurizr.dsl;

final class SoftwareSystemArchetypeDslContext extends ArchetypeDslContext {

SoftwareSystemArchetypeDslContext(Archetype archetype) {
super(archetype);
}

@Override
protected String[] getPermittedTokens() {
return new String[] {
StructurizrDslTokens.DESCRIPTION_TOKEN,
StructurizrDslTokens.TAG_TOKEN,
StructurizrDslTokens.TAGS_TOKEN,
};
}

}
Loading

0 comments on commit 98371df

Please sign in to comment.