From a399b9ffd8bb84352bb65214acc2ddf3eea471cd Mon Sep 17 00:00:00 2001 From: Nicolas Delsaux Date: Mon, 23 May 2022 17:49:34 +0200 Subject: [PATCH 1/3] Extracted all code in a dedicated maven module --- aadarchi-maven-plugin/pom.xml | 27 ++-------- .../maven/plugin/GenerateDiagramsMojo.java | 2 +- .../chalda/classloader/ClassLoaderUtils.java | 0 .../collector/DocumentsCollector.java | 2 +- .../base/enhancers/graph/GraphEmitter.java | 2 +- .../includes/ImplicitIncludeManager.java | 2 +- .../architecture/base/providers/FromDsl.java | 2 +- cdi-in-maven-plugin-helper/README.adoc | 50 +++++++++++++++++++ cdi-in-maven-plugin-helper/pom.xml | 48 ++++++++++++++++++ ...poseMavenPropertiesAsConfigproperties.java | 2 +- .../maven/cdi/helper/log}/BindJULToMaven.java | 2 +- .../log}/MavenLoggingRedirectorHandler.java | 2 +- .../wrappers}/AbstractCDIStarterMojo.java | 4 +- .../maven/cdi/helper/wrappers}/CDIUtil.java | 2 +- .../cdi/helper/wrappers}/CdiBeanWrapper.java | 2 +- .../cdi/helper/wrappers}/CdiProducerBean.java | 2 +- .../maven/cdi/helper/wrappers}/MavenUtil.java | 2 +- .../cdi/helper/wrappers}/MojoProduces.java | 2 +- pom.xml | 3 +- 19 files changed, 119 insertions(+), 39 deletions(-) rename {aadarchi-maven-plugin => base}/src/main/java/cz/chalda/classloader/ClassLoaderUtils.java (100%) create mode 100644 cdi-in-maven-plugin-helper/README.adoc create mode 100644 cdi-in-maven-plugin-helper/pom.xml rename {aadarchi-maven-plugin/src/main/java/org/ndx/agile/architecture/documentation/system/maven/plugin => cdi-in-maven-plugin-helper/src/main/java/org/ndx/agile/architecture/documentation/system/maven/cdi/helper}/ExposeMavenPropertiesAsConfigproperties.java (97%) rename {aadarchi-maven-plugin/src/main/java/org/ndx/agile/architecture/documentation/system/maven/plugin => cdi-in-maven-plugin-helper/src/main/java/org/ndx/agile/architecture/documentation/system/maven/cdi/helper/log}/BindJULToMaven.java (82%) rename {aadarchi-maven-plugin/src/main/java/org/ndx/agile/architecture/documentation/system/maven/plugin => cdi-in-maven-plugin-helper/src/main/java/org/ndx/agile/architecture/documentation/system/maven/cdi/helper/log}/MavenLoggingRedirectorHandler.java (95%) rename {aadarchi-maven-plugin/src/main/java/org/ndx/agile/architecture/documentation/system/maven/plugin/cdi => cdi-in-maven-plugin-helper/src/main/java/org/ndx/agile/architecture/documentation/system/maven/cdi/helper/wrappers}/AbstractCDIStarterMojo.java (97%) rename {aadarchi-maven-plugin/src/main/java/org/ndx/agile/architecture/documentation/system/maven/plugin/cdi => cdi-in-maven-plugin-helper/src/main/java/org/ndx/agile/architecture/documentation/system/maven/cdi/helper/wrappers}/CDIUtil.java (98%) rename {aadarchi-maven-plugin/src/main/java/org/ndx/agile/architecture/documentation/system/maven/plugin/cdi => cdi-in-maven-plugin-helper/src/main/java/org/ndx/agile/architecture/documentation/system/maven/cdi/helper/wrappers}/CdiBeanWrapper.java (95%) rename {aadarchi-maven-plugin/src/main/java/org/ndx/agile/architecture/documentation/system/maven/plugin/cdi => cdi-in-maven-plugin-helper/src/main/java/org/ndx/agile/architecture/documentation/system/maven/cdi/helper/wrappers}/CdiProducerBean.java (98%) rename {aadarchi-maven-plugin/src/main/java/org/ndx/agile/architecture/documentation/system/maven/plugin/cdi => cdi-in-maven-plugin-helper/src/main/java/org/ndx/agile/architecture/documentation/system/maven/cdi/helper/wrappers}/MavenUtil.java (96%) rename {aadarchi-maven-plugin/src/main/java/org/ndx/agile/architecture/documentation/system/maven/plugin/cdi => cdi-in-maven-plugin-helper/src/main/java/org/ndx/agile/architecture/documentation/system/maven/cdi/helper/wrappers}/MojoProduces.java (90%) diff --git a/aadarchi-maven-plugin/pom.xml b/aadarchi-maven-plugin/pom.xml index 20e3f635..0b05d853 100644 --- a/aadarchi-maven-plugin/pom.xml +++ b/aadarchi-maven-plugin/pom.xml @@ -12,25 +12,6 @@ Agile Architecture Documentation System : Maven plugin - - javax.enterprise - cdi-api - - - org.jboss.weld.se - weld-se-core - - - - org.apache.maven - maven-core - 3.8.4 - - - org.apache.maven - maven-plugin-api - 2.0 - org.apache.maven.plugin-tools maven-plugin-annotations @@ -44,13 +25,13 @@ ${project.groupId} - base + cdi-in-maven-plugin-helper ${project.version} - - org.apache.deltaspike.core - deltaspike-core-impl + ${project.groupId} + base + ${project.version} diff --git a/aadarchi-maven-plugin/src/main/java/org/ndx/agile/architecture/documentation/system/maven/plugin/GenerateDiagramsMojo.java b/aadarchi-maven-plugin/src/main/java/org/ndx/agile/architecture/documentation/system/maven/plugin/GenerateDiagramsMojo.java index 1fd795fa..f96af893 100644 --- a/aadarchi-maven-plugin/src/main/java/org/ndx/agile/architecture/documentation/system/maven/plugin/GenerateDiagramsMojo.java +++ b/aadarchi-maven-plugin/src/main/java/org/ndx/agile/architecture/documentation/system/maven/plugin/GenerateDiagramsMojo.java @@ -3,7 +3,7 @@ import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.ResolutionScope; -import org.ndx.agile.architecture.documentation.system.maven.plugin.cdi.AbstractCDIStarterMojo; +import org.ndx.agile.architecture.documentation.system.maven.cdi.helper.wrappers.AbstractCDIStarterMojo; @Mojo(name = "generate-model", defaultPhase = LifecyclePhase.PREPARE_PACKAGE, diff --git a/aadarchi-maven-plugin/src/main/java/cz/chalda/classloader/ClassLoaderUtils.java b/base/src/main/java/cz/chalda/classloader/ClassLoaderUtils.java similarity index 100% rename from aadarchi-maven-plugin/src/main/java/cz/chalda/classloader/ClassLoaderUtils.java rename to base/src/main/java/cz/chalda/classloader/ClassLoaderUtils.java diff --git a/base/src/main/java/org/ndx/agile/architecture/base/enhancers/collector/DocumentsCollector.java b/base/src/main/java/org/ndx/agile/architecture/base/enhancers/collector/DocumentsCollector.java index 2a7837d7..a1f03d62 100644 --- a/base/src/main/java/org/ndx/agile/architecture/base/enhancers/collector/DocumentsCollector.java +++ b/base/src/main/java/org/ndx/agile/architecture/base/enhancers/collector/DocumentsCollector.java @@ -42,7 +42,7 @@ public class DocumentsCollector implements ModelEnhancer { /** * Injecting enhancements base to have a folder where to put our documents. */ - @Inject @ConfigProperty(name=ModelElementKeys.PREFIX+"enhancements", defaultValue = "${basedir}/target/structurizr/enhancements") File enhancementsBase; + @Inject @ConfigProperty(name=ModelElementKeys.PREFIX+"enhancements", defaultValue = "target/structurizr/enhancements") File enhancementsBase; /** * Map that contains all elements that should be automagically included. * First level keys are the enums. diff --git a/base/src/main/java/org/ndx/agile/architecture/base/enhancers/graph/GraphEmitter.java b/base/src/main/java/org/ndx/agile/architecture/base/enhancers/graph/GraphEmitter.java index 8b826ced..ec5fbc92 100644 --- a/base/src/main/java/org/ndx/agile/architecture/base/enhancers/graph/GraphEmitter.java +++ b/base/src/main/java/org/ndx/agile/architecture/base/enhancers/graph/GraphEmitter.java @@ -35,7 +35,7 @@ public class GraphEmitter implements ViewEnhancer { @Inject Logger logger; @Inject - @ConfigProperty(name = ModelElementKeys.AGILE_ARCHITECTURE_DIAGRAMS_PATH, defaultValue = "${basedir}/target/structurizr/diagrams") + @ConfigProperty(name = ModelElementKeys.AGILE_ARCHITECTURE_DIAGRAMS_PATH, defaultValue = "target/structurizr/diagrams") File destination; @Inject @ConfigProperty(name = "force", defaultValue = "false") boolean force; diff --git a/base/src/main/java/org/ndx/agile/architecture/base/enhancers/includes/ImplicitIncludeManager.java b/base/src/main/java/org/ndx/agile/architecture/base/enhancers/includes/ImplicitIncludeManager.java index 43230079..62d9b770 100644 --- a/base/src/main/java/org/ndx/agile/architecture/base/enhancers/includes/ImplicitIncludeManager.java +++ b/base/src/main/java/org/ndx/agile/architecture/base/enhancers/includes/ImplicitIncludeManager.java @@ -35,7 +35,7 @@ public class ImplicitIncludeManager extends ModelElementAdapter { private static final String ASCIIDOC_SOURCE_DIR = "asciidoc.source.dir"; private File sourceDir; - @Inject public void setDocumentsFolder(@ConfigProperty(name=ASCIIDOC_SOURCE_DIR, defaultValue = "${basedir}/src/docs/asciidoc") File sourceDir) { + @Inject public void setDocumentsFolder(@ConfigProperty(name=ASCIIDOC_SOURCE_DIR, defaultValue = "src/docs/asciidoc") File sourceDir) { if(sourceDir==null) { throw new CantCreateImplicitInclude( String.format("To have implicit includes working, you have to define the system property %s", diff --git a/base/src/main/java/org/ndx/agile/architecture/base/providers/FromDsl.java b/base/src/main/java/org/ndx/agile/architecture/base/providers/FromDsl.java index 252f0d69..b626de3a 100644 --- a/base/src/main/java/org/ndx/agile/architecture/base/providers/FromDsl.java +++ b/base/src/main/java/org/ndx/agile/architecture/base/providers/FromDsl.java @@ -21,7 +21,7 @@ public class FromDsl implements ArchitectureModelProvider { private static final String WORKSPACE_DSL = ModelElementKeys.PREFIX + "dsl"; @Inject - @ConfigProperty(name = WORKSPACE_DSL, defaultValue = "${basedir}/src/architecture/resources/workspace.dsl") File workspace; + @ConfigProperty(name = WORKSPACE_DSL, defaultValue = "src/architecture/resources/workspace.dsl") File workspace; @Override public Workspace describeArchitecture() { diff --git a/cdi-in-maven-plugin-helper/README.adoc b/cdi-in-maven-plugin-helper/README.adoc new file mode 100644 index 00000000..496827cf --- /dev/null +++ b/cdi-in-maven-plugin-helper/README.adoc @@ -0,0 +1,50 @@ += CDI In maven plugin Helper + +This small library, heavily borrowing from the defunct https://github.com/shillner/maven-cdi-plugin-utils[itemis maven-cdi-plugin-utils] allows a maven mojo to simply use CDI injection. + +== Requirements + +Write a Mojo which inherits from `AbstractCDIStarterMojo`. + +In that Mojo, simply overwrite the `Class getCDIEnabledRunnableClass()` method, which gets called when Weld has been bootstrapped with all dependencies. + +== Example + +[code, java] +---- +@Mojo(name = "generate-model", + defaultPhase = LifecyclePhase.PREPARE_PACKAGE, + requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME) +public class GenerateDiagramsMojo extends AbstractCDIStarterMojo { + + @Override + protected Class getCDIEnabledRunnableClass() { + return GenerateDiagramsRunnable.class; + } + +} +---- + +This class bootstraps the CDI environment for running the `GenerateDiagramsRunnable` + +[code, java] +---- +public class GenerateDiagramsRunnable implements Runnable { + + @Inject Logger logger; + + @Inject ArchitectureDocumentationBuilder builder; + + @Override + public void run() { + try { + builder.run(); + } catch (IOException e) { + throw new RuntimeException("Unable to generate architecture documentation elements", e); + } + } + +} +---- + +This class is invoked in maven build with all CDI configured. \ No newline at end of file diff --git a/cdi-in-maven-plugin-helper/pom.xml b/cdi-in-maven-plugin-helper/pom.xml new file mode 100644 index 00000000..2627f885 --- /dev/null +++ b/cdi-in-maven-plugin-helper/pom.xml @@ -0,0 +1,48 @@ + + 4.0.0 + + io.github.Riduidel.agile-architecture-documentation-system + system + 0.0.12-SNAPSHOT + + cdi-in-maven-plugin-helper + CDI in Maven helper + This small java library provides a simple way to have a maven Mojo use CDI for bean injection + + + javax.enterprise + cdi-api + + + org.jboss.weld.se + weld-se-core + + + + org.apache.maven + maven-core + 3.8.4 + + + org.apache.maven + maven-plugin-api + 2.0 + + + org.apache.maven.plugin-tools + maven-plugin-annotations + 3.4 + provided + + + org.apache.maven + maven-plugin-api + 3.1.0 + + + + org.apache.deltaspike.core + deltaspike-core-impl + + + \ No newline at end of file diff --git a/aadarchi-maven-plugin/src/main/java/org/ndx/agile/architecture/documentation/system/maven/plugin/ExposeMavenPropertiesAsConfigproperties.java b/cdi-in-maven-plugin-helper/src/main/java/org/ndx/agile/architecture/documentation/system/maven/cdi/helper/ExposeMavenPropertiesAsConfigproperties.java similarity index 97% rename from aadarchi-maven-plugin/src/main/java/org/ndx/agile/architecture/documentation/system/maven/plugin/ExposeMavenPropertiesAsConfigproperties.java rename to cdi-in-maven-plugin-helper/src/main/java/org/ndx/agile/architecture/documentation/system/maven/cdi/helper/ExposeMavenPropertiesAsConfigproperties.java index f2e4c287..17b64cec 100644 --- a/aadarchi-maven-plugin/src/main/java/org/ndx/agile/architecture/documentation/system/maven/plugin/ExposeMavenPropertiesAsConfigproperties.java +++ b/cdi-in-maven-plugin-helper/src/main/java/org/ndx/agile/architecture/documentation/system/maven/cdi/helper/ExposeMavenPropertiesAsConfigproperties.java @@ -1,4 +1,4 @@ -package org.ndx.agile.architecture.documentation.system.maven.plugin; +package org.ndx.agile.architecture.documentation.system.maven.cdi.helper; import java.util.HashMap; import java.util.Map; diff --git a/aadarchi-maven-plugin/src/main/java/org/ndx/agile/architecture/documentation/system/maven/plugin/BindJULToMaven.java b/cdi-in-maven-plugin-helper/src/main/java/org/ndx/agile/architecture/documentation/system/maven/cdi/helper/log/BindJULToMaven.java similarity index 82% rename from aadarchi-maven-plugin/src/main/java/org/ndx/agile/architecture/documentation/system/maven/plugin/BindJULToMaven.java rename to cdi-in-maven-plugin-helper/src/main/java/org/ndx/agile/architecture/documentation/system/maven/cdi/helper/log/BindJULToMaven.java index 134f0fb6..7f1b27f4 100644 --- a/aadarchi-maven-plugin/src/main/java/org/ndx/agile/architecture/documentation/system/maven/plugin/BindJULToMaven.java +++ b/cdi-in-maven-plugin-helper/src/main/java/org/ndx/agile/architecture/documentation/system/maven/cdi/helper/log/BindJULToMaven.java @@ -1,4 +1,4 @@ -package org.ndx.agile.architecture.documentation.system.maven.plugin; +package org.ndx.agile.architecture.documentation.system.maven.cdi.helper.log; import java.util.Arrays; import java.util.logging.Logger; diff --git a/aadarchi-maven-plugin/src/main/java/org/ndx/agile/architecture/documentation/system/maven/plugin/MavenLoggingRedirectorHandler.java b/cdi-in-maven-plugin-helper/src/main/java/org/ndx/agile/architecture/documentation/system/maven/cdi/helper/log/MavenLoggingRedirectorHandler.java similarity index 95% rename from aadarchi-maven-plugin/src/main/java/org/ndx/agile/architecture/documentation/system/maven/plugin/MavenLoggingRedirectorHandler.java rename to cdi-in-maven-plugin-helper/src/main/java/org/ndx/agile/architecture/documentation/system/maven/cdi/helper/log/MavenLoggingRedirectorHandler.java index 917c5cbc..dd479800 100644 --- a/aadarchi-maven-plugin/src/main/java/org/ndx/agile/architecture/documentation/system/maven/plugin/MavenLoggingRedirectorHandler.java +++ b/cdi-in-maven-plugin-helper/src/main/java/org/ndx/agile/architecture/documentation/system/maven/cdi/helper/log/MavenLoggingRedirectorHandler.java @@ -1,4 +1,4 @@ -package org.ndx.agile.architecture.documentation.system.maven.plugin; +package org.ndx.agile.architecture.documentation.system.maven.cdi.helper.log; import org.apache.maven.plugin.logging.Log; diff --git a/aadarchi-maven-plugin/src/main/java/org/ndx/agile/architecture/documentation/system/maven/plugin/cdi/AbstractCDIStarterMojo.java b/cdi-in-maven-plugin-helper/src/main/java/org/ndx/agile/architecture/documentation/system/maven/cdi/helper/wrappers/AbstractCDIStarterMojo.java similarity index 97% rename from aadarchi-maven-plugin/src/main/java/org/ndx/agile/architecture/documentation/system/maven/plugin/cdi/AbstractCDIStarterMojo.java rename to cdi-in-maven-plugin-helper/src/main/java/org/ndx/agile/architecture/documentation/system/maven/cdi/helper/wrappers/AbstractCDIStarterMojo.java index 2292fd7c..e4d44ebf 100644 --- a/aadarchi-maven-plugin/src/main/java/org/ndx/agile/architecture/documentation/system/maven/plugin/cdi/AbstractCDIStarterMojo.java +++ b/cdi-in-maven-plugin-helper/src/main/java/org/ndx/agile/architecture/documentation/system/maven/cdi/helper/wrappers/AbstractCDIStarterMojo.java @@ -1,4 +1,4 @@ -package org.ndx.agile.architecture.documentation.system.maven.plugin.cdi; +package org.ndx.agile.architecture.documentation.system.maven.cdi.helper.wrappers; import java.io.File; import java.lang.reflect.Field; @@ -33,7 +33,7 @@ import org.jboss.weld.config.ConfigurationKey; import org.jboss.weld.environment.se.Weld; import org.jboss.weld.environment.se.WeldContainer; -import org.ndx.agile.architecture.documentation.system.maven.plugin.BindJULToMaven; +import org.ndx.agile.architecture.documentation.system.maven.cdi.helper.log.BindJULToMaven; /** * A base class bootstraping Weld in maven context and ensuring all Maven diff --git a/aadarchi-maven-plugin/src/main/java/org/ndx/agile/architecture/documentation/system/maven/plugin/cdi/CDIUtil.java b/cdi-in-maven-plugin-helper/src/main/java/org/ndx/agile/architecture/documentation/system/maven/cdi/helper/wrappers/CDIUtil.java similarity index 98% rename from aadarchi-maven-plugin/src/main/java/org/ndx/agile/architecture/documentation/system/maven/plugin/cdi/CDIUtil.java rename to cdi-in-maven-plugin-helper/src/main/java/org/ndx/agile/architecture/documentation/system/maven/cdi/helper/wrappers/CDIUtil.java index fc830eeb..1f0615a2 100644 --- a/aadarchi-maven-plugin/src/main/java/org/ndx/agile/architecture/documentation/system/maven/plugin/cdi/CDIUtil.java +++ b/cdi-in-maven-plugin-helper/src/main/java/org/ndx/agile/architecture/documentation/system/maven/cdi/helper/wrappers/CDIUtil.java @@ -1,4 +1,4 @@ -package org.ndx.agile.architecture.documentation.system.maven.plugin.cdi; +package org.ndx.agile.architecture.documentation.system.maven.cdi.helper.wrappers; import java.io.File; import java.io.IOException; diff --git a/aadarchi-maven-plugin/src/main/java/org/ndx/agile/architecture/documentation/system/maven/plugin/cdi/CdiBeanWrapper.java b/cdi-in-maven-plugin-helper/src/main/java/org/ndx/agile/architecture/documentation/system/maven/cdi/helper/wrappers/CdiBeanWrapper.java similarity index 95% rename from aadarchi-maven-plugin/src/main/java/org/ndx/agile/architecture/documentation/system/maven/plugin/cdi/CdiBeanWrapper.java rename to cdi-in-maven-plugin-helper/src/main/java/org/ndx/agile/architecture/documentation/system/maven/cdi/helper/wrappers/CdiBeanWrapper.java index aa3a5870..228ef1bc 100644 --- a/aadarchi-maven-plugin/src/main/java/org/ndx/agile/architecture/documentation/system/maven/plugin/cdi/CdiBeanWrapper.java +++ b/cdi-in-maven-plugin-helper/src/main/java/org/ndx/agile/architecture/documentation/system/maven/cdi/helper/wrappers/CdiBeanWrapper.java @@ -1,4 +1,4 @@ -package org.ndx.agile.architecture.documentation.system.maven.plugin.cdi; +package org.ndx.agile.architecture.documentation.system.maven.cdi.helper.wrappers; import java.lang.annotation.Annotation; import java.lang.reflect.Type; diff --git a/aadarchi-maven-plugin/src/main/java/org/ndx/agile/architecture/documentation/system/maven/plugin/cdi/CdiProducerBean.java b/cdi-in-maven-plugin-helper/src/main/java/org/ndx/agile/architecture/documentation/system/maven/cdi/helper/wrappers/CdiProducerBean.java similarity index 98% rename from aadarchi-maven-plugin/src/main/java/org/ndx/agile/architecture/documentation/system/maven/plugin/cdi/CdiProducerBean.java rename to cdi-in-maven-plugin-helper/src/main/java/org/ndx/agile/architecture/documentation/system/maven/cdi/helper/wrappers/CdiProducerBean.java index a5168670..0f054c62 100644 --- a/aadarchi-maven-plugin/src/main/java/org/ndx/agile/architecture/documentation/system/maven/plugin/cdi/CdiProducerBean.java +++ b/cdi-in-maven-plugin-helper/src/main/java/org/ndx/agile/architecture/documentation/system/maven/cdi/helper/wrappers/CdiProducerBean.java @@ -1,4 +1,4 @@ -package org.ndx.agile.architecture.documentation.system.maven.plugin.cdi; +package org.ndx.agile.architecture.documentation.system.maven.cdi.helper.wrappers; import java.lang.annotation.Annotation; import java.lang.reflect.Method; diff --git a/aadarchi-maven-plugin/src/main/java/org/ndx/agile/architecture/documentation/system/maven/plugin/cdi/MavenUtil.java b/cdi-in-maven-plugin-helper/src/main/java/org/ndx/agile/architecture/documentation/system/maven/cdi/helper/wrappers/MavenUtil.java similarity index 96% rename from aadarchi-maven-plugin/src/main/java/org/ndx/agile/architecture/documentation/system/maven/plugin/cdi/MavenUtil.java rename to cdi-in-maven-plugin-helper/src/main/java/org/ndx/agile/architecture/documentation/system/maven/cdi/helper/wrappers/MavenUtil.java index 1719cf79..9b04f4f2 100644 --- a/aadarchi-maven-plugin/src/main/java/org/ndx/agile/architecture/documentation/system/maven/plugin/cdi/MavenUtil.java +++ b/cdi-in-maven-plugin-helper/src/main/java/org/ndx/agile/architecture/documentation/system/maven/cdi/helper/wrappers/MavenUtil.java @@ -1,4 +1,4 @@ -package org.ndx.agile.architecture.documentation.system.maven.plugin.cdi; +package org.ndx.agile.architecture.documentation.system.maven.cdi.helper.wrappers; import java.io.File; import java.util.List; diff --git a/aadarchi-maven-plugin/src/main/java/org/ndx/agile/architecture/documentation/system/maven/plugin/cdi/MojoProduces.java b/cdi-in-maven-plugin-helper/src/main/java/org/ndx/agile/architecture/documentation/system/maven/cdi/helper/wrappers/MojoProduces.java similarity index 90% rename from aadarchi-maven-plugin/src/main/java/org/ndx/agile/architecture/documentation/system/maven/plugin/cdi/MojoProduces.java rename to cdi-in-maven-plugin-helper/src/main/java/org/ndx/agile/architecture/documentation/system/maven/cdi/helper/wrappers/MojoProduces.java index 7f838874..587b8da9 100644 --- a/aadarchi-maven-plugin/src/main/java/org/ndx/agile/architecture/documentation/system/maven/plugin/cdi/MojoProduces.java +++ b/cdi-in-maven-plugin-helper/src/main/java/org/ndx/agile/architecture/documentation/system/maven/cdi/helper/wrappers/MojoProduces.java @@ -1,4 +1,4 @@ -package org.ndx.agile.architecture.documentation.system.maven.plugin.cdi; +package org.ndx.agile.architecture.documentation.system.maven.cdi.helper.wrappers; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/pom.xml b/pom.xml index c09461a5..a515bedf 100644 --- a/pom.xml +++ b/pom.xml @@ -79,7 +79,8 @@ archetype markdown-to-asciidoc aadarchi-maven-plugin - + cdi-in-maven-plugin-helper + From b4840f3e33ce82da0e4513cc349ae925d67cf6ac Mon Sep 17 00:00:00 2001 From: Nicolas Delsaux Date: Tue, 24 May 2022 18:23:31 +0200 Subject: [PATCH 2/3] Seems like it's working, no? --- aadarchi-maven-plugin/pom.xml | 4 +- .../plugin/GenerateDiagramsRunnable.java | 2 + .../collector/DocumentsCollector.java | 5 +- .../base/enhancers/graph/GraphEmitter.java | 5 +- .../includes/ImplicitIncludeManager.java | 4 +- cdi-in-maven-plugin-helper/pom.xml | 13 ++---- ...oseMavenPropertiesAsConfigProperties.java} | 17 +++---- .../FilterMavenPropertiesInValues.java | 46 +++++++++++++++++++ .../wrappers/AbstractCDIStarterMojo.java | 2 + .../src/main/resources/META-INF/beans.xml | 5 ++ pom.xml | 2 +- 11 files changed, 77 insertions(+), 28 deletions(-) rename cdi-in-maven-plugin-helper/src/main/java/org/ndx/agile/architecture/documentation/system/maven/cdi/helper/{ExposeMavenPropertiesAsConfigproperties.java => properties/ExposeMavenPropertiesAsConfigProperties.java} (82%) create mode 100644 cdi-in-maven-plugin-helper/src/main/java/org/ndx/agile/architecture/documentation/system/maven/cdi/helper/properties/FilterMavenPropertiesInValues.java create mode 100644 cdi-in-maven-plugin-helper/src/main/resources/META-INF/beans.xml diff --git a/aadarchi-maven-plugin/pom.xml b/aadarchi-maven-plugin/pom.xml index 0b05d853..2337771a 100644 --- a/aadarchi-maven-plugin/pom.xml +++ b/aadarchi-maven-plugin/pom.xml @@ -15,13 +15,13 @@ org.apache.maven.plugin-tools maven-plugin-annotations - 3.4 + 3.6.4 provided org.apache.maven maven-plugin-api - 3.1.0 + 3.8.5 ${project.groupId} diff --git a/aadarchi-maven-plugin/src/main/java/org/ndx/agile/architecture/documentation/system/maven/plugin/GenerateDiagramsRunnable.java b/aadarchi-maven-plugin/src/main/java/org/ndx/agile/architecture/documentation/system/maven/plugin/GenerateDiagramsRunnable.java index c6257278..11f7ee66 100644 --- a/aadarchi-maven-plugin/src/main/java/org/ndx/agile/architecture/documentation/system/maven/plugin/GenerateDiagramsRunnable.java +++ b/aadarchi-maven-plugin/src/main/java/org/ndx/agile/architecture/documentation/system/maven/plugin/GenerateDiagramsRunnable.java @@ -3,10 +3,12 @@ import java.io.IOException; import java.util.logging.Logger; +import javax.enterprise.context.ApplicationScoped; import javax.inject.Inject; import org.ndx.agile.architecture.base.ArchitectureDocumentationBuilder; +@ApplicationScoped public class GenerateDiagramsRunnable implements Runnable { @Inject Logger logger; diff --git a/base/src/main/java/org/ndx/agile/architecture/base/enhancers/collector/DocumentsCollector.java b/base/src/main/java/org/ndx/agile/architecture/base/enhancers/collector/DocumentsCollector.java index a1f03d62..2ec986d5 100644 --- a/base/src/main/java/org/ndx/agile/architecture/base/enhancers/collector/DocumentsCollector.java +++ b/base/src/main/java/org/ndx/agile/architecture/base/enhancers/collector/DocumentsCollector.java @@ -39,10 +39,13 @@ */ @com.structurizr.annotation.Component(technology = "Java/CDI") public class DocumentsCollector implements ModelEnhancer { + private File enhancementsBase; /** * Injecting enhancements base to have a folder where to put our documents. */ - @Inject @ConfigProperty(name=ModelElementKeys.PREFIX+"enhancements", defaultValue = "target/structurizr/enhancements") File enhancementsBase; + @Inject public void setEnhancementsBase(@ConfigProperty(name=ModelElementKeys.PREFIX+"enhancements", defaultValue = "${basedir}/target/structurizr/enhancements") File enhancementsBase) { + this.enhancementsBase = enhancementsBase.getAbsoluteFile(); + } /** * Map that contains all elements that should be automagically included. * First level keys are the enums. diff --git a/base/src/main/java/org/ndx/agile/architecture/base/enhancers/graph/GraphEmitter.java b/base/src/main/java/org/ndx/agile/architecture/base/enhancers/graph/GraphEmitter.java index ec5fbc92..9b07b07e 100644 --- a/base/src/main/java/org/ndx/agile/architecture/base/enhancers/graph/GraphEmitter.java +++ b/base/src/main/java/org/ndx/agile/architecture/base/enhancers/graph/GraphEmitter.java @@ -34,9 +34,10 @@ @ApplicationScoped public class GraphEmitter implements ViewEnhancer { @Inject Logger logger; - @Inject - @ConfigProperty(name = ModelElementKeys.AGILE_ARCHITECTURE_DIAGRAMS_PATH, defaultValue = "target/structurizr/diagrams") File destination; + @Inject public void setDestination(@ConfigProperty(name = ModelElementKeys.AGILE_ARCHITECTURE_DIAGRAMS_PATH, defaultValue = "${basedir}/target/structurizr/diagrams") File destination) { + this.destination = destination.getAbsoluteFile(); + } @Inject @ConfigProperty(name = "force", defaultValue = "false") boolean force; @Inject diff --git a/base/src/main/java/org/ndx/agile/architecture/base/enhancers/includes/ImplicitIncludeManager.java b/base/src/main/java/org/ndx/agile/architecture/base/enhancers/includes/ImplicitIncludeManager.java index 62d9b770..eec059e2 100644 --- a/base/src/main/java/org/ndx/agile/architecture/base/enhancers/includes/ImplicitIncludeManager.java +++ b/base/src/main/java/org/ndx/agile/architecture/base/enhancers/includes/ImplicitIncludeManager.java @@ -35,14 +35,14 @@ public class ImplicitIncludeManager extends ModelElementAdapter { private static final String ASCIIDOC_SOURCE_DIR = "asciidoc.source.dir"; private File sourceDir; - @Inject public void setDocumentsFolder(@ConfigProperty(name=ASCIIDOC_SOURCE_DIR, defaultValue = "src/docs/asciidoc") File sourceDir) { + @Inject public void setDocumentsFolder(@ConfigProperty(name=ASCIIDOC_SOURCE_DIR, defaultValue = "${basedir}/src/docs/asciidoc") File sourceDir) { if(sourceDir==null) { throw new CantCreateImplicitInclude( String.format("To have implicit includes working, you have to define the system property %s", ASCIIDOC_SOURCE_DIR) ); } - this.sourceDir = sourceDir; + this.sourceDir = sourceDir.getAbsoluteFile(); } /** * We set it at first element to have those text before all enhancers diff --git a/cdi-in-maven-plugin-helper/pom.xml b/cdi-in-maven-plugin-helper/pom.xml index 2627f885..18d9bcaa 100644 --- a/cdi-in-maven-plugin-helper/pom.xml +++ b/cdi-in-maven-plugin-helper/pom.xml @@ -6,7 +6,7 @@ 0.0.12-SNAPSHOT cdi-in-maven-plugin-helper - CDI in Maven helper + Agile Architecture Documentation System : CDI in Maven helper This small java library provides a simple way to have a maven Mojo use CDI for bean injection @@ -21,24 +21,19 @@ org.apache.maven maven-core - 3.8.4 + 3.8.5 org.apache.maven maven-plugin-api - 2.0 + 3.8.5 org.apache.maven.plugin-tools maven-plugin-annotations - 3.4 + 3.6.4 provided - - org.apache.maven - maven-plugin-api - 3.1.0 - org.apache.deltaspike.core diff --git a/cdi-in-maven-plugin-helper/src/main/java/org/ndx/agile/architecture/documentation/system/maven/cdi/helper/ExposeMavenPropertiesAsConfigproperties.java b/cdi-in-maven-plugin-helper/src/main/java/org/ndx/agile/architecture/documentation/system/maven/cdi/helper/properties/ExposeMavenPropertiesAsConfigProperties.java similarity index 82% rename from cdi-in-maven-plugin-helper/src/main/java/org/ndx/agile/architecture/documentation/system/maven/cdi/helper/ExposeMavenPropertiesAsConfigproperties.java rename to cdi-in-maven-plugin-helper/src/main/java/org/ndx/agile/architecture/documentation/system/maven/cdi/helper/properties/ExposeMavenPropertiesAsConfigProperties.java index 17b64cec..04cce870 100644 --- a/cdi-in-maven-plugin-helper/src/main/java/org/ndx/agile/architecture/documentation/system/maven/cdi/helper/ExposeMavenPropertiesAsConfigproperties.java +++ b/cdi-in-maven-plugin-helper/src/main/java/org/ndx/agile/architecture/documentation/system/maven/cdi/helper/properties/ExposeMavenPropertiesAsConfigProperties.java @@ -1,13 +1,9 @@ -package org.ndx.agile.architecture.documentation.system.maven.cdi.helper; +package org.ndx.agile.architecture.documentation.system.maven.cdi.helper.properties; -import java.util.HashMap; import java.util.Map; -import java.util.Properties; -import java.util.TreeMap; import java.util.logging.Level; import java.util.logging.Logger; -import javax.annotation.PostConstruct; import javax.inject.Inject; import org.apache.deltaspike.core.api.config.Source; @@ -16,18 +12,16 @@ import org.apache.maven.execution.MavenSession; import org.apache.maven.plugin.MojoExecution; import org.apache.maven.plugin.PluginParameterExpressionEvaluator; -import org.apache.maven.project.MavenProject; -import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; @Source -public class ExposeMavenPropertiesAsConfigproperties implements ConfigSource { - private static final Logger logger = Logger.getLogger(ExposeMavenPropertiesAsConfigproperties.class.getName()); +public class ExposeMavenPropertiesAsConfigProperties implements ConfigSource { + private static final Logger logger = Logger.getLogger(ExposeMavenPropertiesAsConfigProperties.class.getName()); private static final int DELTASPIKE_PRIORITY = 1000; private PluginParameterExpressionEvaluator evaluator; - public ExposeMavenPropertiesAsConfigproperties() { + public ExposeMavenPropertiesAsConfigProperties() { super(); } @@ -47,7 +41,7 @@ public String getConfigName() { public Map getProperties() { return null; } - + @Override public String getPropertyValue(String key) { try { @@ -61,6 +55,7 @@ public String getPropertyValue(String key) { key = "${"+key+"}"; } Object value = evaluator.evaluate(key); + logger.info(String.format("Evaluated %s to %s", key, value)); // I'm sorry, but Maven expression evaluator return null when evaluation fails. This is unfortunate. if(value==null) return null; diff --git a/cdi-in-maven-plugin-helper/src/main/java/org/ndx/agile/architecture/documentation/system/maven/cdi/helper/properties/FilterMavenPropertiesInValues.java b/cdi-in-maven-plugin-helper/src/main/java/org/ndx/agile/architecture/documentation/system/maven/cdi/helper/properties/FilterMavenPropertiesInValues.java new file mode 100644 index 00000000..8598aae9 --- /dev/null +++ b/cdi-in-maven-plugin-helper/src/main/java/org/ndx/agile/architecture/documentation/system/maven/cdi/helper/properties/FilterMavenPropertiesInValues.java @@ -0,0 +1,46 @@ +package org.ndx.agile.architecture.documentation.system.maven.cdi.helper.properties; + +import javax.inject.Inject; + +import org.apache.deltaspike.core.api.config.Filter; +import org.apache.deltaspike.core.api.projectstage.ProjectStage; +import org.apache.deltaspike.core.spi.config.ConfigFilter; +import org.apache.maven.execution.MavenSession; +import org.apache.maven.plugin.MojoExecution; +import org.apache.maven.plugin.PluginParameterExpressionEvaluator; +import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; + +@Filter +public class FilterMavenPropertiesInValues implements ConfigFilter { + + private PluginParameterExpressionEvaluator evaluator; + + public FilterMavenPropertiesInValues() { + super(); + } + + @Inject + public void createMavenExpressionEvaluator(MavenSession mavenSession, MojoExecution execution) { + evaluator = new PluginParameterExpressionEvaluator(mavenSession, execution); + } + + @Override + public String filterValue(String key, String value) { + try { + return (String) evaluator.evaluate(value); + } catch (ExpressionEvaluationException e) { + return value; + } + } + + @Override + public String filterValueForLog(String key, String value) { + if (key.contains("password")) { + return "***************"; + } else { + return filterValue(key, value); + } + + } + +} diff --git a/cdi-in-maven-plugin-helper/src/main/java/org/ndx/agile/architecture/documentation/system/maven/cdi/helper/wrappers/AbstractCDIStarterMojo.java b/cdi-in-maven-plugin-helper/src/main/java/org/ndx/agile/architecture/documentation/system/maven/cdi/helper/wrappers/AbstractCDIStarterMojo.java index e4d44ebf..80cdaa53 100644 --- a/cdi-in-maven-plugin-helper/src/main/java/org/ndx/agile/architecture/documentation/system/maven/cdi/helper/wrappers/AbstractCDIStarterMojo.java +++ b/cdi-in-maven-plugin-helper/src/main/java/org/ndx/agile/architecture/documentation/system/maven/cdi/helper/wrappers/AbstractCDIStarterMojo.java @@ -159,6 +159,7 @@ private void addDependenciesFrom(Weld weld, List dependencies) throw ClassRealm realm = pluginDescriptor.getClassRealm(); try { realm.addURL(file.toURI().toURL()); + getLog().info("Adding dependency "+file.getAbsolutePath()+" to CLASSPATH"); } catch (MalformedURLException e) { throw new MojoExecutionException("Unable to parse file path as url", e); } @@ -175,6 +176,7 @@ private void addArtifactsFrom(Weld weld, List dependencies) throws Moj ClassRealm realm = pluginDescriptor.getClassRealm(); try { realm.addURL(file.toURI().toURL()); + getLog().info("Adding artifact "+file.getAbsolutePath()+" to CLASSPATH"); } catch (MalformedURLException e) { throw new MojoExecutionException("Unable to parse file path as url", e); } diff --git a/cdi-in-maven-plugin-helper/src/main/resources/META-INF/beans.xml b/cdi-in-maven-plugin-helper/src/main/resources/META-INF/beans.xml new file mode 100644 index 00000000..af93b3c4 --- /dev/null +++ b/cdi-in-maven-plugin-helper/src/main/resources/META-INF/beans.xml @@ -0,0 +1,5 @@ + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index a515bedf..46d5f160 100644 --- a/pom.xml +++ b/pom.xml @@ -97,7 +97,7 @@ org.apache.deltaspike.core deltaspike-core-impl - 1.9.5 + 1.9.6 com.structurizr From 8a7102cedabd1f0e9e6b7f4151dc98859156a9c2 Mon Sep 17 00:00:00 2001 From: Nicolas Delsaux Date: Tue, 24 May 2022 18:40:33 +0200 Subject: [PATCH 3/3] Remove the evaluation logs from INFO levvel --- .../properties/ExposeMavenPropertiesAsConfigProperties.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cdi-in-maven-plugin-helper/src/main/java/org/ndx/agile/architecture/documentation/system/maven/cdi/helper/properties/ExposeMavenPropertiesAsConfigProperties.java b/cdi-in-maven-plugin-helper/src/main/java/org/ndx/agile/architecture/documentation/system/maven/cdi/helper/properties/ExposeMavenPropertiesAsConfigProperties.java index 04cce870..fa03ddea 100644 --- a/cdi-in-maven-plugin-helper/src/main/java/org/ndx/agile/architecture/documentation/system/maven/cdi/helper/properties/ExposeMavenPropertiesAsConfigProperties.java +++ b/cdi-in-maven-plugin-helper/src/main/java/org/ndx/agile/architecture/documentation/system/maven/cdi/helper/properties/ExposeMavenPropertiesAsConfigProperties.java @@ -55,7 +55,7 @@ public String getPropertyValue(String key) { key = "${"+key+"}"; } Object value = evaluator.evaluate(key); - logger.info(String.format("Evaluated %s to %s", key, value)); + logger.finer(String.format("Evaluated %s to %s", key, value)); // I'm sorry, but Maven expression evaluator return null when evaluation fails. This is unfortunate. if(value==null) return null;