-
-
Notifications
You must be signed in to change notification settings - Fork 291
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial version of DSL wrapper for the component finder.
- Loading branch information
1 parent
477bac9
commit 0f2b05f
Showing
10 changed files
with
446 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
structurizr-dsl/src/main/java/com/structurizr/dsl/ComponentFinderDslContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.structurizr.dsl; | ||
|
||
import com.structurizr.component.ComponentFinderBuilder; | ||
import com.structurizr.model.Container; | ||
|
||
final class ComponentFinderDslContext extends DslContext { | ||
|
||
private final ComponentFinderBuilder componentFinderBuilder = new ComponentFinderBuilder(); | ||
|
||
ComponentFinderDslContext(Container container) { | ||
componentFinderBuilder.forContainer(container); | ||
} | ||
|
||
@Override | ||
protected String[] getPermittedTokens() { | ||
return new String[] { | ||
StructurizrDslTokens.COMPONENT_FINDER_CLASSES_TOKEN, | ||
StructurizrDslTokens.COMPONENT_FINDER_SOURCE_TOKEN, | ||
StructurizrDslTokens.COMPONENT_FINDER_STRATEGY_TOKEN | ||
}; | ||
} | ||
|
||
ComponentFinderBuilder getComponentFinderBuilder() { | ||
return this.componentFinderBuilder; | ||
} | ||
|
||
@Override | ||
void end() { | ||
componentFinderBuilder.build().findComponents(); | ||
} | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
structurizr-dsl/src/main/java/com/structurizr/dsl/ComponentFinderParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.structurizr.dsl; | ||
|
||
final class ComponentFinderParser extends AbstractParser { | ||
|
||
private static final String CLASSES_GRAMMAR = "classes <path>"; | ||
private static final String SOURCE_GRAMMAR = "source <path>"; | ||
|
||
void parseClasses(ComponentFinderDslContext context, Tokens tokens) { | ||
// classes <path> | ||
|
||
if (tokens.hasMoreThan(1)) { | ||
throw new RuntimeException("Too many tokens, expected: " + CLASSES_GRAMMAR); | ||
} | ||
|
||
context.getComponentFinderBuilder().fromClasses(tokens.get(1)); | ||
} | ||
|
||
void parseSource(ComponentFinderDslContext context, Tokens tokens) { | ||
// source <path> | ||
|
||
if (tokens.hasMoreThan(1)) { | ||
throw new RuntimeException("Too many tokens, expected: " + SOURCE_GRAMMAR); | ||
} | ||
|
||
context.getComponentFinderBuilder().fromSource(tokens.get(1)); | ||
} | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
structurizr-dsl/src/main/java/com/structurizr/dsl/ComponentFinderStrategyDslContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.structurizr.dsl; | ||
|
||
import com.structurizr.component.ComponentFinderBuilder; | ||
import com.structurizr.component.ComponentFinderStrategyBuilder; | ||
|
||
final class ComponentFinderStrategyDslContext extends DslContext { | ||
|
||
private final ComponentFinderBuilder componentFinderBuilder; | ||
private final ComponentFinderStrategyBuilder componentFinderStrategyBuilder = new ComponentFinderStrategyBuilder(); | ||
|
||
ComponentFinderStrategyDslContext(ComponentFinderBuilder componentFinderBuilder) { | ||
this.componentFinderBuilder = componentFinderBuilder; | ||
} | ||
|
||
@Override | ||
protected String[] getPermittedTokens() { | ||
return new String[] { | ||
StructurizrDslTokens.COMPONENT_FINDER_STRATEGY_MATCHER_TOKEN, | ||
StructurizrDslTokens.COMPONENT_FINDER_STRATEGY_FILTER_TOKEN, | ||
StructurizrDslTokens.COMPONENT_FINDER_STRATEGY_SUPPORTING_TYPES_TOKEN, | ||
StructurizrDslTokens.COMPONENT_FINDER_STRATEGY_NAMING_TOKEN | ||
}; | ||
} | ||
|
||
ComponentFinderStrategyBuilder getComponentFinderStrategyBuilder() { | ||
return this.componentFinderStrategyBuilder; | ||
} | ||
|
||
@Override | ||
void end() { | ||
componentFinderBuilder.withStrategy(componentFinderStrategyBuilder.build()); | ||
} | ||
|
||
} |
158 changes: 158 additions & 0 deletions
158
structurizr-dsl/src/main/java/com/structurizr/dsl/ComponentFinderStrategyParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
package com.structurizr.dsl; | ||
|
||
import com.structurizr.component.filter.ExcludeTypesByRegexFilter; | ||
import com.structurizr.component.filter.IncludeTypesByRegexFilter; | ||
import com.structurizr.component.matcher.*; | ||
import com.structurizr.component.naming.DefaultPackageNamingStrategy; | ||
import com.structurizr.component.naming.SimpleNamingStrategy; | ||
import com.structurizr.component.naming.FullyQualifiedNamingStrategy; | ||
import com.structurizr.component.supporting.AllReferencedTypesInPackageSupportingTypesStrategy; | ||
import com.structurizr.component.supporting.AllReferencedTypesSupportingTypesStrategy; | ||
import com.structurizr.component.supporting.AllTypesInPackageSupportingTypesStrategy; | ||
import com.structurizr.component.supporting.AllTypesUnderPackageSupportingTypesStrategy; | ||
|
||
final class ComponentFinderStrategyParser extends AbstractParser { | ||
|
||
private static final String MATCHER_GRAMMAR = "matcher <annotation|extends|implements|namesuffix|regex> [parameters]"; | ||
private static final String FILTER_GRAMMAR = "filter <includeregex|excluderegex> [parameters]"; | ||
private static final String SUPPORTING_TYPES_GRAMMAR = "supportingTypes <referenced|referencedinpackage|inpackage|underpackage> [parameters]"; | ||
private static final String NAMING_GRAMMAR = "naming <name|fqn|package>"; | ||
|
||
void parseMatcher(ComponentFinderStrategyDslContext context, Tokens tokens) { | ||
if (tokens.size() < 2) { | ||
throw new RuntimeException("Too few tokens, expected: " + MATCHER_GRAMMAR); | ||
} | ||
|
||
String type = tokens.get(1).toLowerCase(); | ||
switch (type) { | ||
case "annotation": | ||
if (tokens.size() == 4) { | ||
String name = tokens.get(2); | ||
String technology = tokens.get(3); | ||
|
||
context.getComponentFinderStrategyBuilder().matchedBy(new AnnotationTypeMatcher(name, technology)); | ||
} else { | ||
throw new RuntimeException("Expected: " + MATCHER_GRAMMAR); | ||
} | ||
break; | ||
case "extends": | ||
if (tokens.size() == 4) { | ||
String name = tokens.get(2); | ||
String technology = tokens.get(3); | ||
|
||
context.getComponentFinderStrategyBuilder().matchedBy(new ExtendsTypeMatcher(name, technology)); | ||
} else { | ||
throw new RuntimeException("Expected: " + MATCHER_GRAMMAR); | ||
} | ||
break; | ||
case "implements": | ||
if (tokens.size() == 4) { | ||
String name = tokens.get(2); | ||
String technology = tokens.get(3); | ||
|
||
context.getComponentFinderStrategyBuilder().matchedBy(new ImplementsTypeMatcher(name, technology)); | ||
} else { | ||
throw new RuntimeException("Expected: " + MATCHER_GRAMMAR); | ||
} | ||
break; | ||
case "namesuffix": | ||
if (tokens.size() == 4) { | ||
String suffix = tokens.get(2); | ||
String technology = tokens.get(3); | ||
|
||
context.getComponentFinderStrategyBuilder().matchedBy(new NameSuffixTypeMatcher(suffix, technology)); | ||
} else { | ||
throw new RuntimeException("Expected: " + MATCHER_GRAMMAR); | ||
} | ||
break; | ||
case "regex": | ||
if (tokens.size() == 4) { | ||
String regex = tokens.get(2); | ||
String technology = tokens.get(3); | ||
|
||
context.getComponentFinderStrategyBuilder().matchedBy(new RegexTypeMatcher(regex, technology)); | ||
} else { | ||
throw new RuntimeException("Expected: " + MATCHER_GRAMMAR); | ||
} | ||
break; | ||
default: | ||
throw new IllegalArgumentException("Unknown matcher: " + type); | ||
} | ||
} | ||
|
||
void parseFilter(ComponentFinderStrategyDslContext context, Tokens tokens) { | ||
if (tokens.size() < 2) { | ||
throw new RuntimeException("Too few tokens, expected: " + FILTER_GRAMMAR); | ||
} | ||
|
||
String type = tokens.get(1).toLowerCase(); | ||
switch (type) { | ||
case "includeregex": | ||
if (tokens.size() == 3) { | ||
String regex = tokens.get(2); | ||
|
||
context.getComponentFinderStrategyBuilder().filteredBy(new IncludeTypesByRegexFilter(regex)); | ||
} else { | ||
throw new RuntimeException("Expected: " + FILTER_GRAMMAR); | ||
} | ||
break; | ||
case "excluderegex": | ||
if (tokens.size() == 3) { | ||
String regex = tokens.get(2); | ||
|
||
context.getComponentFinderStrategyBuilder().filteredBy(new ExcludeTypesByRegexFilter(regex)); | ||
} else { | ||
throw new RuntimeException("Expected: " + FILTER_GRAMMAR); | ||
} | ||
break; | ||
default: | ||
throw new IllegalArgumentException("Unknown filter: " + type); | ||
} | ||
} | ||
|
||
void parseSupportingTypes(ComponentFinderStrategyDslContext context, Tokens tokens) { | ||
if (tokens.size() < 2) { | ||
throw new RuntimeException("Too few tokens, expected: " + SUPPORTING_TYPES_GRAMMAR); | ||
} | ||
|
||
String type = tokens.get(1).toLowerCase(); | ||
switch (type) { | ||
case "referenced": | ||
context.getComponentFinderStrategyBuilder().supportedBy(new AllReferencedTypesSupportingTypesStrategy()); | ||
break; | ||
case "referencedinpackage": | ||
context.getComponentFinderStrategyBuilder().supportedBy(new AllReferencedTypesInPackageSupportingTypesStrategy()); | ||
break; | ||
case "inpackage": | ||
context.getComponentFinderStrategyBuilder().supportedBy(new AllTypesInPackageSupportingTypesStrategy()); | ||
break; | ||
case "underpackage": | ||
context.getComponentFinderStrategyBuilder().supportedBy(new AllTypesUnderPackageSupportingTypesStrategy()); | ||
break; | ||
default: | ||
throw new IllegalArgumentException("Unknown supporting types strategy: " + type); | ||
} | ||
} | ||
|
||
void parseNaming(ComponentFinderStrategyDslContext context, Tokens tokens) { | ||
if (tokens.size() < 1) { | ||
throw new RuntimeException("Too few tokens, expected: " + NAMING_GRAMMAR); | ||
} | ||
|
||
String type = tokens.get(1).toLowerCase(); | ||
switch (type) { | ||
case "name": | ||
context.getComponentFinderStrategyBuilder().namedBy(new SimpleNamingStrategy()); | ||
break; | ||
case "fqn": | ||
context.getComponentFinderStrategyBuilder().namedBy(new FullyQualifiedNamingStrategy()); | ||
break; | ||
case "package": | ||
context.getComponentFinderStrategyBuilder().namedBy(new DefaultPackageNamingStrategy()); | ||
break; | ||
default: | ||
throw new IllegalArgumentException("Unknown naming strategy: " + type); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.