Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extracted all code in a dedicated maven module #169

Merged
merged 3 commits into from
May 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 6 additions & 25 deletions aadarchi-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,45 +12,26 @@
<name>Agile Architecture Documentation System : Maven plugin</name>

<dependencies>
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.weld.se</groupId>
<artifactId>weld-se-core</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.maven/maven-core -->
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>3.8.4</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.4</version>
<version>3.6.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>3.1.0</version>
<version>3.8.5</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>base</artifactId>
<artifactId>cdi-in-maven-plugin-helper</artifactId>
<version>${project.version}</version>
</dependency>
<!-- Directly referenced to make sure we can create the ConfigSource allowing us to provide maven properties as config properties -->
<dependency>
<groupId>org.apache.deltaspike.core</groupId>
<artifactId>deltaspike-core-impl</artifactId>
<groupId>${project.groupId}</groupId>
<artifactId>base</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "${basedir}/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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@
@ApplicationScoped
public class GraphEmitter implements ViewEnhancer {
@Inject Logger logger;
@Inject
@ConfigProperty(name = ModelElementKeys.AGILE_ARCHITECTURE_DIAGRAMS_PATH, defaultValue = "${basedir}/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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class ImplicitIncludeManager extends ModelElementAdapter {
ASCIIDOC_SOURCE_DIR)
);
}
this.sourceDir = sourceDir;
this.sourceDir = sourceDir.getAbsoluteFile();
}
/**
* We set it at first element to have those text before all enhancers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
50 changes: 50 additions & 0 deletions cdi-in-maven-plugin-helper/README.adoc
Original file line number Diff line number Diff line change
@@ -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<? extends Runnable> 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<? extends Runnable> 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.
43 changes: 43 additions & 0 deletions cdi-in-maven-plugin-helper/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.github.Riduidel.agile-architecture-documentation-system</groupId>
<artifactId>system</artifactId>
<version>0.0.12-SNAPSHOT</version>
</parent>
<artifactId>cdi-in-maven-plugin-helper</artifactId>
<name>Agile Architecture Documentation System : CDI in Maven helper</name>
<description>This small java library provides a simple way to have a maven Mojo use CDI for bean injection</description>
<dependencies>
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.weld.se</groupId>
<artifactId>weld-se-core</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.maven/maven-core -->
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>3.8.5</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>3.8.5</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.6.4</version>
<scope>provided</scope>
</dependency>
<!-- Directly referenced to make sure we can create the ConfigSource allowing us to provide maven properties as config properties -->
<dependency>
<groupId>org.apache.deltaspike.core</groupId>
<artifactId>deltaspike-core-impl</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
package org.ndx.agile.architecture.documentation.system.maven.plugin;
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;
Expand All @@ -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();
}

Expand All @@ -47,7 +41,7 @@ public String getConfigName() {
public Map<String, String> getProperties() {
return null;
}

@Override
public String getPropertyValue(String key) {
try {
Expand All @@ -61,6 +55,7 @@ public String getPropertyValue(String key) {
key = "${"+key+"}";
}
Object value = evaluator.evaluate(key);
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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}

}

}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -159,6 +159,7 @@ private void addDependenciesFrom(Weld weld, List<Dependency> 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);
}
Expand All @@ -175,6 +176,7 @@ private void addArtifactsFrom(Weld weld, List<Artifact> 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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
version="1.1" bean-discovery-mode="all">
</beans>
Loading