9
This commit is contained in:
@@ -20,7 +20,13 @@ public class HeuristicCallGraphEngine extends AbstractCallGraphEngine {
|
|||||||
super(context);
|
super(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
protected Map<String, List<CallEdge>> buildCallGraph() {
|
protected Map<String, List<CallEdge>> buildCallGraph() {
|
||||||
|
Map<String, List<CallEdge>> cached = (Map<String, List<CallEdge>>) context.getCache().get("heuristicCallGraph");
|
||||||
|
if (cached != null) {
|
||||||
|
this.graph = cached;
|
||||||
|
return cached;
|
||||||
|
}
|
||||||
graph = new HashMap<>();
|
graph = new HashMap<>();
|
||||||
for (CompilationUnit cu : context.getCompilationUnits()) {
|
for (CompilationUnit cu : context.getCompilationUnits()) {
|
||||||
cu.accept(new ASTVisitor() {
|
cu.accept(new ASTVisitor() {
|
||||||
@@ -131,6 +137,7 @@ public class HeuristicCallGraphEngine extends AbstractCallGraphEngine {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
context.getCache().put("heuristicCallGraph", graph);
|
||||||
return graph;
|
return graph;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,13 @@ public class JdtCallGraphEngine extends AbstractCallGraphEngine {
|
|||||||
this.injectionAnalyzer = injectionAnalyzer;
|
this.injectionAnalyzer = injectionAnalyzer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
protected Map<String, List<CallEdge>> buildCallGraph() {
|
protected Map<String, List<CallEdge>> buildCallGraph() {
|
||||||
|
Map<String, List<CallEdge>> cached = (Map<String, List<CallEdge>>) context.getCache().get("jdtCallGraph");
|
||||||
|
if (cached != null) {
|
||||||
|
this.graph = cached;
|
||||||
|
return cached;
|
||||||
|
}
|
||||||
graph = new HashMap<>();
|
graph = new HashMap<>();
|
||||||
for (CompilationUnit cu : context.getCompilationUnits()) {
|
for (CompilationUnit cu : context.getCompilationUnits()) {
|
||||||
cu.accept(new ASTVisitor() {
|
cu.accept(new ASTVisitor() {
|
||||||
@@ -131,6 +137,7 @@ public class JdtCallGraphEngine extends AbstractCallGraphEngine {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
context.getCache().put("jdtCallGraph", graph);
|
||||||
return graph;
|
return graph;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,6 +29,8 @@ public class JdtIntelligenceProvider implements CodebaseIntelligenceProvider {
|
|||||||
private final LifecycleDetector lifecycleDetector;
|
private final LifecycleDetector lifecycleDetector;
|
||||||
private final InterceptorDetector interceptorDetector;
|
private final InterceptorDetector interceptorDetector;
|
||||||
private final SpringComponentDetector componentDetector;
|
private final SpringComponentDetector componentDetector;
|
||||||
|
private List<TriggerPoint> cachedTriggers;
|
||||||
|
private List<EntryPoint> cachedEntryPoints;
|
||||||
|
|
||||||
public JdtIntelligenceProvider(CodebaseContext context, Path rootDir) {
|
public JdtIntelligenceProvider(CodebaseContext context, Path rootDir) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
@@ -54,6 +56,9 @@ public class JdtIntelligenceProvider implements CodebaseIntelligenceProvider {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<TriggerPoint> findTriggerPoints() {
|
public List<TriggerPoint> findTriggerPoints() {
|
||||||
|
if (cachedTriggers != null) {
|
||||||
|
return cachedTriggers;
|
||||||
|
}
|
||||||
List<TriggerPoint> allTriggers = new ArrayList<>();
|
List<TriggerPoint> allTriggers = new ArrayList<>();
|
||||||
var cus = context.getCompilationUnits();
|
var cus = context.getCompilationUnits();
|
||||||
log.info("JdtIntelligenceProvider scanning {} compilation units for triggers", cus.size());
|
log.info("JdtIntelligenceProvider scanning {} compilation units for triggers", cus.size());
|
||||||
@@ -62,11 +67,15 @@ public class JdtIntelligenceProvider implements CodebaseIntelligenceProvider {
|
|||||||
allTriggers.addAll(lifecycleDetector.detect(cu));
|
allTriggers.addAll(lifecycleDetector.detect(cu));
|
||||||
}
|
}
|
||||||
log.info("Found {} triggers (including lifecycle) in total", allTriggers.size());
|
log.info("Found {} triggers (including lifecycle) in total", allTriggers.size());
|
||||||
|
cachedTriggers = allTriggers;
|
||||||
return allTriggers;
|
return allTriggers;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<EntryPoint> findEntryPoints() {
|
public List<EntryPoint> findEntryPoints() {
|
||||||
|
if (cachedEntryPoints != null) {
|
||||||
|
return cachedEntryPoints;
|
||||||
|
}
|
||||||
List<EntryPoint> allEntryPoints = new ArrayList<>();
|
List<EntryPoint> allEntryPoints = new ArrayList<>();
|
||||||
var cus = context.getCompilationUnits();
|
var cus = context.getCompilationUnits();
|
||||||
log.info("JdtIntelligenceProvider scanning {} compilation units for entry points", cus.size());
|
log.info("JdtIntelligenceProvider scanning {} compilation units for entry points", cus.size());
|
||||||
@@ -77,6 +86,7 @@ public class JdtIntelligenceProvider implements CodebaseIntelligenceProvider {
|
|||||||
allEntryPoints.addAll(componentDetector.detect(cu));
|
allEntryPoints.addAll(componentDetector.detect(cu));
|
||||||
}
|
}
|
||||||
log.info("Found {} entry points (including interceptors and listeners) in total", allEntryPoints.size());
|
log.info("Found {} entry points (including interceptors and listeners) in total", allEntryPoints.size());
|
||||||
|
cachedEntryPoints = allEntryPoints;
|
||||||
return allEntryPoints;
|
return allEntryPoints;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -41,6 +41,11 @@ public class CodebaseContext {
|
|||||||
private List<LibraryHint> libraryHints = new ArrayList<>();
|
private List<LibraryHint> libraryHints = new ArrayList<>();
|
||||||
private final ObjectMapper objectMapper = new ObjectMapper();
|
private final ObjectMapper objectMapper = new ObjectMapper();
|
||||||
private Path projectRoot;
|
private Path projectRoot;
|
||||||
|
private final Map<String, Object> cache = new HashMap<>();
|
||||||
|
|
||||||
|
public Map<String, Object> getCache() {
|
||||||
|
return cache;
|
||||||
|
}
|
||||||
|
|
||||||
public void setProjectRoot(Path root) {
|
public void setProjectRoot(Path root) {
|
||||||
this.projectRoot = root;
|
this.projectRoot = root;
|
||||||
|
|||||||
@@ -125,4 +125,26 @@ class HeuristicEventMatchingEngineTest {
|
|||||||
|
|
||||||
assertThat(engine.matches(smEvent, triggerPoint)).isFalse();
|
assertThat(engine.matches(smEvent, triggerPoint)).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shouldMatchWildcardIfTypeMatches() {
|
||||||
|
Event smEvent = Event.of("PAY", "com.example.OrderEvents.PAY");
|
||||||
|
TriggerPoint triggerPoint = TriggerPoint.builder()
|
||||||
|
.event("event")
|
||||||
|
.eventTypeFqn("com.example.OrderEvents")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
assertThat(engine.matches(smEvent, triggerPoint)).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shouldNotMatchWildcardIfTypeMismatches() {
|
||||||
|
Event smEvent = Event.of("PAY", "com.example.InvoiceEvents.PAY");
|
||||||
|
TriggerPoint triggerPoint = TriggerPoint.builder()
|
||||||
|
.event("event")
|
||||||
|
.eventTypeFqn("com.example.OrderEvents")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
assertThat(engine.matches(smEvent, triggerPoint)).isFalse();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user