Skip to content

Commit

Permalink
Fixes #284
Browse files Browse the repository at this point in the history
  • Loading branch information
Riduidel committed Oct 28, 2022
1 parent 354f51f commit 385a3c3
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 8 deletions.
40 changes: 32 additions & 8 deletions base/src/main/java/org/ndx/aadarchi/base/ArchitectureEnhancer.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import java.io.File;
import java.util.Comparator;
import java.util.Set;
import java.util.SortedSet;
import java.util.function.Supplier;
import java.util.logging.Logger;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand All @@ -15,7 +17,7 @@

import org.apache.commons.lang3.time.StopWatch;
import org.apache.deltaspike.core.api.config.ConfigProperty;
import org.ndx.aadarchi.base.enhancers.ModelElementKeys;
import org.ndx.aadarchi.base.enhancers.ModelElementKeys.ConfigProperties.DisabledEnhancers;
import org.ndx.aadarchi.base.enhancers.ModelElementKeys.ConfigProperties.EnhancementsDir;
import org.ndx.aadarchi.base.utils.SimpleOutputBuilder;

Expand All @@ -39,6 +41,19 @@ public class ArchitectureEnhancer {
@Inject @UsesComponent(description="Uses all enhancers") Instance<Enhancer> enhancers;
@Inject Logger logger;
@Inject @ConfigProperty(name=EnhancementsDir.NAME, defaultValue = EnhancementsDir.VALUE) File enhancementsBase;
private Set<String> disabledEnhancers = Set.of();
@Inject
public void loadDisabledEnhancers(@ConfigProperty(name=DisabledEnhancers.NAME) String disabledEnhancersNames) {
if(disabledEnhancersNames!=null) {
this.disabledEnhancers = Set.of(disabledEnhancersNames.split(DisabledEnhancers.SEPARATOR));
}
}

public Stream<Enhancer> getEnhancers() {
return enhancers.stream()
.sorted(Comparator.comparingInt(e -> e.priority()))
.filter(this::filterEnhancer);
}

private OutputBuilder outputBuilder;
/**
Expand Down Expand Up @@ -67,17 +82,26 @@ private <Type> Type withClassLoader(Supplier<Type> supplier) {
@PostConstruct public void loadOutputBuilder() {
outputBuilder = new SimpleOutputBuilder(enhancementsBase);
}

private boolean filterEnhancer(Enhancer enhancer) {
String enhancerClassName = enhancer.getClass().getName();
if(disabledEnhancers.contains(enhancerClassName)) {
logger.warning(() -> String.format("Enhancer %s is disabled, so it won't enrich our model", enhancerClassName));
return false;
} else {
return true;
}
}

public void enhance(Workspace workspace) {
classloader = Thread.currentThread().getContextClassLoader();
logger.info(() -> String.format("Enhancers applied to this architecture are\n%s",
enhancers.stream()
.sorted(Comparator.comparingInt(e -> e.priority()))
logger.info(() -> String.format("Enhancers applied to this architecture are\n%s",
getEnhancers()
.map(e -> String.format("%s => %d", e.getClass().getName(), e.priority()))
.collect(Collectors.joining("\n"))));
withStopWatch("Running all enhancements took %s", () -> enhancers.stream()
.sorted(Comparator.comparingInt(e -> e.priority()))
.forEach(enhancer -> enhancerVisitWorkspace(enhancer, workspace)));
withStopWatch("Running all enhancements took %s",
() -> getEnhancers()
.forEach(enhancer -> enhancerVisitWorkspace(enhancer, workspace)));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ interface BasePath {
*/
String NAME = ModelElementKeys.PREFIX+"base.path";
}
interface DisabledEnhancers {
/**
* Use this key to have the enhancers given as value disabled during documentation generation.
* THe disabled enhancer names are given according to the syntax given in logs.
* The used separator is ";"
*/
String NAME = ModelElementKeys.PREFIX+"enhancers.disabled";
String SEPARATOR = ";";
}
}
interface Scm {

Expand Down

0 comments on commit 385a3c3

Please sign in to comment.