-
-
Notifications
You must be signed in to change notification settings - Fork 290
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Separates severity levels from the violations, making it easier for t…
…eams to customise how they use/extend the feature.
- Loading branch information
1 parent
e2a6600
commit cbd3e19
Showing
74 changed files
with
612 additions
and
373 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
54 changes: 54 additions & 0 deletions
54
structurizr-inspection/src/main/java/com/structurizr/inspection/FixedSeverityStrategy.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,54 @@ | ||
package com.structurizr.inspection; | ||
|
||
import com.structurizr.Workspace; | ||
import com.structurizr.model.Element; | ||
import com.structurizr.model.Model; | ||
import com.structurizr.model.Relationship; | ||
import com.structurizr.view.ElementStyle; | ||
import com.structurizr.view.View; | ||
import com.structurizr.view.ViewSet; | ||
|
||
public class FixedSeverityStrategy implements SeverityStrategy { | ||
|
||
private final Severity severity; | ||
|
||
public FixedSeverityStrategy(Severity severity) { | ||
this.severity = severity; | ||
} | ||
|
||
@Override | ||
public Severity getSeverity(Inspection inspection, Workspace workspace) { | ||
return severity; | ||
} | ||
|
||
@Override | ||
public Severity getSeverity(Inspection inspection, ViewSet viewSet) { | ||
return severity; | ||
} | ||
|
||
@Override | ||
public Severity getSeverity(Inspection inspection, View view) { | ||
return severity; | ||
} | ||
|
||
@Override | ||
public Severity getSeverity(Inspection inspection, ElementStyle elementStyle) { | ||
return severity; | ||
} | ||
|
||
@Override | ||
public Severity getSeverity(Inspection inspection, Model model) { | ||
return severity; | ||
} | ||
|
||
@Override | ||
public Severity getSeverity(Inspection inspection, Element element) { | ||
return severity; | ||
} | ||
|
||
@Override | ||
public Severity getSeverity(Inspection inspection, Relationship relationship) { | ||
return severity; | ||
} | ||
|
||
} |
60 changes: 9 additions & 51 deletions
60
structurizr-inspection/src/main/java/com/structurizr/inspection/Inspection.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 |
---|---|---|
@@ -1,73 +1,31 @@ | ||
package com.structurizr.inspection; | ||
|
||
import com.structurizr.PropertyHolder; | ||
import com.structurizr.Workspace; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
public abstract class Inspection { | ||
|
||
private static final String STRUCTURIZR_INSPECTION_PREFIX = "structurizr.inspection."; | ||
|
||
private final Workspace workspace; | ||
private final Inspector inspector; | ||
|
||
protected Inspection(Workspace workspace) { | ||
this.workspace = workspace; | ||
protected Inspection(Inspector inspector) { | ||
this.inspector = inspector; | ||
} | ||
|
||
protected abstract String getType(); | ||
protected abstract String getType(); | ||
|
||
protected Workspace getWorkspace() { | ||
return workspace; | ||
public Inspector getInspector() { | ||
return inspector; | ||
} | ||
|
||
protected Severity getSeverity(PropertyHolder... propertyHolders) { | ||
List<String> types = generateTypes(); | ||
|
||
for (String type : types) { | ||
for (PropertyHolder propertyHolder : propertyHolders) { | ||
if (propertyHolder != null) { | ||
if (propertyHolder.getProperties().containsKey(type)) { | ||
return Severity.valueOf(propertyHolder.getProperties().get(type).toUpperCase()); | ||
} | ||
} | ||
} | ||
} | ||
|
||
return Severity.ERROR; | ||
protected Workspace getWorkspace() { | ||
return inspector.getWorkspace(); | ||
} | ||
|
||
protected Violation noViolation() { | ||
return null; | ||
} | ||
|
||
protected Violation violation(String description) { | ||
return new Violation(STRUCTURIZR_INSPECTION_PREFIX + getType(), description); | ||
} | ||
|
||
List<String> generateTypes() { | ||
// example: | ||
// structurizr.inspection.model.component.description | ||
// structurizr.inspection.model.component.* | ||
// structurizr.inspection.model.* | ||
// structurizr.inspection.* | ||
|
||
List<String> types = new ArrayList<>(); | ||
|
||
String[] parts = getType().split("\\."); | ||
String buf = STRUCTURIZR_INSPECTION_PREFIX; | ||
types.add(buf + "*"); | ||
for (int i = 0; i < parts.length-1; i++) { | ||
buf = buf + parts[i] + "."; | ||
types.add(buf + "*"); | ||
} | ||
|
||
types.add(STRUCTURIZR_INSPECTION_PREFIX + getType()); | ||
Collections.reverse(types); | ||
|
||
return types; | ||
return new Violation(getType(), description); | ||
} | ||
|
||
} |
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
109 changes: 109 additions & 0 deletions
109
...zr-inspection/src/main/java/com/structurizr/inspection/PropertyBasedSeverityStrategy.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,109 @@ | ||
package com.structurizr.inspection; | ||
|
||
import com.structurizr.PropertyHolder; | ||
import com.structurizr.Workspace; | ||
import com.structurizr.model.Element; | ||
import com.structurizr.model.Model; | ||
import com.structurizr.model.Relationship; | ||
import com.structurizr.util.StringUtils; | ||
import com.structurizr.view.ElementStyle; | ||
import com.structurizr.view.View; | ||
import com.structurizr.view.ViewSet; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
public class PropertyBasedSeverityStrategy implements SeverityStrategy { | ||
|
||
private static final String STRUCTURIZR_INSPECTION_PREFIX = "structurizr.inspection."; | ||
|
||
public PropertyBasedSeverityStrategy() { | ||
} | ||
|
||
@Override | ||
public Severity getSeverity(Inspection inspection, Workspace workspace) { | ||
return getSeverityFromProperties(inspection, workspace); | ||
} | ||
|
||
@Override | ||
public Severity getSeverity(Inspection inspection, ViewSet viewSet) { | ||
return getSeverityFromProperties(inspection, inspection.getWorkspace(), viewSet.getConfiguration()); | ||
} | ||
|
||
@Override | ||
public Severity getSeverity(Inspection inspection, View view) { | ||
return getSeverityFromProperties(inspection, inspection.getWorkspace(), inspection.getWorkspace().getViews().getConfiguration(), view); | ||
} | ||
|
||
@Override | ||
public Severity getSeverity(Inspection inspection, ElementStyle elementStyle) { | ||
return getSeverityFromProperties(inspection, inspection.getWorkspace(), inspection.getWorkspace().getViews().getConfiguration(), elementStyle); | ||
} | ||
|
||
@Override | ||
public Severity getSeverity(Inspection inspection, Model model) { | ||
return getSeverityFromProperties(inspection, inspection.getWorkspace(), model); | ||
} | ||
|
||
@Override | ||
public Severity getSeverity(Inspection inspection, Element element) { | ||
Element parentElement = element.getParent(); | ||
|
||
return getSeverityFromProperties(inspection, inspection.getWorkspace(), inspection.getWorkspace().getModel(), parentElement, element); | ||
} | ||
|
||
@Override | ||
public Severity getSeverity(Inspection inspection, Relationship relationship) { | ||
Element source = relationship.getSource(); | ||
Relationship linkedRelationship = null; | ||
if (!StringUtils.isNullOrEmpty(relationship.getLinkedRelationshipId())) { | ||
inspection.getWorkspace().getModel().getRelationship(relationship.getLinkedRelationshipId()); | ||
} | ||
|
||
return getSeverityFromProperties(inspection, inspection.getWorkspace(), inspection.getWorkspace().getModel(), source.getParent(), source, linkedRelationship, relationship); | ||
} | ||
|
||
protected Severity getSeverityFromProperties(Inspection inspection, PropertyHolder... propertyHolders) { | ||
List<String> types = generatePropertyNames(inspection.getType()); | ||
|
||
for (String type : types) { | ||
for (PropertyHolder propertyHolder : propertyHolders) { | ||
if (propertyHolder != null) { | ||
if (propertyHolder.getProperties().containsKey(type)) { | ||
return Severity.valueOf(propertyHolder.getProperties().get(type).toUpperCase()); | ||
} | ||
} | ||
} | ||
} | ||
|
||
return Severity.ERROR; | ||
} | ||
|
||
protected List<String> generatePropertyNames(String inspection) { | ||
// example input: | ||
// structurizr.inspection.model.component.description | ||
// | ||
// example output: | ||
// structurizr.inspection.model.component.description | ||
// structurizr.inspection.model.component.* | ||
// structurizr.inspection.model.* | ||
// structurizr.inspection.* | ||
|
||
List<String> types = new ArrayList<>(); | ||
|
||
String[] parts = inspection.split("\\."); | ||
String buf = STRUCTURIZR_INSPECTION_PREFIX; | ||
types.add(buf + "*"); | ||
for (int i = 0; i < parts.length-1; i++) { | ||
buf = buf + parts[i] + "."; | ||
types.add(buf + "*"); | ||
} | ||
|
||
types.add(STRUCTURIZR_INSPECTION_PREFIX + inspection); | ||
Collections.reverse(types); | ||
|
||
return types; | ||
} | ||
|
||
} |
Oops, something went wrong.