Skip to content

Commit

Permalink
Fixes #140 (#146)
Browse files Browse the repository at this point in the history
  • Loading branch information
Riduidel authored Apr 28, 2022
1 parent 61a6a63 commit c3c26ac
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 2 deletions.
4 changes: 4 additions & 0 deletions base/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.structurizr</groupId>
<artifactId>structurizr-dsl</artifactId>
</dependency>
<dependency>
<groupId>com.structurizr</groupId>
<artifactId>structurizr-plantuml</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package org.ndx.agile.architecture.base;

import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Any;
import javax.enterprise.inject.Instance;
import javax.enterprise.inject.se.SeContainer;
import javax.enterprise.inject.se.SeContainerInitializer;
import javax.inject.Inject;
Expand Down Expand Up @@ -38,16 +41,29 @@ public static void main(String[] args) throws Throwable {

@Inject Logger logger;
@Inject @UsesComponent(description = "Adds information to initial architecture description") ArchitectureEnhancer enhancer;
@Inject @UsesComponent(description = "Generates initial architecture description") ArchitectureModelProvider provider;
@Inject @UsesComponent(description = "Generates initial architecture description") @Any Instance<ArchitectureModelProvider> availableProviders;

/**
* Run method that will allow the description to be invoked and augmentations to be performed
* prior to have elements written. You should not have to overwrite this method.
* @throws IOException
*/
public void run() throws IOException {
Workspace workspace = provider.describeArchitecture();
Workspace workspace = getArchitecture();
logger.info("Architecture has been described. Now enhancing it (including writing the diagrams)!");
enhancer.enhance(workspace);
}

private Workspace getArchitecture() {
for(ArchitectureModelProvider provider : availableProviders) {
try {
return provider.describeArchitecture();
} catch(Throwable e) {
logger.log(Level.WARNING,
String.format("model provider %s failed to load any workspace", provider.getClass().getName()),
e);
}
}
throw new UnsupportedOperationException("There is no instance of ArchitectureModelProvider defined in project, and no workspace.dsl file to parse");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package org.ndx.agile.architecture.base.providers;

import java.io.File;

import javax.enterprise.inject.Alternative;
import javax.inject.Inject;

import org.apache.deltaspike.core.api.config.ConfigProperty;
import org.ndx.agile.architecture.base.ArchitectureModelProvider;
import org.ndx.agile.architecture.base.enhancers.ModelElementKeys;

import com.structurizr.Workspace;
import com.structurizr.dsl.StructurizrDslParser;
import com.structurizr.dsl.StructurizrDslParserException;

@Alternative
public class FromDsl implements ArchitectureModelProvider {

private static final String WORKSPACE_DSL = ModelElementKeys.PREFIX + "dsl";
@Inject
@ConfigProperty(name = WORKSPACE_DSL, defaultValue = "src/architecture/resources/workspace.dsl") File workspace;

@Override
public Workspace describeArchitecture() {
if(!workspace.exists()) {
throw new UnsupportedOperationException(String.format(
"Parsing a workspace.dsl file supposes the file exists.\n"
+ "We tried to read file %s but there was nothing.\n"
+ "Please either move that file into that location or set the property %s",
workspace.getAbsolutePath(),
WORKSPACE_DSL));
}
StructurizrDslParser parser = new StructurizrDslParser();
try {
parser.parse(workspace);
} catch (StructurizrDslParserException e) {
throw new RuntimeException("Can't read workspace.dsl", e);
}
return parser.getWorkspace();
}

}
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@
<artifactId>deltaspike-core-impl</artifactId>
<version>1.9.5</version>
</dependency>
<dependency>
<groupId>com.structurizr</groupId>
<artifactId>structurizr-dsl</artifactId>
<version>1.18.0</version>
</dependency>
<dependency>
<groupId>com.structurizr</groupId>
<artifactId>structurizr-client</artifactId>
Expand Down

0 comments on commit c3c26ac

Please sign in to comment.