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

ArC dev mode: introduce quarkus.arc.dev-mode.generate-dependency-graphs #37621

Merged
merged 1 commit into from
Dec 18, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,10 @@ public class ArcDevModeConfig {
@ConfigItem(defaultValue = "false")
public boolean monitoringEnabled;

/**
* If set to true then the dependency graphs are generated and available in the Dev UI.
*/
@ConfigItem(defaultValue = "true")
public boolean generateDependencyGraphs;

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.Set;
import java.util.stream.Collectors;

import io.quarkus.arc.deployment.ArcConfig;
import io.quarkus.arc.deployment.CompletedApplicationClassPredicateBuildItem;
import io.quarkus.arc.deployment.ValidationPhaseBuildItem;
import io.quarkus.arc.processor.BeanDeploymentValidator;
Expand All @@ -29,7 +30,7 @@
public class ArcDevModeApiProcessor {

@BuildStep(onlyIf = IsDevelopment.class)
public void collectBeanInfo(ValidationPhaseBuildItem validationPhaseBuildItem,
public void collectBeanInfo(ArcConfig config, ValidationPhaseBuildItem validationPhaseBuildItem,
CompletedApplicationClassPredicateBuildItem predicate,
BuildProducer<ArcBeanInfoBuildItem> arcBeanInfoProducer) {
BeanDeploymentValidator.ValidationContext validationContext = validationPhaseBuildItem.getContext();
Expand Down Expand Up @@ -63,35 +64,36 @@ public void collectBeanInfo(ValidationPhaseBuildItem validationPhaseBuildItem,
}

// Build dependency graphs
BeanResolver resolver = validationPhaseBuildItem.getBeanResolver();
Collection<BeanInfo> beans = validationContext.get(BuildExtension.Key.BEANS);
Map<BeanInfo, List<InjectionPointInfo>> directDependents = new HashMap<>();
List<InjectionPointInfo> allInjectionPoints = new ArrayList<>();
Map<BeanInfo, List<BeanInfo>> declaringToProducers = validationContext.beans().producers()
.collect(Collectors.groupingBy(BeanInfo::getDeclaringBean));
for (BeanInfo b : beans) {
if (b.hasInjectionPoint()) {
for (InjectionPointInfo ip : b.getAllInjectionPoints()) {
if (ip.getTargetBean().isPresent()) {
allInjectionPoints.add(ip);
Map<String, List<String>> beanDependenciesMap = new HashMap<>();
if (config.devMode.generateDependencyGraphs) {
BeanResolver resolver = validationPhaseBuildItem.getBeanResolver();
Collection<BeanInfo> beans = validationContext.get(BuildExtension.Key.BEANS);
Map<BeanInfo, List<InjectionPointInfo>> directDependents = new HashMap<>();
List<InjectionPointInfo> allInjectionPoints = new ArrayList<>();
Map<BeanInfo, List<BeanInfo>> declaringToProducers = validationContext.beans().producers()
.collect(Collectors.groupingBy(BeanInfo::getDeclaringBean));
for (BeanInfo b : beans) {
if (b.hasInjectionPoint()) {
for (InjectionPointInfo ip : b.getAllInjectionPoints()) {
if (ip.getTargetBean().isPresent()) {
allInjectionPoints.add(ip);
}
}
}
}
for (BeanInfo bean : beans) {
DependencyGraph dependencyGraph = buildDependencyGraph(bean, validationContext, resolver, beanInfos,
allInjectionPoints, declaringToProducers,
directDependents);
beanInfos.addDependencyGraph(bean.getIdentifier(), dependencyGraph);
// id -> [dep1Id, dep2Id]
beanDependenciesMap.put(bean.getIdentifier(),
dependencyGraph.filterLinks(link -> link.type.equals("directDependency")).nodes.stream()
.map(DevBeanInfo::getId).filter(id -> !id.equals(bean.getIdentifier()))
.collect(Collectors.toList()));
}
}

Map<String, List<String>> beanDependenciesMap = new HashMap<>();

for (BeanInfo bean : beans) {
DependencyGraph dependencyGraph = buildDependencyGraph(bean, validationContext, resolver, beanInfos,
allInjectionPoints, declaringToProducers,
directDependents);
beanInfos.addDependencyGraph(bean.getIdentifier(), dependencyGraph);
// id -> [dep1Id, dep2Id]
beanDependenciesMap.put(bean.getIdentifier(),
dependencyGraph.filterLinks(link -> link.type.equals("directDependency")).nodes.stream()
.map(DevBeanInfo::getId).filter(id -> !id.equals(bean.getIdentifier()))
.collect(Collectors.toList()));
}
// Set the global that could be used at runtime when generating the json payload for /q/arc/beans
DevConsoleManager.setGlobal(DevBeanInfos.BEAN_DEPENDENCIES, beanDependenciesMap);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

public class DependencyGraph {

static final DependencyGraph EMPTY = new DependencyGraph(Set.of(), Set.of());

public final Set<DevBeanInfo> nodes;
public final Set<Link> links;
public final int maxLevel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ public DependencyGraph getDependencyGraph(String beanId) {
if (maxLevel == null) {
maxLevel = DEFAULT_MAX_DEPENDENCY_LEVEL;
}
if (dependencyGraphs.isEmpty()) {
return DependencyGraph.EMPTY;
}
DependencyGraph graph = dependencyGraphs.get(beanId);
return graph.maxLevel <= maxLevel ? graph : graph.forLevel(maxLevel);
}
Expand Down
Loading