Skip to content

Commit

Permalink
Removes the Workspace.countAndLogWarnings() method with an initial …
Browse files Browse the repository at this point in the history
…version of something more flexible.
  • Loading branch information
simonbrowndotje committed Jan 9, 2024
1 parent ab30296 commit 99d4ccc
Show file tree
Hide file tree
Showing 63 changed files with 1,896 additions and 90 deletions.
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
rootProject.name = 'structurizr-java'

include 'structurizr-assistant'
include 'structurizr-client'
include 'structurizr-core'
include 'structurizr-dsl'
Expand Down
3 changes: 3 additions & 0 deletions structurizr-assistant/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# structurizr-assistant

[![Maven Central](https://img.shields.io/maven-central/v/com.structurizr/structurizr-assistant.svg?label=Maven%20Central)](https://search.maven.org/artifact/com.structurizr/structurizr-assistant)
7 changes: 7 additions & 0 deletions structurizr-assistant/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
dependencies {

api project(':structurizr-core')

testImplementation 'org.junit.jupiter:junit-jupiter:5.9.2'

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

import java.util.ArrayList;
import java.util.Collection;

abstract class Assistant {

private final Collection<Recommendation> recommendations = new ArrayList<>();

public Collection<Recommendation> getRecommendations() {
return new ArrayList<>(recommendations);
}

protected void add(Recommendation recommendation) {
if (recommendation != null) {
recommendations.add(recommendation);
}
}

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

import com.structurizr.Workspace;
import com.structurizr.assistant.model.*;
import com.structurizr.assistant.view.ContainerViewsForMultipleSoftwareSystemsInspection;
import com.structurizr.assistant.view.EmptyViewsInspection;
import com.structurizr.assistant.view.SystemContextViewsForMultipleSoftwareSystemsInspection;
import com.structurizr.assistant.workspace.WorkspaceScopeInspection;
import com.structurizr.model.*;

public class DefaultAssistant extends Assistant {

private static final String ALL_RECOMMENDATIONS = "structurizr.recommendations";

public DefaultAssistant(Workspace workspace) {
if (workspace.getProperties().getOrDefault(ALL_RECOMMENDATIONS, "true").equalsIgnoreCase("false")) {
// skip all inspections
return;
}

runWorkspaceInspections(workspace);
runModelInspections(workspace);
runViewInspections(workspace);
}

private void runWorkspaceInspections(Workspace workspace) {
add(new WorkspaceScopeInspection(workspace).run());
}

private void runModelInspections(Workspace workspace) {
add(new EmptyModelInspection(workspace).run());
add(new MultipleSoftwareSystemsDetailedInspection(workspace).run());
ElementNotIncludedInAnyViewsInspection elementNotIncludedInAnyViewsCheck = new ElementNotIncludedInAnyViewsInspection(workspace);
OrphanedElementInspection orphanedElementCheck = new OrphanedElementInspection(workspace);
for (Element element : workspace.getModel().getElements()) {
add(elementNotIncludedInAnyViewsCheck.run(element));
add(orphanedElementCheck.run(element));

if (element instanceof Person) {
add(new PersonDescriptionInspection(workspace).run(element));
}

if (element instanceof SoftwareSystem) {
add(new SoftwareSystemDescriptionInspection(workspace).run(element));
}

if (element instanceof Container) {
add(new ContainerDescriptionInspection(workspace).run(element));
add(new ContainerTechnologyInspection(workspace).run(element));
}

if (element instanceof Component) {
add(new ComponentDescriptionInspection(workspace).run(element));
add(new ComponentTechnologyInspection(workspace).run(element));
}
}
}

private void runViewInspections(Workspace workspace) {
add(new EmptyViewsInspection(workspace).run());
add(new SystemContextViewsForMultipleSoftwareSystemsInspection(workspace).run());
add(new ContainerViewsForMultipleSoftwareSystemsInspection(workspace).run());
}

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

import com.structurizr.PropertyHolder;
import com.structurizr.Workspace;

public abstract class Inspection {

private static final String STRUCTURIZR_RECOMMENDATIONS_PREFIX = "structurizr.recommendations.";

private final Workspace workspace;

protected Inspection(Workspace workspace) {
this.workspace = workspace;
}

protected abstract String getType();

protected Workspace getWorkspace() {
return workspace;
}

protected boolean isEnabled(String type, PropertyHolder... propertyHolders) {
String value = "true";

for (PropertyHolder propertyHolder : propertyHolders) {
if (propertyHolder != null) {
value = propertyHolder.getProperties().getOrDefault(STRUCTURIZR_RECOMMENDATIONS_PREFIX + type, value);
}
}

return !value.equalsIgnoreCase("false");
}

protected Recommendation noRecommendation() {
return null;
}

protected Recommendation lowPriorityRecommendation(String description) {
return new Recommendation(STRUCTURIZR_RECOMMENDATIONS_PREFIX + getType(), Priority.Low, description);
}

protected Recommendation mediumPriorityRecommendation(String description) {
return new Recommendation(STRUCTURIZR_RECOMMENDATIONS_PREFIX + getType(), Priority.Medium, description);
}

protected Recommendation highPriorityRecommendation(String description) {
return new Recommendation(STRUCTURIZR_RECOMMENDATIONS_PREFIX + getType(), Priority.High, description);
}

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

public enum Priority {

Low,
Medium,
High

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

public final class Recommendation {

private final String type;
private final Priority priority;
private final String description;

Recommendation(String type, Priority priority, String description) {
this.type = type;
this.priority = priority;
this.description = description;
}

public String getType() {
return type;
}

public Priority getPriority() {
return priority;
}

public String getDescription() {
return description;
}

@Override
public String toString() {
return type + " | " + priority + " | " + description;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.structurizr.assistant.model;

import com.structurizr.Workspace;

public class ComponentDescriptionInspection extends ElementDescriptionInspection {

public ComponentDescriptionInspection(Workspace workspace) {
super(workspace);
}

@Override
protected String getType() {
return "model.component.description";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.structurizr.assistant.model;

import com.structurizr.Workspace;
import com.structurizr.assistant.Recommendation;
import com.structurizr.model.Component;
import com.structurizr.model.Element;

abstract class ComponentInspection extends ElementInspection {

public ComponentInspection(Workspace workspace) {
super(workspace);
}

@Override
protected Recommendation inspect(Element element) {
return inspect((Component)element);
}

protected abstract Recommendation inspect(Component component);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.structurizr.assistant.model;

import com.structurizr.Workspace;
import com.structurizr.assistant.Recommendation;
import com.structurizr.model.Component;
import com.structurizr.util.StringUtils;

public class ComponentTechnologyInspection extends ComponentInspection {

public ComponentTechnologyInspection(Workspace workspace) {
super(workspace);
}

@Override
protected Recommendation inspect(Component component) {
if (StringUtils.isNullOrEmpty(component.getDescription())) {
return lowPriorityRecommendation("Add a technology to the " + terminologyFor(component).toLowerCase() + " named \"" + component.getName() + "\".");
}

return noRecommendation();
}

@Override
protected String getType() {
return "model.component.technology";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.structurizr.assistant.model;

import com.structurizr.Workspace;

public class ContainerDescriptionInspection extends ElementDescriptionInspection {

public ContainerDescriptionInspection(Workspace workspace) {
super(workspace);
}

@Override
protected String getType() {
return "model.container.description";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.structurizr.assistant.model;

import com.structurizr.Workspace;
import com.structurizr.assistant.Recommendation;
import com.structurizr.model.Container;
import com.structurizr.model.Element;

abstract class ContainerInspection extends ElementInspection {

public ContainerInspection(Workspace workspace) {
super(workspace);
}

@Override
protected Recommendation inspect(Element element) {
return inspect((Container)element);
}

protected abstract Recommendation inspect(Container container);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.structurizr.assistant.model;

import com.structurizr.Workspace;
import com.structurizr.assistant.Recommendation;
import com.structurizr.model.Container;
import com.structurizr.util.StringUtils;

public class ContainerTechnologyInspection extends ContainerInspection {

public ContainerTechnologyInspection(Workspace workspace) {
super(workspace);
}

@Override
protected Recommendation inspect(Container container) {
if (StringUtils.isNullOrEmpty(container.getTechnology())) {
return mediumPriorityRecommendation("Add a technology to the " + terminologyFor(container).toLowerCase() + " named \"" + container.getName() + "\".");
}

return noRecommendation();
}

@Override
protected String getType() {
return "model.container.technology";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.structurizr.assistant.model;

import com.structurizr.Workspace;

public class DeploymentNodeDescriptionInspection extends ElementDescriptionInspection {

public DeploymentNodeDescriptionInspection(Workspace workspace) {
super(workspace);
}

@Override
protected String getType() {
return "model.deploymentnode.description";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.structurizr.assistant.model;

import com.structurizr.Workspace;
import com.structurizr.assistant.Recommendation;
import com.structurizr.model.DeploymentNode;
import com.structurizr.model.Element;

abstract class DeploymentNodeInspection extends ElementInspection {

public DeploymentNodeInspection(Workspace workspace) {
super(workspace);
}

@Override
protected Recommendation inspect(Element element) {
return inspect((DeploymentNode)element);
}

protected abstract Recommendation inspect(DeploymentNode deploymentNode);

}
Loading

0 comments on commit 99d4ccc

Please sign in to comment.