Skip to content

Commit

Permalink
Fixes #192
Browse files Browse the repository at this point in the history
  • Loading branch information
Riduidel committed Jun 22, 2022
1 parent eaf6e06 commit 0786a68
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,63 +19,6 @@ workspace "aadarchi-documentation-system" {
"aadarchi.issue.manager" "https://github.com/Riduidel/aadarchi-documentation-system/issues"
"aadarchi.maven.coordinates" "io.github.Riduidel.aadarchi-documentation-system:base"
}
ArchitectureEnhancer = component "ArchitectureEnhancer" "Invokes all enhancers with respect for their respective priorities" "Java, CDI"
gitlab_scm_handler = component "gitlab-scm-handler" "" "Java, gitlab"{
properties {
"aadarchi.java.source" "../gitlab-scm-handler/src/main/java/"
"aadarchi.scm.path" "gitlab-scm-handler"
"aadarchi.maven.pom" "../gitlab-scm-handler/pom.xml"
"aadarchi.scm.project" "https://github.com/Riduidel/aadarchi-documentation-system.git"
"aadarchi.issue.manager" "https://github.com/Riduidel/aadarchi-documentation-system/issues"
"aadarchi.maven.coordinates" "io.github.Riduidel.aadarchi-documentation-system:gitlab-scm-handler"
}
}
GraphEmitter = component "GraphEmitter" "Generates all graph output in the destination folder" "Java, CDI"
cdi_config_extension_35 = component "cdi-config-extension" {
properties {
"aadarchi.java.source" "../cdi-config-extension/src/main/java/"
"aadarchi.scm.path" "maven-metadata-inferer"
"aadarchi.maven.pom" "../cdi-config-extension/pom.xml"
"aadarchi.scm.project" "https://github.com/Riduidel/aadarchi-documentation-system.git"
"aadarchi.issue.manager" "https://github.com/Riduidel/aadarchi-documentation-system/issues"
"aadarchi.maven.coordinates" "io.github.Riduidel.aadarchi-documentation-system:cdi-config-extension"
}
}
maven_metadata_inferer_37 = component "maven-metadata-inferer" {
properties {
"aadarchi.java.source" "../maven-metadata-inferer/src/main/java/"
"aadarchi.scm.path" "maven-metadata-inferer"
"aadarchi.maven.pom" "../maven-metadata-inferer/pom.xml"
"aadarchi.scm.project" "https://github.com/Riduidel/aadarchi-documentation-system.git"
"aadarchi.issue.manager" "https://github.com/Riduidel/aadarchi-documentation-system/issues"
"aadarchi.maven.coordinates" "io.github.Riduidel.aadarchi-documentation-system:maven-metadata-inferer"
}
}
SCMReadmeReader = component "SCMReadmeReader" "Read the project readme and renders it as asciidoc" "Java"
ArchitectureDocumentationBuilder_15 = component "ArchitectureDocumentationBuilder" "Main component reading architecture from any provider then enhancing it" "Java, CDI"
SCMLinkGenerator = component "SCMLinkGenerator" "Generates a link to project SCM" "Java"
ImplicitIncludeManager_17 = component "ImplicitIncludeManager" "" "Java"
github_scm_handler_25 = component "github-scm-handler" {
properties {
"aadarchi.java.source" "../github-scm-handler/src/main/java/"
"aadarchi.scm.path" "github-scm-handler"
"aadarchi.maven.pom" "../github-scm-handler/pom.xml"
"aadarchi.scm.project" "https://github.com/Riduidel/aadarchi-documentation-system.git"
"aadarchi.issue.manager" "https://github.com/Riduidel/aadarchi-documentation-system/issues"
"aadarchi.maven.coordinates" "io.github.Riduidel.aadarchi-documentation-system:github-scm-handler"
}
}
DocumentsCollector = component "DocumentsCollector" "" "Java"
adr_tickets_extractor_31 = component "adr-tickets-extractor" {
properties {
"aadarchi.java.source" "../adr-tickets-extractor/src/main/java/"
"aadarchi.scm.path" "adr-tickets-extractor"
"aadarchi.maven.pom" "../adr-tickets-extractor/pom.xml"
"aadarchi.scm.project" "https://github.com/Riduidel/aadarchi-documentation-system.git"
"aadarchi.issue.manager" "https://github.com/Riduidel/aadarchi-documentation-system/issues"
"aadarchi.maven.coordinates" "io.github.Riduidel.aadarchi-documentation-system:adr-tickets-extractor"
}
}
}
asciidoc_39 = container "asciidoc" "The asciidoctor engine" "Java"
archetype_6 = container "archetype" "" "maven"{
Expand All @@ -88,46 +31,14 @@ workspace "aadarchi-documentation-system" {
}
}
}
ArchitectureEnhancer -> ImplicitIncludeManager_17 "Generates includes for all enhancers" ""
person_architect -> aadarchi "Writes" ""
adr_tickets_extractor_31 -> github_scm_handler_25 "Read tickets from GitHub if configured so" ""
ArchitectureDocumentationBuilder_15 -> maven_metadata_inferer_37 "Infer most of element details from Maven infos" ""
ArchitectureEnhancer -> SCMReadmeReader "Includes elements readme when they exist" ""
person_stakeholder -> aadarchi "Read" ""
ArchitectureEnhancer -> SCMLinkGenerator "Generates links to SCM sources" ""
adr_tickets_extractor_31 -> gitlab_scm_handler "Read tickets from Gitlab if configured so" ""
person_architect -> archetype_6 "Bootstrap a valid project" ""
ArchitectureDocumentationBuilder_15 -> cdi_config_extension_35 "Eases out some CDI code" ""
SCMLinkGenerator -> gitlab_scm_handler "Get project source link" ""
maven -> aadarchi_base "Generates diagrams and asciidoc includes" ""
ArchitectureEnhancer -> DocumentsCollector "Collects documents in source folder" ""
maven -> ArchitectureDocumentationBuilder_15 "Invokes that Java executable during maven build" ""
maven -> asciidoc_39 "Generates documentation as usable text in HTML/PDF/..." ""
SCMReadmeReader -> gitlab_scm_handler "Get project readme" ""
person_architect -> maven "Generates documentation" ""
SCMLinkGenerator -> github_scm_handler_25 "Get project source link" ""
ArchitectureEnhancer -> adr_tickets_extractor_31 "Produces ADR reporting" ""
ArchitectureDocumentationBuilder_15 -> ArchitectureEnhancer "Adds information to initial architecture description" ""
ArchitectureEnhancer -> GraphEmitter "Generates diagrams in PlantUML format" ""
SCMReadmeReader -> github_scm_handler_25 "Get project readme" ""
maven -> ArchitectureDocumentationBuilder_15 "Invokes that Java executable during maven build" ""
maven -> aadarchi_base "Generates diagrams and asciidoc includes" ""
maven -> asciidoc_39 "Generates documentation as usable text in HTML/PDF/..." ""
ArchitectureEnhancer -> DocumentsCollector "Collects documents in source folder" ""
ArchitectureEnhancer -> SCMLinkGenerator "Generates links to SCM sources" ""
ArchitectureEnhancer -> SCMReadmeReader "Includes elements readme when they exist" ""
ArchitectureEnhancer -> ImplicitIncludeManager_17 "Generates includes for all enhancers" ""
ArchitectureEnhancer -> GraphEmitter "Generates diagrams in PlantUML format" ""
ArchitectureEnhancer -> adr_tickets_extractor_31 "Produces ADR reporting" ""
SCMReadmeReader -> github_scm_handler_25 "Get project readme" ""
SCMReadmeReader -> gitlab_scm_handler "Get project readme" ""
ArchitectureDocumentationBuilder_15 -> ArchitectureEnhancer "Adds information to initial architecture description" ""
ArchitectureDocumentationBuilder_15 -> cdi_config_extension_35 "Eases out some CDI code" ""
ArchitectureDocumentationBuilder_15 -> maven_metadata_inferer_37 "Infer most of element details from Maven infos" ""
SCMLinkGenerator -> github_scm_handler_25 "Get project source link" ""
SCMLinkGenerator -> gitlab_scm_handler "Get project source link" ""
adr_tickets_extractor_31 -> gitlab_scm_handler "Read tickets from Gitlab if configured so" ""
adr_tickets_extractor_31 -> github_scm_handler_25 "Read tickets from GitHub if configured so" ""
}
views {
styles {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package org.ndx.aadarchi;

import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URLClassLoader;
import java.nio.file.Path;
import java.util.LinkedList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.inject.Inject;

import org.ndx.aadarchi.base.enhancers.ModelElementAdapter;
import org.ndx.aadarchi.base.enhancers.ModelElementKeys;
import org.ndx.aadarchi.base.utils.FileResolver;

import com.structurizr.analysis.ComponentFinder;
import com.structurizr.analysis.ComponentFinderStrategy;
import com.structurizr.analysis.SourceCodeComponentFinderStrategy;
import com.structurizr.analysis.StructurizrAnnotationsComponentFinderStrategy;
import com.structurizr.model.Component;
import com.structurizr.model.Container;

/**
* Enhancer that detects the components in each container for various
* sub-elements to work correctly
*/

public class ComponentDetector extends ModelElementAdapter {
@Inject Logger logger;
@Inject FileResolver fileResolver;

@Override
public int priority() {
return TOP_PRIORITY_FOR_INTERNAL_ENHANCERS;
}

/**
* When visiting container, we fond all associated components and load them immediatly
*/
@Override
public boolean startVisit(Container container) {
if(container.getProperties().containsKey(ModelElementKeys.JAVA_PACKAGES)) {
try {
ComponentFinder componentFinder = new ComponentFinder(
container,
"org.ndx.aadarchi",
strategies(container)
);
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
if (contextClassLoader instanceof URLClassLoader) {
URLClassLoader urlClassLoader = (URLClassLoader) contextClassLoader;
componentFinder.setUrlClassLoader(urlClassLoader);
}
componentFinder.findComponents();
} catch (Exception e) {
logger.log(Level.WARNING,
String.format("Unable to detect components in %s", container));
}
} else {
logger.warning(
String.format("As there are no %s property defined on container %s, we're not able to detect components in that container",
ModelElementKeys.JAVA_PACKAGES, container.getCanonicalName()));
}
return super.startVisit(container);
}

private ComponentFinderStrategy[] strategies(Container container) throws MalformedURLException, URISyntaxException {
List<ComponentFinderStrategy> returned = new LinkedList<>();
returned.add(new StructurizrAnnotationsComponentFinderStrategy());
if(container.getProperties().containsKey(ModelElementKeys.JAVA_SOURCES)) {
Path sourceFolderAsPath = fileResolver.fileAsUrltoPath(container.getProperties().get(ModelElementKeys.JAVA_SOURCES));
returned.add(new SourceCodeComponentFinderStrategy(sourceFolderAsPath.toFile()));
}
return returned.toArray(new ComponentFinderStrategy[returned.size()]);
}

@Override
public boolean startVisit(Component component) {
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.ndx.aadarchi;

import org.ndx.aadarchi.base.AgileArchitectureException;

public class ComponentDetectorException extends AgileArchitectureException {

public ComponentDetectorException(String message) {
super(message);
}

public ComponentDetectorException(Throwable cause) {
super(cause);
}

public ComponentDetectorException(String message, Throwable cause) {
super(message, cause);
}

}

0 comments on commit 0786a68

Please sign in to comment.