Skip to content
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
24 changes: 14 additions & 10 deletions src/main/java/io/github/randomcodespace/iq/analyzer/Analyzer.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@
*/
@Service
public class Analyzer {
private static final String PROP_FRAMEWORK = "framework";
private static final String PROP_ROOT = "root";
private static final String PROP_SERVICE = "service";


private static final Logger log = LoggerFactory.getLogger(Analyzer.class);

Expand Down Expand Up @@ -335,7 +339,7 @@ private AnalysisResult runWithCache(Path root, Integer parallelism, AnalysisCach
// 5b. Detect service boundaries and create SERVICE nodes
report.accept("Detecting service boundaries...");
var serviceDetector = new ServiceDetector();
String projectDirName = root.getFileName() != null ? root.getFileName().toString() : "root";
String projectDirName = root.getFileName() != null ? root.getFileName().toString() : PROP_ROOT;
var serviceResult = serviceDetector.detect(allNodes, builder.getEdges(), projectDirName, root);
if (!serviceResult.serviceNodes().isEmpty()) {
serviceResult.serviceNodes().forEach(n -> n.setProvenance(builder.getProvenance()));
Expand All @@ -348,7 +352,7 @@ private AnalysisResult runWithCache(Path root, Integer parallelism, AnalysisCach
String serviceName = config.getServiceName();
if (serviceName != null && !serviceName.isBlank()) {
for (CodeNode node : allNodes) {
node.getProperties().put("service", serviceName);
node.getProperties().put(PROP_SERVICE, serviceName);
}
}

Expand Down Expand Up @@ -381,7 +385,7 @@ private AnalysisResult runWithCache(Path root, Integer parallelism, AnalysisCach
// 7b. Compute framework breakdown from node properties
Map<String, Integer> frameworkBreakdown = new HashMap<>();
for (CodeNode node : allNodes) {
Object fw = node.getProperties().get("framework");
Object fw = node.getProperties().get(PROP_FRAMEWORK);
if (fw != null && !fw.toString().isEmpty()) {
frameworkBreakdown.merge(fw.toString(), 1, Integer::sum);
}
Expand Down Expand Up @@ -611,13 +615,13 @@ private AnalysisResult runBatchedWithCache(Path root, Integer parallelism, int b
String svcName = config.getServiceName();
if (svcName != null && !svcName.isBlank()) {
for (CodeNode node : result.nodes()) {
node.getProperties().put("service", svcName);
node.getProperties().put(PROP_SERVICE, svcName);
}
}
// Track breakdowns
for (CodeNode node : result.nodes()) {
nodeBreakdown.merge(node.getKind().getValue(), 1, Integer::sum);
Object fw = node.getProperties().get("framework");
Object fw = node.getProperties().get(PROP_FRAMEWORK);
if (fw != null && !fw.toString().isEmpty()) {
frameworkBreakdown.merge(fw.toString(), 1, Integer::sum);
}
Expand Down Expand Up @@ -971,12 +975,12 @@ private int[] processSmartBatch(
String svcName = config.getServiceName();
if (svcName != null && !svcName.isBlank()) {
for (CodeNode node : result.nodes()) {
node.getProperties().put("service", svcName);
node.getProperties().put(PROP_SERVICE, svcName);
}
}
for (CodeNode node : result.nodes()) {
nodeBreakdown.merge(node.getKind().getValue(), 1, Integer::sum);
Object fw = node.getProperties().get("framework");
Object fw = node.getProperties().get(PROP_FRAMEWORK);
if (fw != null && !fw.toString().isEmpty()) {
frameworkBreakdown.merge(fw.toString(), 1, Integer::sum);
}
Expand All @@ -1001,7 +1005,7 @@ private int[] processSmartBatch(
* Partition discovered files into modules based on build-file boundary markers.
* <p>
* Files are assigned to the deepest module directory that contains them.
* Files with no matching module are placed in a {@code "root"} partition.
* Files with no matching module are placed in a {@code PROP_ROOT} partition.
* The returned map is a {@link TreeMap} for deterministic iteration.
*
* @param root absolute repository root (used only for logging)
Expand All @@ -1021,7 +1025,7 @@ Map<String, List<DiscoveredFile>> detectModules(Path root, List<DiscoveredFile>
// If no module boundaries found, treat everything as root
if (moduleDirs.isEmpty()) {
Map<String, List<DiscoveredFile>> single = new TreeMap<>();
single.put("root", new ArrayList<>(files));
single.put(PROP_ROOT, new ArrayList<>(files));
return single;
}

Expand All @@ -1045,7 +1049,7 @@ Map<String, List<DiscoveredFile>> detectModules(Path root, List<DiscoveredFile>
}
}

String key = bestModule != null ? bestModule : "root";
String key = bestModule != null ? bestModule : PROP_ROOT;
result.computeIfAbsent(key, k -> new ArrayList<>()).add(file);
}

Expand Down
Loading
Loading